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_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_check_point_check_service.hpp b/appsrc/service/device_monitor_service.hpp similarity index 53% rename from appsrc/service/device_check_point_check_service.hpp rename to appsrc/service/device_monitor_service.hpp index 056ae48..cdf505e 100644 --- a/appsrc/service/device_check_point_check_service.hpp +++ b/appsrc/service/device_monitor_service.hpp @@ -10,6 +10,7 @@ #include // #include "baseservice/baseservice.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" namespace iflytop { /** @@ -17,23 +18,21 @@ namespace iflytop { * 设备空闲状态异常监听 */ +class DeviceMonitorService : public enable_shared_from_this { + THISCLASS(DeviceMonitorService); -class DeviceCheckPointCheckService : public enable_shared_from_this { - THISCLASS(DeviceCheckPointCheckService); + SERVICE(DeviceIoControlService, deviceIoControlService); + unique_ptr m_thread; - vector checkPoints; + bool evaporationBinWaterLevel = false; + bool deviceBottomWaterLevel = false; - unique_ptr m_thread; public: void initialize(); - vector getAllCheckPoints(); - bool isPassed(); - private: - - void resetPassState(); + void checkLoopThread(); }; } // namespace iflytop