uavcan.protocol.enumeration.Indication.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.protocol.param.NumericValue.h>
  6. #define UAVCAN_PROTOCOL_ENUMERATION_INDICATION_MAX_SIZE 102
  7. #define UAVCAN_PROTOCOL_ENUMERATION_INDICATION_SIGNATURE (0x884CB63050A84F35ULL)
  8. #define UAVCAN_PROTOCOL_ENUMERATION_INDICATION_ID 380
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_protocol_enumeration_Indication_cxx_iface;
  11. #endif
  12. struct uavcan_protocol_enumeration_Indication {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_protocol_enumeration_Indication_cxx_iface;
  15. #endif
  16. struct uavcan_protocol_param_NumericValue value;
  17. struct { uint8_t len; uint8_t data[92]; }parameter_name;
  18. };
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. uint32_t _uavcan_protocol_enumeration_Indication_encode(struct uavcan_protocol_enumeration_Indication* msg, uint8_t* buffer
  24. #if CANARD_ENABLE_TAO_OPTION
  25. , bool tao
  26. #endif
  27. );
  28. bool _uavcan_protocol_enumeration_Indication_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_enumeration_Indication* msg);
  29. static inline uint32_t uavcan_protocol_enumeration_Indication_encode(struct uavcan_protocol_enumeration_Indication* msg, uint8_t* buffer
  30. #if CANARD_ENABLE_TAO_OPTION
  31. , bool tao
  32. #endif
  33. ) {
  34. return _uavcan_protocol_enumeration_Indication_encode(msg, buffer
  35. #if CANARD_ENABLE_TAO_OPTION
  36. , tao
  37. #endif
  38. );
  39. }
  40. static inline bool uavcan_protocol_enumeration_Indication_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_enumeration_Indication* msg) {
  41. return _uavcan_protocol_enumeration_Indication_decode(transfer, msg);
  42. }
  43. #if defined(CANARD_DSDLC_INTERNAL)
  44. static inline void __uavcan_protocol_enumeration_Indication_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_enumeration_Indication* msg, bool tao);
  45. static inline bool __uavcan_protocol_enumeration_Indication_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_enumeration_Indication* msg, bool tao);
  46. void __uavcan_protocol_enumeration_Indication_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_enumeration_Indication* msg, bool tao) {
  47. (void)buffer;
  48. (void)bit_ofs;
  49. (void)msg;
  50. (void)tao;
  51. *bit_ofs += 6;
  52. __uavcan_protocol_param_NumericValue_encode(buffer, bit_ofs, &msg->value, false);
  53. #pragma GCC diagnostic push
  54. #pragma GCC diagnostic ignored "-Wtype-limits"
  55. const uint8_t parameter_name_len = msg->parameter_name.len > 92 ? 92 : msg->parameter_name.len;
  56. #pragma GCC diagnostic pop
  57. if (!tao) {
  58. canardEncodeScalar(buffer, *bit_ofs, 7, &parameter_name_len);
  59. *bit_ofs += 7;
  60. }
  61. for (size_t i=0; i < parameter_name_len; i++) {
  62. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->parameter_name.data[i]);
  63. *bit_ofs += 8;
  64. }
  65. }
  66. /*
  67. decode uavcan_protocol_enumeration_Indication, return true on failure, false on success
  68. */
  69. bool __uavcan_protocol_enumeration_Indication_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_enumeration_Indication* msg, bool tao) {
  70. (void)transfer;
  71. (void)bit_ofs;
  72. (void)msg;
  73. (void)tao;
  74. *bit_ofs += 6;
  75. if (__uavcan_protocol_param_NumericValue_decode(transfer, bit_ofs, &msg->value, false)) {return true;}
  76. if (!tao) {
  77. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->parameter_name.len);
  78. *bit_ofs += 7;
  79. } else {
  80. msg->parameter_name.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  81. }
  82. #pragma GCC diagnostic push
  83. #pragma GCC diagnostic ignored "-Wtype-limits"
  84. if (msg->parameter_name.len > 92) {
  85. return true; /* invalid value */
  86. }
  87. #pragma GCC diagnostic pop
  88. for (size_t i=0; i < msg->parameter_name.len; i++) {
  89. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->parameter_name.data[i]);
  90. *bit_ofs += 8;
  91. }
  92. return false; /* success */
  93. }
  94. #endif
  95. #ifdef CANARD_DSDLC_TEST_BUILD
  96. struct uavcan_protocol_enumeration_Indication sample_uavcan_protocol_enumeration_Indication_msg(void);
  97. #endif
  98. #ifdef __cplusplus
  99. } // extern "C"
  100. #ifdef DRONECAN_CXX_WRAPPERS
  101. #include <canard/cxx_wrappers.h>
  102. BROADCAST_MESSAGE_CXX_IFACE(uavcan_protocol_enumeration_Indication, UAVCAN_PROTOCOL_ENUMERATION_INDICATION_ID, UAVCAN_PROTOCOL_ENUMERATION_INDICATION_SIGNATURE, UAVCAN_PROTOCOL_ENUMERATION_INDICATION_MAX_SIZE);
  103. #endif
  104. #endif