uavcan.equipment.esc.RPMCommand.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_RPMCOMMAND_MAX_SIZE 46
  6. #define UAVCAN_EQUIPMENT_ESC_RPMCOMMAND_SIGNATURE (0xCE0F9F621CF7E70BULL)
  7. #define UAVCAN_EQUIPMENT_ESC_RPMCOMMAND_ID 1031
  8. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  9. class uavcan_equipment_esc_RPMCommand_cxx_iface;
  10. #endif
  11. struct uavcan_equipment_esc_RPMCommand {
  12. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  13. using cxx_iface = uavcan_equipment_esc_RPMCommand_cxx_iface;
  14. #endif
  15. struct { uint8_t len; int32_t data[20]; }rpm;
  16. };
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. uint32_t _uavcan_equipment_esc_RPMCommand_encode(struct uavcan_equipment_esc_RPMCommand* msg, uint8_t* buffer
  22. #if CANARD_ENABLE_TAO_OPTION
  23. , bool tao
  24. #endif
  25. );
  26. bool _uavcan_equipment_esc_RPMCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_esc_RPMCommand* msg);
  27. static inline uint32_t uavcan_equipment_esc_RPMCommand_encode(struct uavcan_equipment_esc_RPMCommand* msg, uint8_t* buffer
  28. #if CANARD_ENABLE_TAO_OPTION
  29. , bool tao
  30. #endif
  31. ) {
  32. return _uavcan_equipment_esc_RPMCommand_encode(msg, buffer
  33. #if CANARD_ENABLE_TAO_OPTION
  34. , tao
  35. #endif
  36. );
  37. }
  38. static inline bool uavcan_equipment_esc_RPMCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_esc_RPMCommand* msg) {
  39. return _uavcan_equipment_esc_RPMCommand_decode(transfer, msg);
  40. }
  41. #if defined(CANARD_DSDLC_INTERNAL)
  42. static inline void __uavcan_equipment_esc_RPMCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RPMCommand* msg, bool tao);
  43. static inline bool __uavcan_equipment_esc_RPMCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RPMCommand* msg, bool tao);
  44. void __uavcan_equipment_esc_RPMCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RPMCommand* 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 rpm_len = msg->rpm.len > 20 ? 20 : msg->rpm.len;
  52. #pragma GCC diagnostic pop
  53. if (!tao) {
  54. canardEncodeScalar(buffer, *bit_ofs, 5, &rpm_len);
  55. *bit_ofs += 5;
  56. }
  57. for (size_t i=0; i < rpm_len; i++) {
  58. canardEncodeScalar(buffer, *bit_ofs, 18, &msg->rpm.data[i]);
  59. *bit_ofs += 18;
  60. }
  61. }
  62. /*
  63. decode uavcan_equipment_esc_RPMCommand, return true on failure, false on success
  64. */
  65. bool __uavcan_equipment_esc_RPMCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_esc_RPMCommand* 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->rpm.len);
  72. *bit_ofs += 5;
  73. } else {
  74. msg->rpm.len = ((transfer->payload_len*8)-*bit_ofs)/18;
  75. }
  76. #pragma GCC diagnostic push
  77. #pragma GCC diagnostic ignored "-Wtype-limits"
  78. if (msg->rpm.len > 20) {
  79. return true; /* invalid value */
  80. }
  81. #pragma GCC diagnostic pop
  82. for (size_t i=0; i < msg->rpm.len; i++) {
  83. canardDecodeScalar(transfer, *bit_ofs, 18, true, &msg->rpm.data[i]);
  84. *bit_ofs += 18;
  85. }
  86. return false; /* success */
  87. }
  88. #endif
  89. #ifdef CANARD_DSDLC_TEST_BUILD
  90. struct uavcan_equipment_esc_RPMCommand sample_uavcan_equipment_esc_RPMCommand_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_RPMCommand, UAVCAN_EQUIPMENT_ESC_RPMCOMMAND_ID, UAVCAN_EQUIPMENT_ESC_RPMCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RPMCOMMAND_MAX_SIZE);
  97. #endif
  98. #endif