uavcan.protocol.debug.LogMessage.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.protocol.debug.LogLevel.h>
  6. #define UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_MAX_SIZE 123
  7. #define UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_SIGNATURE (0xD654A48E0C049D75ULL)
  8. #define UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_ID 16383
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_protocol_debug_LogMessage_cxx_iface;
  11. #endif
  12. struct uavcan_protocol_debug_LogMessage {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_protocol_debug_LogMessage_cxx_iface;
  15. #endif
  16. struct uavcan_protocol_debug_LogLevel level;
  17. struct { uint8_t len; uint8_t data[31]; }source;
  18. struct { uint8_t len; uint8_t data[90]; }text;
  19. };
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. uint32_t _uavcan_protocol_debug_LogMessage_encode(struct uavcan_protocol_debug_LogMessage* msg, uint8_t* buffer
  25. #if CANARD_ENABLE_TAO_OPTION
  26. , bool tao
  27. #endif
  28. );
  29. bool _uavcan_protocol_debug_LogMessage_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_debug_LogMessage* msg);
  30. static inline uint32_t uavcan_protocol_debug_LogMessage_encode(struct uavcan_protocol_debug_LogMessage* msg, uint8_t* buffer
  31. #if CANARD_ENABLE_TAO_OPTION
  32. , bool tao
  33. #endif
  34. ) {
  35. return _uavcan_protocol_debug_LogMessage_encode(msg, buffer
  36. #if CANARD_ENABLE_TAO_OPTION
  37. , tao
  38. #endif
  39. );
  40. }
  41. static inline bool uavcan_protocol_debug_LogMessage_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_debug_LogMessage* msg) {
  42. return _uavcan_protocol_debug_LogMessage_decode(transfer, msg);
  43. }
  44. #if defined(CANARD_DSDLC_INTERNAL)
  45. static inline void __uavcan_protocol_debug_LogMessage_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_debug_LogMessage* msg, bool tao);
  46. static inline bool __uavcan_protocol_debug_LogMessage_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_debug_LogMessage* msg, bool tao);
  47. void __uavcan_protocol_debug_LogMessage_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_debug_LogMessage* msg, bool tao) {
  48. (void)buffer;
  49. (void)bit_ofs;
  50. (void)msg;
  51. (void)tao;
  52. __uavcan_protocol_debug_LogLevel_encode(buffer, bit_ofs, &msg->level, false);
  53. #pragma GCC diagnostic push
  54. #pragma GCC diagnostic ignored "-Wtype-limits"
  55. const uint8_t source_len = msg->source.len > 31 ? 31 : msg->source.len;
  56. #pragma GCC diagnostic pop
  57. canardEncodeScalar(buffer, *bit_ofs, 5, &source_len);
  58. *bit_ofs += 5;
  59. for (size_t i=0; i < source_len; i++) {
  60. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->source.data[i]);
  61. *bit_ofs += 8;
  62. }
  63. #pragma GCC diagnostic push
  64. #pragma GCC diagnostic ignored "-Wtype-limits"
  65. const uint8_t text_len = msg->text.len > 90 ? 90 : msg->text.len;
  66. #pragma GCC diagnostic pop
  67. if (!tao) {
  68. canardEncodeScalar(buffer, *bit_ofs, 7, &text_len);
  69. *bit_ofs += 7;
  70. }
  71. for (size_t i=0; i < text_len; i++) {
  72. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->text.data[i]);
  73. *bit_ofs += 8;
  74. }
  75. }
  76. /*
  77. decode uavcan_protocol_debug_LogMessage, return true on failure, false on success
  78. */
  79. bool __uavcan_protocol_debug_LogMessage_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_debug_LogMessage* msg, bool tao) {
  80. (void)transfer;
  81. (void)bit_ofs;
  82. (void)msg;
  83. (void)tao;
  84. if (__uavcan_protocol_debug_LogLevel_decode(transfer, bit_ofs, &msg->level, false)) {return true;}
  85. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->source.len);
  86. *bit_ofs += 5;
  87. #pragma GCC diagnostic push
  88. #pragma GCC diagnostic ignored "-Wtype-limits"
  89. if (msg->source.len > 31) {
  90. return true; /* invalid value */
  91. }
  92. #pragma GCC diagnostic pop
  93. for (size_t i=0; i < msg->source.len; i++) {
  94. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->source.data[i]);
  95. *bit_ofs += 8;
  96. }
  97. if (!tao) {
  98. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->text.len);
  99. *bit_ofs += 7;
  100. } else {
  101. msg->text.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  102. }
  103. #pragma GCC diagnostic push
  104. #pragma GCC diagnostic ignored "-Wtype-limits"
  105. if (msg->text.len > 90) {
  106. return true; /* invalid value */
  107. }
  108. #pragma GCC diagnostic pop
  109. for (size_t i=0; i < msg->text.len; i++) {
  110. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->text.data[i]);
  111. *bit_ofs += 8;
  112. }
  113. return false; /* success */
  114. }
  115. #endif
  116. #ifdef CANARD_DSDLC_TEST_BUILD
  117. struct uavcan_protocol_debug_LogMessage sample_uavcan_protocol_debug_LogMessage_msg(void);
  118. #endif
  119. #ifdef __cplusplus
  120. } // extern "C"
  121. #ifdef DRONECAN_CXX_WRAPPERS
  122. #include <canard/cxx_wrappers.h>
  123. BROADCAST_MESSAGE_CXX_IFACE(uavcan_protocol_debug_LogMessage, UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_ID, UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_SIGNATURE, UAVCAN_PROTOCOL_DEBUG_LOGMESSAGE_MAX_SIZE);
  124. #endif
  125. #endif