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.

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