Browse Source

update

storage-in-realtime
zhaohe 12 months ago
parent
commit
7bf99d9ae8
  1. 70
      appsrc/service/app/add_liquid_service.cpp
  2. 4
      appsrc/service/app/add_liquid_service.hpp
  3. 2
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp
  4. 38
      appsrc/service/app/drain_liquid_service.cpp
  5. 2
      appsrc/service/app/drain_liquid_service.hpp
  6. 3
      appsrc/service/disinfection_logs_service.cpp

70
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<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() {

4
appsrc/service/app/add_liquid_service.hpp

@ -56,7 +56,7 @@ class AddLiquidService : public enable_shared_from_this<AddLiquidService> {
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
shared_ptr<DeviceIoControlService> m_dcs;
shared_ptr<DeviceIoControlService> m_dics;
shared_ptr<DisinfectantWeightUpdateService> m_dwus;
state_t m_workstate = kidle;
@ -76,7 +76,7 @@ class AddLiquidService : public enable_shared_from_this<AddLiquidService> {
void fn_getServiceConfig(shared_ptr<MsgProcessContext> cxt);
private:
void addLiquidWork(int stopatg);
void addLiquidWork(int stopatg, bool& errorflag);
};
} // namespace iflytop

2
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, "");
}

38
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<MsgProcessContext> 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<AppWarningPromoptEvent>(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();
}

2
appsrc/service/app/drain_liquid_service.hpp

@ -49,7 +49,7 @@ class DrainLiquidService : public enable_shared_from_this<DrainLiquidService> {
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
shared_ptr<DeviceIoControlService> m_dcs;
shared_ptr<DeviceIoControlService> m_dics;
shared_ptr<DisinfectantWeightUpdateService> m_dwus;
state_t m_workstate = kidle;

3
appsrc/service/disinfection_logs_service.cpp

@ -159,8 +159,9 @@ void DisinfectionLogsService::finishDisinfectionSession() {
* @brief
* 1.
* 2.PDF文件缓存
*
*/
clearRecordFiles();
}

Loading…
Cancel
Save