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.

90 lines
3.7 KiB

1 year ago
1 year ago
  1. #include "disinfection_printer_service.hpp"
  2. using namespace iflytop;
  3. static string format_zsystem_tp(zsystem_tp tp) {
  4. time_t time = system_clock().to_time_t(tp);
  5. struct tm tm = {0};
  6. localtime_r(&time, &tm);
  7. return fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tm.tm_year + 1900, //
  8. tm.tm_mon + 1, //
  9. tm.tm_mday, //
  10. tm.tm_hour, //
  11. tm.tm_min, tm.tm_sec);
  12. }
  13. void DisinfectionPrinterService::initialize() {
  14. logger->info("initialize");
  15. GET_TO_SERVICE(m_deviceIoControlService);
  16. m_workThread.reset(new Thread("DisinfectionPrinterServiceThread", [this]() {
  17. while (true) {
  18. shared_ptr<DisinfectionPrinterTask> task;
  19. {
  20. lock_guard<recursive_mutex> lock(lock_);
  21. if (!tasks.empty()) {
  22. task = tasks.front();
  23. tasks.pop();
  24. }
  25. }
  26. if (!task) {
  27. this_thread::sleep_for(chrono::milliseconds(1000));
  28. continue;
  29. }
  30. printTask(task);
  31. }
  32. }));
  33. }
  34. void DisinfectionPrinterService::pushPrintTask(shared_ptr<DisinfectionPrinterTask> task) {
  35. lock_guard<recursive_mutex> lock(lock_);
  36. logger->info("pushPrintTask");
  37. tasks.push(task);
  38. }
  39. void DisinfectionPrinterService::printTask(shared_ptr<DisinfectionPrinterTask> task) {
  40. /**
  41. * @brief
  42. */
  43. auto dio = m_deviceIoControlService;
  44. int32_t totaltime_s = zsystem_clock().tpToS(task->complete_tp) - zsystem_clock().tpToS(task->start_tp);
  45. dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n"));
  46. dio->printerPrintf(fmt::format(" 全思美特\n"));
  47. dio->printerPrintf(fmt::format("操作人 {}\n", task->usr));
  48. dio->printerPrintf(fmt::format("开始时间 {}\n", format_zsystem_tp(task->start_tp)));
  49. dio->printerPrintf(fmt::format("结束时间 {}\n", format_zsystem_tp(task->complete_tp)));
  50. dio->printerPrintf(fmt::format("总耗时 {}:{}\n", totaltime_s / 60, totaltime_s % 60));
  51. dio->printerPrintf(fmt::format("消毒液使用 {}g\n", task->disinfectantUsage));
  52. dio->printerPrintf(fmt::format("目标LOG {}\n", task->targetLog));
  53. dio->printerPrintf(fmt::format("实际LOG {}\n", task->actualLog));
  54. dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n"));
  55. disinfection_state_t state = kstate_idle;
  56. for (size_t i = 0; i < task->stateSnapshotList.size(); i++) {
  57. disinfection_state_t now_state = task->stateSnapshotList[i]->state;
  58. shared_ptr<StateSnapshot> ss = task->stateSnapshotList[i];
  59. if (now_state != state) {
  60. dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time)));
  61. if (now_state == kstate_preheat) {
  62. dio->printerPrintf(fmt::format("预热中...\n"));
  63. } else if (now_state == kstate_preheat) {
  64. dio->printerPrintf(fmt::format("消毒中...\n"));
  65. } else if (now_state == kstate_degradation) {
  66. dio->printerPrintf(fmt::format("降解中...\n"));
  67. } else if (now_state == kstate_finished) {
  68. dio->printerPrintf(fmt::format("结束...\n"));
  69. }
  70. dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
  71. } else {
  72. if (now_state == kstate_degradation) {
  73. dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time)));
  74. dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
  75. }
  76. }
  77. }
  78. dio->printerPrintf(fmt::format("\n"));
  79. dio->printerPrintf(fmt::format("\n"));
  80. dio->printerPrintf(fmt::format("\n"));
  81. }