#include "disinfection_printer_service.hpp" using namespace iflytop; 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 task; { lock_guard 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 task) { lock_guard lock(lock_); logger->info("pushPrintTask"); tasks.push(task); } void DisinfectionPrinterService::printTask(shared_ptr task) { /** * @brief 打印 */ auto dio = m_deviceIoControlService; int32_t totaltime_s = zsystem_clock().tpToS(task->complete_tp) - zsystem_clock().tpToS(task->start_tp); int32_t total_hours = totaltime_s / 3600; int32_t total_mins = (totaltime_s % 3600) / 60; int32_t total_secs = totaltime_s % 60; 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("总耗时(hh:mm::ss) {}:{}:{}\n", total_hours, total_mins, total_secs)); 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 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 {:.2f}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel)); state = now_state; } 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")); }