uavcan.tunnel.Call_res.h 3.3 KB

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