|
|
@ -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<AppWarningPromoptEvent>(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() { |
|
|
|