uavcan.protocol.param.NumericValue.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.protocol.param.Empty.h>
  6. #define UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_MAX_SIZE 9
  7. #define UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_SIGNATURE (0xDA6D6FEA22E3587ULL)
  8. enum uavcan_protocol_param_NumericValue_type_t {
  9. UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_EMPTY,
  10. UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE,
  11. UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_REAL_VALUE,
  12. };
  13. struct uavcan_protocol_param_NumericValue {
  14. enum uavcan_protocol_param_NumericValue_type_t union_tag;
  15. union {
  16. struct uavcan_protocol_param_Empty empty;
  17. int64_t integer_value;
  18. float real_value;
  19. };
  20. };
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. uint32_t _uavcan_protocol_param_NumericValue_encode(struct uavcan_protocol_param_NumericValue* msg, uint8_t* buffer
  26. #if CANARD_ENABLE_TAO_OPTION
  27. , bool tao
  28. #endif
  29. );
  30. bool _uavcan_protocol_param_NumericValue_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_param_NumericValue* msg);
  31. static inline uint32_t uavcan_protocol_param_NumericValue_encode(struct uavcan_protocol_param_NumericValue* msg, uint8_t* buffer
  32. #if CANARD_ENABLE_TAO_OPTION
  33. , bool tao
  34. #endif
  35. ) {
  36. return _uavcan_protocol_param_NumericValue_encode(msg, buffer
  37. #if CANARD_ENABLE_TAO_OPTION
  38. , tao
  39. #endif
  40. );
  41. }
  42. static inline bool uavcan_protocol_param_NumericValue_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_param_NumericValue* msg) {
  43. return _uavcan_protocol_param_NumericValue_decode(transfer, msg);
  44. }
  45. #if defined(CANARD_DSDLC_INTERNAL)
  46. static inline void __uavcan_protocol_param_NumericValue_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_param_NumericValue* msg, bool tao);
  47. static inline bool __uavcan_protocol_param_NumericValue_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_param_NumericValue* msg, bool tao);
  48. void __uavcan_protocol_param_NumericValue_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_param_NumericValue* msg, bool tao) {
  49. (void)buffer;
  50. (void)bit_ofs;
  51. (void)msg;
  52. (void)tao;
  53. uint8_t union_tag = msg->union_tag;
  54. canardEncodeScalar(buffer, *bit_ofs, 2, &union_tag);
  55. *bit_ofs += 2;
  56. switch(msg->union_tag) {
  57. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_EMPTY: {
  58. __uavcan_protocol_param_Empty_encode(buffer, bit_ofs, &msg->empty, tao);
  59. break;
  60. }
  61. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE: {
  62. canardEncodeScalar(buffer, *bit_ofs, 64, &msg->integer_value);
  63. *bit_ofs += 64;
  64. break;
  65. }
  66. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_REAL_VALUE: {
  67. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->real_value);
  68. *bit_ofs += 32;
  69. break;
  70. }
  71. }
  72. }
  73. /*
  74. decode uavcan_protocol_param_NumericValue, return true on failure, false on success
  75. */
  76. bool __uavcan_protocol_param_NumericValue_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_param_NumericValue* msg, bool tao) {
  77. (void)transfer;
  78. (void)bit_ofs;
  79. (void)msg;
  80. (void)tao;
  81. uint8_t union_tag;
  82. canardDecodeScalar(transfer, *bit_ofs, 2, false, &union_tag);
  83. *bit_ofs += 2;
  84. #pragma GCC diagnostic push
  85. #pragma GCC diagnostic ignored "-Wtype-limits"
  86. if (union_tag >= 3) {
  87. return true; /* invalid value */
  88. }
  89. #pragma GCC diagnostic pop
  90. msg->union_tag = (enum uavcan_protocol_param_NumericValue_type_t)union_tag;
  91. switch(msg->union_tag) {
  92. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_EMPTY: {
  93. if (__uavcan_protocol_param_Empty_decode(transfer, bit_ofs, &msg->empty, tao)) {return true;}
  94. break;
  95. }
  96. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE: {
  97. canardDecodeScalar(transfer, *bit_ofs, 64, true, &msg->integer_value);
  98. *bit_ofs += 64;
  99. break;
  100. }
  101. case UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_REAL_VALUE: {
  102. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->real_value);
  103. *bit_ofs += 32;
  104. break;
  105. }
  106. }
  107. return false; /* success */
  108. }
  109. #endif
  110. #ifdef CANARD_DSDLC_TEST_BUILD
  111. struct uavcan_protocol_param_NumericValue sample_uavcan_protocol_param_NumericValue_msg(void);
  112. #endif
  113. #ifdef __cplusplus
  114. } // extern "C"
  115. #ifdef DRONECAN_CXX_WRAPPERS
  116. #include <canard/cxx_wrappers.h>
  117. #endif
  118. #endif