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.
138 lines
4.3 KiB
138 lines
4.3 KiB
#include "disinfection_ctl_service.hpp"
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
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); }
|
|
void DisinfectionCtrlService::startDisinfection(int loglevel, float roomVol) {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
if (m_disinfectionThread) {
|
|
stopDisinfection();
|
|
}
|
|
|
|
m_disinfectionID = createDisinfectionID();
|
|
m_remaintime = 20 * 60;
|
|
m_isDisinfectionRunning = true;
|
|
logger->info("startDisinfection {} {} {}", loglevel, roomVol, m_disinfectionID);
|
|
m_drainingWorkState = 1;
|
|
|
|
m_zcanHost->writeio(0, 1);
|
|
m_zcanHost->writeio(1, 1);
|
|
sleep(1);
|
|
m_zcanHost->writeio(2, 1);
|
|
m_zcanHost->writeio(3, 1);
|
|
sleep(1);
|
|
m_zcanHost->writeio(4, 1);
|
|
m_zcanHost->writeio(5, 1);
|
|
sleep(1);
|
|
m_zcanHost->pumpctrl_c1004(2, 300, 1000);
|
|
|
|
m_disinfectionThread.reset(new Thread("m_disinfectionThread", [this, loglevel]() {
|
|
// do something
|
|
// m_disinfectionThread->detach();
|
|
ThisThread thisThread;
|
|
|
|
// 发送开始拍照消息
|
|
logger->info("start disinfection {}", m_disinfectionID);
|
|
|
|
while (!thisThread.getExitFlag()) {
|
|
m_remaintime--;
|
|
if (m_remaintime == 0) {
|
|
logger->info("disinfection finished {}", m_disinfectionID);
|
|
break;
|
|
}
|
|
logger->info("disinfection running {} {}s", m_disinfectionID, m_remaintime);
|
|
thisThread.sleepForMs(1000);
|
|
}
|
|
|
|
{ m_isDisinfectionRunning = false; }
|
|
}));
|
|
}
|
|
|
|
int DisinfectionCtrlService::getDisinfectionWorkState() { return m_disinfectionWorkState; }
|
|
int DisinfectionCtrlService::getReplenishingFluidsWorkState() { return m_replenishingFluidsWorkState; }
|
|
int DisinfectionCtrlService::getDrainingWorkState() { return m_drainingWorkState; }
|
|
|
|
void DisinfectionCtrlService::pauseDisinfection() { m_drainingWorkState = 2; }
|
|
void DisinfectionCtrlService::continueDisinfection() { m_drainingWorkState = 1; }
|
|
void DisinfectionCtrlService::stopDisinfection() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
if (m_disinfectionThread) {
|
|
m_disinfectionThread->join();
|
|
m_disinfectionThread = nullptr;
|
|
}
|
|
m_remaintime = 0;
|
|
logger->info("stop disinfection {}", m_disinfectionID);
|
|
|
|
m_zcanHost->writeio(0, 0);
|
|
m_zcanHost->writeio(1, 0);
|
|
sleep(1);
|
|
m_zcanHost->writeio(2, 0);
|
|
m_zcanHost->writeio(3, 0);
|
|
sleep(1);
|
|
m_zcanHost->writeio(4, 0);
|
|
m_zcanHost->writeio(5, 0);
|
|
sleep(1);
|
|
m_zcanHost->pumpctrl_c1004(2, 300, 0);
|
|
m_drainingWorkState = 0;
|
|
}
|
|
bool DisinfectionCtrlService::isDisinfectionRunning() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
return m_isDisinfectionRunning;
|
|
}
|
|
|
|
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() {
|
|
logger->info("startReplenishingFluids");
|
|
m_zcanHost->pumpctrl_c1004(1, 300, 1000);
|
|
m_replenishingFluidsWorkState = 1;
|
|
}
|
|
void DisinfectionCtrlService::stopReplenishingFluids() {
|
|
logger->info("stopReplenishingFluids");
|
|
m_zcanHost->pumpctrl_c1004(1, 300, 0);
|
|
m_replenishingFluidsWorkState = 0;
|
|
}
|
|
|
|
void DisinfectionCtrlService::startDraining() {
|
|
logger->info("startDraining");
|
|
m_zcanHost->pumpctrl_c1004(1, 300, -1000);
|
|
m_replenishingFluidsWorkState = 1;
|
|
}
|
|
void DisinfectionCtrlService::stopDraining() {
|
|
logger->info("stopDraining");
|
|
m_zcanHost->pumpctrl_c1004(1, 300, 0);
|
|
m_replenishingFluidsWorkState = 0;
|
|
}
|