5 changed files with 156 additions and 60 deletions
-
76service/disinfection_ctl_service.cpp
-
17service/disinfection_ctl_service.hpp
-
89service/disinfection_printer_service.cpp
-
9service/disinfection_printer_service.hpp
-
25service/disinfection_state.hpp
@ -1,5 +1,90 @@ |
|||
#include "disinfection_printer_service.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
void DisinfectionPrinterService::initialize() {} |
|||
void DisinfectionPrinterService::pushPrintTask(shared_ptr<DisinfectionPrinterTask> task) {} |
|||
static string format_zsystem_tp(zsystem_tp tp) { |
|||
time_t time = system_clock().to_time_t(tp); |
|||
struct tm tm = {0}; |
|||
localtime_r(&time, &tm); |
|||
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 DisinfectionPrinterService::initialize() { |
|||
logger->info("initialize"); |
|||
GET_TO_SERVICE(m_deviceIoControlService); |
|||
|
|||
m_workThread.reset(new Thread("DisinfectionPrinterServiceThread", [this]() { |
|||
while (true) { |
|||
shared_ptr<DisinfectionPrinterTask> task; |
|||
{ |
|||
lock_guard<recursive_mutex> lock(lock_); |
|||
if (!tasks.empty()) { |
|||
task = tasks.front(); |
|||
tasks.pop(); |
|||
} |
|||
} |
|||
if (!task) { |
|||
this_thread::sleep_for(chrono::milliseconds(1000)); |
|||
continue; |
|||
} |
|||
|
|||
printTask(task); |
|||
} |
|||
})); |
|||
} |
|||
void DisinfectionPrinterService::pushPrintTask(shared_ptr<DisinfectionPrinterTask> task) { |
|||
lock_guard<recursive_mutex> lock(lock_); |
|||
logger->info("pushPrintTask"); |
|||
tasks.push(task); |
|||
} |
|||
|
|||
void DisinfectionPrinterService::printTask(shared_ptr<DisinfectionPrinterTask> task) { |
|||
/**
|
|||
* @brief 打印 |
|||
*/ |
|||
auto dio = m_deviceIoControlService; |
|||
int32_t totaltime_s = zsystem_clock().tpToS(task->complete_tp) - zsystem_clock().tpToS(task->start_tp); |
|||
|
|||
dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n")); |
|||
dio->printerPrintf(fmt::format(" 全思美特\n")); |
|||
dio->printerPrintf(fmt::format("操作人 {}\n", task->usr)); |
|||
dio->printerPrintf(fmt::format("开始时间 {}\n", format_zsystem_tp(task->start_tp))); |
|||
dio->printerPrintf(fmt::format("结束时间 {}\n", format_zsystem_tp(task->complete_tp))); |
|||
dio->printerPrintf(fmt::format("总耗时 {}:{}\n", totaltime_s / 60, totaltime_s % 60)); |
|||
dio->printerPrintf(fmt::format("消毒液使用 {}g\n", task->disinfectantUsage)); |
|||
dio->printerPrintf(fmt::format("目标LOG {}\n", task->targetLog)); |
|||
dio->printerPrintf(fmt::format("实际LOG {}\n", task->actualLog)); |
|||
dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n")); |
|||
|
|||
disinfection_state_t state = kstate_idle; |
|||
for (size_t i = 0; i < task->stateSnapshotList.size(); i++) { |
|||
disinfection_state_t now_state = task->stateSnapshotList[i]->state; |
|||
shared_ptr<StateSnapshot> ss = task->stateSnapshotList[i]; |
|||
|
|||
if (now_state != state) { |
|||
dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time))); |
|||
if (now_state == kstate_preheat) { |
|||
dio->printerPrintf(fmt::format("预热中...\n")); |
|||
} else if (now_state == kstate_preheat) { |
|||
dio->printerPrintf(fmt::format("消毒中...\n")); |
|||
} else if (now_state == kstate_degradation) { |
|||
dio->printerPrintf(fmt::format("降解中...\n")); |
|||
} else if (now_state == kstate_finished) { |
|||
dio->printerPrintf(fmt::format("结束...\n")); |
|||
} |
|||
dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel)); |
|||
} else { |
|||
if (now_state == kstate_degradation) { |
|||
dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time))); |
|||
dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
dio->printerPrintf(fmt::format("\n")); |
|||
dio->printerPrintf(fmt::format("\n")); |
|||
dio->printerPrintf(fmt::format("\n")); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue