uavcan.equipment.esc.RawCommand.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_MAX_SIZE 36
  6. #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE (0x217F5C87D7EC951DULL)
  7. #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID 1030
  8. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  9. class uavcan_equipment_esc_RawCommand_cxx_iface;
  10. #endif
  11. struct uavcan_equipment_esc_RawCommand {
  12. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  13. using cxx_iface = uavcan_equipment_esc_RawCommand_cxx_iface;
  14. #endif
  15. struct { uint8_t len; int16_t data[20]; }cmd;
  16. };
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. uint32_t _uavcan_equipment_esc_RawCommand_encode(struct uavcan_equipment_esc_RawCommand* msg, uint8_t* buffer
  22. #if CANARD_ENABLE_TAO_OPTION
  23. , bool tao
  24. #endif
  25. );
  26. bool _uavcan_equipment_esc_RawCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_esc_RawCommand* msg);
  27. static inline uint32_t uavcan_equipment_esc_RawCommand_encode(struct uavcan_equipment_esc_RawCommand* msg, uint8_t* buffer
  28. #if CANARD_ENABLE_TAO_OPTION
  29. , bool tao
  30. #endif
  31. ) {
  32. return _uavcan_equipment_esc_RawCommand_encode(msg, buffer
  33. #if CANARD_ENABLE_TAO_OPTION
  34. , tao
  35. #endif
  36. );
  37. }
  38. static inline bool uavcan_equipment_esc_RawCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_esc_RawCommand* msg) {
  39. return _uavcan_equipment_esc_RawCommand_decode(transfer, msg);
  40. }
  41. #if defined(CANARD_DSDLC_INTERNAL)
  42. static inline void __uavcan_equipment_esc_RawCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RawCommand* msg, bool tao);
  43. static inline bool __uavcan_equipment_esc_RawCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RawCommand* msg, bool tao);
  44. void __uavcan_equipment_esc_RawCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RawCommand* msg, bool tao) {
  45. (void)buffer;
  46. (void)bit_ofs;
  47. (void)msg;
  48. (void)tao;
  49. #pragma GCC diagnostic push
  50. #pragma GCC diagnostic ignored "-Wtype-limits"
  51. const uint8_t cmd_len = msg->cmd.len > 20 ? 20 : msg->cmd.len;
  52. #pragma GCC diagnostic pop
  53. if (!tao) {
  54. canardEncodeScalar(buffer, *bit_ofs, 5, &cmd_len);
  55. *bit_ofs += 5;
  56. }
  57. for (size_t i=0; i < cmd_len; i++) {
  58. canardEncodeScalar(buffer, *bit_ofs, 14, &msg->cmd.data[i]);
  59. *bit_ofs += 14;
  60. }
  61. }
  62. /*
  63. decode uavcan_equipment_esc_RawCommand, return true on failure, false on success
  64. */
  65. bool __uavcan_equipment_esc_RawCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RawCommand* msg, bool tao) {
  66. (void)transfer;
  67. (void)bit_ofs;
  68. (void)msg;
  69. (void)tao;
  70. if (!tao) {
  71. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->cmd.len);
  72. *bit_ofs += 5;
  73. } else {
  74. msg->cmd.len = ((transfer->payload_len*8)-*bit_ofs)/14;
  75. }
  76. #pragma GCC diagnostic push
  77. #pragma GCC diagnostic ignored "-Wtype-limits"
  78. if (msg->cmd.len > 20) {
  79. return true; /* invalid value */
  80. }
  81. #pragma GCC diagnostic pop
  82. for (size_t i=0; i < msg->cmd.len; i++) {
  83. canardDecodeScalar(transfer, *bit_ofs, 14, true, &msg->cmd.data[i]);
  84. *bit_ofs += 14;
  85. }
  86. return false; /* success */
  87. }
  88. #endif
  89. #ifdef CANARD_DSDLC_TEST_BUILD
  90. struct uavcan_equipment_esc_RawCommand sample_uavcan_equipment_esc_RawCommand_msg(void);
  91. #endif
  92. #ifdef __cplusplus
  93. } // extern "C"
  94. #ifdef DRONECAN_CXX_WRAPPERS
  95. #include <canard/cxx_wrappers.h>
  96. BROADCAST_MESSAGE_CXX_IFACE(uavcan_equipment_esc_RawCommand, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_MAX_SIZE);
  97. #endif
  98. #endif