uavcan.equipment.actuator.ArrayCommand.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.equipment.actuator.Command.h>
  6. #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_MAX_SIZE 61
  7. #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE (0xD8A7486238EC3AF3ULL)
  8. #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID 1010
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_equipment_actuator_ArrayCommand_cxx_iface;
  11. #endif
  12. struct uavcan_equipment_actuator_ArrayCommand {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_equipment_actuator_ArrayCommand_cxx_iface;
  15. #endif
  16. struct { uint8_t len; struct uavcan_equipment_actuator_Command data[15]; }commands;
  17. };
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. uint32_t _uavcan_equipment_actuator_ArrayCommand_encode(struct uavcan_equipment_actuator_ArrayCommand* msg, uint8_t* buffer
  23. #if CANARD_ENABLE_TAO_OPTION
  24. , bool tao
  25. #endif
  26. );
  27. bool _uavcan_equipment_actuator_ArrayCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_actuator_ArrayCommand* msg);
  28. static inline uint32_t uavcan_equipment_actuator_ArrayCommand_encode(struct uavcan_equipment_actuator_ArrayCommand* msg, uint8_t* buffer
  29. #if CANARD_ENABLE_TAO_OPTION
  30. , bool tao
  31. #endif
  32. ) {
  33. return _uavcan_equipment_actuator_ArrayCommand_encode(msg, buffer
  34. #if CANARD_ENABLE_TAO_OPTION
  35. , tao
  36. #endif
  37. );
  38. }
  39. static inline bool uavcan_equipment_actuator_ArrayCommand_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_actuator_ArrayCommand* msg) {
  40. return _uavcan_equipment_actuator_ArrayCommand_decode(transfer, msg);
  41. }
  42. #if defined(CANARD_DSDLC_INTERNAL)
  43. static inline void __uavcan_equipment_actuator_ArrayCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_ArrayCommand* msg, bool tao);
  44. static inline bool __uavcan_equipment_actuator_ArrayCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_ArrayCommand* msg, bool tao);
  45. void __uavcan_equipment_actuator_ArrayCommand_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_ArrayCommand* msg, bool tao) {
  46. (void)buffer;
  47. (void)bit_ofs;
  48. (void)msg;
  49. (void)tao;
  50. #pragma GCC diagnostic push
  51. #pragma GCC diagnostic ignored "-Wtype-limits"
  52. const uint8_t commands_len = msg->commands.len > 15 ? 15 : msg->commands.len;
  53. #pragma GCC diagnostic pop
  54. if (!tao) {
  55. canardEncodeScalar(buffer, *bit_ofs, 4, &commands_len);
  56. *bit_ofs += 4;
  57. }
  58. for (size_t i=0; i < commands_len; i++) {
  59. __uavcan_equipment_actuator_Command_encode(buffer, bit_ofs, &msg->commands.data[i], false);
  60. }
  61. }
  62. /*
  63. decode uavcan_equipment_actuator_ArrayCommand, return true on failure, false on success
  64. */
  65. bool __uavcan_equipment_actuator_ArrayCommand_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_ArrayCommand* msg, bool tao) {
  66. (void)transfer;
  67. (void)bit_ofs;
  68. (void)msg;
  69. (void)tao;
  70. if (!tao) {
  71. canardDecodeScalar(transfer, *bit_ofs, 4, false, &msg->commands.len);
  72. *bit_ofs += 4;
  73. }
  74. if (tao) {
  75. msg->commands.len = 0;
  76. size_t max_len = 15;
  77. uint32_t max_bits = (transfer->payload_len*8)-7; // TAO elements must be >= 8 bits
  78. while (max_bits > *bit_ofs) {
  79. if (!max_len-- || __uavcan_equipment_actuator_Command_decode(transfer, bit_ofs, &msg->commands.data[msg->commands.len], false)) {return true;}
  80. msg->commands.len++;
  81. }
  82. } else {
  83. #pragma GCC diagnostic push
  84. #pragma GCC diagnostic ignored "-Wtype-limits"
  85. if (msg->commands.len > 15) {
  86. return true; /* invalid value */
  87. }
  88. #pragma GCC diagnostic pop
  89. for (size_t i=0; i < msg->commands.len; i++) {
  90. if (__uavcan_equipment_actuator_Command_decode(transfer, bit_ofs, &msg->commands.data[i], false)) {return true;}
  91. }
  92. }
  93. return false; /* success */
  94. }
  95. #endif
  96. #ifdef CANARD_DSDLC_TEST_BUILD
  97. struct uavcan_equipment_actuator_ArrayCommand sample_uavcan_equipment_actuator_ArrayCommand_msg(void);
  98. #endif
  99. #ifdef __cplusplus
  100. } // extern "C"
  101. #ifdef DRONECAN_CXX_WRAPPERS
  102. #include <canard/cxx_wrappers.h>
  103. BROADCAST_MESSAGE_CXX_IFACE(uavcan_equipment_actuator_ArrayCommand, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_MAX_SIZE);
  104. #endif
  105. #endif