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.

157 lines
5.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
  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 "hardware.hpp"
  18. #include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
  19. #include "sdk\components\string_utils.hpp"
  20. #include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
  21. #include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
  22. #include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
  23. #include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
  24. #define TAG "main"
  25. namespace iflytop {
  26. Main gmain;
  27. };
  28. using namespace iflytop;
  29. void dumphexdata(uint8_t *data, int32_t len) {
  30. for (int32_t i = 0; i < len; i++) {
  31. printf("%02X ", data[i]);
  32. }
  33. printf("\n");
  34. }
  35. /*******************************************************************************
  36. * GLOBAL *
  37. *******************************************************************************/
  38. IflytopCanProtocolStackProcesser m_protocolStack;
  39. Hardware m_hardware;
  40. ZGPIO debuglight;
  41. ZCanReceiver m_canReceiver;
  42. /*******************************************************************************
  43. * MESSAGE_HANDLER *
  44. *******************************************************************************/
  45. /**
  46. * @brief CAN接收到消息
  47. */
  48. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  49. // ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
  50. static uint8_t rxdata[1024] = {0};
  51. memset(rxdata, 0, sizeof(rxdata));
  52. Cmdheader_t *cmdheader = (Cmdheader_t *)packet;
  53. bool match = false;
  54. int32_t receipt_size = 0;
  55. int32_t ecode = m_hardware.process_rx_packet(Hardware::from_where_t::kcan, packet, len, rxdata, receipt_size, match);
  56. if (match) {
  57. if (ecode != 0) {
  58. m_canReceiver.sendErrorAck(cmdheader, ecode);
  59. } else {
  60. m_canReceiver.sendAck(cmdheader, rxdata, receipt_size);
  61. }
  62. }
  63. }
  64. /**
  65. * @brief
  66. */
  67. static void processUARTEachLine(char *packet, size_t len) {
  68. static uint8_t rxdata[1024] = {0};
  69. int32_t receipt_size = 0;
  70. bool match = false;
  71. memset(rxdata, 0, sizeof(rxdata));
  72. //
  73. int32_t bytelen = 0;
  74. uint8_t *hexbytes = StringUtils::hex_str_to_bytes((char *)packet, len, bytelen);
  75. if (hexbytes == NULL) {
  76. ZLOGE(TAG, "hex_str_to_bytes failed");
  77. return;
  78. }
  79. dumphexdata(hexbytes, bytelen);
  80. int32_t ecode = m_hardware.process_rx_packet(Hardware::kuart, hexbytes, bytelen, rxdata, receipt_size, match);
  81. if (match) {
  82. printf("match\n");
  83. if (ecode < 0) {
  84. printf("ecode :%d\n", ecode);
  85. return;
  86. }
  87. dumphexdata(rxdata, receipt_size);
  88. }
  89. printf("\n");
  90. }
  91. static void processUartRX(uint8_t *packet, size_t len) {
  92. for (size_t i = 0; i < len; i++) {
  93. if (packet[i] == '\n' || packet[i] == '\r') {
  94. packet[i] = '\0';
  95. }
  96. }
  97. for (size_t i = 0; i < len; i++) {
  98. if (i == 0) {
  99. processUARTEachLine((char *)packet, strlen((char *)packet));
  100. } else if (packet[i - 1] == '\0' && packet[i] != '\0') {
  101. processUARTEachLine((char *)packet + i, strlen((char *)packet + i));
  102. }
  103. }
  104. }
  105. /*******************************************************************************
  106. * MAIN *
  107. *******************************************************************************/
  108. void Main::run() {
  109. ZHALCORE::cfg_t oscfg = {
  110. .delayhtim = &DELAY_US_TIMER,
  111. .debuguart = &DEBUG_UART,
  112. };
  113. ZHALCORE::getInstance()->initialize(oscfg);
  114. ZLOGI(TAG, "little_disinfection_liquid_path_control:%s", VERSION);
  115. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  116. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  117. m_hardware.initialize(DEVICE_ID);
  118. static ZUART uartreceiver;
  119. static ZUART::cfg_t uartreceiver_cfg = {
  120. .name = "uartreceiver",
  121. .huart = &DEBUG_UART,
  122. .rxbuffersize = 512,
  123. .rxovertime_ms = 30,
  124. };
  125. uartreceiver.initialize(&uartreceiver_cfg);
  126. uartreceiver.setrxcb([this](uint8_t *data, size_t len) { processUartRX(data, len); });
  127. uartreceiver.startRxIt();
  128. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  129. m_canReceiver.init(cfg);
  130. m_canReceiver.registerListener(this);
  131. ZLOGI(TAG, "init done");
  132. while (1) {
  133. ZHALCORE::getInstance()->loop();
  134. m_hardware.loop();
  135. uartreceiver.forceCchedule();
  136. }
  137. }