diff --git a/README.md b/README.md index 055bee1..16a9a28 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,10 @@ VERSION 1.2.0 1. 排液时,多排 VERSION 1.2.1 1. 支持H2O2传感器全部数据的读取和打印 +VERSION 1.2.2 + 1. 添加设备异常检测服务 + 2. 去掉Prompt概念,直接将AppEvent透传给前端 + TODO: 1.添加用户增加用户查重检查 2.添加 diff --git a/app_protocols/apperrorcode/apperrorcode.hpp b/app_protocols/apperrorcode/apperrorcode.hpp index f778beb..0e50f19 100644 --- a/app_protocols/apperrorcode/apperrorcode.hpp +++ b/app_protocols/apperrorcode/apperrorcode.hpp @@ -53,6 +53,8 @@ typedef enum { kappe_liquid_ctrl_reboot = 10300, kappe_power_control_reboot = 10301, + kappe_device_checkpoint_check_fail = 20000, // + } apperror_t; } diff --git a/appsrc/appbase/appevent/app_checkpoint_check_fail_event.hpp b/appsrc/appbase/appevent/app_checkpoint_check_fail_event.hpp new file mode 100644 index 0000000..c600b1f --- /dev/null +++ b/appsrc/appbase/appevent/app_checkpoint_check_fail_event.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "iapp_event.hpp" +namespace iflytop { + +class AppCheckPointCheckFailEvent : public IAppEvent { + private: + public: + AppCheckPointCheckFailEvent() : IAppEvent(AppEventType::AppCheckPointCheckFailEvent) {} + virtual ~AppCheckPointCheckFailEvent() {} + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppCheckPointCheckFailEvent, uuid, type); + virtual json toJson() { return json(*this); } +}; + +} // 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 index 112b10c..4809bb4 100644 --- a/appsrc/appbase/appevent/app_disinfection_finished_event.hpp +++ b/appsrc/appbase/appevent/app_disinfection_finished_event.hpp @@ -17,10 +17,17 @@ class AppDisinfectionFinishedEvent : public IAppEvent { shared_ptr disinfectionStatistics; public: - AppDisinfectionFinishedEvent(string sessionId, shared_ptr disinfectionStatistics) : sessionId(sessionId), disinfectionStatistics(disinfectionStatistics) {} + AppDisinfectionFinishedEvent(string sessionId, shared_ptr disinfectionStatistics) + : // + IAppEvent(AppEventType::AppDisinfectionFinishedEvent), + sessionId(sessionId), + disinfectionStatistics(disinfectionStatistics) {} virtual ~AppDisinfectionFinishedEvent() {} string getSessionId() { return sessionId; } shared_ptr getDisinfectionStatistics() { return disinfectionStatistics; } + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppDisinfectionFinishedEvent, uuid, type,sessionId); + virtual json toJson() { return json(*this); } }; } // 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 index 70bf877..e99d785 100644 --- a/appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp +++ b/appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp @@ -32,9 +32,12 @@ class AppDisinfectionSnapshotEvent : public IAppEvent { shared_ptr stateSnapshot; public: - AppDisinfectionSnapshotEvent(shared_ptr stateSnapshot) : stateSnapshot(stateSnapshot) {} + AppDisinfectionSnapshotEvent(shared_ptr stateSnapshot) : IAppEvent(AppEventType::AppDisinfectionSnapshotEvent),stateSnapshot(stateSnapshot) {} virtual ~AppDisinfectionSnapshotEvent() {} shared_ptr getStateSnapshot() { return stateSnapshot; } + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppDisinfectionSnapshotEvent, uuid,type); + virtual json toJson() { return json(*this); } }; } // 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 index ee5096e..d0e0cdc 100644 --- a/appsrc/appbase/appevent/app_disinfection_start_event.hpp +++ b/appsrc/appbase/appevent/app_disinfection_start_event.hpp @@ -7,9 +7,12 @@ class AppDisinfectionStartEvent : public IAppEvent { string sessionId; public: - AppDisinfectionStartEvent(string sessionId) : sessionId(sessionId) {} + AppDisinfectionStartEvent(string sessionId) : IAppEvent(AppEventType::AppDisinfectionStartEvent),sessionId(sessionId) {} virtual ~AppDisinfectionStartEvent() {} string getSessionId() { return sessionId; } + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppDisinfectionStartEvent, uuid,type,sessionId); + virtual json toJson() { return json(*this); } }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_event_type.cpp b/appsrc/appbase/appevent/app_event_type.cpp new file mode 100644 index 0000000..77b6162 --- /dev/null +++ b/appsrc/appbase/appevent/app_event_type.cpp @@ -0,0 +1,2 @@ +#include "app_event_type.hpp" +AppEventType_ZENUM_IMPL \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_event_type.hpp b/appsrc/appbase/appevent/app_event_type.hpp new file mode 100644 index 0000000..6adda99 --- /dev/null +++ b/appsrc/appbase/appevent/app_event_type.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "iflytop/core/components/zenum_template/zenum_template.hpp" + +#define AppEventType_ZENUM_IMPL ZENUM_IMPL(AppEventType, AppEventType_LIST) +#define AppEventType_LIST(type, marco) /**/ \ + marco(type, AppDisinfectionFinishedEvent) /**/ \ + marco(type, AppDisinfectionSnapshotEvent) /**/ \ + marco(type, AppDisinfectionStartEvent) /**/ \ + marco(type, AppPromoptEvent) /**/ \ + marco(type, AppWarningPromoptEvent) /**/ \ + marco(type, AppCheckPointCheckFailEvent) /**/ + +ZENUM_DECLAR(AppEventType, AppEventType_LIST); \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_events.hpp b/appsrc/appbase/appevent/app_events.hpp index eb36750..a8490a0 100644 --- a/appsrc/appbase/appevent/app_events.hpp +++ b/appsrc/appbase/appevent/app_events.hpp @@ -4,4 +4,6 @@ #include "app_disinfection_start_event.hpp" #include "app_promopt_event.hpp" #include "app_warning_promopt_event.hpp" -#include "iapp_event.hpp" \ No newline at end of file +#include "iapp_event.hpp" +#include "app_event_type.hpp" +#include "app_checkpoint_check_fail_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 de20c21..9b28f41 100644 --- a/appsrc/appbase/appevent/app_promopt_event.hpp +++ b/appsrc/appbase/appevent/app_promopt_event.hpp @@ -7,9 +7,12 @@ class AppPromoptEvent : public IAppEvent { string message; public: - AppPromoptEvent(string message) : message(message) {} + AppPromoptEvent(string message) : IAppEvent(AppEventType::AppPromoptEvent), message(message) {} virtual ~AppPromoptEvent() {} string getMessage() { return message; } + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppPromoptEvent, uuid, type, message); + virtual json toJson() { return json(*this); } }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_warning_promopt_event.hpp b/appsrc/appbase/appevent/app_warning_promopt_event.hpp index 7a414b0..7f6f98a 100644 --- a/appsrc/appbase/appevent/app_warning_promopt_event.hpp +++ b/appsrc/appbase/appevent/app_warning_promopt_event.hpp @@ -5,26 +5,27 @@ namespace iflytop { class AppWarningPromoptEvent : public IAppEvent { private: int32_t ecode; - // string fromClass; - // string fromFn; - string traceinfo; string description; + string traceinfo; + // ecode2str(appWarningPromoptEvent->getEcode()), extmessage public: - AppWarningPromoptEvent(int ecode) : ecode(ecode) {} - AppWarningPromoptEvent(const appexception& e) { + AppWarningPromoptEvent(int ecode) : IAppEvent(AppEventType::AppWarningPromoptEvent), ecode(ecode) { description = ecode2str(ecode); } + AppWarningPromoptEvent(const appexception &e) : IAppEvent(AppEventType::AppWarningPromoptEvent) { ecode = e.ecode; - // fromClass = e.fromClass; - // fromFn = e.fromFn; + description = ecode2str(ecode); traceinfo = e.traceinfo; - description = e.description; } virtual ~AppWarningPromoptEvent() {} - int getEcode() { return ecode; } - // const string &getFromClass() { return fromClass; } - // const string &getFromFn() { return fromFn; } + int getEcode() { return ecode; } const string &getTraceinfo() { return traceinfo; } const string &getDescription() { return description; } + + /******************************************************************************* + * JSON * + *******************************************************************************/ + NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppWarningPromoptEvent, uuid,type, ecode, traceinfo, description); + virtual json toJson() { return json(*this); } }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/iapp_event.hpp b/appsrc/appbase/appevent/iapp_event.hpp index 0712f2b..ca9852c 100644 --- a/appsrc/appbase/appevent/iapp_event.hpp +++ b/appsrc/appbase/appevent/iapp_event.hpp @@ -9,12 +9,21 @@ #include #include #include + +#include "app_event_type.hpp" +#include "appbase/appbase.hpp" namespace iflytop { using namespace std; class IAppEvent { public: - IAppEvent(/* args */) {} + string uuid = UUID().toString(); + AppEventType type; + + public: + IAppEvent(AppEventType type) : type(type) {} virtual ~IAppEvent() {} + + virtual json toJson() = 0; }; -} // namespace ifytop \ No newline at end of file +} // namespace iflytop \ No newline at end of file diff --git a/appsrc/appsetting/project_port/basic/zappversion.hpp b/appsrc/appsetting/project_port/basic/zappversion.hpp index 6262dde..e5ba8b2 100644 --- a/appsrc/appsetting/project_port/basic/zappversion.hpp +++ b/appsrc/appsetting/project_port/basic/zappversion.hpp @@ -1,3 +1,3 @@ #pragma once -#define VERSION "1.2.1" +#define VERSION "1.2.2" #define PROJECT_NAME "TRANSMIT_DM" \ 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 4ec325f..ad9f5d7 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -559,17 +559,17 @@ void DisinfectionCtrlService::processStateDisinfection(DisinfectionEvent* event) changeToNextState(); } - if (dics->WaterSensor_readDeviceBottom()) { - logger->error("kappe_the_bottom_of_the_device_has_water"); - pushSnapshot(createErrorSnapshot(err::kappe_the_bottom_of_the_device_has_water)); - sm.changeState(DisinfectionState::finished); - } - - if (dics->WaterSensor_readEvaporationBin()) { - logger->error("kappe_the_evaporation_bin_has_water"); - pushSnapshot(createErrorSnapshot(err::kappe_the_evaporation_bin_has_water)); - sm.changeState(DisinfectionState::finished); - } + // if (dics->WaterSensor_readDeviceBottom()) { + // logger->error("kappe_the_bottom_of_the_device_has_water"); + // pushSnapshot(createErrorSnapshot(err::kappe_the_bottom_of_the_device_has_water)); + // sm.changeState(DisinfectionState::finished); + // } + + // if (dics->WaterSensor_readEvaporationBin()) { + // logger->error("kappe_the_evaporation_bin_has_water"); + // pushSnapshot(createErrorSnapshot(err::kappe_the_evaporation_bin_has_water)); + // sm.changeState(DisinfectionState::finished); + // } // AppEventBus if (PORT.isHasDisinfectantBucket()) { diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index 6c9d8c5..fa18fa9 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -12,6 +12,7 @@ #include "service/test_page_mgr_service.hpp" #include "service/user_mgr_service.hpp" // +#include "device_check_point_check_service.hpp" #include "service/app/add_liquid_service.hpp" #include "service/app/air_leak_detect_test.hpp" #include "service/app/disinfection_ctrl_service_ext.hpp" @@ -34,28 +35,10 @@ void AppCore::dosystem(string order, bool dump) { } static void installEcodeInfo() { - // kerr_motor_reset_error = 100, - // kerr_motor_subdevice_offline = 101, - // kerr_motor_driver_error = 102, - // kerr_motor_undervoltage_error = 103, - // kerr_motor_unkown_error = 104, - - // kerr_motor_overtemperature_flag = 105, - // kerr_motor_overtemperature_pre_warning_flag = 106, - // kerr_motor_short_to_ground_indicator_phase_A = 107, - // kerr_motor_short_to_ground_indicator_phase_B = 108, - // kerr_motor_open_load_indicator_phase_A = 109, - // kerr_motor_open_load_indicator_phase_B = 110, - // kerr_motor_standstill_indicator = 111, - - // kerr_AirBlowerError = 200, // 空压机异常 - // kerr_HeaterError = 201, // 加热片异常 - // kerr_BlowerError = 202, // 鼓风机异常 - // kerr_ProportionalValveError = 203, // 气密性测试专用空压机异常 - REG_ENUM_TYPE(SettingId, SettingId::getEnumStrList()); REG_ENUM_TYPE(AirLeakTestMode, AirLeakTestMode::getEnumStrList()); REG_ENUM_TYPE(UsrRoleType, UsrRoleType::getEnumStrList()); + REG_ENUM_TYPE(AppEventType, AppEventType::getEnumStrList()); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_reset_error, "电机复位错误"); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_subdevice_offline, "电机子设备离线"); @@ -90,8 +73,9 @@ static void installEcodeInfo() { AppEcodeInfoMgr::ins().regEcodeInfo(kappe_passwd_error, "密码错误"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_disinfectant_insufficient, "消毒液不足"); - AppEcodeInfoMgr::ins().regEcodeInfo(kappe_the_bottom_of_the_device_has_water, "设备底部有水"); - AppEcodeInfoMgr::ins().regEcodeInfo(kappe_the_evaporation_bin_has_water, "蒸发仓有水"); + + AppEcodeInfoMgr::ins().regEcodeInfo(kappe_the_bottom_of_the_device_has_water, "硬件仓内有液体"); + AppEcodeInfoMgr::ins().regEcodeInfo(kappe_the_evaporation_bin_has_water, "蒸发仓内有液体"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_the_sensor_is_prehearting, "传感器正在预热"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_not_detect_udisk, "未检测到U盘"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_udisk_wr_fail, "U盘读写错误"); @@ -155,6 +139,7 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(DisinfectionCtrlServiceExt); BUILD_AND_REG_SERRVICE(DrainLiquidService); BUILD_AND_REG_SERRVICE(DebugPageTestService); + BUILD_AND_REG_SERRVICE(DeviceCheckPointCheckService); // GET_SERVICE(IflytopFrontEndService)->startListen(); @@ -180,193 +165,47 @@ void AppCore::initialize() { // shared_ptr AppEventBus::ins()->onEvent.connect([this](shared_ptr event) { - auto appWarningPromoptEvent = dynamic_pointer_cast(event); - if (appWarningPromoptEvent) { - string extmessage = ""; - - // extmessage += fmt::format("fromClass:{}\n", appWarningPromoptEvent->getFromClass()); - // extmessage += fmt::format("fromFn:{}\n", appWarningPromoptEvent->getFromFn()); - extmessage += fmt::format("description:{}\n", appWarningPromoptEvent->getDescription()); - extmessage += fmt::format("traceinfo:{}\n", appWarningPromoptEvent->getTraceinfo()); - - insertPrompt(Prompt::createWarning(ecode2str(appWarningPromoptEvent->getEcode()), extmessage)); - onDeviceStateChange(); - return; - } - auto appPromoptEvent = dynamic_pointer_cast(event); - if (appPromoptEvent) { - insertPrompt(Prompt::createInfo(appPromoptEvent->getMessage())); - onDeviceStateChange(); + if (dynamic_pointer_cast(event) || // + dynamic_pointer_cast(event) || // + dynamic_pointer_cast(event)) { + insertAppEvent(event); return; } }); REG_EXTFN_VOID(getState, void(void)); - REG_EXTFN(promptConfirm, void(string), promptId); - REG_EXTFN_VOID(promptGetAll, void(void)); - REG_EXTFN_VOID(promptGetNext, void(void)); - - // - REG_EXTFN_VOID(ForTest_enterTestMode, void(void)); - REG_EXTFN_VOID(ForTest_exitTestMode, void(void)); - REG_EXTFN(ForTest_startGenFakeH2O2Data, void(json), data); - REG_EXTFN_VOID(ForTest_stopGenFakeH2O2Data, void(void)); - REG_EXTFN_VOID(ForTest_getGenFakeH2O2DataDemoJson, void(void)); - REG_EXTFN_VOID(ForTest_triggerOnePrompt, void(void)); + REG_EXTFN(appEventConfirm, void(string), evenid); }; int AppCore::demofn(int a, int b) { return 0; } void AppCore::getState(shared_ptr cxt) { - lock_guard lock(warningPromptListMutex); + lock_guard lock(appEventListMutex); cxt->rely = getState(); } -void AppCore::promptConfirm(shared_ptr cxt, string promptId) { - lock_guard lock(warningPromptListMutex); - for (auto it = warningPromptList.begin(); it != warningPromptList.end(); it++) { - if ((*it)->promptId == promptId) { - warningPromptList.erase(it); +void AppCore::appEventConfirm(shared_ptr cxt, string evenid) { + lock_guard lock(appEventListMutex); + for (auto it = appEventList.begin(); it != appEventList.end(); it++) { + if ((*it)->uuid == evenid) { + appEventList.erase(it); break; } } GET_SERVICE(WarningLightControler)->setwarningFlag(false); } -void AppCore::promptGetAll(shared_ptr cxt) { - lock_guard lock(warningPromptListMutex); - auto rely = cxt->rely; - rely["prompts"] = json::array(); - for (auto& p : warningPromptList) { - rely["prompts"].push_back(*p); - } -} - -void AppCore::promptGetNext(shared_ptr cxt) { - lock_guard lock(warningPromptListMutex); - auto rely = cxt->rely; - if (warningPromptList.size() > 0) { - rely["prompt"] = *warningPromptList.front(); - } -} -void AppCore::ForTest_enterTestMode(shared_ptr cxt) { DS->setTestMode(true); } -void AppCore::ForTest_exitTestMode(shared_ptr cxt) { DS->setTestMode(false); } - -typedef struct { - float h2o2[3]; - float rh[3]; - float temp[3]; - float rs[3]; - bool random[3]; - bool enable[3]; -} fake_h2o2_data_cache_t; -#if 0 - -#endif - -void AppCore::ForTest_startGenFakeH2O2Data(shared_ptr cxt, json data) { - if (m_genFakeH2O2DataThread) { - m_genFakeH2O2DataThread->join(); - m_genFakeH2O2DataThread = nullptr; - } - - fake_h2o2_data_cache_t cache; - for (size_t i = 0; i < 3; i++) { - cache.h2o2[i] = data[i]["h2o2"]; - cache.rh[i] = data[i]["rh"]; - cache.temp[i] = data[i]["temp"]; - cache.rs[i] = data[i]["rs"]; - cache.random[i] = data[i]["random"]; - cache.enable[i] = data[i]["enable"]; - } - - m_genFakeH2O2DataThread.reset(new Thread("genFakeH2O2DataThread", [this, cache]() { - while (!ThisThread().getExitFlag()) { - ThisThread().sleepForMs(1000); - - for (size_t i = 0; i < 3; i++) { - if (cache.enable[i]) { - float h2o2 = cache.random[i] ? (rand() % 100) : cache.h2o2[i]; - float rh = cache.random[i] ? (rand() % 100) : cache.rh[i]; - float temp = cache.random[i] ? (rand() % 100) : cache.temp[i]; - float rs = cache.random[i] ? (rand() % 100) : cache.rs[i]; - - logger->debug("genFakeH2O2DataThread: h2o2={}, rh={}, temp={}, rs={}", h2o2, rh, temp, rs); - H2O2ReportData data; - m_dics->getH2O2SensorMgr()->updateH2o2SensorData(i, &data, h2o2, rh, temp, rs); - } - } - } - })); -} -void AppCore::ForTest_stopGenFakeH2O2Data(shared_ptr cxt) { - if (m_genFakeH2O2DataThread) { - m_genFakeH2O2DataThread->join(); - m_genFakeH2O2DataThread = nullptr; - } -} -void AppCore::ForTest_getGenFakeH2O2DataDemoJson(shared_ptr cxt) { - // { - // "messageType": "Command", - // "fnName": "ForTest_startGenFakeH2O2Data", - // "className": "AppCore", - // "messageId": "1234", - // "timeStamp": 1234, - // "params": { - // "data": [ - // { - // "h2o2": 0, - // "rh": 0, - // "temp": 0, - // "rs": 0, - // "random": true, - // "enable": true - // }, - // { - // "h2o2": 0, - // "rh": 0, - // "temp": 0, - // "rs": 0, - // "random": true, - // "enable": true - // }, - // { - // "h2o2": 0, - // "rh": 0, - // "temp": 0, - // "rs": 0, - // "random": true, - // "enable": true - // } - // ] - // } - // } - - json ret; - ret["messageType"] = "Command"; - ret["fnName"] = "ForTest_startGenFakeH2O2Data"; - ret["className"] = "AppCore"; - ret["messageId"] = "123"; - ret["timeStamp"] = 123; - ret["params"]["data"] = json::array(); - for (size_t i = 0; i < 3; i++) { - json item; - item["h2o2"] = 0; - item["rh"] = 0; - item["temp"] = 0; - item["rs"] = 0; - item["random"] = true; - item["enable"] = true; - ret["params"]["data"].push_back(item); - } - cxt->rely = ret; -} - void AppCore::loop() {} void AppCore::onDeviceStateChange() { SEND_CLASS_REPORT("AppCore", "onDeviceStateChange", getState()); } -void AppCore::insertPrompt(shared_ptr prompt) { - lock_guard lock(warningPromptListMutex); - warningPromptList.push_back(prompt); - if (prompt->isWarning) GET_SERVICE(WarningLightControler)->setwarningFlag(true); +void AppCore::insertAppEvent(shared_ptr event) { + lock_guard lock(appEventListMutex); + appEventList.push_back(event); + onDeviceStateChange(); + + if (dynamic_pointer_cast(event)) { + GET_SERVICE(WarningLightControler)->setwarningFlag(true); + } else if (dynamic_pointer_cast(event)) { + GET_SERVICE(WarningLightControler)->setwarningFlag(true); + } } json AppCore::getState() { @@ -379,9 +218,9 @@ json AppCore::getState() { ret["testMode"]["isInTestMode"] = DS->isTestMode(); - ret["prompts"] = json::array(); - for (auto& p : warningPromptList) { - ret["prompts"].push_back(*p); + ret["appEvents"] = json::array(); + for (auto& p : appEventList) { + ret["appEvents"].push_back(p->toJson()); } return ret; } diff --git a/appsrc/service/app_core.hpp b/appsrc/service/app_core.hpp index 1ad6885..3cdaede 100644 --- a/appsrc/service/app_core.hpp +++ b/appsrc/service/app_core.hpp @@ -34,36 +34,16 @@ namespace iflytop { using namespace std; using namespace core; -class Prompt { - public: - string promptId = UUID().toString(); - bool isWarning = false; - string message = ""; - string extMessage = ""; - bool confirmedByUser = false; - - public: - Prompt(bool isWarning, string message) : isWarning(isWarning), message(message) {} - Prompt(bool isWarning, string message, string extMessage) : isWarning(isWarning), message(message), extMessage(extMessage) {} - - public: - NLOHMANN_DEFINE_TYPE_INTRUSIVE(Prompt, promptId, message, extMessage, confirmedByUser, isWarning); - - static shared_ptr createWarning(string message, string extmessage) { return make_shared(true, message, extmessage); } - static shared_ptr createInfo(string message) { return make_shared(false, message); } -}; - class AppCore : public enable_shared_from_this { THISCLASS(AppCore); shared_ptr m_dics; - unique_ptr wq; - list> warningPromptList; - recursive_mutex warningPromptListMutex; - steady_clock::time_point lastUsrConfirmTime; + unique_ptr wq; + list> appEventList; + recursive_mutex appEventListMutex; + - unique_ptr m_genFakeH2O2DataThread; public: AppCore() {}; @@ -71,18 +51,8 @@ class AppCore : public enable_shared_from_this { private: void getState(shared_ptr cxt); - void promptConfirm(shared_ptr cxt, string promptId); - void promptGetAll(shared_ptr cxt); - void promptGetNext(shared_ptr cxt); - // 测试 - void ForTest_enterTestMode(shared_ptr cxt); - void ForTest_exitTestMode(shared_ptr cxt); - - void ForTest_triggerOnePrompt(shared_ptr cxt) { AppEventBus::ins()->pushPromoptEvent("这是一个测试提示信息"); } + void appEventConfirm(shared_ptr cxt, string appevenid); - void ForTest_startGenFakeH2O2Data(shared_ptr cxt, json data); - void ForTest_stopGenFakeH2O2Data(shared_ptr cxt); - void ForTest_getGenFakeH2O2DataDemoJson(shared_ptr cxt); private: json getState(); @@ -92,6 +62,6 @@ class AppCore : public enable_shared_from_this { private: void onDeviceStateChange(); - void insertPrompt(shared_ptr prompt); + void insertAppEvent(shared_ptr appEvent); }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/service/debug_page_test_service.cpp b/appsrc/service/debug_page_test_service.cpp index e6e8e1a..8dc60eb 100644 --- a/appsrc/service/debug_page_test_service.cpp +++ b/appsrc/service/debug_page_test_service.cpp @@ -1,6 +1,19 @@ #include "debug_page_test_service.hpp" + +#include "appsrc/service/hardware/base/h2o2_sensor_data_mgr.hpp" +#include "hardware/device_io_ctrl_service.hpp" using namespace iflytop; void DebugPageTestService::initialize() { + REG_EXTFN_VOID(enterTestMode, void(void)); + REG_EXTFN_VOID(exitTestMode, void(void)); + REG_EXTFN(startGenFakeH2O2Data, void(json), data); + REG_EXTFN_VOID(stopGenFakeH2O2Data, void(void)); + REG_EXTFN_VOID(getGenFakeH2O2DataDemoJson, void(void)); + + REG_EXTFN_VOID(triggerAppWarningPromoptEvent, void(void)); + REG_EXTFN(triggerPromptEvent, void(string), message); + REG_EXTFN_VOID(triggerAppCheckPointFailEvent, void(void)); + REG_EXTFN(test_int, int(json), param0); REG_EXTFN(test_int, int(SettingId), param0); REG_EXTFN(test_int, int(int), param0); @@ -27,4 +40,92 @@ void DebugPageTestService::test_vector_string(shared_ptr cxt, void DebugPageTestService::test_vector_double(shared_ptr cxt, vector param0) {} void DebugPageTestService::test_vecto_json(shared_ptr cxt, vector param0) {} void DebugPageTestService::test_vecto_bool(shared_ptr cxt, vector param0) {} -void DebugPageTestService::test_vecto_enum(shared_ptr cxt, vector param0) {} \ No newline at end of file +void DebugPageTestService::test_vecto_enum(shared_ptr cxt, vector param0) {} +// + +void DebugPageTestService::enterTestMode(shared_ptr cxt) { DS->setTestMode(true); } +void DebugPageTestService::exitTestMode(shared_ptr cxt) { DS->setTestMode(false); } + +typedef struct { + float h2o2[3]; + float rh[3]; + float temp[3]; + float rs[3]; + bool random[3]; + bool enable[3]; +} fake_h2o2_data_cache_t; +#if 0 + +#endif + +void DebugPageTestService::startGenFakeH2O2Data(shared_ptr cxt, json data) { + if (m_genFakeH2O2DataThread) { + m_genFakeH2O2DataThread->join(); + m_genFakeH2O2DataThread = nullptr; + } + + fake_h2o2_data_cache_t cache; + for (size_t i = 0; i < 3; i++) { + cache.h2o2[i] = data[i]["h2o2"]; + cache.rh[i] = data[i]["rh"]; + cache.temp[i] = data[i]["temp"]; + cache.rs[i] = data[i]["rs"]; + cache.random[i] = data[i]["random"]; + cache.enable[i] = data[i]["enable"]; + } + + m_genFakeH2O2DataThread.reset(new Thread("genFakeH2O2DataThread", [this, cache]() { + while (!ThisThread().getExitFlag()) { + ThisThread().sleepForMs(1000); + + for (size_t i = 0; i < 3; i++) { + if (cache.enable[i]) { + float h2o2 = cache.random[i] ? (rand() % 100) : cache.h2o2[i]; + float rh = cache.random[i] ? (rand() % 100) : cache.rh[i]; + float temp = cache.random[i] ? (rand() % 100) : cache.temp[i]; + float rs = cache.random[i] ? (rand() % 100) : cache.rs[i]; + + logger->debug("genFakeH2O2DataThread: h2o2={}, rh={}, temp={}, rs={}", h2o2, rh, temp, rs); + H2O2ReportData data; + GET_SERVICE(DeviceIoControlService)->getH2O2SensorMgr()->updateH2o2SensorData(i, &data, h2o2, rh, temp, rs); + } + } + } + })); +} +void DebugPageTestService::stopGenFakeH2O2Data(shared_ptr cxt) { + if (m_genFakeH2O2DataThread) { + m_genFakeH2O2DataThread->join(); + m_genFakeH2O2DataThread = nullptr; + } +} +void DebugPageTestService::getGenFakeH2O2DataDemoJson(shared_ptr cxt) { + json ret; + ret["messageType"] = "Command"; + ret["fnName"] = "startGenFakeH2O2Data"; + ret["className"] = "DebugPageTestService"; + ret["messageId"] = "123"; + ret["timeStamp"] = 123; + ret["params"]["data"] = json::array(); + for (size_t i = 0; i < 3; i++) { + json item; + item["h2o2"] = 0; + item["rh"] = 0; + item["temp"] = 0; + item["rs"] = 0; + item["random"] = true; + item["enable"] = true; + ret["params"]["data"].push_back(item); + } + cxt->rely = ret; +} + +void DebugPageTestService::triggerAppWarningPromoptEvent(shared_ptr cxt) { // + AppEventBus::ins()->pushWarningPromptEvent(err::kappe_disinfectant_insufficient); +} +void DebugPageTestService::triggerPromptEvent(shared_ptr cxt, string message) { // + AppEventBus::ins()->pushPromoptEvent(message); +} +void DebugPageTestService::triggerAppCheckPointFailEvent(shared_ptr cxt) { // + AppEventBus::ins()->push(make_shared()); +} diff --git a/appsrc/service/debug_page_test_service.hpp b/appsrc/service/debug_page_test_service.hpp index 29715b7..cf38409 100644 --- a/appsrc/service/debug_page_test_service.hpp +++ b/appsrc/service/debug_page_test_service.hpp @@ -13,11 +13,23 @@ namespace iflytop { class DebugPageTestService : public enable_shared_from_this { THISCLASS(DebugPageTestService); + unique_ptr m_genFakeH2O2DataThread; public: void initialize(); private: + + void triggerAppWarningPromoptEvent(shared_ptr cxt); + void triggerPromptEvent(shared_ptr cxt,string message); + void triggerAppCheckPointFailEvent(shared_ptr cxt); + + void enterTestMode(shared_ptr cxt); + void exitTestMode(shared_ptr cxt); + void startGenFakeH2O2Data(shared_ptr cxt, json data); + void stopGenFakeH2O2Data(shared_ptr cxt); + void getGenFakeH2O2DataDemoJson(shared_ptr cxt); + void test_json(shared_ptr cxt, json param0); void test_enum(shared_ptr cxt, SettingId param0); void test_int(shared_ptr cxt, int param0); diff --git a/appsrc/service/device_check_point_check_service.cpp b/appsrc/service/device_check_point_check_service.cpp new file mode 100644 index 0000000..c3fb19e --- /dev/null +++ b/appsrc/service/device_check_point_check_service.cpp @@ -0,0 +1,77 @@ +#include "device_check_point_check_service.hpp" + +#include "service/app/add_liquid_service.hpp" +#include "service/app/air_leak_detect_test.hpp" +#include "service/app/disinfection_ctrl/disinfection_ctrl_service.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" + +using namespace iflytop; +void DeviceCheckPointCheckService::initialize() { // + + checkPoints.push_back(CheckPoint(kCheckPointCode_evaporationBinWSTrigger, "蒸发仓内液位检查", false)); + checkPoints.push_back(CheckPoint(kCheckPointCode_deviceBottomWSTrigger, "硬件仓液位检测", false)); + + REG_TYPE(CheckPoint); + REG_TYPE(vector); + REG_FN_VOID(getAllCheckPoints, vector(void)); + REG_FN_VOID(isPassed, bool(void)); + + m_thread.reset(new Thread("DeviceCheckPointCheckServiceThread", [this]() { + while (true) { + sleep(1); + + // // 非空闲状态不检查 + // if (DS->getDeviceState() != DeviceState::Idle) { + // continue; + // } + + bool oldstate = isPassed(); + // logger->info("DeviceCheckPointCheckServiceThread"); + + // 检查各个检查点 + for (auto& checkPoint : checkPoints) { + CheckPointCode_t checkPointIndex = checkPoint.index; + if (checkPointIndex == kCheckPointCode_evaporationBinWSTrigger) { + if (GET_SERVICE(DeviceIoControlService)->WaterSensor_readEvaporationBin()) { + checkPoint.passed = true; + } else { + checkPoint.passed = false; + } + } else if (checkPointIndex == kCheckPointCode_deviceBottomWSTrigger) { + if (GET_SERVICE(DeviceIoControlService)->WaterSensor_readDeviceBottom()) { + checkPoint.passed = true; + } else { + checkPoint.passed = false; + } + } + } + + bool newstate = isPassed(); + if (newstate != oldstate) { + if (newstate) { + if (DS->getDeviceState() == DeviceState::Disinfection) { + GET_SERVICE(DisinfectionCtrlService)->stop(); + } else if (DS->getDeviceState() == DeviceState::AddingLiquid) { + GET_SERVICE(AddLiquidService)->stop(); + } else if (DS->getDeviceState() == DeviceState::DrainingLiquid) { + GET_SERVICE(AddLiquidService)->stop(); + } else if (DS->getDeviceState() == DeviceState::AirLeakDetectTesting) { + GET_SERVICE(AirLeakDetectTest)->stop(); + } + AppEventBus::ins()->push(make_shared()); + } + } + } + })); +} + +vector DeviceCheckPointCheckService::getAllCheckPoints() { return checkPoints; } + +bool DeviceCheckPointCheckService::isPassed() { + for (auto& checkPoint : checkPoints) { + if (checkPoint.passed) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/appsrc/service/device_check_point_check_service.hpp b/appsrc/service/device_check_point_check_service.hpp new file mode 100644 index 0000000..c1d4eaa --- /dev/null +++ b/appsrc/service/device_check_point_check_service.hpp @@ -0,0 +1,52 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +namespace iflytop { + +/** + * @brief + * 设备空闲状态异常监听 + */ + +typedef enum { + kCheckPointCode_Unknown = 0, + kCheckPointCode_evaporationBinWSTrigger, + kCheckPointCode_deviceBottomWSTrigger, +} CheckPointCode_t; + +class CheckPoint { + public: + CheckPointCode_t index; + string name; + bool passed; + + CheckPoint(CheckPointCode_t index, const string& name, bool passed) : index(index), name(name), passed(passed) {} + NLOHMANN_DEFINE_TYPE_INTRUSIVE(CheckPoint, index, name, passed); +}; + +class DeviceCheckPointCheckService : public enable_shared_from_this { + THISCLASS(DeviceCheckPointCheckService); + + vector checkPoints; + + unique_ptr m_thread; + + public: + void initialize(); + + vector getAllCheckPoints(); + bool isPassed(); + + private: +}; + +} // namespace iflytop