|
|
@ -15,6 +15,7 @@ |
|
|
|
using namespace iflytop; |
|
|
|
using namespace std; |
|
|
|
#define DVALUE_COMPUTEPERIOD_TIME_S (10.0)
|
|
|
|
#define DUMP_LOG_PERIOD (5 * 60.0)
|
|
|
|
#define MAX_VOLUME (5000)
|
|
|
|
|
|
|
|
namespace iflytop { |
|
|
@ -246,8 +247,8 @@ void DisinfectionCtrlService::log(DisinfectionContext& context) { |
|
|
|
cx.h2o2[0], cx.temp[0], cx.humid[0], cx.saturation[0], //
|
|
|
|
cx.h2o2[1], cx.temp[1], cx.humid[1], cx.saturation[1], //
|
|
|
|
cx.h2o2[2], cx.temp[2], cx.humid[2], cx.saturation[2], //
|
|
|
|
m_context.max_h2o2, m_context.min_h2o2, m_context.max_humid, m_context.max_saturation, //
|
|
|
|
(int32_t)dvalue, (int32_t)m_context.state_now_loglevel, (int32_t)m_context.cfg_targetLoglevel, //
|
|
|
|
m_context.min_h2o2, m_context.max_h2o2, m_context.max_humid, m_context.max_saturation, //
|
|
|
|
(int32_t)dvalue, m_context.state_now_loglevel, (int32_t)m_context.cfg_targetLoglevel, //
|
|
|
|
ds->heatingStrip_getstate(), ds->airBlower_getstate(), ds->airCompressor_getstate(), ds->sprayLiquidPump_getGPM(), //
|
|
|
|
m_deviceIoControlService->getDisinfectantVolume_g(), formattimeS(remaintime))); |
|
|
|
#endif
|
|
|
@ -321,6 +322,8 @@ void DisinfectionCtrlService::initContext(DisinfectionContext& context, |
|
|
|
m_deviceIoControlService->warningLightCtrl(0, 0, 1, 0); |
|
|
|
m_deviceIoControlService->heartingPlate_setPower(true); |
|
|
|
context.csvlogger = createCSVLogger(context.m_disinfectionID); |
|
|
|
|
|
|
|
m_context.firstLog = true; |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::finishDisinfection(DisinfectionContext& context) { |
|
|
@ -413,39 +416,22 @@ void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& cont |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
// logger->info("disinfection running {} {}s preheatFlag:{}", m_context.m_disinfectionID, m_context.state_remaintime, m_context.m_preheatFlag);
|
|
|
|
ThisThread thisThread; |
|
|
|
m_context.state_remaintime--; |
|
|
|
bool forcelog = false; |
|
|
|
if (m_context.state_remaintime < 0) { |
|
|
|
m_context.state_remaintime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 更新传感器信息 |
|
|
|
*/ |
|
|
|
updateH2O2SensorData(m_context); |
|
|
|
void DisinfectionCtrlService::processState_Preheat(DisinfectionContext& context) { |
|
|
|
/**
|
|
|
|
* @brief 计算D值 |
|
|
|
* @brief 预热中 |
|
|
|
*/ |
|
|
|
m_context.state_dvalue = 0; |
|
|
|
processPreheatState(m_context); |
|
|
|
} |
|
|
|
void DisinfectionCtrlService::processState_Disinfection(DisinfectionContext& context, bool& updatedval) { |
|
|
|
m_context.state_dvalue = getDisinfectionDValue(m_context.min_h2o2); |
|
|
|
|
|
|
|
if (zsteady_clock().elapsedTimeS(m_context.state_last_compute_dvalue_tp) > DVALUE_COMPUTEPERIOD_TIME_S) { |
|
|
|
m_context.state_last_compute_dvalue_tp = zsteady_clock().now(); |
|
|
|
//
|
|
|
|
if (m_context.m_state == kstate_disinfection) { |
|
|
|
m_context.state_now_loglevel = computeNowLogLevel(m_context); |
|
|
|
computeRemainTime(m_context); |
|
|
|
} |
|
|
|
updatedval = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (m_context.m_state == kstate_preheat) { |
|
|
|
/**
|
|
|
|
* @brief 预热中 |
|
|
|
*/ |
|
|
|
processPreheatState(m_context); |
|
|
|
} else if (m_context.m_state == kstate_disinfection) { |
|
|
|
/**
|
|
|
|
* @brief 消毒中 |
|
|
|
*/ |
|
|
@ -461,26 +447,58 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
usleep(1000 * 1000); |
|
|
|
m_deviceIoControlService->heartingPlate_setPower(false); |
|
|
|
m_context.m_state = kstate_degradation; |
|
|
|
forcelog = true; |
|
|
|
} |
|
|
|
|
|
|
|
} else if (m_context.m_state == kstate_degradation) { |
|
|
|
/**
|
|
|
|
* @brief 等待h2o2浓度下降 |
|
|
|
*/ |
|
|
|
} |
|
|
|
void DisinfectionCtrlService::processState_Degradation(DisinfectionContext& context) { |
|
|
|
// 降解
|
|
|
|
m_context.state_dvalue = 0; |
|
|
|
logger->info("waitting for h2o2 concentration to safe value {}=>{}", m_context.min_h2o2, 1); |
|
|
|
if (m_context.min_h2o2 < 1) { |
|
|
|
logger->info("h2o2 concentration to safe value"); |
|
|
|
breakflag = true; |
|
|
|
m_context.m_state = kstate_finished; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (m_context.m_state != kstate_finished && thisThread.getExitFlag()) { |
|
|
|
breakflag = true; |
|
|
|
void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
// logger->info("disinfection running {} {}s preheatFlag:{}", m_context.m_disinfectionID, m_context.state_remaintime, m_context.m_preheatFlag);
|
|
|
|
ThisThread thisThread; |
|
|
|
disinfection_state_t enterstate; |
|
|
|
disinfection_state_t exitstate; |
|
|
|
bool statechanged = false; |
|
|
|
bool updatedval = false; |
|
|
|
|
|
|
|
enterstate = m_context.m_state; |
|
|
|
m_context.state_remaintime--; |
|
|
|
|
|
|
|
if (m_context.state_remaintime < 0) m_context.state_remaintime = 0; |
|
|
|
updateH2O2SensorData(m_context); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 状态处理 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (thisThread.getExitFlag()) { |
|
|
|
m_context.m_state = kstate_finished; |
|
|
|
} else if (m_context.m_state == kstate_preheat) { |
|
|
|
processState_Preheat(m_context); |
|
|
|
} else if (m_context.m_state == kstate_disinfection) { |
|
|
|
processState_Disinfection(m_context, updatedval); |
|
|
|
} else if (m_context.m_state == kstate_degradation) { |
|
|
|
processState_Degradation(m_context); |
|
|
|
} |
|
|
|
|
|
|
|
if (breakflag) { |
|
|
|
exitstate = m_context.m_state; |
|
|
|
if (exitstate != enterstate) { |
|
|
|
statechanged = true; |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 打印日志 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (exitstate == kstate_finished) { |
|
|
|
/**
|
|
|
|
* @brief 消毒结束 |
|
|
|
*/ |
|
|
|
breakflag = true; |
|
|
|
m_context.complete_tp = zsystem_clock().now(); |
|
|
|
m_context.afterDisinfectantVolume_g = m_deviceIoControlService->getDisinfectantVolume_g(); |
|
|
|
if (m_context.m_state != kstate_finished) { |
|
|
@ -493,13 +511,16 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { |
|
|
|
pushDisinfectionPrinterTask(m_context); |
|
|
|
finishDisinfection(m_context); |
|
|
|
m_context.csvlogger = nullptr; |
|
|
|
|
|
|
|
} else { |
|
|
|
if (forcelog || zsteady_clock().elapsedTimeS(m_context.state_lastlog_tp) > DVALUE_COMPUTEPERIOD_TIME_S) { |
|
|
|
if (updatedval) { |
|
|
|
log(m_context); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_context.firstLog || statechanged || zsteady_clock().elapsedTimeS(m_context.state_lastlog_tp) > DUMP_LOG_PERIOD) { |
|
|
|
m_context.state_lastlog_tp = zsteady_clock().now(); |
|
|
|
takeStateSnapshot(m_context); |
|
|
|
dumpDisinfectionLogsToCSV(m_context); |
|
|
|
log(m_context); |
|
|
|
m_context.firstLog = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -560,10 +581,8 @@ void DisinfectionCtrlService::stopDisinfection() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int DisinfectionCtrlService::getDisinfectionWorkState() { return m_context.m_state; } |
|
|
|
|
|
|
|
|
|
|
|
int32_t DisinfectionCtrlService::getEstimatedRemainingTimeS() { |
|
|
|
if (m_context.m_state == kstate_preheat) { |
|
|
|
return getPreHeatRaminTimeS(); |
|
|
@ -590,12 +609,8 @@ int32_t DisinfectionCtrlService::getPreHeatRaminTimeS() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
string DisinfectionCtrlService::getDisinfectionID() { |
|
|
|
return m_context.m_disinfectionID; |
|
|
|
} |
|
|
|
bool DisinfectionCtrlService::isPreheatState() { |
|
|
|
return m_context.m_state == kstate_preheat; |
|
|
|
} |
|
|
|
string DisinfectionCtrlService::getDisinfectionID() { return m_context.m_disinfectionID; } |
|
|
|
bool DisinfectionCtrlService::isPreheatState() { return m_context.m_state == kstate_preheat; } |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* // 加液 *
|
|
|
|