uavcan.equipment.gnss.RTCMStream.h 4.0 KB

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