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.

257 lines
12 KiB

12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
12 months ago
9 months ago
9 months ago
8 months ago
9 months ago
1 month ago
1 month ago
1 month ago
12 months ago
  1. #include "dmapp.hpp"
  2. #include "board/hal/zhal_initer.hpp"
  3. //
  4. #include "dmapp_controler/blower_controller.hpp"
  5. #include "dmapp_service/blower_ctrl_service.hpp"
  6. #include "dmapp_controler/air_compressor_controller.hpp"
  7. #include "dmapp_service/air_compressor_ctrl_service.hpp"
  8. using namespace iflytop;
  9. using namespace transmit_disfection_protocol;
  10. #define TAG "DMAPP"
  11. //
  12. // 参考 https://iflytop1.feishu.cn/wiki/GF8LwUjeJiNJ9DkcuEEcZLZMnTf?fromScene=spaceOverview 进行配置
  13. //
  14. DisinfectionApp* DisinfectionApp::ins() {
  15. static DisinfectionApp instance;
  16. return &instance;
  17. }
  18. const char* DisinfectionApp::getName() { return "DisinfectionApp"; }
  19. void DisinfectionApp::initialize() {
  20. int btid = PublicBoard::ins()->getBoardTypeId();
  21. // only support
  22. // large space disinfection machine,
  23. // small space disinfection machine,
  24. // pipe disinfection machine,
  25. // DT600B,
  26. ZASSERT(PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B() || PORT::isDrawBarDM());
  27. /***********************************************************************************************************************
  28. * *
  29. ***********************************************************************************************************************/
  30. if (PORT::isPowerCtrlBoard() //
  31. && (PORT::isLargeSpaceDM() || //
  32. PORT::isSamllSpaceDM() || //
  33. PORT::isPipeDM() || //
  34. PORT::isDT600B() || //
  35. PORT::isDrawBarDM())) {
  36. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  37. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_9);
  38. }
  39. /***********************************************************************************************************************
  40. * *
  41. ***********************************************************************************************************************/
  42. if (BlowerCtrlService::isSupport()) {
  43. BlowerCtrlService::initialize(); // 初始化风机控制硬件
  44. BlowerController::initialize(); // 解析相关协议
  45. }
  46. /***********************************************************************************************************************
  47. * *
  48. ***********************************************************************************************************************/
  49. if (AirCompressorCtrlService::isSupport()) {
  50. AirCompressorCtrlService::initialize(); // 初始化空压机控制硬件
  51. AirCompressorController::initialize(); // 解析相关协议
  52. }
  53. /***********************************************************************************************************************
  54. * *
  55. ***********************************************************************************************************************/
  56. // null
  57. //
  58. /***********************************************************************************************************************
  59. * H2O2传感器 *
  60. ***********************************************************************************************************************/
  61. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  62. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  63. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  64. osDelay(3000);
  65. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3);
  66. }
  67. /***********************************************************************************************************************
  68. * *
  69. ***********************************************************************************************************************/
  70. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  71. ZLOGI(TAG, "WaterSensor init");
  72. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  73. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  74. REG_LAMADA_FN(kfn_device_bottom_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, deviceBottomWS.read()); });
  75. REG_LAMADA_FN(kfn_evaporation_tank_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, evaporationBinWS.read()); });
  76. }
  77. /***********************************************************************************************************************
  78. * TMC电机初始化 *
  79. ***********************************************************************************************************************/
  80. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  81. // TMC电机初始化
  82. ZLOGI(TAG, "TMCMotorGroup init");
  83. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  84. tmcPowerGroup.initialize(PB2, {&hspi1, PA4 /*cs*/, PB12 /*en*/}, {&hspi1, PC4 /*cs*/, PB13 /*en*/});
  85. }
  86. /***********************************************************************************************************************
  87. * *
  88. ***********************************************************************************************************************/
  89. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  90. // 三色指示灯初始化
  91. ZLOGI(TAG, "WarningLightDriver init");
  92. wlDriver.initialize(PD8, PD7, PD9, PD10);
  93. }
  94. /***********************************************************************************************************************
  95. * *
  96. ***********************************************************************************************************************/
  97. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  98. ZLOGI(TAG, "PXXPSBus init");
  99. osDelay(1500); // 等待传感器上电
  100. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  101. psBus.initialize(&huart3);
  102. }
  103. /***********************************************************************************************************************
  104. * *
  105. ***********************************************************************************************************************/
  106. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  107. ZLOGI(TAG, "ProportionalValveCtrl init");
  108. ZHALIniter::HUART2_INIT(PD5, PD6, 9600, UART_STOPBITS_1);
  109. proportionalValveCtrl.initialize(&huart2);
  110. }
  111. /***********************************************************************************************************************
  112. * *
  113. ***********************************************************************************************************************/
  114. // kAirLeakTestMode_disinfection
  115. // kAirLeakTestMode_inflation
  116. // kAirLeakTestMode_leakTest
  117. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  118. static air_leak_test_mode_t airLeakTestMode = kAirLeakTestMode_disinfection;
  119. if (PORT::isPipeDM()) {
  120. static ZGPIO eValve0;
  121. static ZGPIO eValve1;
  122. static ZGPIO eValve2;
  123. eValve0.initAsOutput(PD14, kxs_gpio_nopull, true, false);
  124. eValve1.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  125. eValve2.initAsOutput(PC6, kxs_gpio_nopull, true, false); // 空气通道电磁阀
  126. REG_LAMADA_FN(kfn_air_leak_test_set_mode, [&](ProcessContext* cxt) {
  127. if (GET_PARAM(0) == kAirLeakTestMode_disinfection) {
  128. eValve2.write(0); // 内管路
  129. eValve0.write(0); // 联通
  130. eValve1.write(0); // 联通
  131. } else if (GET_PARAM(0) == kAirLeakTestMode_inflation) {
  132. eValve2.write(1); // 联通空气
  133. eValve0.write(0); // 联通
  134. eValve1.write(0); // 联通
  135. } else if (GET_PARAM(0) == kAirLeakTestMode_leakTest) {
  136. eValve2.write(0); // 内管路
  137. eValve0.write(1); // 封闭
  138. eValve1.write(1); // 封闭
  139. }
  140. airLeakTestMode = (air_leak_test_mode_t)GET_PARAM(0);
  141. zcanbus_send_ack(cxt->packet, NULL, 0);
  142. });
  143. REG_LAMADA_FN(kfn_air_leak_test_get_mode, [&](ProcessContext* cxt) {
  144. int32_t mode = airLeakTestMode;
  145. zcanbus_send_ack(cxt->packet, mode);
  146. });
  147. } else if (PORT::isDrawBarDM()) {
  148. static ZGPIO eValve0;
  149. static ZGPIO eValve1;
  150. eValve0.initAsOutput(PD15, kxs_gpio_nopull, false, false);
  151. eValve1.initAsOutput(PC6, kxs_gpio_nopull, false, false);
  152. REG_LAMADA_FN(kfn_air_leak_test_set_mode, [&](ProcessContext* cxt) {
  153. if (GET_PARAM(0) == kAirLeakTestMode_disinfection) {
  154. eValve0.write(1);
  155. eValve1.write(1);
  156. } else if (GET_PARAM(0) == kAirLeakTestMode_inflation) {
  157. eValve0.write(0);
  158. eValve1.write(1);
  159. } else if (GET_PARAM(0) == kAirLeakTestMode_leakTest) {
  160. eValve0.write(1);
  161. eValve1.write(0);
  162. }
  163. airLeakTestMode = (air_leak_test_mode_t)GET_PARAM(0);
  164. zcanbus_send_ack(cxt->packet, NULL, 0);
  165. });
  166. REG_LAMADA_FN(kfn_air_leak_test_get_mode, [&](ProcessContext* cxt) {
  167. int32_t mode = airLeakTestMode;
  168. zcanbus_send_ack(cxt->packet, mode);
  169. });
  170. }
  171. }
  172. /**
  173. * @brief
  174. *
  175. */
  176. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  177. static ZGPIO valve;
  178. valve.initAsOutput(PB3, kxs_gpio_nopull, true, false);
  179. REG_LAMADA_FN(kfn_set_add_fluid_channel_selector_valve, [&](ProcessContext* cxt) {
  180. if (GET_PARAM(0) == 0) {
  181. valve.write(0);
  182. } else {
  183. valve.write(1);
  184. }
  185. zcanbus_send_ack(cxt->packet, NULL, 0);
  186. });
  187. }
  188. /**
  189. * @brief
  190. */
  191. if (PORT::isLiquidCtrlBoard() && (PORT::isDT600B())) {
  192. // 初始化
  193. static ZGPIO io0;
  194. static bool io0enable = false;
  195. static ZGPIO io1;
  196. static bool io1enable = false;
  197. static ZGPIO io2;
  198. static bool io2enable = false;
  199. if (PORT::isDT600B()) {
  200. io0.initAsInput(PD11, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  201. io0enable = true;
  202. }
  203. if (io0enable || io1enable || io2enable) {
  204. REG_LAMADA_FN(kfn_disinfectant_bucket_level_sensor_read_level, [&](ProcessContext* cxt) {
  205. int32_t liquid_level_state = 0;
  206. bool io0state = false;
  207. bool io1state = false;
  208. bool io2state = false;
  209. if (io0enable) io0state = io0.read();
  210. if (io1enable) io1state = io1.read();
  211. if (io2enable) io2state = io2.read();
  212. if (io2state) {
  213. liquid_level_state = 3; // 液位最高
  214. } else if (io1state) {
  215. liquid_level_state = 2; // 液位中等
  216. } else if (io0state) {
  217. liquid_level_state = 1; // 液位最低
  218. } else {
  219. liquid_level_state = 0; // 无液位
  220. }
  221. zcanbus_send_ack(cxt->packet, liquid_level_state);
  222. });
  223. }
  224. }
  225. }
  226. /***********************************************************************************************************************
  227. * PROTOCOL_BIND *
  228. ***********************************************************************************************************************/