|
|
@ -53,10 +53,10 @@ static string getTime() { |
|
|
|
|
|
|
|
time_t t = time(nullptr); |
|
|
|
struct tm* tmp = localtime_r(&t, &tm); |
|
|
|
return fmt::format("{:0>4}-{:0>2}{:0>2}-{:0>2}{:0>2}{:0>2}", tm.tm_year + 1900, //
|
|
|
|
tm.tm_mon + 1, //
|
|
|
|
tm.tm_mday, //
|
|
|
|
tm.tm_hour, //
|
|
|
|
return fmt::format("{:0>4}-{:0>2}{:0>2}-{:0>2}:{:0>2}:{:0>2}", tm.tm_year + 1900, //
|
|
|
|
tm.tm_mon + 1, //
|
|
|
|
tm.tm_mday, //
|
|
|
|
tm.tm_hour, //
|
|
|
|
tm.tm_min, tm.tm_sec); |
|
|
|
} |
|
|
|
|
|
|
@ -113,8 +113,7 @@ void DisinfectionCtrlService::computeRemainTime(DisinfectionContext& context) { |
|
|
|
/**
|
|
|
|
* @brief 计算Dvalue |
|
|
|
*/ |
|
|
|
float dvalue = getDisinfectionDValue(context.h2o2data.min_h2o2); |
|
|
|
context.dvalue = dvalue; |
|
|
|
float dvalue = context.dvalue; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 计算 m_nowLoglevel |
|
|
@ -128,17 +127,28 @@ void DisinfectionCtrlService::computeRemainTime(DisinfectionContext& context) { |
|
|
|
logger->info("computeRemainTime minh2o2 {} dvalue {}", context.h2o2data.min_h2o2, dvalue); |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::initContext(DisinfectionContext& context, int loglevel, float roomVol) { |
|
|
|
context.m_disinfectionID = createDisinfectionID(); |
|
|
|
context.pre_heat_time_s = m_dbService->getSettingVal("pre_heat_time_s"); |
|
|
|
context.stoped_gs = m_dbService->getSettingVal("stoped_gs"); |
|
|
|
context.continued_gs = m_dbService->getSettingVal("continued_gs"); |
|
|
|
context.stoped_satur = m_dbService->getSettingVal("stoped_satur"); |
|
|
|
context.continued_satur = m_dbService->getSettingVal("continued_satur"); |
|
|
|
context.stoped_humi = m_dbService->getSettingVal("stoped_humi"); |
|
|
|
context.continued_humi = m_dbService->getSettingVal("continued_humi"); |
|
|
|
|
|
|
|
logger->info("startDisinfection {} {} {}", m_context.m_loglevel, m_context.m_roomvol, m_context.m_disinfectionID); |
|
|
|
void DisinfectionCtrlService::initContext(DisinfectionContext& context, //
|
|
|
|
int loglevel, //
|
|
|
|
float injection_pump_speed, //
|
|
|
|
float stoped_gs, //
|
|
|
|
float continued_gs, //
|
|
|
|
float stoped_satur, //
|
|
|
|
float continued_satur, //
|
|
|
|
float stoped_humi, //
|
|
|
|
float continued_humi //
|
|
|
|
) { |
|
|
|
context.m_disinfectionID = createDisinfectionID(); |
|
|
|
context.pre_heat_time_s = m_dbService->getSettingVal("pre_heat_time_s"); |
|
|
|
context.stoped_gs = stoped_gs; |
|
|
|
context.continued_gs = continued_gs; |
|
|
|
context.stoped_satur = stoped_satur; |
|
|
|
context.continued_satur = continued_satur; |
|
|
|
context.stoped_humi = stoped_humi; |
|
|
|
context.continued_humi = continued_humi; |
|
|
|
context.injection_pump_speed = injection_pump_speed; |
|
|
|
context.injection_pump_speed_changed = true; |
|
|
|
|
|
|
|
logger->info("startDisinfection {} {}", m_context.m_loglevel, m_context.m_disinfectionID); |
|
|
|
logger->info(" stoped_gs {}", context.stoped_gs); |
|
|
|
logger->info(" continued_gs {}", context.continued_gs); |
|
|
|
logger->info(" stoped_satur {}", context.stoped_satur); |
|
|
@ -154,7 +164,6 @@ void DisinfectionCtrlService::initContext(DisinfectionContext& context, int logl |
|
|
|
context.m_targetLoglevel = loglevel; |
|
|
|
context.m_nowLoglevel = 0; |
|
|
|
context.m_loglevel = loglevel; |
|
|
|
context.m_roomvol = roomVol; |
|
|
|
// m_context.m_preheatFlag = true;
|
|
|
|
m_context.dvalue = 0; |
|
|
|
// m_context.stopedflag = false;
|
|
|
@ -176,18 +185,58 @@ void DisinfectionCtrlService::initContext(DisinfectionContext& context, int logl |
|
|
|
// ds->getPressureSensorData(1), ds->getPressureSensorData(2), ds->getPressureSensorData(3), ds->getPressureSensorData(4), //
|
|
|
|
// m_deviceIoControlService->getDisinfectantVolume_g(), //
|
|
|
|
// m_context.m_remaintime
|
|
|
|
|
|
|
|
context.csvlogger->write( |
|
|
|
"time," //
|
|
|
|
"h2o21,temp1,humi1,saturation1," //
|
|
|
|
"h2o22,temp2,humi2,saturation2," //
|
|
|
|
"h2o23,temp3,humi3,saturation3," //
|
|
|
|
"dvalue,loglevel,targetloglevel," //
|
|
|
|
"heating,blower,compressor,pump," //
|
|
|
|
"pressure1,pressure2,pressure3,pressure4," //
|
|
|
|
"disinfectantVolume," //
|
|
|
|
"remaintime\n" //
|
|
|
|
"time," //
|
|
|
|
"hydrogen_peroxide_volume[1],temperature[1],relative_humidity[1],h2o_h2o2_rs[1]," //
|
|
|
|
// "h2o22,temp2,humi2,saturation2," //
|
|
|
|
// "h2o23,temp3,humi3,saturation3," //
|
|
|
|
"dvalue,loglevel,targetloglevel," //
|
|
|
|
"heating,blower,compressor,pump," //
|
|
|
|
"disinfectantVolume," //
|
|
|
|
"remaintime\n" //
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// logger->info("hydrogen_peroxide_volume :{}", m_hpp272_data_1.hydrogen_peroxide_volume);
|
|
|
|
// logger->info("h2o_h2o2_rs :{}", m_hpp272_data_1.h2o_h2o2_rs);
|
|
|
|
// logger->info("temperature1 :{}", m_hpp272_data_1.temperature1);
|
|
|
|
// logger->info("relative_humidity :{}", m_hpp272_data_1.relative_humidity);
|
|
|
|
// logger->info("absolute_hydrogen_peroxide :{}", m_hpp272_data_1.absolute_hydrogen_peroxide);
|
|
|
|
// logger->info("h2o_h2o2dew_point_temperature :{}", m_hpp272_data_1.h2o_h2o2dew_point_temperature);
|
|
|
|
// logger->info("reserved1 :{}", m_hpp272_data_1.reserved1);
|
|
|
|
// logger->info("water_volume :{}", m_hpp272_data_1.water_volume);
|
|
|
|
// logger->info("water_vapor_pressure :{}", m_hpp272_data_1.water_vapor_pressure);
|
|
|
|
// logger->info("absolute_humidity :{}", m_hpp272_data_1.absolute_humidity);
|
|
|
|
// logger->info("water_vapor_saturation_pressure_h2o:{}", m_hpp272_data_1.water_vapor_saturation_pressure_h2o);
|
|
|
|
// logger->info("temperature2 :{}", m_hpp272_data_1.temperature2);
|
|
|
|
// logger->info("h2o2_vapor_pressure :{}", m_hpp272_data_1.h2o2_vapor_pressure);
|
|
|
|
// logger->info("water_vapor_saturation_pressure_h2o_h2o2:{}", m_hpp272_data_1.water_vapor_saturation_pressure_h2o_h2o2);
|
|
|
|
|
|
|
|
void DisinfectionCtrlService::dumpDisinfectionLogsToCSV(DisinfectionContext& context) { |
|
|
|
auto* sensors = &m_context.h2o2data.h2o2sensor_data[0]; |
|
|
|
auto ds = m_deviceIoControlService; |
|
|
|
context.csvlogger->write( |
|
|
|
fmt::format("{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
// "{},{},{},{}," //
|
|
|
|
// "{},{},{},{}," //
|
|
|
|
"{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{}," //
|
|
|
|
"{}\n" //
|
|
|
|
, |
|
|
|
getTime(), //
|
|
|
|
sensors[0].h2o2, sensors[0].temp, sensors[0].humid, sensors[0].saturation, //
|
|
|
|
// sensors[1].h2o2, sensors[1].temp, sensors[1].humid, sensors[1].saturation, //
|
|
|
|
// sensors[2].h2o2, sensors[2].temp, sensors[2].humid, sensors[2].saturation, //
|
|
|
|
m_context.dvalue, m_context.m_nowLoglevel, (int)m_context.m_targetLoglevel, //
|
|
|
|
ds->heatingStrip_getstate(), ds->airBlower_getstate(), ds->airCompressor_getstate(), ds->sprayLiquidPump_getGPM(), //
|
|
|
|
m_deviceIoControlService->getDisinfectantVolume_g(), //
|
|
|
|
m_context.m_remaintime)); |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::finishDisinfection(DisinfectionContext& context) { |
|
|
|
context.m_remaintime = 0; |
|
|
|
logger->info("stop disinfection {}", context.m_disinfectionID); |
|
|
@ -221,7 +270,7 @@ void DisinfectionCtrlService::processPreheatState(DisinfectionContext& context) |
|
|
|
m_deviceIoControlService->airCompressor_setState(true); |
|
|
|
usleep(1000 * 1000); |
|
|
|
// sprayLiquidPump_open();
|
|
|
|
m_deviceIoControlService->sprayLiquidPump_open(); |
|
|
|
m_deviceIoControlService->sprayLiquidPump_open(context.injection_pump_speed); |
|
|
|
context.m_state = kdisinfection; |
|
|
|
// context.m_preheatFlag = false;
|
|
|
|
// context.sprayLiquidFlag = true;
|
|
|
@ -230,75 +279,8 @@ void DisinfectionCtrlService::processPreheatState(DisinfectionContext& context) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::dumpDisinfectionLogsToCSV(DisinfectionContext& context) { |
|
|
|
#if 0
|
|
|
|
context.csvlogger->write(fmt::format("{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n", |
|
|
|
zsteady_clock().elapsedTimeS(m_context.m_starttp), //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].saturation, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].saturation, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].saturation, //
|
|
|
|
m_context.dvalue, //
|
|
|
|
m_context.m_nowLoglevel, //
|
|
|
|
m_context.m_targetLoglevel, //
|
|
|
|
m_context.m_remaintime //
|
|
|
|
)); |
|
|
|
#endif
|
|
|
|
auto* sensors = &m_context.h2o2data.h2o2sensor_data[0]; |
|
|
|
auto ds = m_deviceIoControlService; |
|
|
|
context.csvlogger->write( |
|
|
|
fmt::format("{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{},{},{},{}," //
|
|
|
|
"{}," //
|
|
|
|
"{}\n" //
|
|
|
|
, |
|
|
|
getTime(), //
|
|
|
|
sensors[0].h2o2, sensors[0].temp, sensors[0].humid, sensors[0].saturation, //
|
|
|
|
sensors[1].h2o2, sensors[1].temp, sensors[1].humid, sensors[1].saturation, //
|
|
|
|
sensors[2].h2o2, sensors[2].temp, sensors[2].humid, sensors[2].saturation, //
|
|
|
|
m_context.dvalue, m_context.m_nowLoglevel, (int)m_context.m_targetLoglevel, //
|
|
|
|
ds->heatingStrip_getstate(), ds->airBlower_getstate(), ds->airCompressor_getstate(), ds->sprayLiquidPump_getRPM(), //
|
|
|
|
ds->getPressureSensorData(1), ds->getPressureSensorData(2), ds->getPressureSensorData(3), ds->getPressureSensorData(4), //
|
|
|
|
m_deviceIoControlService->getDisinfectantVolume_g(), //
|
|
|
|
m_context.m_remaintime)); |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::dumpDisinfectionLogs(DisinfectionContext& context) { |
|
|
|
float h2o2_g = m_deviceIoControlService->getDisinfectantVolume_g(); |
|
|
|
#if 0
|
|
|
|
logger->info("T:{},ho1:{},t1:{},hu1:{},s1:{},ho2:{},t2:{},hu2:{},s2:{},ho3:{},t3:{},hu3:{},s3:{},dv:{},log:{},tlog:{},rt:{}", |
|
|
|
zsteady_clock().elapsedTimeS(m_context.m_starttp), //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[0].saturation, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[1].saturation, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].h2o2, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].temp, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].humid, //
|
|
|
|
m_context.h2o2data.h2o2sensor_data[2].saturation, //
|
|
|
|
m_context.dvalue, //
|
|
|
|
m_context.m_nowLoglevel, //
|
|
|
|
m_context.m_targetLoglevel, //
|
|
|
|
m_context.m_remaintime //
|
|
|
|
); |
|
|
|
#endif
|
|
|
|
// float h2o2_g = m_deviceIoControlService->getDisinfectantVolume_g();
|
|
|
|
auto* sensors = &m_context.h2o2data.h2o2sensor_data[0]; |
|
|
|
auto ds = m_deviceIoControlService; |
|
|
|
logger->info( |
|
|
@ -323,23 +305,20 @@ void DisinfectionCtrlService::dumpDisinfectionLogs(DisinfectionContext& context) |
|
|
|
m_context.m_remaintime); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* 消毒中状态处理 |
|
|
|
*/ |
|
|
|
void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& context) { |
|
|
|
ZCHECK(context.m_state == kdisinfection || context.m_state == kdisinfection_take_a_break, "state error"); |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 读取传感器数值 |
|
|
|
* @brief 周期性计算剩余时间 |
|
|
|
*/ |
|
|
|
m_deviceIoControlService->getAllSensorData(m_context.h2o2data); |
|
|
|
|
|
|
|
if (zsteady_clock().elapsedTimeS(m_context.m_lastComputeDvalueTp) > DVALUE_COMPUTEPERIOD_TIME_S) { |
|
|
|
m_context.m_lastComputeDvalueTp = zsteady_clock().now(); |
|
|
|
/**
|
|
|
|
* @brief 周期性计算剩余时间 |
|
|
|
*/ |
|
|
|
computeRemainTime(m_context); |
|
|
|
// dumpDisinfectionLogsToCSV(m_context);
|
|
|
|
} |
|
|
|
|
|
|
|
dumpDisinfectionLogs(m_context); |
|
|
|
/**
|
|
|
|
* @brief 根据湿度启停喷雾 |
|
|
|
*/ |
|
|
@ -351,6 +330,11 @@ void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& cont |
|
|
|
float nowh2o2 = m_context.h2o2data.max_h2o2; |
|
|
|
float humid = m_context.h2o2data.max_humid; |
|
|
|
|
|
|
|
if (m_context.injection_pump_speed_changed) { |
|
|
|
m_deviceIoControlService->sprayLiquidPump_open(context.injection_pump_speed); |
|
|
|
m_context.injection_pump_speed_changed = false; |
|
|
|
} |
|
|
|
|
|
|
|
// humid > m_context.stoped_satur
|
|
|
|
if (nowSatur > m_context.stoped_satur || nowh2o2 > m_context.stoped_gs || humid > m_context.stoped_humi) { |
|
|
|
logger->info("stop sprayLiquid"); |
|
|
@ -371,7 +355,7 @@ void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& cont |
|
|
|
if (nowSatur < m_context.continued_satur && nowh2o2 < m_context.continued_gs && humid < context.continued_humi) { |
|
|
|
logger->info("start sprayLiquid"); |
|
|
|
|
|
|
|
m_deviceIoControlService->sprayLiquidPump_open(); |
|
|
|
m_deviceIoControlService->sprayLiquidPump_open(context.injection_pump_speed); |
|
|
|
usleep(1000 * 1000); |
|
|
|
m_deviceIoControlService->airCompressor_setState(true); |
|
|
|
m_context.m_state = kdisinfection; |
|
|
@ -382,8 +366,19 @@ void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& cont |
|
|
|
void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
// logger->info("disinfection running {} {}s preheatFlag:{}", m_context.m_disinfectionID, m_context.m_remaintime, m_context.m_preheatFlag);
|
|
|
|
m_context.m_remaintime--; |
|
|
|
if (m_context.m_remaintime < 0) { |
|
|
|
m_context.m_remaintime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 更新传感器信息 |
|
|
|
*/ |
|
|
|
m_deviceIoControlService->getAllSensorData(m_context.h2o2data); |
|
|
|
/**
|
|
|
|
* @brief 计算D值 |
|
|
|
*/ |
|
|
|
m_context.dvalue = getDisinfectionDValue(m_context.h2o2data.min_h2o2); |
|
|
|
|
|
|
|
if (m_context.m_state == kpreheat) { |
|
|
|
/**
|
|
|
|
* @brief 预热中 |
|
|
@ -405,12 +400,13 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
m_deviceIoControlService->heartingPlate_setPower(false); |
|
|
|
m_context.m_state = kwait_for_h2o2_down; |
|
|
|
} |
|
|
|
|
|
|
|
} else if (m_context.m_state == kwait_for_h2o2_down) { |
|
|
|
/**
|
|
|
|
* @brief 等待h2o2浓度下降 |
|
|
|
*/ |
|
|
|
logger->info("waitting for h2o2 concentration to safe value {}=>{}", m_context.h2o2data.min_h2o2, 1); |
|
|
|
if (m_context.h2o2data.min_h2o2 <= 1) { |
|
|
|
if (m_context.h2o2data.min_h2o2 < 1) { |
|
|
|
logger->info("h2o2 concentration to safe value"); |
|
|
|
breakflag = true; |
|
|
|
m_context.m_state = kfinished; |
|
|
@ -419,13 +415,29 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
ZCHECK(false, "state error"); |
|
|
|
} |
|
|
|
|
|
|
|
if (zsteady_clock().elapsedTimeS(m_context.m_lastlogTp) > DVALUE_COMPUTEPERIOD_TIME_S) { |
|
|
|
if (breakflag || zsteady_clock().elapsedTimeS(m_context.m_lastlogTp) > DVALUE_COMPUTEPERIOD_TIME_S) { |
|
|
|
m_context.m_lastlogTp = zsteady_clock().now(); |
|
|
|
dumpDisinfectionLogs(m_context); |
|
|
|
dumpDisinfectionLogsToCSV(m_context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::startDisinfection(int loglevel, float roomVol) { |
|
|
|
void DisinfectionCtrlService::changeInjectionPumpSpeed(int speed) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
logger->info("changeInjectionPumpSpeed {}=>{}", m_context.injection_pump_speed, speed); |
|
|
|
m_context.injection_pump_speed = speed; |
|
|
|
m_context.injection_pump_speed_changed = true; |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::startDisinfection(int loglevel, //
|
|
|
|
float injection_pump_speed, //
|
|
|
|
float stoped_gs, //
|
|
|
|
float continued_gs, //
|
|
|
|
float stoped_satur, //
|
|
|
|
float continued_satur, //
|
|
|
|
float stoped_humi, //
|
|
|
|
float continued_humi //
|
|
|
|
) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
|
|
|
|
/**
|
|
|
@ -436,7 +448,7 @@ void DisinfectionCtrlService::startDisinfection(int loglevel, float roomVol) { |
|
|
|
if (m_disinfectionThread) { |
|
|
|
stopDisinfection(); |
|
|
|
} |
|
|
|
initContext(m_context, loglevel, roomVol); |
|
|
|
initContext(m_context, loglevel, injection_pump_speed, stoped_gs, continued_gs, stoped_satur, continued_satur, stoped_humi, continued_humi); |
|
|
|
|
|
|
|
m_disinfectionThread.reset(new Thread("m_disinfectionThread", [this]() { |
|
|
|
ThisThread thisThread; |
|
|
@ -474,7 +486,7 @@ int32_t DisinfectionCtrlService::getPreHeatRaminTimeS() { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
int32_t remaintime = 0; |
|
|
|
if (m_context.m_state == kpreheat) { |
|
|
|
remaintime = m_context.pre_heat_time_s - zsteady_clock().elapsedTimeS(m_context.m_starttp); |
|
|
|
remaintime = m_context.pre_heat_time_s - zsteady_clock().elapsedTimeS(m_context.m_starttp); |
|
|
|
if (remaintime < 0) { |
|
|
|
remaintime = 0; |
|
|
|
} |
|
|
|