Browse Source

update

storage-in-realtime
zhaohe 12 months ago
parent
commit
eca89d7d9f
  1. 1
      appsrc/appbase/appbase.hpp
  2. 31
      appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp
  3. 15
      appsrc/appbase/appevent/app_disinfection_finished_event.hpp
  4. 34
      appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp
  5. 15
      appsrc/appbase/appevent/app_disinfection_start_event.hpp
  6. 5
      appsrc/appbase/appevent/app_events.hpp
  7. 1
      appsrc/appbase/appevent/app_promopt_event.hpp
  8. 25
      appsrc/appbase/disinfection_snapshot.hpp
  9. 31
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp
  10. 27
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp
  11. 42
      appsrc/service/disinfection_logs_service.cpp
  12. 29
      appsrc/service/disinfection_logs_service.hpp
  13. 15
      appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp
  14. 19
      appsrc/service/hardware/disinfectant_weight_update_service.cpp

1
appsrc/appbase/appbase.hpp

@ -12,3 +12,4 @@
#include "appbase/appbean/pumpid.hpp" #include "appbase/appbean/pumpid.hpp"
#include "appbase/appbean/test_page_iterm.hpp" #include "appbase/appbean/test_page_iterm.hpp"
#include "appbean/device_state.hpp" #include "appbean/device_state.hpp"
#include "appbase/appbean/h2o2_sensor_data_snapshot.hpp"

31
appsrc/appbase/appbean/h2o2_sensor_data_snapshot.hpp

@ -0,0 +1,31 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
namespace iflytop {
using namespace std;
class H2O2SensorDataSnapshot {
public:
vector<bool> isExpired = {};
vector<float> h2o2 = {}; // ppm
vector<float> humid = {}; // %RH
vector<float> temp = {}; // °C
vector<float> saturation = {}; // %RS
float minH2O2 = 0;
float maxH2O2 = 0;
float maxHumid = 0;
float maxSaturation = 0;
int getSensorDataNum() { return h2o2.size(); }
};
} // namespace iflytop

15
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

34
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<H2O2SensorDataSnapshot> h2o2Snapshot;
float dval;
float nlog;
float tlog;
int remainDisinfectant;
int remainTime;
};
class AppDisinfectionSnapshotEvent : public IAppEvent {
private:
shared_ptr<DisinfectionStateSnapshot> stateSnapshot;
public:
AppDisinfectionSnapshotEvent(shared_ptr<DisinfectionStateSnapshot> stateSnapshot) : stateSnapshot(stateSnapshot) {}
virtual ~AppDisinfectionSnapshotEvent() {}
shared_ptr<DisinfectionStateSnapshot> getStateSnapshot() { return stateSnapshot; }
};
} // namespace iflytop

15
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

5
appsrc/appbase/appevent/app_events.hpp

@ -1,4 +1,7 @@
#pragma once #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_promopt_event.hpp"
#include "app_warning_promopt_event.hpp" #include "app_warning_promopt_event.hpp"
#include "iapp_event.hpp"
#include "iapp_event.hpp"

1
appsrc/appbase/appevent/app_promopt_event.hpp

@ -1,3 +1,4 @@
#pragma once
#include "iapp_event.hpp" #include "iapp_event.hpp"
namespace iflytop { namespace iflytop {

25
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

31
appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp

@ -347,14 +347,44 @@ void DisinfectionCtrlService::changeToNextState() {
void DisinfectionCtrlService::processStateIdle(DisinfectionEvent* event) {} 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) { void DisinfectionCtrlService::processStateInit(DisinfectionEvent* event) {
if (event->event == kevent_enter_state) { if (event->event == kevent_enter_state) {
/** /**
* @brief * @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<AppDisinfectionStartEvent>(s_sessionId));
GET_SERVICE(WarningLightControler)->setworkFlag(true); GET_SERVICE(WarningLightControler)->setworkFlag(true);
changeToNextState(); changeToNextState();
logger->info("start disinfection {}", s_sessionId);
} }
} }
@ -592,6 +622,7 @@ void DisinfectionCtrlService::processStateFinished(DisinfectionEvent* event) {
// tryLogSatate(true); // tryLogSatate(true);
tryLogState(true); tryLogState(true);
logger->info("finished disinfection {}", s_sessionId); logger->info("finished disinfection {}", s_sessionId);
AppEventBus::ins()->push(make_shared<AppDisinfectionFinishedEvent>(s_sessionId));
return; return;
} }
} }

27
appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp

@ -45,19 +45,19 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
unique_ptr<Thread> m_thread; unique_ptr<Thread> 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<H2O2SensorDataSnapshot> 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<H2O2SensorDataSnapshot> s_h2o2Snapshot = {};
int32_t s_dvalue = 0;
int32_t s_remaintime = 0;
float s_nlog = {};
int s_beforeDisinfectantVolume_g = {}; // 消毒前消毒剂量
int s_afterDisinfectantVolume_g = {}; // 消毒后消毒剂量
public: public:
void initialize(); void initialize();
@ -72,6 +72,7 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
static void updateRemainTime(int dval, float nlog, float tlog, int& remaintime); static void updateRemainTime(int dval, float nlog, float tlog, int& remaintime);
bool isTimeToPauseDisinfection(); bool isTimeToPauseDisinfection();
bool isTimeToResumeDisinfection(); bool isTimeToResumeDisinfection();
string createDisinfectionID();
public: public:
// impl // impl

42
appsrc/service/disinfection_logs_service.cpp

@ -152,7 +152,7 @@ void DisinfectionLogsService::startNewDisinfectionSession(string sessionId) { /
m_snapshots.clear(); m_snapshots.clear();
m_sessionId = sessionId; m_sessionId = sessionId;
} }
void DisinfectionLogsService::pushStateSnapshot(shared_ptr<StateSnapshot> snapshot) { m_snapshots.push_back(snapshot); }
void DisinfectionLogsService::pushStateSnapshot(shared_ptr<DisinfectionStateSnapshot> snapshot) { m_snapshots.push_back(snapshot); }
void DisinfectionLogsService::finishDisinfectionSession() { void DisinfectionLogsService::finishDisinfectionSession() {
dumpDisinfectionRecord(m_sessionId, m_snapshots); dumpDisinfectionRecord(m_sessionId, m_snapshots);
/** /**
@ -170,32 +170,36 @@ void DisinfectionLogsService::finishDisinfectionSession() {
* @param sessionId * @param sessionId
* @param snapshots * @param snapshots
*/ */
void DisinfectionLogsService::dumpDisinfectionRecord(string sessionId, list<shared_ptr<StateSnapshot>> snapshots) {
void DisinfectionLogsService::dumpDisinfectionRecord(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots) {
// //
// 保存到记录到csv文件中 // 保存到记录到csv文件中
// //
ZCSV csv; ZCSV csv;
for (auto& s : snapshots) { 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::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::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)); csv.addValue(m_csvHeaderDict.getChName(CSVHeader::dval), /******************/ fmt::format("{}", s->dval));

29
appsrc/service/disinfection_logs_service.hpp

@ -18,29 +18,6 @@
namespace iflytop { 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<DisinfectionLogsService> { class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsService> {
THISCLASS(DisinfectionLogsService); THISCLASS(DisinfectionLogsService);
@ -51,7 +28,7 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
shared_ptr<UDiskMgrService> m_udiskMgrService; shared_ptr<UDiskMgrService> m_udiskMgrService;
string m_sessionId; string m_sessionId;
list<shared_ptr<StateSnapshot>> m_snapshots;
list<shared_ptr<DisinfectionStateSnapshot>> m_snapshots;
ZDictionary m_csvHeaderDict; ZDictionary m_csvHeaderDict;
ZDictionary m_dmStateDict; ZDictionary m_dmStateDict;
@ -61,11 +38,11 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
void initialize(); void initialize();
void startNewDisinfectionSession(string sessionId); void startNewDisinfectionSession(string sessionId);
void pushStateSnapshot(shared_ptr<StateSnapshot> snapshot);
void pushStateSnapshot(shared_ptr<DisinfectionStateSnapshot> snapshot);
void finishDisinfectionSession(); void finishDisinfectionSession();
private: private:
void dumpDisinfectionRecord(string sessionId, list<shared_ptr<StateSnapshot>> snapshots);
void dumpDisinfectionRecord(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
private: private:
/******************************************************************************* /*******************************************************************************

15
appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp

@ -40,22 +40,7 @@ class H2O2SensorDataCache {
float saturation = -1; // %RS float saturation = -1; // %RS
}; };
class H2O2SensorDataSnapshot {
public:
vector<bool> isExpired = {};
vector<float> h2o2 = {}; // ppm
vector<float> humid = {}; // %RH
vector<float> temp = {}; // °C
vector<float> 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<H2O2SensorDataMgr> { class H2O2SensorDataMgr : public enable_shared_from_this<H2O2SensorDataMgr> {
THISCLASS(H2O2SensorDataMgr); THISCLASS(H2O2SensorDataMgr);

19
appsrc/service/hardware/disinfectant_weight_update_service.cpp

@ -6,16 +6,23 @@ using namespace std;
void DisinfectantWeightUpdateService::initialize() { // void DisinfectantWeightUpdateService::initialize() { //
GET_TO_SERVICE(deviceIoControlService); 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() { // 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() { void DisinfectantWeightUpdateService::updateWeightThread() {
while (true) { while (true) {

Loading…
Cancel
Save