From 9c541e56eccbdcdd26d02c25e0b5a6d1cf8ed517 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 3 Jul 2025 19:35:54 +0800 Subject: [PATCH] =?UTF-8?q?v2.4.3=20|=20=20=E5=8E=BB=E6=8E=89=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=87=AA=E6=A3=80=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appsrc/service/app_core.cpp | 9 +- .../service/device_check_point_check_service.cpp | 108 --------------------- .../service/device_check_point_check_service.hpp | 39 -------- appsrc/service/device_monitor_service.cpp | 95 ++++++++++++++++++ appsrc/service/device_monitor_service.hpp | 38 ++++++++ 5 files changed, 138 insertions(+), 151 deletions(-) delete mode 100644 appsrc/service/device_check_point_check_service.cpp delete mode 100644 appsrc/service/device_check_point_check_service.hpp create mode 100644 appsrc/service/device_monitor_service.cpp create mode 100644 appsrc/service/device_monitor_service.hpp diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index 73f5aa3..1fc1639 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -12,7 +12,7 @@ #include "service/test_page_ctrl_service.hpp" #include "service/user_mgr_service.hpp" // -#include "device_check_point_check_service.hpp" +#include "device_monitor_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" @@ -26,9 +26,9 @@ #include "baseservice/db/device_ext_setting_dao.hpp" #include "calibration/h2o2_liquid_weight_sensor_calibration_service.hpp" #include "equipment_usage_info_mgr_service.hpp" +#include "service/hardware/h2o2_sensor_state_sync.hpp" #include "service/hardware/sensor_state_sync_service.hpp" #include "setting/ext_setting_mgr_service.hpp" -#include "service/hardware/h2o2_sensor_state_sync.hpp" // DeviceExtSettingDAO @@ -144,7 +144,7 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(WarningLightControler); BUILD_AND_REG_SERRVICE(SensorStateSyncService); BUILD_AND_REG_SERRVICE(H2O2SensorStateSyncService); - + // BUILD_AND_REG_SERRVICE(PipelinePressureControl); BUILD_AND_REG_SERRVICE(UDiskMgrService); @@ -169,11 +169,12 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(DisinfectionCtrlServiceExt); BUILD_AND_REG_SERRVICE(DrainLiquidService); BUILD_AND_REG_SERRVICE(DebugPageTestService); - BUILD_AND_REG_SERRVICE(DeviceCheckPointCheckService); BUILD_AND_REG_SERRVICE(H2O2LiquidWeightSensorCalibrationService); // H2O2液体重量传感器校准 BUILD_AND_REG_SERRVICE(ExtSettingMgrService); BUILD_AND_REG_SERRVICE(EquipmentUsageInfoMgrService); + BUILD_AND_REG_SERRVICE(DeviceMonitorService); + // int cnt = 0; // while (true) { // uint64_t tp = zsys_get_ticket(); diff --git a/appsrc/service/device_check_point_check_service.cpp b/appsrc/service/device_check_point_check_service.cpp deleted file mode 100644 index e2f8101..0000000 --- a/appsrc/service/device_check_point_check_service.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#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/app/drain_liquid_service.hpp" -#include "service/hardware/device_io_ctrl_service.hpp" - -using namespace iflytop; -void DeviceCheckPointCheckService::initialize() { // - - checkPoints.push_back(CheckPoint(kCheckPointCode_evaporationBinWSTrigger, "蒸发仓内液位检查", true)); - checkPoints.push_back(CheckPoint(kCheckPointCode_deviceBottomWSTrigger, "硬件仓液位检测", true)); - - 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->isLogin()) { - resetPassState(); - continue; - } - - // // 非空闲状态不检查 - // if (DS->getDeviceState() != DeviceState::Idle) { - // continue; - // } - - bool oldstate = isPassed(); - // logger->info("DeviceCheckPointCheckServiceThread"); - - // 检查各个检查点 - for (auto& checkPoint : checkPoints) { - CheckPointCode_t checkPointIndex = checkPoint.index; - - try { - if (checkPointIndex == kCheckPointCode_evaporationBinWSTrigger) { - if (GET_SERVICE(DeviceIoControlService)->WaterSensor_readEvaporationBin()) { - checkPoint.passed = false; - checkPoint.ecode = err::kappe_the_evaporation_bin_has_water; - checkPoint.ecodeInfo = ecode2str(checkPoint.ecode); - } else { - checkPoint.passed = true; - checkPoint.ecode = 0; - } - } else if (checkPointIndex == kCheckPointCode_deviceBottomWSTrigger) { - if (GET_SERVICE(DeviceIoControlService)->WaterSensor_readDeviceBottom()) { - checkPoint.passed = false; - checkPoint.ecode = err::kappe_the_bottom_of_the_device_has_water; - checkPoint.ecodeInfo = ecode2str(checkPoint.ecode); - } else { - checkPoint.passed = true; - checkPoint.ecode = 0; - } - } - } catch (const std::exception& e) { - // - // 硬件错误这里不做处理 - } - } - - 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(DrainLiquidService)->stop(); - } else if (DS->getDeviceState() == DeviceState::AirLeakDetectTesting) { - GET_SERVICE(AirLeakDetectTest)->stop(); - } - - vector errCheckPoints; - for (auto& checkPoint : checkPoints) { - if (!checkPoint.passed) { - errCheckPoints.push_back(checkPoint); - } - } - AppEventBus::ins()->push(make_shared(errCheckPoints)); - } - } - } - })); -} - -vector DeviceCheckPointCheckService::getAllCheckPoints() { return checkPoints; } - -void DeviceCheckPointCheckService::resetPassState() { - for (auto& checkPoint : checkPoints) { - checkPoint.passed = true; - } -} - -bool DeviceCheckPointCheckService::isPassed() { - for (auto& checkPoint : checkPoints) { - if (!checkPoint.passed) { - return false; - } - } - return true; -} \ 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 deleted file mode 100644 index 056ae48..0000000 --- a/appsrc/service/device_check_point_check_service.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -// -#include "baseservice/baseservice.hpp" -namespace iflytop { - -/** - * @brief - * 设备空闲状态异常监听 - */ - - -class DeviceCheckPointCheckService : public enable_shared_from_this { - THISCLASS(DeviceCheckPointCheckService); - - vector checkPoints; - - unique_ptr m_thread; - - public: - void initialize(); - - vector getAllCheckPoints(); - bool isPassed(); - - private: - - void resetPassState(); -}; - -} // namespace iflytop diff --git a/appsrc/service/device_monitor_service.cpp b/appsrc/service/device_monitor_service.cpp new file mode 100644 index 0000000..893c97e --- /dev/null +++ b/appsrc/service/device_monitor_service.cpp @@ -0,0 +1,95 @@ +#include "device_monitor_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/app/drain_liquid_service.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" + +using namespace iflytop; +void DeviceMonitorService::initialize() { // + + m_thread.reset(new Thread("DeviceMonitorService-Thread", [this]() { + while (true) { + sleep(1); + + if (!DS->isLogin()) { + continue; + } + + bool triggerError = false; + + { + /******************************************************************************* + * evaporationBinWaterLevel CHECK * + *******************************************************************************/ + if (!evaporationBinWaterLevel) { + bool sensorState = deviceIoControlService->WaterSensor_readEvaporationBin(); + if (sensorState) { + evaporationBinWaterLevel = true; + logger->error("Evaporation bin water sensor triggered"); + triggerError = true; + + AppEventBus::ins()->push(make_shared(err::kappe_the_evaporation_bin_has_water)); + } + } else { + bool trigger = false; + for (int i = 0; i < 10; i++) { + if (deviceIoControlService->WaterSensor_readEvaporationBin()) { + trigger = true; + break; + } + usleep(100); + } + + if (!trigger) { + evaporationBinWaterLevel = false; + logger->info("Evaporation bin water sensor reset"); + } + } + } + + { + /******************************************************************************* + * deviceBottomWaterLevel check * + *******************************************************************************/ + if (!deviceBottomWaterLevel) { + bool sensorState = deviceIoControlService->WaterSensor_readDeviceBottom(); + if (sensorState) { + deviceBottomWaterLevel = true; + logger->error("Device bottom water sensor triggered"); + triggerError = true; + + AppEventBus::ins()->push(make_shared(err::kappe_the_bottom_of_the_device_has_water)); + } + } else { + bool trigger = false; + for (int i = 0; i < 10; i++) { + if (deviceIoControlService->WaterSensor_readDeviceBottom()) { + trigger = true; + break; + } + usleep(100); + } + + if (!trigger) { + deviceBottomWaterLevel = false; + logger->info("Device bottom water sensor reset"); + } + } + } + + if (triggerError) { + 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(DrainLiquidService)->stop(); + } else if (DS->getDeviceState() == DeviceState::AirLeakDetectTesting) { + GET_SERVICE(AirLeakDetectTest)->stop(); + } + } + } + })); +} diff --git a/appsrc/service/device_monitor_service.hpp b/appsrc/service/device_monitor_service.hpp new file mode 100644 index 0000000..cdf505e --- /dev/null +++ b/appsrc/service/device_monitor_service.hpp @@ -0,0 +1,38 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" +namespace iflytop { + +/** + * @brief + * 设备空闲状态异常监听 + */ + +class DeviceMonitorService : public enable_shared_from_this { + THISCLASS(DeviceMonitorService); + + SERVICE(DeviceIoControlService, deviceIoControlService); + unique_ptr m_thread; + + bool evaporationBinWaterLevel = false; + bool deviceBottomWaterLevel = false; + + + public: + void initialize(); + + private: + void checkLoopThread(); +}; + +} // namespace iflytop