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.

170 lines
4.6 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
  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 "sdk\components\zcan_module\zcan_high_power_electrical_ctl_module.hpp"
  24. #include "sdk\components\zcan_module\zcan_m211887_module_manager.hpp"
  25. #define TAG "main"
  26. namespace iflytop {
  27. Main gmain;
  28. };
  29. using namespace iflytop;
  30. IflytopCanProtocolStackProcesser m_protocolStack;
  31. // TMC5130 m_motor1;
  32. // TMC5130 m_motor2;
  33. ZGPIO debuglight;
  34. ZGPIO AirCompressorCtrl1;
  35. ZGPIO AirCompressorCtrl2;
  36. ZGPIO AirBlowerCtrl1;
  37. ZGPIO AirBlowerCtrl2;
  38. ZGPIO HeatingStripCtrl1;
  39. ZGPIO HeatingStripCtrl2;
  40. ZGPIO output8;
  41. ZGPIO output9;
  42. ZCanReceiver m_canReceiver;
  43. ZCanBasicOrderModule m_basicOrderModule;
  44. ZCanHighPowerElectricalCtlModule m_highPowerElectricalCtlModule;
  45. ZCanM211887ModuleManager m_m211887ModuleManager;
  46. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  47. printf("can rx from %d %d,", rxbuf->id, len);
  48. for (size_t i = 0; i < len; i++) {
  49. printf("%02X ", packet[i]);
  50. }
  51. printf("\n");
  52. }
  53. void Main::run() {
  54. ZHALCORE::cfg_t oscfg = {
  55. .delayhtim = &DELAY_US_TIMER,
  56. .debuguart = &DEBUG_UART,
  57. };
  58. ZHALCORE::getInstance()->initialize(oscfg);
  59. ZLOGI(TAG, "zapp:%s", VERSION);
  60. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  61. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  62. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  63. m_canReceiver.init(cfg);
  64. m_canReceiver.registerListener(this);
  65. AirCompressorCtrl1.initAsOutput(PC2, ZGPIO::kMode_nopull, true, false);
  66. AirCompressorCtrl2.initAsOutput(PC3, ZGPIO::kMode_nopull, true, false);
  67. AirBlowerCtrl1.initAsOutput(PC4, ZGPIO::kMode_nopull, true, false);
  68. AirBlowerCtrl2.initAsOutput(PC5, ZGPIO::kMode_nopull, true, false);
  69. HeatingStripCtrl1.initAsOutput(PC6, ZGPIO::kMode_nopull, true, false);
  70. HeatingStripCtrl2.initAsOutput(PC7, ZGPIO::kMode_nopull, true, false);
  71. output8.initAsOutput(PD13, ZGPIO::kMode_nopull, true, false);
  72. output9.initAsOutput(PD14, ZGPIO::kMode_nopull, true, false);
  73. // ZHAL_CORE_REG(3000, {
  74. // AirCompressorCtrl1.toggleState();
  75. // AirCompressorCtrl2.toggleState();
  76. // AirBlowerCtrl1.toggleState();
  77. // AirBlowerCtrl2.toggleState();
  78. // HeatingStripCtrl1.toggleState();
  79. // HeatingStripCtrl2.toggleState();
  80. // });
  81. /**
  82. * @brief
  83. */
  84. m_basicOrderModule.initialize(&m_canReceiver);
  85. m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) { return false; });
  86. m_basicOrderModule.regOutCtl([this](uint8_t id, bool val) {
  87. ZLOGI(TAG, "set io %d %d", id, val);
  88. if (id == 0) {
  89. AirCompressorCtrl1.setState(val);
  90. return true;
  91. }
  92. if (id == 1) {
  93. AirCompressorCtrl2.setState(val);
  94. return true;
  95. }
  96. if (id == 2) {
  97. AirBlowerCtrl1.setState(val);
  98. return true;
  99. }
  100. if (id == 3) {
  101. AirBlowerCtrl2.setState(val);
  102. return true;
  103. }
  104. if (id == 4) {
  105. HeatingStripCtrl1.setState(val);
  106. return true;
  107. }
  108. if (id == 5) {
  109. HeatingStripCtrl2.setState(val);
  110. return true;
  111. }
  112. if (id == 8) {
  113. output8.setState(val);
  114. return true;
  115. }
  116. if (id == 9) {
  117. output9.setState(val);
  118. return true;
  119. }
  120. return false;
  121. });
  122. m_basicOrderModule.regReadAdcVal([this](uint8_t id, int32_t &val) {
  123. if (id == 0) {
  124. val = 1;
  125. return true;
  126. }
  127. if (id == 1) {
  128. val = 2;
  129. return true;
  130. }
  131. if (id == 2) {
  132. val = 3;
  133. return true;
  134. }
  135. return false;
  136. });
  137. // m_m211887ModuleManager.initialize(&m_canReceiver);
  138. // m_m211887ModuleManager.regSubmodule(1, &huart3,1);
  139. ZLOGI(TAG, "init done");
  140. while (1) {
  141. ZHALCORE::getInstance()->loop();
  142. }
  143. }