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.

85 lines
3.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
  1. #pragma once
  2. #include <stdint.h>
  3. #define ZPACKET_STRUCT(ordername, type, ...) \
  4. typedef struct { \
  5. __VA_ARGS__ \
  6. } ordername##_##type##_t
  7. #define ZPACKET_CMD_ACK(ordername, cmdpara, ackpara) \
  8. typedef struct { \
  9. cmdpara \
  10. } ordername##_##cmd##_t; \
  11. typedef struct { \
  12. ackpara \
  13. } ordername##_##ack##_t
  14. #define ZPACKET_CMD_ACK_AND_REPORT(ordername, cmdpara, ackpara, reportpara) \
  15. typedef struct { \
  16. cmdpara \
  17. } ordername##_##cmd##_t; \
  18. typedef struct { \
  19. ackpara \
  20. } ordername##_##ack##_t; \
  21. typedef struct { \
  22. reportpara \
  23. } ordername##_##report##_t
  24. #define PROCESS_PACKET(ordername, varid) \
  25. if (rxcmd->iscmd(ordername)) { \
  26. auto* cmd = rxcmd->get_data_as<ordername##_##cmd##_t>(); \
  27. auto* ack = (ordername##_##ack##_t*)m_txbuf; \
  28. static_assert(sizeof(*ack) < sizeof(m_txbuf), "ack size too large"); \
  29. auto __attribute__((unused)) cmdheader = rxcmd->get_cmdheader(); \
  30. uint32_t errorcode = 0; \
  31. if (cmd->id == varid) {
  32. #define PROCESS_REPORT(type) \
  33. auto* report = (type##_report_t*)m_txbuf; \
  34. static_assert(sizeof(*report) < sizeof(m_txbuf), "report size too large"); \
  35. ZLOGI(TAG, #type " exec_status:%d", status); \
  36. report->exec_status = status; \
  37. m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)report, sizeof(*report));
  38. #define END_PROCESS_PACKET() \
  39. if (errorcode == 0) { \
  40. m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); \
  41. } else { \
  42. m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), m_id, errorcode); \
  43. } \
  44. } \
  45. return; \
  46. }
  47. #define END_PP END_PROCESS_PACKET
  48. #define CMD(x) x
  49. #define ACK(x) x
  50. #define REPORT(x) x
  51. namespace iflytop {
  52. namespace zcr {
  53. #pragma pack(push, 1)
  54. typedef struct {
  55. uint16_t packetindex;
  56. uint16_t cmdid;
  57. uint8_t subcmdid;
  58. uint8_t packetType;
  59. uint8_t data[];
  60. } Cmdheader_t;
  61. #pragma pack(pop)
  62. typedef enum {
  63. kpt_cmd = 0,
  64. kpt_ack = 1,
  65. kpt_error_ack = 2,
  66. kpt_cmd_exec_status_report = 3,
  67. kpt_report = 4,
  68. } PacketType_t;
  69. #define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
  70. #define SUBCMDID(cmdid) (cmdid & 0xff)
  71. #define MODULE_CMDID(cmdid) (cmdid >> 8)
  72. } // namespace zcr
  73. } // namespace iflytop
  74. #define ZCAN_CMD_PUBLIC_DEVICE_ID_STEP_MOTOR_BOARD_OFFEST 200