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.

101 lines
3.4 KiB

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. auto cmdheader = rxcmd->get_cmdheader(); \
  29. uint32_t errorcode = 0; \
  30. if (cmd->id == varid) { \
  31. ack->id = cmd->id;
  32. #define END_PROCESS_PACKET() \
  33. if (errorcode == 0) { \
  34. m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); \
  35. } else { \
  36. m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), errorcode); \
  37. } \
  38. } \
  39. return; \
  40. }
  41. #define CMD(x) x
  42. #define ACK(x) x
  43. #define REPORT(x) x
  44. namespace iflytop {
  45. namespace zcr {
  46. typedef uint8_t u8;
  47. typedef uint16_t u16;
  48. typedef uint32_t u32;
  49. typedef uint64_t u64;
  50. typedef int8_t s8;
  51. typedef int16_t s16;
  52. typedef int32_t s32;
  53. typedef int64_t s64;
  54. typedef float f32;
  55. typedef double f64;
  56. #pragma pack(push, 1)
  57. typedef struct {
  58. uint16_t packetindex;
  59. uint16_t cmdid;
  60. uint8_t subcmdid;
  61. uint8_t packetType;
  62. uint8_t data[];
  63. } Cmdheader_t;
  64. #pragma pack(pop)
  65. typedef enum {
  66. kpt_cmd = 0,
  67. kpt_ack = 1,
  68. kpt_error_ack = 2,
  69. kpt_cmd_exec_status_report = 3,
  70. } PacketType_t;
  71. typedef enum {
  72. kset_cmd_type_read = 0,
  73. kset_cmd_type_set = 1,
  74. } SetCmdOperationType_t;
  75. typedef enum {
  76. kMotorStopType_stop = 0,
  77. kMotorStopType_break = 1,
  78. } MotorStopType_t;
  79. #define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
  80. typedef enum {
  81. kmodule_statu_idle,
  82. kmodule_statu_work,
  83. kmodule_statu_exception,
  84. } module_statu_type_t;
  85. } // namespace zcr
  86. } // namespace iflytop