You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
266 lines
7.8 KiB
266 lines
7.8 KiB
#include "disinfection_ctl_service.hpp"
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
/**
|
|
* @brief
|
|
* 流程
|
|
* 预热:
|
|
*
|
|
* 风机开
|
|
* 1s
|
|
* 空压机
|
|
* 1s
|
|
* 蠕动泵
|
|
* 1s
|
|
*
|
|
*
|
|
* 关蠕动泵
|
|
* 1s
|
|
* 关空压机
|
|
* 1s
|
|
* 关风机
|
|
*
|
|
*/
|
|
|
|
#define PRE_HEAT_TIME (5 * 60)
|
|
|
|
void DisinfectionCtrlService::drainingPump_open() { m_zcanHost->pumpctrl_c1004(1, 100, -300, 1, 20); }
|
|
void DisinfectionCtrlService::drainingPump_close() { m_zcanHost->pumpctrl_c1004(1, 100, 0, 1, 20); }
|
|
|
|
void DisinfectionCtrlService::replenishingFluidsPump_open() { m_zcanHost->pumpctrl_c1004(1, 100, 300, 1, 20); }
|
|
void DisinfectionCtrlService::replenishingFluidsPump_close() { m_zcanHost->pumpctrl_c1004(1, 100, 0, 1, 20); }
|
|
|
|
void DisinfectionCtrlService::sprayLiquidPump_open() { m_zcanHost->pumpctrl_c1004(2, 100, 200, 1, 15); }
|
|
void DisinfectionCtrlService::sprayLiquidPump_close() { m_zcanHost->pumpctrl_c1004(2, 100, 0, 1, 15); }
|
|
|
|
void DisinfectionCtrlService::airCompressor(bool val) {
|
|
if (val) {
|
|
m_zcanHost->writeio(0, 1);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(1, 1);
|
|
} else {
|
|
m_zcanHost->writeio(1, 0);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(0, 0);
|
|
}
|
|
}
|
|
|
|
void DisinfectionCtrlService::blower_setPower(bool val) {
|
|
if (val) {
|
|
m_zcanHost->writeio(2, 1);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(3, 1);
|
|
} else {
|
|
m_zcanHost->writeio(3, 0);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(2, 0);
|
|
}
|
|
}
|
|
void DisinfectionCtrlService::heartingPlate_setPower(bool val) {
|
|
if (val) {
|
|
m_zcanHost->writeio(4, 1);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(5, 1);
|
|
} else {
|
|
m_zcanHost->writeio(5, 0);
|
|
usleep(500 * 100);
|
|
m_zcanHost->writeio(4, 0);
|
|
}
|
|
}
|
|
|
|
DisinfectionCtrlService::DisinfectionCtrlService() {}
|
|
|
|
string DisinfectionCtrlService::createDisinfectionID() {
|
|
struct tm tm = {0};
|
|
|
|
time_t t = time(nullptr);
|
|
if (t == -1) {
|
|
logger->error("time(nullptr) failed");
|
|
exit(-1);
|
|
}
|
|
struct tm* tmp = localtime_r(&t, &tm);
|
|
if (!tmp) {
|
|
logger->error("localtime_r failed");
|
|
exit(-1);
|
|
}
|
|
// tm = *utctime::tm_increment_hour(&tm, 8);
|
|
// logger->info("trace sendmsg_startCapture {}:{}", __FILE__, __LINE__);
|
|
return fmt::format("{:0>4}-{:0>2}{:0>2}-{:0>2}{:0>2}{:0>2}", tm.tm_year + 1900, //
|
|
tm.tm_mon + 1, //
|
|
tm.tm_mday, //
|
|
tm.tm_hour, //
|
|
tm.tm_min, tm.tm_sec);
|
|
}
|
|
|
|
void DisinfectionCtrlService::initialize() {
|
|
GET_TO_SERVICE(m_zcanHost);
|
|
GET_TO_SERVICE(m_sensorDataScan);
|
|
|
|
drainingPump_close();
|
|
replenishingFluidsPump_close();
|
|
sprayLiquidPump_close();
|
|
|
|
heartingPlate_setPower(false);
|
|
blower_setPower(false);
|
|
airCompressor(false);
|
|
}
|
|
void DisinfectionCtrlService::startDisinfection(int loglevel, float roomVol) {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
if (m_disinfectionThread) {
|
|
stopDisinfection();
|
|
}
|
|
|
|
m_disinfectionID = createDisinfectionID();
|
|
// m_remaintime = loglevel * 20 * 60; // 计算总的加热时间
|
|
m_remaintime = PRE_HEAT_TIME + loglevel * 20 * 60 * (roomVol / 20.0); // 计算总的加热时间
|
|
m_disinfectionWorkState = 1;
|
|
|
|
m_disinfectionThread.reset(new Thread("m_disinfectionThread", [this, roomVol, loglevel]() {
|
|
ThisThread thisThread;
|
|
// bool preHeartFinishedFlag = false;
|
|
|
|
logger->info("startDisinfection {} {} {}", loglevel, roomVol, m_disinfectionID);
|
|
|
|
auto starttime = zsteady_clock().now();
|
|
heartingPlate_setPower(true);
|
|
m_preheatFlag = 1;
|
|
while (!thisThread.getExitFlag()) {
|
|
thisThread.sleepForMs(1000);
|
|
if (m_disinfectionWorkState == 2) {
|
|
logger->info("disinfection paused {} {}", m_disinfectionID, m_remaintime);
|
|
continue;
|
|
}
|
|
|
|
m_remaintime--;
|
|
if (m_remaintime == 0) {
|
|
logger->info("disinfection finished {}", m_disinfectionID);
|
|
break;
|
|
}
|
|
|
|
logger->info("disinfection running {} {}s preheatFlag:{}", m_disinfectionID, m_remaintime, m_preheatFlag);
|
|
|
|
if (m_preheatFlag && zsteady_clock().elapsedTimeS(starttime) > PRE_HEAT_TIME) {
|
|
logger->info("preheat finished {}", m_disinfectionID);
|
|
blower_setPower(true);
|
|
usleep(1000 * 1000);
|
|
airCompressor(true);
|
|
usleep(1000 * 1000);
|
|
sprayLiquidPump_open();
|
|
m_preheatFlag = false;
|
|
}
|
|
}
|
|
|
|
m_remaintime = 0;
|
|
logger->info("stop disinfection {}", m_disinfectionID);
|
|
|
|
sprayLiquidPump_close();
|
|
usleep(1000 * 1000);
|
|
airCompressor(false);
|
|
usleep(1000 * 1000);
|
|
blower_setPower(false);
|
|
usleep(1000 * 1000);
|
|
heartingPlate_setPower(false);
|
|
m_disinfectionWorkState = 3;
|
|
}));
|
|
}
|
|
|
|
int DisinfectionCtrlService::getDisinfectionWorkState() { return m_disinfectionWorkState; }
|
|
|
|
void DisinfectionCtrlService::pauseDisinfection() { m_disinfectionWorkState = 2; }
|
|
void DisinfectionCtrlService::continueDisinfection() { m_disinfectionWorkState = 1; }
|
|
void DisinfectionCtrlService::stopDisinfection() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
m_disinfectionWorkState = 0;
|
|
}
|
|
|
|
int32_t DisinfectionCtrlService::getEstimatedRemainingTimeS() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
return m_remaintime;
|
|
}
|
|
string DisinfectionCtrlService::getDisinfectionID() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
return m_disinfectionID;
|
|
}
|
|
|
|
// 加液
|
|
void DisinfectionCtrlService::startReplenishingFluids(int stopatg) {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
int32_t nowvolume = m_sensorDataScan->getDisinfectantVolume_g();
|
|
if (nowvolume > stopatg) {
|
|
logger->warn("start Replenishing fail, nowvolume {} > stopatg {}", nowvolume, stopatg);
|
|
return;
|
|
}
|
|
|
|
m_disinfectionThread.reset(new Thread("disinfectionThread", [this, stopatg]() {
|
|
ThisThread thisThread;
|
|
replenishingFluidsPump_open();
|
|
logger->info("startReplenishingFluids {}g", stopatg);
|
|
while (!thisThread.getExitFlag()) {
|
|
int32_t nowvolume = m_sensorDataScan->getDisinfectantVolume_g();
|
|
logger->info("replenishingFluids {}g", nowvolume);
|
|
if (nowvolume > stopatg) {
|
|
break;
|
|
}
|
|
|
|
if (nowvolume > 4500) {
|
|
logger->warn("replenishingFluids reach full level {}g", nowvolume);
|
|
break;
|
|
}
|
|
|
|
thisThread.sleepForMs(1000);
|
|
}
|
|
logger->info("stopReplenishingFluids");
|
|
replenishingFluidsPump_close();
|
|
m_replenishingFluidsWorkState = 0;
|
|
}));
|
|
|
|
//
|
|
m_replenishingFluidsWorkState = 1;
|
|
logger->info("startReplenishingFluids ");
|
|
}
|
|
// 停止加液
|
|
void DisinfectionCtrlService::stopReplenishingFluids() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
|
|
logger->info("stopReplenishingFluids");
|
|
replenishingFluidsPump_close();
|
|
m_replenishingFluidsWorkState = 0;
|
|
}
|
|
// 开始排液
|
|
void DisinfectionCtrlService::startDraining() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
|
|
logger->info("startDraining");
|
|
drainingPump_open();
|
|
m_drainingWorkState = 1;
|
|
}
|
|
// 停止排液体
|
|
void DisinfectionCtrlService::stopDraining() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
logger->info("stopDraining");
|
|
m_drainingWorkState = 0;
|
|
drainingPump_close();
|
|
}
|
|
int DisinfectionCtrlService::getReplenishingFluidsWorkState() { return m_replenishingFluidsWorkState; }
|
|
int DisinfectionCtrlService::getDrainingWorkState() { return m_drainingWorkState; }
|