diff --git a/appsrc/service/app/add_liquid_service.cpp b/appsrc/service/app/add_liquid_service.cpp index e1cb0d7..5641688 100644 --- a/appsrc/service/app/add_liquid_service.cpp +++ b/appsrc/service/app/add_liquid_service.cpp @@ -1,5 +1,10 @@ #include "add_liquid_service.hpp" using namespace iflytop; +/** + * @brief + * + */ +#define EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES 1000 void AddLiquidService::initialize() { logger->info("AddLiquidService initialize"); @@ -17,6 +22,27 @@ void AddLiquidService::start(int stopatg) { THROW_APP_EXCEPTION(getDeviceBusyReason(nowstate), ""); } + if (DS->getAppExceptionFlag()) { + THROW_APP_EXCEPTION(err::kappe_exception_flag_is_setted, ""); + } + + if (DS->getDeviceState() != DeviceState::Idle) { + THROW_APP_EXCEPTION(err::kappe_state_is_busy, ""); + } + + if (zsteady_clock().gets() < SENSOR_PREHEART_TIME_S) { + THROW_APP_EXCEPTION(err::kappe_sensor_is_pre_hearting, ""); + } + + if (m_thread && !m_thread->isWaitingForJoin()) { + THROW_APP_EXCEPTION(err::kappe_disinfection_state_is_wrong, ""); + } + + if (m_dics->WaterSensor_readDeviceBottom()) { + THROW_APP_EXCEPTION(err::kappe_the_bottom_of_the_device_has_water, ""); + } + + if (m_thread) { m_thread->join(); m_thread = nullptr; @@ -37,59 +63,65 @@ void AddLiquidService::start(int stopatg) { m_workstate = kaddingLiquid; m_thread.reset(new Thread("addLiquid", [this, stopatg]() { + ThisThread thisThread; + bool errorflag = false; + try { - addLiquidWork(stopatg); + addLiquidWork(stopatg, errorflag); } catch (const appexception& e) { logger->error("addLiquidWork exception: {}", e.what()); DS->setAppExceptionFlag(e); } + logger->info("empty line liquid done"); + + if (!errorflag && !thisThread.getExitFlag()) { + GET_SERVICE(IflytopFrontEndService)->sendPrompt("加液完成"); + } m_workstate = kidle; })); // logger->info("start add liquid success"); } -void AddLiquidService::addLiquidWork(int stopatg) { +void AddLiquidService::addLiquidWork(int stopatg, bool& errorflag) { ThisThread thisThread; /** * @brief 开始加液 */ logger->info("start add liquid"); - m_dcs->AddLiquidPump_addLiquid(); + m_dics->AddLiquidPump_addLiquid(); while (!thisThread.getExitFlag()) { int32_t nowvolume = m_dwus->getWeight(); logger->info("replenishingFluids {}g", nowvolume); if (nowvolume > stopatg) { break; } + + if (m_dics->WaterSensor_readDeviceBottom()) { + logger->error("the bottom of the device has water"); + AppEventBus::ins()->push(make_shared(err::kappe_the_bottom_of_the_device_has_water)); + errorflag = true; + m_dics->AddLiquidPump_stop(); + return; + } + thisThread.sleepForMs(300); } - m_dcs->AddLiquidPump_stop(); + m_dics->AddLiquidPump_stop(); /** * @brief 排空管路 */ m_workstate = kemptyLineLiquid; logger->info("start drain the liquid from the line"); - m_dcs->SprayPump_startInRPM(-PORT.getEmptyPipeSprayPumpRPM()); + m_dics->SprayPump_startInRPM(-PORT.getEmptyPipeSprayPumpRPM()); thisThread.sleepForMs(1000); - m_dcs->AddLiquidPump_run(-23); // @TODO:提取常数到系统配置中 -#define EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES 1000 + m_dics->AddLiquidPump_run(-23); // @TODO:提取常数到系统配置中 for (size_t i = 0; i < EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES; i++) { if (thisThread.getExitFlag()) break; thisThread.sleepForMs(100); } - m_dcs->AddLiquidPump_stop(); - m_dcs->SprayPump_stop(); - - /** - * @brief 加液完成 - */ - logger->info("empty line liquid done"); - m_workstate = kidle; - - if (!thisThread.getExitFlag()) { - GET_SERVICE(IflytopFrontEndService)->sendPrompt("加液完成"); - } + m_dics->AddLiquidPump_stop(); + m_dics->SprayPump_stop(); } void AddLiquidService::stop() { diff --git a/appsrc/service/app/add_liquid_service.hpp b/appsrc/service/app/add_liquid_service.hpp index bc3103c..46473ad 100644 --- a/appsrc/service/app/add_liquid_service.hpp +++ b/appsrc/service/app/add_liquid_service.hpp @@ -56,7 +56,7 @@ class AddLiquidService : public enable_shared_from_this { shared_ptr m_db; shared_ptr m_ds; shared_ptr m_gConfig; - shared_ptr m_dcs; + shared_ptr m_dics; shared_ptr m_dwus; state_t m_workstate = kidle; @@ -76,7 +76,7 @@ class AddLiquidService : public enable_shared_from_this { void fn_getServiceConfig(shared_ptr cxt); private: - void addLiquidWork(int stopatg); + void addLiquidWork(int stopatg, bool& errorflag); }; } // namespace iflytop diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp index 8576a95..79aa427 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -186,7 +186,7 @@ void DisinfectionCtrlService::checkBeforeStart() { THROW_APP_EXCEPTION(err::kappe_sensor_is_pre_hearting, ""); } - if (m_thread->isWaitingForJoin()) { + if (m_thread&&!m_thread->isWaitingForJoin()) { THROW_APP_EXCEPTION(err::kappe_disinfection_state_is_wrong, ""); } diff --git a/appsrc/service/app/drain_liquid_service.cpp b/appsrc/service/app/drain_liquid_service.cpp index a12358c..e7030d1 100644 --- a/appsrc/service/app/drain_liquid_service.cpp +++ b/appsrc/service/app/drain_liquid_service.cpp @@ -18,6 +18,26 @@ void DrainLiquidService::start() { THROW_APP_EXCEPTION(getDeviceBusyReason(nowstate), ""); } + if (DS->getAppExceptionFlag()) { + THROW_APP_EXCEPTION(err::kappe_exception_flag_is_setted, ""); + } + + if (DS->getDeviceState() != DeviceState::Idle) { + THROW_APP_EXCEPTION(err::kappe_state_is_busy, ""); + } + + if (zsteady_clock().gets() < SENSOR_PREHEART_TIME_S) { + THROW_APP_EXCEPTION(err::kappe_sensor_is_pre_hearting, ""); + } + + if (m_thread && !m_thread->isWaitingForJoin()) { + THROW_APP_EXCEPTION(err::kappe_disinfection_state_is_wrong, ""); + } + + if (m_dics->WaterSensor_readDeviceBottom()) { + THROW_APP_EXCEPTION(err::kappe_the_bottom_of_the_device_has_water, ""); + } + if (m_thread) { m_thread->join(); m_thread = nullptr; @@ -59,8 +79,8 @@ void DrainLiquidService::fn_getServiceConfig(shared_ptr cxt) void DrainLiquidService::workThread() { ThisThread thisThread; - m_dcs->AddLiquidPump_drainLiquid(); - m_dcs->SprayPump_startInRPM(-PORT.getEmptyPipeSprayPumpRPM()); + m_dics->AddLiquidPump_drainLiquid(); + m_dics->SprayPump_startInRPM(-PORT.getEmptyPipeSprayPumpRPM()); logger->info("startDraining "); auto startdrainingtime = zsteady_clock().now(); @@ -76,6 +96,11 @@ void DrainLiquidService::workThread() { volumeReachZeroFlag = true; } + if (m_dics->WaterSensor_readDeviceBottom()) { + AppEventBus::ins()->push(make_shared(err::kappe_the_bottom_of_the_device_has_water)); + break; + } + if (volumeReachZeroFlag) { logger->info("stopDraining after {} s", DRAINLIQUID_EXT_TIME_S - zsteady_clock().elapsedTimeS(volumeReachZeroTime)); if (zsteady_clock().elapsedTimeS(volumeReachZeroTime) > DRAINLIQUID_EXT_TIME_S) { @@ -85,11 +110,8 @@ void DrainLiquidService::workThread() { thisThread.sleepForMs(500); } - logger->info("stopDraining"); - m_dcs->AddLiquidPump_stop(); - m_dcs->SprayPump_stop(); - if (!thisThread.getExitFlag()) { - GET_SERVICE(IflytopFrontEndService)->sendPrompt("排液完成"); - } + logger->info("stopDraining"); + m_dics->AddLiquidPump_stop(); + m_dics->SprayPump_stop(); } diff --git a/appsrc/service/app/drain_liquid_service.hpp b/appsrc/service/app/drain_liquid_service.hpp index d0967dd..f93fa41 100644 --- a/appsrc/service/app/drain_liquid_service.hpp +++ b/appsrc/service/app/drain_liquid_service.hpp @@ -49,7 +49,7 @@ class DrainLiquidService : public enable_shared_from_this { shared_ptr m_db; shared_ptr m_ds; shared_ptr m_gConfig; - shared_ptr m_dcs; + shared_ptr m_dics; shared_ptr m_dwus; state_t m_workstate = kidle; diff --git a/appsrc/service/disinfection_logs_service.cpp b/appsrc/service/disinfection_logs_service.cpp index 73915bf..2884312 100644 --- a/appsrc/service/disinfection_logs_service.cpp +++ b/appsrc/service/disinfection_logs_service.cpp @@ -159,8 +159,9 @@ void DisinfectionLogsService::finishDisinfectionSession() { * @brief * 1.创建打印文件缓存 * 2.创建PDF文件缓存 - * */ + + clearRecordFiles(); }