uavcan.protocol.param.GetSet_req.h 4.0 KB

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