uavcan.tunnel.Targetted.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.tunnel.Protocol.h>
  6. #define UAVCAN_TUNNEL_TARGETTED_MAX_SIZE 127
  7. #define UAVCAN_TUNNEL_TARGETTED_SIGNATURE (0xB138E7EA72A2A2E9ULL)
  8. #define UAVCAN_TUNNEL_TARGETTED_ID 3001
  9. #define UAVCAN_TUNNEL_TARGETTED_OPTION_LOCK_PORT 1
  10. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  11. class uavcan_tunnel_Targetted_cxx_iface;
  12. #endif
  13. struct uavcan_tunnel_Targetted {
  14. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  15. using cxx_iface = uavcan_tunnel_Targetted_cxx_iface;
  16. #endif
  17. struct uavcan_tunnel_Protocol protocol;
  18. uint8_t target_node;
  19. int8_t serial_id;
  20. uint8_t options;
  21. uint32_t baudrate;
  22. struct { uint8_t len; uint8_t data[120]; }buffer;
  23. };
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. uint32_t _uavcan_tunnel_Targetted_encode(struct uavcan_tunnel_Targetted* msg, uint8_t* buffer
  29. #if CANARD_ENABLE_TAO_OPTION
  30. , bool tao
  31. #endif
  32. );
  33. bool _uavcan_tunnel_Targetted_decode(const CanardRxTransfer* transfer, struct uavcan_tunnel_Targetted* msg);
  34. static inline uint32_t uavcan_tunnel_Targetted_encode(struct uavcan_tunnel_Targetted* msg, uint8_t* buffer
  35. #if CANARD_ENABLE_TAO_OPTION
  36. , bool tao
  37. #endif
  38. ) {
  39. return _uavcan_tunnel_Targetted_encode(msg, buffer
  40. #if CANARD_ENABLE_TAO_OPTION
  41. , tao
  42. #endif
  43. );
  44. }
  45. static inline bool uavcan_tunnel_Targetted_decode(const CanardRxTransfer* transfer, struct uavcan_tunnel_Targetted* msg) {
  46. return _uavcan_tunnel_Targetted_decode(transfer, msg);
  47. }
  48. #if defined(CANARD_DSDLC_INTERNAL)
  49. static inline void __uavcan_tunnel_Targetted_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_tunnel_Targetted* msg, bool tao);
  50. static inline bool __uavcan_tunnel_Targetted_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_tunnel_Targetted* msg, bool tao);
  51. void __uavcan_tunnel_Targetted_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_tunnel_Targetted* msg, bool tao) {
  52. (void)buffer;
  53. (void)bit_ofs;
  54. (void)msg;
  55. (void)tao;
  56. __uavcan_tunnel_Protocol_encode(buffer, bit_ofs, &msg->protocol, false);
  57. canardEncodeScalar(buffer, *bit_ofs, 7, &msg->target_node);
  58. *bit_ofs += 7;
  59. canardEncodeScalar(buffer, *bit_ofs, 5, &msg->serial_id);
  60. *bit_ofs += 5;
  61. canardEncodeScalar(buffer, *bit_ofs, 4, &msg->options);
  62. *bit_ofs += 4;
  63. canardEncodeScalar(buffer, *bit_ofs, 24, &msg->baudrate);
  64. *bit_ofs += 24;
  65. #pragma GCC diagnostic push
  66. #pragma GCC diagnostic ignored "-Wtype-limits"
  67. const uint8_t buffer_len = msg->buffer.len > 120 ? 120 : msg->buffer.len;
  68. #pragma GCC diagnostic pop
  69. if (!tao) {
  70. canardEncodeScalar(buffer, *bit_ofs, 7, &buffer_len);
  71. *bit_ofs += 7;
  72. }
  73. for (size_t i=0; i < buffer_len; i++) {
  74. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->buffer.data[i]);
  75. *bit_ofs += 8;
  76. }
  77. }
  78. /*
  79. decode uavcan_tunnel_Targetted, return true on failure, false on success
  80. */
  81. bool __uavcan_tunnel_Targetted_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_tunnel_Targetted* msg, bool tao) {
  82. (void)transfer;
  83. (void)bit_ofs;
  84. (void)msg;
  85. (void)tao;
  86. if (__uavcan_tunnel_Protocol_decode(transfer, bit_ofs, &msg->protocol, false)) {return true;}
  87. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->target_node);
  88. *bit_ofs += 7;
  89. canardDecodeScalar(transfer, *bit_ofs, 5, true, &msg->serial_id);
  90. *bit_ofs += 5;
  91. canardDecodeScalar(transfer, *bit_ofs, 4, false, &msg->options);
  92. *bit_ofs += 4;
  93. canardDecodeScalar(transfer, *bit_ofs, 24, false, &msg->baudrate);
  94. *bit_ofs += 24;
  95. if (!tao) {
  96. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->buffer.len);
  97. *bit_ofs += 7;
  98. } else {
  99. msg->buffer.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  100. }
  101. #pragma GCC diagnostic push
  102. #pragma GCC diagnostic ignored "-Wtype-limits"
  103. if (msg->buffer.len > 120) {
  104. return true; /* invalid value */
  105. }
  106. #pragma GCC diagnostic pop
  107. for (size_t i=0; i < msg->buffer.len; i++) {
  108. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->buffer.data[i]);
  109. *bit_ofs += 8;
  110. }
  111. return false; /* success */
  112. }
  113. #endif
  114. #ifdef CANARD_DSDLC_TEST_BUILD
  115. struct uavcan_tunnel_Targetted sample_uavcan_tunnel_Targetted_msg(void);
  116. #endif
  117. #ifdef __cplusplus
  118. } // extern "C"
  119. #ifdef DRONECAN_CXX_WRAPPERS
  120. #include <canard/cxx_wrappers.h>
  121. BROADCAST_MESSAGE_CXX_IFACE(uavcan_tunnel_Targetted, UAVCAN_TUNNEL_TARGETTED_ID, UAVCAN_TUNNEL_TARGETTED_SIGNATURE, UAVCAN_TUNNEL_TARGETTED_MAX_SIZE);
  122. #endif
  123. #endif