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.

181 lines
5.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. //
  2. // Created by zwsd
  3. //
  4. #pragma once
  5. #include <fstream>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <memory>
  10. #include <mutex>
  11. #include <set>
  12. #include <sstream>
  13. #include <string>
  14. #include <vector>
  15. #include "db/db_service.hpp"
  16. #include "disinfection_logs_manager.hpp"
  17. #include "iflytop/components/zcanreceiver/zcanhost.hpp"
  18. #include "iflytop/core/core.hpp"
  19. #include "service/device_io_control_service.hpp"
  20. #include "zservice_container/zservice_container.hpp"
  21. /**
  22. * @brief
  23. *
  24. * service: DisinfectionCtrlService
  25. *
  26. * :
  27. * :
  28. * :
  29. * :
  30. *
  31. */
  32. namespace iflytop {
  33. using namespace std;
  34. using namespace core;
  35. class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlService> {
  36. ENABLE_LOGGER(DisinfectionCtrlService);
  37. public:
  38. typedef enum {
  39. kidle = 0,
  40. kpreheat = 1,
  41. kdisinfection = 2,
  42. kdisinfection_take_a_break = 3,
  43. kwait_for_h2o2_down = 4,
  44. kfinished = 5,
  45. } state_t;
  46. private:
  47. unique_ptr<Thread> m_disinfectionThread;
  48. shared_ptr<DeviceIoControlService> m_deviceIoControlService;
  49. shared_ptr<DBService> m_dbService;
  50. shared_ptr<DisinfectionLogsManager> m_disinfectionLogsManager;
  51. recursive_mutex lock_;
  52. int m_disinfectionWorkState = 0;
  53. int m_replenishingFluidsWorkState = 0;
  54. int m_drainingWorkState = 0;
  55. shared_ptr<ZCanHost> m_zcanHost;
  56. class DisinfectionContext {
  57. public:
  58. string m_disinfectionID;
  59. zsteady_tp m_starttp;
  60. zsteady_tp m_lastComputeDvalueTp;
  61. zsteady_tp m_lastlogTp;
  62. DeviceIoControlService::all_h2o2sensor_data_t h2o2data;
  63. // bool m_preheatFlag = false;
  64. // bool stopedflag = false; // 消毒停止标志,但继续等待h2o2浓度下降
  65. int m_remaintime = 0;
  66. float m_targetLoglevel = 0;
  67. float m_nowLoglevel = 0;
  68. float dvalue = 0;
  69. state_t m_state = kidle;
  70. // bool sprayLiquidFlag = false;
  71. int injection_pump_speed;
  72. bool injection_pump_speed_changed = false;
  73. int pre_heat_time_s = 0;
  74. int stoped_gs = 0;
  75. int continued_gs = 0;
  76. int stoped_satur = 0;
  77. int continued_satur = 0;
  78. int stoped_humi = 0;
  79. int continued_humi = 0;
  80. shared_ptr<DisinfectionLogger> csvlogger;
  81. };
  82. public:
  83. DisinfectionContext m_context;
  84. public:
  85. DisinfectionCtrlService();
  86. public:
  87. void initialize();
  88. /**
  89. * @brief
  90. *
  91. * @param loglevel
  92. */
  93. void startDisinfection(int loglevel, //
  94. int injection_pump_speed, //
  95. int stoped_gs, //
  96. int continued_gs, //
  97. int stoped_satur, //
  98. int continued_satur, //
  99. int stoped_humi, //
  100. int continued_humi //
  101. );
  102. void changeDisinfectionParameter(int injection_pump_speed, //
  103. int stoped_gs, //
  104. int continued_gs, //
  105. int stoped_satur, //
  106. int continued_satur, //
  107. int stoped_humi, //
  108. int continued_humi //
  109. );
  110. void stopDisinfection();
  111. int getDisinfectionWorkState();
  112. int getReplenishingFluidsWorkState();
  113. int getDrainingWorkState();
  114. /*******************************************************************************
  115. * *
  116. *******************************************************************************/
  117. void startReplenishingFluids(int stopatg);
  118. void stopReplenishingFluids();
  119. /*******************************************************************************
  120. * *
  121. *******************************************************************************/
  122. void startDraining();
  123. void stopDraining();
  124. /*******************************************************************************
  125. * State *
  126. *******************************************************************************/
  127. bool isDisinfectionRunning();
  128. int32_t getEstimatedRemainingTimeS();
  129. string getDisinfectionID();
  130. bool isPreheatState();
  131. int32_t getPreHeatRaminTimeS();
  132. private:
  133. string createDisinfectionID();
  134. private:
  135. float getDisinfectionDValue(float ppm);
  136. void initContext(DisinfectionContext& context, //
  137. int loglevel, //
  138. float injection_pump_speed, //
  139. float stoped_gs, //
  140. float continued_gs, //
  141. float stoped_satur, //
  142. float continued_satur, //
  143. float stoped_humi, //
  144. float continued_humi //
  145. );
  146. void computeRemainTime(DisinfectionContext& context);
  147. float computeNowLogLevel(DisinfectionContext& context);
  148. void processPreheatState(DisinfectionContext& context);
  149. void processDisinfectionState(DisinfectionContext& context);
  150. void dumpDisinfectionLogs(DisinfectionContext& context);
  151. void dumpDisinfectionLogsToCSV(DisinfectionContext& context);
  152. void finishDisinfection(DisinfectionContext& context);
  153. void disinfectionLoop(bool& breakflag);
  154. };
  155. } // namespace iflytop