uavcan.equipment.ahrs.RawIMU.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.Timestamp.h>
  6. #define UAVCAN_EQUIPMENT_AHRS_RAWIMU_MAX_SIZE 120
  7. #define UAVCAN_EQUIPMENT_AHRS_RAWIMU_SIGNATURE (0x8280632C40E574B5ULL)
  8. #define UAVCAN_EQUIPMENT_AHRS_RAWIMU_ID 1003
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_equipment_ahrs_RawIMU_cxx_iface;
  11. #endif
  12. struct uavcan_equipment_ahrs_RawIMU {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_equipment_ahrs_RawIMU_cxx_iface;
  15. #endif
  16. struct uavcan_Timestamp timestamp;
  17. float integration_interval;
  18. float rate_gyro_latest[3];
  19. float rate_gyro_integral[3];
  20. float accelerometer_latest[3];
  21. float accelerometer_integral[3];
  22. struct { uint8_t len; float data[36]; }covariance;
  23. };
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. uint32_t _uavcan_equipment_ahrs_RawIMU_encode(struct uavcan_equipment_ahrs_RawIMU* msg, uint8_t* buffer
  29. #if CANARD_ENABLE_TAO_OPTION
  30. , bool tao
  31. #endif
  32. );
  33. bool _uavcan_equipment_ahrs_RawIMU_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_ahrs_RawIMU* msg);
  34. static inline uint32_t uavcan_equipment_ahrs_RawIMU_encode(struct uavcan_equipment_ahrs_RawIMU* msg, uint8_t* buffer
  35. #if CANARD_ENABLE_TAO_OPTION
  36. , bool tao
  37. #endif
  38. ) {
  39. return _uavcan_equipment_ahrs_RawIMU_encode(msg, buffer
  40. #if CANARD_ENABLE_TAO_OPTION
  41. , tao
  42. #endif
  43. );
  44. }
  45. static inline bool uavcan_equipment_ahrs_RawIMU_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_ahrs_RawIMU* msg) {
  46. return _uavcan_equipment_ahrs_RawIMU_decode(transfer, msg);
  47. }
  48. #if defined(CANARD_DSDLC_INTERNAL)
  49. static inline void __uavcan_equipment_ahrs_RawIMU_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_ahrs_RawIMU* msg, bool tao);
  50. static inline bool __uavcan_equipment_ahrs_RawIMU_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_ahrs_RawIMU* msg, bool tao);
  51. void __uavcan_equipment_ahrs_RawIMU_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_ahrs_RawIMU* msg, bool tao) {
  52. (void)buffer;
  53. (void)bit_ofs;
  54. (void)msg;
  55. (void)tao;
  56. __uavcan_Timestamp_encode(buffer, bit_ofs, &msg->timestamp, false);
  57. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->integration_interval);
  58. *bit_ofs += 32;
  59. for (size_t i=0; i < 3; i++) {
  60. {
  61. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->rate_gyro_latest[i]);
  62. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  63. }
  64. *bit_ofs += 16;
  65. }
  66. for (size_t i=0; i < 3; i++) {
  67. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->rate_gyro_integral[i]);
  68. *bit_ofs += 32;
  69. }
  70. for (size_t i=0; i < 3; i++) {
  71. {
  72. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->accelerometer_latest[i]);
  73. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  74. }
  75. *bit_ofs += 16;
  76. }
  77. for (size_t i=0; i < 3; i++) {
  78. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->accelerometer_integral[i]);
  79. *bit_ofs += 32;
  80. }
  81. #pragma GCC diagnostic push
  82. #pragma GCC diagnostic ignored "-Wtype-limits"
  83. const uint8_t covariance_len = msg->covariance.len > 36 ? 36 : msg->covariance.len;
  84. #pragma GCC diagnostic pop
  85. if (!tao) {
  86. canardEncodeScalar(buffer, *bit_ofs, 6, &covariance_len);
  87. *bit_ofs += 6;
  88. }
  89. for (size_t i=0; i < covariance_len; i++) {
  90. {
  91. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->covariance.data[i]);
  92. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  93. }
  94. *bit_ofs += 16;
  95. }
  96. }
  97. /*
  98. decode uavcan_equipment_ahrs_RawIMU, return true on failure, false on success
  99. */
  100. bool __uavcan_equipment_ahrs_RawIMU_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_ahrs_RawIMU* msg, bool tao) {
  101. (void)transfer;
  102. (void)bit_ofs;
  103. (void)msg;
  104. (void)tao;
  105. if (__uavcan_Timestamp_decode(transfer, bit_ofs, &msg->timestamp, false)) {return true;}
  106. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->integration_interval);
  107. *bit_ofs += 32;
  108. for (size_t i=0; i < 3; i++) {
  109. {
  110. uint16_t float16_val;
  111. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  112. msg->rate_gyro_latest[i] = canardConvertFloat16ToNativeFloat(float16_val);
  113. }
  114. *bit_ofs += 16;
  115. }
  116. for (size_t i=0; i < 3; i++) {
  117. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->rate_gyro_integral[i]);
  118. *bit_ofs += 32;
  119. }
  120. for (size_t i=0; i < 3; i++) {
  121. {
  122. uint16_t float16_val;
  123. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  124. msg->accelerometer_latest[i] = canardConvertFloat16ToNativeFloat(float16_val);
  125. }
  126. *bit_ofs += 16;
  127. }
  128. for (size_t i=0; i < 3; i++) {
  129. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->accelerometer_integral[i]);
  130. *bit_ofs += 32;
  131. }
  132. if (!tao) {
  133. canardDecodeScalar(transfer, *bit_ofs, 6, false, &msg->covariance.len);
  134. *bit_ofs += 6;
  135. } else {
  136. msg->covariance.len = ((transfer->payload_len*8)-*bit_ofs)/16;
  137. }
  138. #pragma GCC diagnostic push
  139. #pragma GCC diagnostic ignored "-Wtype-limits"
  140. if (msg->covariance.len > 36) {
  141. return true; /* invalid value */
  142. }
  143. #pragma GCC diagnostic pop
  144. for (size_t i=0; i < msg->covariance.len; i++) {
  145. {
  146. uint16_t float16_val;
  147. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  148. msg->covariance.data[i] = canardConvertFloat16ToNativeFloat(float16_val);
  149. }
  150. *bit_ofs += 16;
  151. }
  152. return false; /* success */
  153. }
  154. #endif
  155. #ifdef CANARD_DSDLC_TEST_BUILD
  156. struct uavcan_equipment_ahrs_RawIMU sample_uavcan_equipment_ahrs_RawIMU_msg(void);
  157. #endif
  158. #ifdef __cplusplus
  159. } // extern "C"
  160. #ifdef DRONECAN_CXX_WRAPPERS
  161. #include <canard/cxx_wrappers.h>
  162. BROADCAST_MESSAGE_CXX_IFACE(uavcan_equipment_ahrs_RawIMU, UAVCAN_EQUIPMENT_AHRS_RAWIMU_ID, UAVCAN_EQUIPMENT_AHRS_RAWIMU_SIGNATURE, UAVCAN_EQUIPMENT_AHRS_RAWIMU_MAX_SIZE);
  163. #endif
  164. #endif