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.

227 lines
6.2 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
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. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. // #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
  8. #include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
  9. #include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
  10. #include "sdk/hal/zhal.hpp"
  11. #include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
  12. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  13. #include "sdk\components\m3078\m3078_code_scaner.hpp"
  14. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  15. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  16. //
  17. #include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
  18. #include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
  19. #include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
  20. #include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
  21. #include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
  22. //
  23. #include "adc.h"
  24. #include "sdk\components\zcan_module\zcan_high_power_electrical_ctl_module.hpp"
  25. #include "sdk\components\zcan_module\zcan_m211887_module_manager.hpp"
  26. #include "h2o2_sensor.hpp"
  27. #define TAG "main"
  28. namespace iflytop {
  29. Main gmain;
  30. };
  31. using namespace iflytop;
  32. IflytopCanProtocolStackProcesser m_protocolStack;
  33. // TMC5130 m_motor1;
  34. // TMC5130 m_motor2;
  35. ZGPIO debuglight;
  36. ZGPIO AirCompressorCtrl1;
  37. ZGPIO AirCompressorCtrl2;
  38. ZGPIO AirBlowerCtrl1;
  39. ZGPIO AirBlowerCtrl2;
  40. ZGPIO HeatingStripCtrl1;
  41. ZGPIO HeatingStripCtrl2;
  42. ZGPIO output8;
  43. ZGPIO output9;
  44. ZCanReceiver m_canReceiver;
  45. ZCanBasicOrderModule m_basicOrderModule;
  46. ZCanHighPowerElectricalCtlModule m_highPowerElectricalCtlModule;
  47. H2O2Sensor m_h2o2_sensor;
  48. // ch(1-6Chnnal),times(读取次数)
  49. uint32_t ADC_Get_Average(uint8_t ch, uint8_t times) {
  50. ADC_ChannelConfTypeDef sConfig; // 通道初始化
  51. uint32_t value_sum = 0;
  52. uint8_t i;
  53. switch (ch) // 选择ADC通道
  54. {
  55. case 1:
  56. sConfig.Channel = ADC_CHANNEL_1;
  57. break;
  58. case 2:
  59. sConfig.Channel = ADC_CHANNEL_2;
  60. break;
  61. case 3:
  62. sConfig.Channel = ADC_CHANNEL_3;
  63. break;
  64. case 4:
  65. sConfig.Channel = ADC_CHANNEL_4;
  66. break;
  67. case 5:
  68. sConfig.Channel = ADC_CHANNEL_5;
  69. break;
  70. case 6:
  71. sConfig.Channel = ADC_CHANNEL_6;
  72. break;
  73. }
  74. sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; // 采用周期239.5周期
  75. sConfig.Rank = 1;
  76. HAL_ADC_ConfigChannel(&hadc1, &sConfig);
  77. for (i = 0; i < times; i++) {
  78. HAL_ADC_Start(&hadc1); // 启动转换
  79. HAL_ADC_PollForConversion(&hadc1, 30); // 等待转化结束
  80. value_sum += HAL_ADC_GetValue(&hadc1); // 求和
  81. HAL_ADC_Stop(&hadc1); // 停止转换
  82. }
  83. return value_sum / times; // 返回平均值
  84. }
  85. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  86. // printf("can rx from %d %d,", rxbuf->id, len);
  87. // for (size_t i = 0; i < len; i++) {
  88. // printf("%02X ", packet[i]);
  89. // }
  90. // printf("\n");
  91. }
  92. void Main::run() {
  93. ZHALCORE::cfg_t oscfg = {
  94. .delayhtim = &DELAY_US_TIMER,
  95. .debuguart = &DEBUG_UART,
  96. };
  97. ZHALCORE::getInstance()->initialize(oscfg);
  98. ZLOGI(TAG, "high_power_ctrl_prj:%s", VERSION);
  99. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  100. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  101. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  102. m_canReceiver.init(cfg);
  103. m_canReceiver.registerListener(this);
  104. AirCompressorCtrl1.initAsOutput(PC2, ZGPIO::kMode_nopull, true, false);
  105. AirCompressorCtrl2.initAsOutput(PC3, ZGPIO::kMode_nopull, true, false);
  106. AirBlowerCtrl1.initAsOutput(PC4, ZGPIO::kMode_nopull, true, false);
  107. AirBlowerCtrl2.initAsOutput(PC5, ZGPIO::kMode_nopull, true, false);
  108. HeatingStripCtrl1.initAsOutput(PC6, ZGPIO::kMode_nopull, true, false);
  109. HeatingStripCtrl2.initAsOutput(PC7, ZGPIO::kMode_nopull, true, false);
  110. output8.initAsOutput(PD13, ZGPIO::kMode_nopull, true, false);
  111. output9.initAsOutput(PD14, ZGPIO::kMode_nopull, true, false);
  112. // ZHAL_CORE_REG(3000, {
  113. // AirCompressorCtrl1.toggleState();
  114. // AirCompressorCtrl2.toggleState();
  115. // AirBlowerCtrl1.toggleState();
  116. // AirBlowerCtrl2.toggleState();
  117. // HeatingStripCtrl1.toggleState();
  118. // HeatingStripCtrl2.toggleState();
  119. // });
  120. /**
  121. * @brief
  122. */
  123. m_basicOrderModule.initialize(&m_canReceiver);
  124. m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) { return false; });
  125. m_basicOrderModule.regOutCtl([this](uint8_t id, bool val) {
  126. ZLOGI(TAG, "set io %d %d", id, val);
  127. if (id == 0) {
  128. AirCompressorCtrl1.setState(val);
  129. return true;
  130. }
  131. if (id == 1) {
  132. AirCompressorCtrl2.setState(val);
  133. return true;
  134. }
  135. if (id == 2) {
  136. AirBlowerCtrl1.setState(val);
  137. return true;
  138. }
  139. if (id == 3) {
  140. AirBlowerCtrl2.setState(val);
  141. return true;
  142. }
  143. if (id == 4) {
  144. HeatingStripCtrl1.setState(val);
  145. return true;
  146. }
  147. if (id == 5) {
  148. HeatingStripCtrl2.setState(val);
  149. return true;
  150. }
  151. if (id == 8) {
  152. output8.setState(val);
  153. return true;
  154. }
  155. if (id == 9) {
  156. output9.setState(val);
  157. return true;
  158. }
  159. return false;
  160. });
  161. m_basicOrderModule.regReadAdcVal([this](uint8_t id, int32_t &val) {
  162. if (id == 0) {
  163. val = ADC_Get_Average(0, 12);
  164. return true;
  165. }
  166. if (id == 1) {
  167. val = ADC_Get_Average(1, 12);
  168. return true;
  169. }
  170. if (id == 2) {
  171. val = ADC_Get_Average(2, 12);
  172. return true;
  173. }
  174. if (id == 3) {
  175. val = ADC_Get_Average(3, 12);
  176. return true;
  177. }
  178. if (id == 8) {
  179. val = ADC_Get_Average(8, 12);
  180. return true;
  181. }
  182. if (id == 9) {
  183. val = ADC_Get_Average(9, 12);
  184. return true;
  185. }
  186. return false;
  187. });
  188. m_h2o2_sensor.initialize(&m_canReceiver);
  189. m_h2o2_sensor.regSubmodule(1, &huart3, 0x01);
  190. // while(true){
  191. // uint8_t buf[10] ={1,2,3,4,5,6,7,8,9,10};
  192. // HAL_UART_Transmit(&huart3,buf,10,1000);
  193. // HAL_Delay(10);
  194. // }
  195. ZLOGI(TAG, "init done");
  196. while (1) {
  197. ZHALCORE::getInstance()->loop();
  198. // m_h2o2_sensor.readSensorData();
  199. }
  200. }