Browse Source

update

master
zhaohe 1 year ago
parent
commit
fbef21706d
  1. 165
      service/disinfection_ctl_service.cpp
  2. 5
      service/disinfection_ctl_service.hpp
  3. 9
      service/disinfection_printer_service.cpp
  4. 4
      service/disinfection_state.hpp

165
service/disinfection_ctl_service.cpp

@ -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 {
@ -181,13 +182,13 @@ void DisinfectionCtrlService::dumpDisinfectionLogsToCSV(DisinfectionContext& con
int remaintime = getEstimatedRemainingTimeS();
context.csvlogger->write(
fmt::format("{},"
"{},{},{},{},"
"{},{},{},{},"
"{},{},{},{},"
"{},{},{},"
"{},{},{},{},"
"{},{}"
fmt::format(" {} ,"
" {} , {} , {} , {} ,"
" {} , {} , {} , {} ,"
" {} , {} , {} , {} ,"
" {} , {} , {} ,"
" {} , {} , {} , {} ,"
" {} , {} "
"\n",
getTime(), //
h2o2str[0], tempstr[0], humidstr[0], satstr[0], //
@ -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,74 +416,89 @@ 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);
}
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
*/
processDisinfectionState(m_context);
//
if (m_context.state_remaintime <= 0 && m_context.state_now_loglevel > (m_context.cfg_targetLoglevel + 0.01)) {
m_context.state_remaintime = 0;
m_context.state_now_loglevel = m_context.cfg_targetLoglevel + 0.01;
logger->info("disinfection finished {},but waitting for h2o2 to safe", m_context.m_disinfectionID);
m_deviceIoControlService->sprayLiquidPump_close();
usleep(1000 * 1000);
m_deviceIoControlService->airCompressor_setState(false);
usleep(1000 * 1000);
m_deviceIoControlService->heartingPlate_setPower(false);
m_context.m_state = kstate_degradation;
forcelog = true;
}
/**
* @brief
*/
processDisinfectionState(m_context);
//
if (m_context.state_remaintime <= 0 && m_context.state_now_loglevel > (m_context.cfg_targetLoglevel + 0.01)) {
m_context.state_remaintime = 0;
m_context.state_now_loglevel = m_context.cfg_targetLoglevel + 0.01;
logger->info("disinfection finished {},but waitting for h2o2 to safe", m_context.m_disinfectionID);
m_deviceIoControlService->sprayLiquidPump_close();
usleep(1000 * 1000);
m_deviceIoControlService->airCompressor_setState(false);
usleep(1000 * 1000);
m_deviceIoControlService->heartingPlate_setPower(false);
m_context.m_state = kstate_degradation;
}
}
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");
m_context.m_state = kstate_finished;
}
}
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) {
/**
* @brief h2o2浓度下降
*/
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;
}
processState_Degradation(m_context);
}
if (m_context.m_state != kstate_finished && thisThread.getExitFlag()) {
breakflag = true;
exitstate = m_context.m_state;
if (exitstate != enterstate) {
statechanged = true;
}
if (breakflag) {
/*******************************************************************************
* *
*******************************************************************************/
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; }
/*******************************************************************************
* // 加液 *

5
service/disinfection_ctl_service.hpp

@ -135,9 +135,12 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
void processDisinfectionState(DisinfectionContext& context);
void finishDisinfection(DisinfectionContext& context);
void disinfectionLoop(bool& breakflag);
void processState_Preheat(DisinfectionContext& context);
void processState_Disinfection(DisinfectionContext& context, bool& updatedval);
void processState_Degradation(DisinfectionContext& context);
private:
shared_ptr<DisinfectionLogger> createCSVLogger(string log_file_name);
void dumpDisinfectionLogsToCSV(DisinfectionContext& context);

9
service/disinfection_printer_service.cpp

@ -48,12 +48,16 @@ void DisinfectionPrinterService::printTask(shared_ptr<DisinfectionPrinterTask> t
auto dio = m_deviceIoControlService;
int32_t totaltime_s = zsystem_clock().tpToS(task->complete_tp) - zsystem_clock().tpToS(task->start_tp);
int32_t total_hours = totaltime_s / 3600;
int32_t total_mins = (totaltime_s % 3600) / 60;
int32_t total_secs = totaltime_s % 60;
dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n"));
dio->printerPrintf(fmt::format(" 全思美特\n"));
dio->printerPrintf(fmt::format("操作人 {}\n", task->usr));
dio->printerPrintf(fmt::format("开始时间 {}\n", format_zsystem_tp(task->start_tp)));
dio->printerPrintf(fmt::format("结束时间 {}\n", format_zsystem_tp(task->complete_tp)));
dio->printerPrintf(fmt::format("总耗时 {}:{}\n", totaltime_s / 60, totaltime_s % 60));
dio->printerPrintf(fmt::format("总耗时(hh:mm::ss) {}:{}:{}\n", total_hours, total_mins, total_secs));
dio->printerPrintf(fmt::format("消毒液使用 {}g\n", task->disinfectantUsage));
dio->printerPrintf(fmt::format("目标LOG {}\n", task->targetLog));
dio->printerPrintf(fmt::format("实际LOG {}\n", task->actualLog));
@ -75,7 +79,8 @@ void DisinfectionPrinterService::printTask(shared_ptr<DisinfectionPrinterTask> t
} else if (now_state == kstate_finished) {
dio->printerPrintf(fmt::format("结束...\n"));
}
dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {:.2f}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
state = now_state;
} else {
if (now_state == kstate_degradation) {
dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time)));

4
service/disinfection_state.hpp

@ -57,7 +57,7 @@ class StateSnapshot {
int max_humid;
int max_saturation;
int dloglevel;
float dloglevel;
};
class DisinfectionPrinterTask {
@ -133,6 +133,8 @@ class DisinfectionContext {
int beforeDisinfectantVolume_g; // 消毒前消毒剂量
int afterDisinfectantVolume_g; // 消毒后消毒剂量
bool firstLog;
};
} // namespace iflytop
Loading…
Cancel
Save