uavcan.protocol.param.GetSet_res.h 4.8 KB

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