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.

95 lines
3.9 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
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. int32_t total_hours = totaltime_s / 3600;
  46. int32_t total_mins = (totaltime_s % 3600) / 60;
  47. int32_t total_secs = totaltime_s % 60;
  48. dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n"));
  49. dio->printerPrintf(fmt::format(" 全思美特\n"));
  50. dio->printerPrintf(fmt::format("操作人 {}\n", task->usr));
  51. dio->printerPrintf(fmt::format("开始时间 {}\n", format_zsystem_tp(task->start_tp)));
  52. dio->printerPrintf(fmt::format("结束时间 {}\n", format_zsystem_tp(task->complete_tp)));
  53. dio->printerPrintf(fmt::format("总耗时(hh:mm::ss) {}:{}:{}\n", total_hours, total_mins, total_secs));
  54. dio->printerPrintf(fmt::format("消毒液使用 {}g\n", task->disinfectantUsage));
  55. dio->printerPrintf(fmt::format("目标LOG {}\n", task->targetLog));
  56. dio->printerPrintf(fmt::format("实际LOG {}\n", task->actualLog));
  57. dio->printerPrintf(fmt::format("= = = = = = = = = = = = = = = \n"));
  58. disinfection_state_t state = kstate_idle;
  59. for (size_t i = 0; i < task->stateSnapshotList.size(); i++) {
  60. disinfection_state_t now_state = task->stateSnapshotList[i]->state;
  61. shared_ptr<StateSnapshot> ss = task->stateSnapshotList[i];
  62. if (now_state != state) {
  63. dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time)));
  64. if (now_state == kstate_preheat) {
  65. dio->printerPrintf(fmt::format("预热中...\n"));
  66. } else if (now_state == kstate_preheat) {
  67. dio->printerPrintf(fmt::format("消毒中...\n"));
  68. } else if (now_state == kstate_degradation) {
  69. dio->printerPrintf(fmt::format("降解中...\n"));
  70. } else if (now_state == kstate_finished) {
  71. dio->printerPrintf(fmt::format("结束...\n"));
  72. }
  73. dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {:.2f}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
  74. state = now_state;
  75. } else {
  76. if (now_state == kstate_degradation) {
  77. dio->printerPrintf(fmt::format("{}\n", format_zsystem_tp(ss->time)));
  78. dio->printerPrintf(fmt::format("{}ppm {}%RS {}%RH {}Log\n", ss->min_h2o2, ss->max_saturation, ss->max_humid, ss->dloglevel));
  79. }
  80. }
  81. }
  82. dio->printerPrintf(fmt::format("\n"));
  83. dio->printerPrintf(fmt::format("\n"));
  84. dio->printerPrintf(fmt::format("\n"));
  85. }