From eca89d7d9f43e47dcfb802ec3a2e10fe3d1ebdfd Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 18 Aug 2024 21:22:35 +0800 Subject: [PATCH] update --- appsrc/appbase/appbase.hpp | 1 + .../appbase/appbean/h2o2_sensor_data_snapshot.hpp | 31 ++++++++++++++++ .../appevent/app_disinfection_finished_event.hpp | 15 ++++++++ .../appevent/app_disinfection_snapshot_event.hpp | 34 ++++++++++++++++++ .../appevent/app_disinfection_start_event.hpp | 15 ++++++++ appsrc/appbase/appevent/app_events.hpp | 5 ++- appsrc/appbase/appevent/app_promopt_event.hpp | 1 + appsrc/appbase/disinfection_snapshot.hpp | 25 ------------- .../disinfection_ctrl_service.cpp | 31 ++++++++++++++++ .../disinfection_ctrl_service.hpp | 27 +++++++------- appsrc/service/disinfection_logs_service.cpp | 42 ++++++++++++---------- appsrc/service/disinfection_logs_service.hpp | 29 ++------------- .../service/hardware/base/h2o2_sensor_data_mgr.hpp | 15 -------- .../disinfectant_weight_update_service.cpp | 19 ++++++---- 14 files changed, 185 insertions(+), 105 deletions(-) create mode 100644 appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp create mode 100644 appsrc/appbase/appevent/app_disinfection_finished_event.hpp create mode 100644 appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp create mode 100644 appsrc/appbase/appevent/app_disinfection_start_event.hpp diff --git a/appsrc/appbase/appbase.hpp b/appsrc/appbase/appbase.hpp index 8f58166..beabd9c 100644 --- a/appsrc/appbase/appbase.hpp +++ b/appsrc/appbase/appbase.hpp @@ -12,3 +12,4 @@ #include "appbase/appbean/pumpid.hpp" #include "appbase/appbean/test_page_iterm.hpp" #include "appbean/device_state.hpp" +#include "appbase/appbean/h2o2_sensor_data_snapshot.hpp" diff --git a/appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp b/appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp new file mode 100644 index 0000000..ae1527d --- /dev/null +++ b/appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace iflytop { +using namespace std; + +class H2O2SensorDataSnapshot { + public: + vector isExpired = {}; + + vector h2o2 = {}; // ppm + vector humid = {}; // %RH + vector temp = {}; // °C + vector saturation = {}; // %RS + + float minH2O2 = 0; + float maxH2O2 = 0; + float maxHumid = 0; + float maxSaturation = 0; + + int getSensorDataNum() { return h2o2.size(); } +}; +} // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_disinfection_finished_event.hpp b/appsrc/appbase/appevent/app_disinfection_finished_event.hpp new file mode 100644 index 0000000..77ac4f6 --- /dev/null +++ b/appsrc/appbase/appevent/app_disinfection_finished_event.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "iapp_event.hpp" +namespace iflytop { + +class AppDisinfectionFinishedEvent : public IAppEvent { + private: + string sessionId; + + public: + AppDisinfectionFinishedEvent(string sessionId) : sessionId(sessionId) {} + virtual ~AppDisinfectionFinishedEvent() {} + string getSessionId() { return sessionId; } +}; + +} // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp b/appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp new file mode 100644 index 0000000..0af314b --- /dev/null +++ b/appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "appbase/appbean/disinfection_state.hpp" +#include "appbase/appbean/h2o2_sensor_data_snapshot.hpp" +#include "iapp_event.hpp" +#include "iflytop/core/core.hpp" +namespace iflytop { + +class DisinfectionStateSnapshot { + public: + DisinfectionState state; + zsystem_tp time; + + shared_ptr h2o2Snapshot; + + float dval; + float nlog; + float tlog; + + int remainDisinfectant; + int remainTime; +}; + +class AppDisinfectionSnapshotEvent : public IAppEvent { + private: + shared_ptr stateSnapshot; + + public: + AppDisinfectionSnapshotEvent(shared_ptr stateSnapshot) : stateSnapshot(stateSnapshot) {} + virtual ~AppDisinfectionSnapshotEvent() {} + shared_ptr getStateSnapshot() { return stateSnapshot; } +}; + +} // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_disinfection_start_event.hpp b/appsrc/appbase/appevent/app_disinfection_start_event.hpp new file mode 100644 index 0000000..ee5096e --- /dev/null +++ b/appsrc/appbase/appevent/app_disinfection_start_event.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "iapp_event.hpp" +namespace iflytop { + +class AppDisinfectionStartEvent : public IAppEvent { + private: + string sessionId; + + public: + AppDisinfectionStartEvent(string sessionId) : sessionId(sessionId) {} + virtual ~AppDisinfectionStartEvent() {} + string getSessionId() { return sessionId; } +}; + +} // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_events.hpp b/appsrc/appbase/appevent/app_events.hpp index 533532a..eb36750 100644 --- a/appsrc/appbase/appevent/app_events.hpp +++ b/appsrc/appbase/appevent/app_events.hpp @@ -1,4 +1,7 @@ #pragma once +#include "app_disinfection_finished_event.hpp" +#include "app_disinfection_snapshot_event.hpp" +#include "app_disinfection_start_event.hpp" #include "app_promopt_event.hpp" #include "app_warning_promopt_event.hpp" -#include "iapp_event.hpp" +#include "iapp_event.hpp" \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_promopt_event.hpp b/appsrc/appbase/appevent/app_promopt_event.hpp index 69f98be..de20c21 100644 --- a/appsrc/appbase/appevent/app_promopt_event.hpp +++ b/appsrc/appbase/appevent/app_promopt_event.hpp @@ -1,3 +1,4 @@ +#pragma once #include "iapp_event.hpp" namespace iflytop { diff --git a/appsrc/appbase/disinfection_snapshot.hpp b/appsrc/appbase/disinfection_snapshot.hpp index 37b9030..e69de29 100644 --- a/appsrc/appbase/disinfection_snapshot.hpp +++ b/appsrc/appbase/disinfection_snapshot.hpp @@ -1,25 +0,0 @@ -#pragma once -#include "appbean/disinfection_state.hpp" -#include "iflytop/core/components/timeutils.hpp" - -namespace iflytop { -using namespace core; - -class StateSnapshot { - public: - DisinfectionState state; - zsystem_tp time; - - int32_t h2o2[10]; // ppm - int32_t humid[10]; // %RH - int32_t temp[10]; // °C - int32_t saturation[10]; // %RS - - int min_h2o2; - int max_h2o2; - int max_humid; - int max_saturation; - - float dloglevel; -}; -} // namespace iflytop \ No newline at end of file diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp index 79d500f..18a7a7b 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -347,14 +347,44 @@ void DisinfectionCtrlService::changeToNextState() { void DisinfectionCtrlService::processStateIdle(DisinfectionEvent* event) {} +string DisinfectionCtrlService::createDisinfectionID() { + struct tm tm = {0}; + time_t t = time(nullptr); + if (t == -1) { + logger->error("time(nullptr) failed"); + exit(-1); + } + struct tm* tmp = localtime_r(&t, &tm); + if (!tmp) { + logger->error("localtime_r failed"); + exit(-1); + } + return fmt::format("{:0>4}-{: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); +} + void DisinfectionCtrlService::processStateInit(DisinfectionEvent* event) { if (event->event == kevent_enter_state) { /** * @brief 开始消毒 */ + s_sessionId = createDisinfectionID(); + s_remaintime = m_tlog * 60 * 60; // 计算总的加热时间 + s_nlog = 0; + s_dvalue = 0; + s_start_tp = zsystem_clock().now(); + s_start_steady_tp = zsteady_clock().now(); + s_afterDisinfectantVolume_g = 0; + s_beforeDisinfectantVolume_g = dwus->getWeight(); + AppEventBus::ins()->push(make_shared(s_sessionId)); + GET_SERVICE(WarningLightControler)->setworkFlag(true); changeToNextState(); + logger->info("start disinfection {}", s_sessionId); } } @@ -592,6 +622,7 @@ void DisinfectionCtrlService::processStateFinished(DisinfectionEvent* event) { // tryLogSatate(true); tryLogState(true); logger->info("finished disinfection {}", s_sessionId); + AppEventBus::ins()->push(make_shared(s_sessionId)); return; } } diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp index bb760b2..c49d5b7 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp @@ -45,19 +45,19 @@ class DisinfectionCtrlService : public enable_shared_from_this m_thread; // 实时任务状态 - string s_sessionId; - zsystem_tp s_start_tp; - zsystem_tp s_complete_tp; - zsteady_tp start_steady_tp; - zsteady_tp s_lastTakeSnapt; // 上次日志时间 - zsteady_tp s_lastComputeDvalueTp; // 上次计算dvalue时间 - bool s_isDisinfectionTakeBreak = false; - shared_ptr s_h2o2Snapshot; - int32_t s_dvalue = 0; - int32_t s_remaintime; - float s_nlog; - int s_beforeDisinfectantVolume_g; // 消毒前消毒剂量 - int s_afterDisinfectantVolume_g; // 消毒后消毒剂量 + string s_sessionId = {}; + zsystem_tp s_start_tp = {}; + zsystem_tp s_complete_tp = {}; + zsteady_tp s_start_steady_tp = {}; + zsteady_tp s_lastTakeSnapt = {}; // 上次日志时间 + zsteady_tp s_lastComputeDvalueTp = {}; // 上次计算dvalue时间 + bool s_isDisinfectionTakeBreak = false; + shared_ptr s_h2o2Snapshot = {}; + int32_t s_dvalue = 0; + int32_t s_remaintime = 0; + float s_nlog = {}; + int s_beforeDisinfectantVolume_g = {}; // 消毒前消毒剂量 + int s_afterDisinfectantVolume_g = {}; // 消毒后消毒剂量 public: void initialize(); @@ -72,6 +72,7 @@ class DisinfectionCtrlService : public enable_shared_from_this snapshot) { m_snapshots.push_back(snapshot); } +void DisinfectionLogsService::pushStateSnapshot(shared_ptr snapshot) { m_snapshots.push_back(snapshot); } void DisinfectionLogsService::finishDisinfectionSession() { dumpDisinfectionRecord(m_sessionId, m_snapshots); /** @@ -170,32 +170,36 @@ void DisinfectionLogsService::finishDisinfectionSession() { * @param sessionId * @param snapshots */ -void DisinfectionLogsService::dumpDisinfectionRecord(string sessionId, list> snapshots) { +void DisinfectionLogsService::dumpDisinfectionRecord(string sessionId, list> snapshots) { // // 保存到记录到csv文件中 // ZCSV csv; - for (auto& s : snapshots) { csv.addValue(m_csvHeaderDict.getChName(CSVHeader::time), /******************/ tu_sys::fmt(s->time, "%Y-%m-%d %H:%M:%S")); csv.addValue(m_csvHeaderDict.getChName(CSVHeader::state), /*****************/ m_dmStateDict.getChName(s->state)); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_0), /***************/ formatSensorVal(s->h2o2[0])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_0), /****************/ formatSensorVal(s->temp[0])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_0), /******************/ formatSensorVal(s->rh[0])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_0), /******************/ formatSensorVal(s->rs[0])); - - if (ProjectPort::ins().getExtH2O2SensorNum() >= 1) { - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_1), /***************/ formatSensorVal(s->h2o2[1])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_1), /****************/ formatSensorVal(s->temp[1])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_1), /******************/ formatSensorVal(s->rh[1])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_1), /******************/ formatSensorVal(s->rs[1])); - } - if (ProjectPort::ins().getExtH2O2SensorNum() >= 2) { - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_2), /***************/ formatSensorVal(s->h2o2[2])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_2), /****************/ formatSensorVal(s->temp[2])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_2), /******************/ formatSensorVal(s->rh[2])); - csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_2), /******************/ formatSensorVal(s->rs[2])); + auto h2o2data = s->h2o2Snapshot; + for (uint32_t i = 0; i < h2o2data->getSensorDataNum(); i++) { + if (i == 0) { + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_0), /***************/ h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->h2o2[0])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_0), /****************/ h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->temp[0])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_0), /******************/ h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->humid[0])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_0), /******************/ h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->saturation[0])); + } + if (i == 1) { + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_1), /***************/ h2o2data->isExpired[1] ? "N/A" : formatSensorVal(h2o2data->h2o2[1])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_1), /****************/ h2o2data->isExpired[1] ? "N/A" : formatSensorVal(h2o2data->temp[1])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_1), /******************/ h2o2data->isExpired[1] ? "N/A" : formatSensorVal(h2o2data->humid[1])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_1), /******************/ h2o2data->isExpired[1] ? "N/A" : formatSensorVal(h2o2data->saturation[1])); + } + + if (i == 2) { + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::ho2o2_2), /***************/ h2o2data->isExpired[2] ? "N/A" : formatSensorVal(h2o2data->h2o2[2])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::temp_2), /****************/ h2o2data->isExpired[2] ? "N/A" : formatSensorVal(h2o2data->temp[2])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rh_2), /******************/ h2o2data->isExpired[2] ? "N/A" : formatSensorVal(h2o2data->humid[2])); + csv.addValue(m_csvHeaderDict.getChName(CSVHeader::rs_2), /******************/ h2o2data->isExpired[2] ? "N/A" : formatSensorVal(h2o2data->saturation[2])); + } } csv.addValue(m_csvHeaderDict.getChName(CSVHeader::dval), /******************/ fmt::format("{}", s->dval)); diff --git a/appsrc/service/disinfection_logs_service.hpp b/appsrc/service/disinfection_logs_service.hpp index b4341f2..41b371c 100644 --- a/appsrc/service/disinfection_logs_service.hpp +++ b/appsrc/service/disinfection_logs_service.hpp @@ -18,29 +18,6 @@ namespace iflytop { -class StateSnapshot { - public: - DisinfectionState state; - zsystem_tp time; - - int32_t h2o2[MAX_SUPPORT_SENSOR]; // ppm - int32_t rh[MAX_SUPPORT_SENSOR]; // %RH - int32_t temp[MAX_SUPPORT_SENSOR]; // °C - int32_t rs[MAX_SUPPORT_SENSOR]; // %RS - - int min_h2o2; - int max_h2o2; - int max_humid; - int max_saturation; - - float dval; - float nlog; - float tlog; - - int remainDisinfectant; - int pumpVel; - int remainTime; -}; class DisinfectionLogsService : public enable_shared_from_this { THISCLASS(DisinfectionLogsService); @@ -51,7 +28,7 @@ class DisinfectionLogsService : public enable_shared_from_this m_udiskMgrService; string m_sessionId; - list> m_snapshots; + list> m_snapshots; ZDictionary m_csvHeaderDict; ZDictionary m_dmStateDict; @@ -61,11 +38,11 @@ class DisinfectionLogsService : public enable_shared_from_this snapshot); + void pushStateSnapshot(shared_ptr snapshot); void finishDisinfectionSession(); private: - void dumpDisinfectionRecord(string sessionId, list> snapshots); + void dumpDisinfectionRecord(string sessionId, list> snapshots); private: /******************************************************************************* diff --git a/appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp b/appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp index 10ab66a..c5aa4e9 100644 --- a/appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp +++ b/appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp @@ -40,22 +40,7 @@ class H2O2SensorDataCache { float saturation = -1; // %RS }; -class H2O2SensorDataSnapshot { - public: - vector isExpired = {}; - - vector h2o2 = {}; // ppm - vector humid = {}; // %RH - vector temp = {}; // °C - vector saturation = {}; // %RS - float minH2O2 = 0; - float maxH2O2 = 0; - float maxHumid = 0; - float maxSaturation = 0; - - int getSensorDataNum() { return h2o2.size(); } -}; class H2O2SensorDataMgr : public enable_shared_from_this { THISCLASS(H2O2SensorDataMgr); diff --git a/appsrc/service/hardware/disinfectant_weight_update_service.cpp b/appsrc/service/hardware/disinfectant_weight_update_service.cpp index 16ce601..9a516d1 100644 --- a/appsrc/service/hardware/disinfectant_weight_update_service.cpp +++ b/appsrc/service/hardware/disinfectant_weight_update_service.cpp @@ -6,16 +6,23 @@ using namespace std; void DisinfectantWeightUpdateService::initialize() { // GET_TO_SERVICE(deviceIoControlService); - updateThread.reset(new Thread("DisinfectantWeightUpdateService", [this]() { // - updateWeightThread(); - })); + + if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { + updateThread.reset(new Thread("DisinfectantWeightUpdateService", [this]() { // + updateWeightThread(); + })); + } } float DisinfectantWeightUpdateService::getWeight() { // - if (DS->getAppExceptionFlag()) { - THROW_APP_EXCEPTION(DS->getAppExceptionCode(), DS->getAppExceptionMessage()); + if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { + if (DS->getAppExceptionFlag()) { + THROW_APP_EXCEPTION(DS->getAppExceptionCode(), DS->getAppExceptionMessage()); + } + return weightCache; + } else { + return 0; } - return weightCache; } void DisinfectantWeightUpdateService::updateWeightThread() { while (true) {