dronecan.remoteid.Location.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define DRONECAN_REMOTEID_LOCATION_MAX_SIZE 58
  6. #define DRONECAN_REMOTEID_LOCATION_SIGNATURE (0xEAA3A2C5BCB14CAAULL)
  7. #define DRONECAN_REMOTEID_LOCATION_ID 20031
  8. #define DRONECAN_REMOTEID_LOCATION_ODID_STATUS_UNDECLARED 0
  9. #define DRONECAN_REMOTEID_LOCATION_ODID_STATUS_GROUND 1
  10. #define DRONECAN_REMOTEID_LOCATION_ODID_STATUS_AIRBORNE 2
  11. #define DRONECAN_REMOTEID_LOCATION_ODID_STATUS_EMERGENCY 3
  12. #define DRONECAN_REMOTEID_LOCATION_ODID_HEIGHT_REF_OVER_TAKEOFF 0
  13. #define DRONECAN_REMOTEID_LOCATION_ODID_HEIGHT_REF_OVER_GROUND 1
  14. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_UNKNOWN 0
  15. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_10NM 1
  16. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_4NM 2
  17. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_2NM 3
  18. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_1NM 4
  19. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_0_5NM 5
  20. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_0_3NM 6
  21. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_0_1NM 7
  22. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_0_05NM 8
  23. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_30_METER 9
  24. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_10_METER 10
  25. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_3_METER 11
  26. #define DRONECAN_REMOTEID_LOCATION_ODID_HOR_ACC_1_METER 12
  27. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_UNKNOWN 0
  28. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_150_METER 1
  29. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_45_METER 2
  30. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_25_METER 3
  31. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_10_METER 4
  32. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_3_METER 5
  33. #define DRONECAN_REMOTEID_LOCATION_ODID_VER_ACC_1_METER 6
  34. #define DRONECAN_REMOTEID_LOCATION_ODID_SPEED_ACC_UNKNOWN 0
  35. #define DRONECAN_REMOTEID_LOCATION_ODID_SPEED_ACC_10_METERS_PER_SECOND 1
  36. #define DRONECAN_REMOTEID_LOCATION_ODID_SPEED_ACC_3_METERS_PER_SECOND 2
  37. #define DRONECAN_REMOTEID_LOCATION_ODID_SPEED_ACC_1_METERS_PER_SECOND 3
  38. #define DRONECAN_REMOTEID_LOCATION_ODID_SPEED_ACC_0_3_METERS_PER_SECOND 4
  39. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_1_SECOND 1
  40. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_2_SECOND 2
  41. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_3_SECOND 3
  42. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_4_SECOND 4
  43. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_5_SECOND 5
  44. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_6_SECOND 6
  45. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_7_SECOND 7
  46. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_8_SECOND 8
  47. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_0_9_SECOND 9
  48. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_0_SECOND 10
  49. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_1_SECOND 11
  50. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_2_SECOND 12
  51. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_3_SECOND 13
  52. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_4_SECOND 14
  53. #define DRONECAN_REMOTEID_LOCATION_ODID_TIME_ACC_1_5_SECOND 15
  54. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  55. class dronecan_remoteid_Location_cxx_iface;
  56. #endif
  57. struct dronecan_remoteid_Location {
  58. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  59. using cxx_iface = dronecan_remoteid_Location_cxx_iface;
  60. #endif
  61. struct { uint8_t len; uint8_t data[20]; }id_or_mac;
  62. uint8_t status;
  63. uint16_t direction;
  64. uint16_t speed_horizontal;
  65. int16_t speed_vertical;
  66. int32_t latitude;
  67. int32_t longitude;
  68. float altitude_barometric;
  69. float altitude_geodetic;
  70. uint8_t height_reference;
  71. float height;
  72. uint8_t horizontal_accuracy;
  73. uint8_t vertical_accuracy;
  74. uint8_t barometer_accuracy;
  75. uint8_t speed_accuracy;
  76. float timestamp;
  77. uint8_t timestamp_accuracy;
  78. };
  79. #ifdef __cplusplus
  80. extern "C"
  81. {
  82. #endif
  83. uint32_t dronecan_remoteid_Location_encode(struct dronecan_remoteid_Location* msg, uint8_t* buffer
  84. #if CANARD_ENABLE_TAO_OPTION
  85. , bool tao
  86. #endif
  87. );
  88. bool dronecan_remoteid_Location_decode(const CanardRxTransfer* transfer, struct dronecan_remoteid_Location* msg);
  89. #if defined(CANARD_DSDLC_INTERNAL)
  90. static inline void _dronecan_remoteid_Location_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_Location* msg, bool tao);
  91. static inline bool _dronecan_remoteid_Location_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_Location* msg, bool tao);
  92. void _dronecan_remoteid_Location_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_Location* msg, bool tao) {
  93. (void)buffer;
  94. (void)bit_ofs;
  95. (void)msg;
  96. (void)tao;
  97. #pragma GCC diagnostic push
  98. #pragma GCC diagnostic ignored "-Wtype-limits"
  99. const uint8_t id_or_mac_len = msg->id_or_mac.len > 20 ? 20 : msg->id_or_mac.len;
  100. #pragma GCC diagnostic pop
  101. canardEncodeScalar(buffer, *bit_ofs, 5, &id_or_mac_len);
  102. *bit_ofs += 5;
  103. for (size_t i=0; i < id_or_mac_len; i++) {
  104. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->id_or_mac.data[i]);
  105. *bit_ofs += 8;
  106. }
  107. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->status);
  108. *bit_ofs += 8;
  109. canardEncodeScalar(buffer, *bit_ofs, 16, &msg->direction);
  110. *bit_ofs += 16;
  111. canardEncodeScalar(buffer, *bit_ofs, 16, &msg->speed_horizontal);
  112. *bit_ofs += 16;
  113. canardEncodeScalar(buffer, *bit_ofs, 16, &msg->speed_vertical);
  114. *bit_ofs += 16;
  115. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->latitude);
  116. *bit_ofs += 32;
  117. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->longitude);
  118. *bit_ofs += 32;
  119. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->altitude_barometric);
  120. *bit_ofs += 32;
  121. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->altitude_geodetic);
  122. *bit_ofs += 32;
  123. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->height_reference);
  124. *bit_ofs += 8;
  125. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->height);
  126. *bit_ofs += 32;
  127. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->horizontal_accuracy);
  128. *bit_ofs += 8;
  129. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->vertical_accuracy);
  130. *bit_ofs += 8;
  131. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->barometer_accuracy);
  132. *bit_ofs += 8;
  133. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->speed_accuracy);
  134. *bit_ofs += 8;
  135. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->timestamp);
  136. *bit_ofs += 32;
  137. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->timestamp_accuracy);
  138. *bit_ofs += 8;
  139. }
  140. /*
  141. decode dronecan_remoteid_Location, return true on failure, false on success
  142. */
  143. bool _dronecan_remoteid_Location_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_Location* msg, bool tao) {
  144. (void)transfer;
  145. (void)bit_ofs;
  146. (void)msg;
  147. (void)tao;
  148. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->id_or_mac.len);
  149. *bit_ofs += 5;
  150. #pragma GCC diagnostic push
  151. #pragma GCC diagnostic ignored "-Wtype-limits"
  152. if (msg->id_or_mac.len > 20) {
  153. return true; /* invalid value */
  154. }
  155. #pragma GCC diagnostic pop
  156. for (size_t i=0; i < msg->id_or_mac.len; i++) {
  157. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->id_or_mac.data[i]);
  158. *bit_ofs += 8;
  159. }
  160. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->status);
  161. *bit_ofs += 8;
  162. canardDecodeScalar(transfer, *bit_ofs, 16, false, &msg->direction);
  163. *bit_ofs += 16;
  164. canardDecodeScalar(transfer, *bit_ofs, 16, false, &msg->speed_horizontal);
  165. *bit_ofs += 16;
  166. canardDecodeScalar(transfer, *bit_ofs, 16, true, &msg->speed_vertical);
  167. *bit_ofs += 16;
  168. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->latitude);
  169. *bit_ofs += 32;
  170. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->longitude);
  171. *bit_ofs += 32;
  172. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->altitude_barometric);
  173. *bit_ofs += 32;
  174. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->altitude_geodetic);
  175. *bit_ofs += 32;
  176. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->height_reference);
  177. *bit_ofs += 8;
  178. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->height);
  179. *bit_ofs += 32;
  180. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->horizontal_accuracy);
  181. *bit_ofs += 8;
  182. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->vertical_accuracy);
  183. *bit_ofs += 8;
  184. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->barometer_accuracy);
  185. *bit_ofs += 8;
  186. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->speed_accuracy);
  187. *bit_ofs += 8;
  188. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->timestamp);
  189. *bit_ofs += 32;
  190. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->timestamp_accuracy);
  191. *bit_ofs += 8;
  192. return false; /* success */
  193. }
  194. #endif
  195. #ifdef CANARD_DSDLC_TEST_BUILD
  196. struct dronecan_remoteid_Location sample_dronecan_remoteid_Location_msg(void);
  197. #endif
  198. #ifdef __cplusplus
  199. } // extern "C"
  200. #ifdef DRONECAN_CXX_WRAPPERS
  201. #include <canard/cxx_wrappers.h>
  202. BROADCAST_MESSAGE_CXX_IFACE(dronecan_remoteid_Location, DRONECAN_REMOTEID_LOCATION_ID, DRONECAN_REMOTEID_LOCATION_SIGNATURE, DRONECAN_REMOTEID_LOCATION_MAX_SIZE);
  203. #endif
  204. #endif