全司美特-单片机程序
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.

232 lines
9.2 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 year ago
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 year ago
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 year ago
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 year ago
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 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "dmapp.hpp"
  2. /**
  3. * @brief
  4. *
  5. *
  6. *
  7. *
  8. *
  9. * -----
  10. *
  11. * :
  12. * 1.
  13. * 2.
  14. *
  15. * :
  16. * 1. ()
  17. *
  18. * ------
  19. *
  20. *
  21. *
  22. *
  23. */
  24. using namespace iflytop;
  25. using namespace transmit_disfection_protocol;
  26. #define TAG "DMAPP"
  27. DisinfectionApp* DisinfectionApp::ins() {
  28. static DisinfectionApp instance;
  29. return &instance;
  30. }
  31. const char* DisinfectionApp::getName() { return "DisinfectionApp"; }
  32. void DisinfectionApp::initialize() {
  33. int btid = PublicBoard::ins()->getBoardTypeId();
  34. //
  35. // 加热片
  36. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  37. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  38. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_8);
  39. bindHeaterCtrler();
  40. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  41. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  42. heaterCtrler.initialize(PC7, NULL, 0, &hadc1, ADC_CHANNEL_1);
  43. bindHeaterCtrler();
  44. }
  45. // 风机
  46. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard)) {
  47. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  48. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  49. bindBlowerCtrler();
  50. } else if (isBoardType(kPipeDMPowerCtrlBoard)) {
  51. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  52. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  53. blowerCtrler.initializeAsHighPowerUartBlower(&huart2, &hadc1, ADC_CHANNEL_1);
  54. bindBlowerCtrler();
  55. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  56. DBDMPowerCtrlBoard::HTIM3_INIT();
  57. blowerCtrler.initializeAsMiniPwmBlower(&htim3, TIM_CHANNEL_3, PC6 /*en*/, PC9 /*fb*/);
  58. bindBlowerCtrler();
  59. }
  60. // 空压机
  61. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  62. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  63. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  64. bindAirComCtrler();
  65. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  66. airComCtrler.initialize(PD14, NULL, 0);
  67. }
  68. // 气密性测试空压机
  69. // kfn_air_tightness_test_ac_ctrl
  70. if (isBoardType(kPipeDMPowerCtrlBoard)) {
  71. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  72. airComCtrler.air_compressor_ctrl(GET_PARAM(0));
  73. airComCtrler.air_compressor_ctrl_safe_valve(GET_PARAM(0));
  74. zcanbus_send_ack(cxt->packet, NULL, 0);
  75. });
  76. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  77. static ZGPIO airCompressorCtrlGpio;
  78. airCompressorCtrlGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  79. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  80. airCompressorCtrlGpio.write(GET_PARAM(0));
  81. zcanbus_send_ack(cxt->packet, NULL, 0);
  82. });
  83. }
  84. // H2O2传感器
  85. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  86. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  87. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  88. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3);
  89. bindH2o2Sensor();
  90. }
  91. // 水浸传感器
  92. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) {
  93. ZLOGI(TAG, "WaterSensor init");
  94. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  95. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  96. bindDeviceBottomWS();
  97. bindEvaporationBinWS();
  98. }
  99. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  100. // TMC电机初始化
  101. ZLOGI(TAG, "TMCMotorGroup init");
  102. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  103. tmcPowerGroup.initialize(PB2, {&hspi1, PC4 /*cs*/, PB13 /*en*/}, {&hspi1, PA4 /*cs*/, PB12 /*en*/});
  104. bindTmcPowerGroup();
  105. }
  106. // 三色指示灯
  107. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) {
  108. // 三色指示灯初始化
  109. ZLOGI(TAG, "WarningLightDriver init");
  110. wlDriver.initialize(PD8, PD7, PD9, PD10);
  111. bindWlDriver();
  112. }
  113. // 压力传感器初始化
  114. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  115. ZLOGI(TAG, "PXXPSBus init");
  116. osDelay(1500); // 等待传感器上电
  117. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  118. psBus.initialize(&huart3);
  119. bindPsBus();
  120. }
  121. // 比例阀初始化
  122. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  123. ZLOGI(TAG, "ProportionalValveCtrl init");
  124. LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(9600);
  125. proportionalValveCtrl.initialize(&huart2);
  126. bindProportionalValveCtrl();
  127. }
  128. // 气密性测试通道
  129. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  130. static ZGPIO airTightnessTestChGpio;
  131. static ZGPIO eValve;
  132. airTightnessTestChGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  133. eValve.initAsOutput(PD14, kxs_gpio_nopull, false, true);
  134. REG_LAMADA_FN(kfn_air_tightness_test_close_off_ch, [&](ProcessContext* cxt) {
  135. airTightnessTestChGpio.write(1); // 内管路,气密性测试
  136. eValve.write(0); // 电磁阀闭合
  137. zcanbus_send_ack(cxt->packet, NULL, 0);
  138. });
  139. REG_LAMADA_FN(kfn_air_tightness_test_release_ch, [&](ProcessContext* cxt) {
  140. airTightnessTestChGpio.write(0); // 连接空气
  141. eValve.write(1); // 电磁阀打开
  142. zcanbus_send_ack(cxt->packet, NULL, 0);
  143. });
  144. }
  145. }
  146. /***********************************************************************************************************************
  147. * PROTOCOL_BIND *
  148. ***********************************************************************************************************************/
  149. void DisinfectionApp::bindHeaterCtrler() {
  150. BIND_FN(HeaterController, &heaterCtrler, fn_heater_ctrl);
  151. BIND_FN(HeaterController, &heaterCtrler, fn_heater_ctrl_safe_valve);
  152. BIND_FN(HeaterController, &heaterCtrler, fn_heater_read_electric_current);
  153. BIND_FN(HeaterController, &heaterCtrler, fn_heater_read_temperature_data);
  154. }
  155. void DisinfectionApp::bindBlowerCtrler() {
  156. BIND_FN(BlowerController, &blowerCtrler, fn_blower_ctrl);
  157. BIND_FN(BlowerController, &blowerCtrler, fn_blower_ctrl_safe_valve);
  158. BIND_FN(BlowerController, &blowerCtrler, fn_blower_read_electric_current);
  159. BIND_FN(BlowerController, &blowerCtrler, fn_blower_is_error);
  160. }
  161. void DisinfectionApp::bindAirComCtrler() {
  162. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_ctrl);
  163. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_ctrl_safe_valve);
  164. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_read_electric_current);
  165. }
  166. void DisinfectionApp::bindH2o2Sensor() {
  167. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_calibration_date);
  168. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_sub_ic_errorcode);
  169. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_sub_ic_reg);
  170. }
  171. void DisinfectionApp::bindWlDriver() { BIND_FN(WarningLightDriver, &wlDriver, fn_triple_warning_light_ctl); }
  172. void DisinfectionApp::bindTmcPowerGroup() {
  173. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_rotate);
  174. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_stop);
  175. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_set_ihold_irun_idelay);
  176. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_set_acc);
  177. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_set_ramp);
  178. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_set_tzw);
  179. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_set_subic_reg);
  180. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_get_subic_reg);
  181. BIND_FN(TmcMotorGroup, &tmcPowerGroup, fn_pump_ping);
  182. }
  183. void DisinfectionApp::bindPsBus() {
  184. BIND_FN(PXXPSBus, &psBus, fn_psbus_read_data);
  185. BIND_FN(PXXPSBus, &psBus, fn_psbus_scan);
  186. }
  187. void DisinfectionApp::bindEvaporationBinWS() {
  188. ProtocolProcesserMgr::ins()->regCmdProcesser( //
  189. CmdProcesser(kfn_evaporation_tank_water_sensor_read_state, //
  190. [this](ProcessContext* cxt) {
  191. int32_t val = evaporationBinWS.read();
  192. zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val));
  193. }));
  194. }
  195. void DisinfectionApp::bindDeviceBottomWS() {
  196. ProtocolProcesserMgr::ins()->regCmdProcesser( //
  197. CmdProcesser(kfn_device_bottom_water_sensor_read_state, //
  198. [this](ProcessContext* cxt) {
  199. int32_t val = deviceBottomWS.read();
  200. zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val));
  201. }));
  202. }
  203. void DisinfectionApp::bindProportionalValveCtrl() {
  204. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_set_valve);
  205. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_read_pos);
  206. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_is_busy);
  207. }