5 changed files with 138 additions and 151 deletions
-
9appsrc/service/app_core.cpp
-
108appsrc/service/device_check_point_check_service.cpp
-
95appsrc/service/device_monitor_service.cpp
-
17appsrc/service/device_monitor_service.hpp
@ -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<CheckPoint>); |
|
||||
REG_FN_VOID(getAllCheckPoints, vector<CheckPoint>(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<CheckPoint> errCheckPoints; |
|
||||
for (auto& checkPoint : checkPoints) { |
|
||||
if (!checkPoint.passed) { |
|
||||
errCheckPoints.push_back(checkPoint); |
|
||||
} |
|
||||
} |
|
||||
AppEventBus::ins()->push(make_shared<AppCheckPointCheckFailEvent>(errCheckPoints)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
})); |
|
||||
} |
|
||||
|
|
||||
vector<CheckPoint> 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; |
|
||||
} |
|
@ -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<AppWarningPromoptEvent>(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<AppWarningPromoptEvent>(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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
})); |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue