uavcan.protocol.GetTransportStats_res.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.protocol.CANIfaceStats.h>
  6. #define UAVCAN_PROTOCOL_GETTRANSPORTSTATS_RESPONSE_MAX_SIZE 73
  7. #define UAVCAN_PROTOCOL_GETTRANSPORTSTATS_RESPONSE_SIGNATURE (0xBE6F76A7EC312B04ULL)
  8. #define UAVCAN_PROTOCOL_GETTRANSPORTSTATS_RESPONSE_ID 4
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_protocol_GetTransportStats_cxx_iface;
  11. #endif
  12. struct uavcan_protocol_GetTransportStatsResponse {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_protocol_GetTransportStats_cxx_iface;
  15. #endif
  16. uint64_t transfers_tx;
  17. uint64_t transfers_rx;
  18. uint64_t transfer_errors;
  19. struct { uint8_t len; struct uavcan_protocol_CANIfaceStats data[3]; }can_iface_stats;
  20. };
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. uint32_t _uavcan_protocol_GetTransportStatsResponse_encode(struct uavcan_protocol_GetTransportStatsResponse* msg, uint8_t* buffer
  26. #if CANARD_ENABLE_TAO_OPTION
  27. , bool tao
  28. #endif
  29. );
  30. bool _uavcan_protocol_GetTransportStatsResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_GetTransportStatsResponse* msg);
  31. static inline uint32_t uavcan_protocol_GetTransportStatsResponse_encode(struct uavcan_protocol_GetTransportStatsResponse* msg, uint8_t* buffer
  32. #if CANARD_ENABLE_TAO_OPTION
  33. , bool tao
  34. #endif
  35. ) {
  36. return _uavcan_protocol_GetTransportStatsResponse_encode(msg, buffer
  37. #if CANARD_ENABLE_TAO_OPTION
  38. , tao
  39. #endif
  40. );
  41. }
  42. static inline bool uavcan_protocol_GetTransportStatsResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_GetTransportStatsResponse* msg) {
  43. return _uavcan_protocol_GetTransportStatsResponse_decode(transfer, msg);
  44. }
  45. #if defined(CANARD_DSDLC_INTERNAL)
  46. static inline void __uavcan_protocol_GetTransportStatsResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_GetTransportStatsResponse* msg, bool tao);
  47. static inline bool __uavcan_protocol_GetTransportStatsResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_GetTransportStatsResponse* msg, bool tao);
  48. void __uavcan_protocol_GetTransportStatsResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_GetTransportStatsResponse* msg, bool tao) {
  49. (void)buffer;
  50. (void)bit_ofs;
  51. (void)msg;
  52. (void)tao;
  53. canardEncodeScalar(buffer, *bit_ofs, 48, &msg->transfers_tx);
  54. *bit_ofs += 48;
  55. canardEncodeScalar(buffer, *bit_ofs, 48, &msg->transfers_rx);
  56. *bit_ofs += 48;
  57. canardEncodeScalar(buffer, *bit_ofs, 48, &msg->transfer_errors);
  58. *bit_ofs += 48;
  59. #pragma GCC diagnostic push
  60. #pragma GCC diagnostic ignored "-Wtype-limits"
  61. const uint8_t can_iface_stats_len = msg->can_iface_stats.len > 3 ? 3 : msg->can_iface_stats.len;
  62. #pragma GCC diagnostic pop
  63. if (!tao) {
  64. canardEncodeScalar(buffer, *bit_ofs, 2, &can_iface_stats_len);
  65. *bit_ofs += 2;
  66. }
  67. for (size_t i=0; i < can_iface_stats_len; i++) {
  68. __uavcan_protocol_CANIfaceStats_encode(buffer, bit_ofs, &msg->can_iface_stats.data[i], false);
  69. }
  70. }
  71. /*
  72. decode uavcan_protocol_GetTransportStatsResponse, return true on failure, false on success
  73. */
  74. bool __uavcan_protocol_GetTransportStatsResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_GetTransportStatsResponse* msg, bool tao) {
  75. (void)transfer;
  76. (void)bit_ofs;
  77. (void)msg;
  78. (void)tao;
  79. canardDecodeScalar(transfer, *bit_ofs, 48, false, &msg->transfers_tx);
  80. *bit_ofs += 48;
  81. canardDecodeScalar(transfer, *bit_ofs, 48, false, &msg->transfers_rx);
  82. *bit_ofs += 48;
  83. canardDecodeScalar(transfer, *bit_ofs, 48, false, &msg->transfer_errors);
  84. *bit_ofs += 48;
  85. if (!tao) {
  86. canardDecodeScalar(transfer, *bit_ofs, 2, false, &msg->can_iface_stats.len);
  87. *bit_ofs += 2;
  88. }
  89. if (tao) {
  90. msg->can_iface_stats.len = 0;
  91. size_t max_len = 3;
  92. uint32_t max_bits = (transfer->payload_len*8)-7; // TAO elements must be >= 8 bits
  93. while (max_bits > *bit_ofs) {
  94. if (!max_len-- || __uavcan_protocol_CANIfaceStats_decode(transfer, bit_ofs, &msg->can_iface_stats.data[msg->can_iface_stats.len], false)) {return true;}
  95. msg->can_iface_stats.len++;
  96. }
  97. } else {
  98. #pragma GCC diagnostic push
  99. #pragma GCC diagnostic ignored "-Wtype-limits"
  100. if (msg->can_iface_stats.len > 3) {
  101. return true; /* invalid value */
  102. }
  103. #pragma GCC diagnostic pop
  104. for (size_t i=0; i < msg->can_iface_stats.len; i++) {
  105. if (__uavcan_protocol_CANIfaceStats_decode(transfer, bit_ofs, &msg->can_iface_stats.data[i], false)) {return true;}
  106. }
  107. }
  108. return false; /* success */
  109. }
  110. #endif
  111. #ifdef CANARD_DSDLC_TEST_BUILD
  112. struct uavcan_protocol_GetTransportStatsResponse sample_uavcan_protocol_GetTransportStatsResponse_msg(void);
  113. #endif
  114. #ifdef __cplusplus
  115. } // extern "C"
  116. #ifdef DRONECAN_CXX_WRAPPERS
  117. #include <canard/cxx_wrappers.h>
  118. #endif
  119. #endif