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.

139 lines
4.7 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
  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, sizeof(receipt_size));
  61. }
  62. }
  63. }
  64. /**
  65. * @brief
  66. */
  67. static void processUartRX(uint8_t *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. printf("processUartRX %d\n", len);
  73. //
  74. int32_t bytelen = 0;
  75. uint8_t *hexbytes = StringUtils::hex_str_to_bytes((char *)packet, len, bytelen);
  76. if (hexbytes == NULL) {
  77. ZLOGE(TAG, "hex_str_to_bytes failed");
  78. return;
  79. }
  80. dumphexdata(hexbytes, bytelen);
  81. int32_t ecode = m_hardware.process_rx_packet(Hardware::kuart, hexbytes, bytelen, rxdata, receipt_size, match);
  82. if (match) {
  83. printf("match\n");
  84. if (ecode < 0) {
  85. printf("ecode :%d\n", ecode);
  86. return;
  87. }
  88. dumphexdata(rxdata, receipt_size);
  89. }
  90. }
  91. /*******************************************************************************
  92. * MAIN *
  93. *******************************************************************************/
  94. void Main::run() {
  95. ZHALCORE::cfg_t oscfg = {
  96. .delayhtim = &DELAY_US_TIMER,
  97. .debuguart = &DEBUG_UART,
  98. };
  99. ZHALCORE::getInstance()->initialize(oscfg);
  100. ZLOGI(TAG, "little_disinfection_liquid_path_control:%s", VERSION);
  101. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  102. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  103. m_hardware.initialize(DEVICE_ID);
  104. static ZUART uartreceiver;
  105. static ZUART::cfg_t uartreceiver_cfg = {
  106. .name = "uartreceiver",
  107. .huart = &DEBUG_UART,
  108. .rxbuffersize = 512,
  109. .rxovertime_ms = 30,
  110. };
  111. uartreceiver.initialize(&uartreceiver_cfg);
  112. uartreceiver.setrxcb([this](uint8_t *data, size_t len) { processUartRX(data, len); });
  113. uartreceiver.startRxIt();
  114. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  115. m_canReceiver.init(cfg);
  116. m_canReceiver.registerListener(this);
  117. ZLOGI(TAG, "init done");
  118. while (1) {
  119. ZHALCORE::getInstance()->loop();
  120. m_hardware.loop();
  121. uartreceiver.forceCchedule();
  122. }
  123. }