uavcan.protocol.enumeration.Begin_req.h 4.1 KB

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