/Modules/MAVLink/common/mavlink_msg_terrain_data.h

https://gitlab.com/krucios/Astraeus_FW · C Header · 304 lines · 181 code · 25 blank · 98 comment · 6 complexity · 3a622c6f00252f48227c86e13f1a3b14 MD5 · raw file

  1. // MESSAGE TERRAIN_DATA PACKING
  2. #define MAVLINK_MSG_ID_TERRAIN_DATA 134
  3. MAVPACKED(
  4. typedef struct __mavlink_terrain_data_t {
  5. int32_t lat; /*< Latitude of SW corner of first grid (degrees *10^7)*/
  6. int32_t lon; /*< Longitude of SW corner of first grid (in degrees *10^7)*/
  7. uint16_t grid_spacing; /*< Grid spacing in meters*/
  8. int16_t data[16]; /*< Terrain data in meters AMSL*/
  9. uint8_t gridbit; /*< bit within the terrain request mask*/
  10. }) mavlink_terrain_data_t;
  11. #define MAVLINK_MSG_ID_TERRAIN_DATA_LEN 43
  12. #define MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN 43
  13. #define MAVLINK_MSG_ID_134_LEN 43
  14. #define MAVLINK_MSG_ID_134_MIN_LEN 43
  15. #define MAVLINK_MSG_ID_TERRAIN_DATA_CRC 229
  16. #define MAVLINK_MSG_ID_134_CRC 229
  17. #define MAVLINK_MSG_TERRAIN_DATA_FIELD_DATA_LEN 16
  18. #if MAVLINK_COMMAND_24BIT
  19. #define MAVLINK_MESSAGE_INFO_TERRAIN_DATA { \
  20. 134, \
  21. "TERRAIN_DATA", \
  22. 5, \
  23. { { "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_terrain_data_t, lat) }, \
  24. { "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_terrain_data_t, lon) }, \
  25. { "grid_spacing", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_terrain_data_t, grid_spacing) }, \
  26. { "data", NULL, MAVLINK_TYPE_INT16_T, 16, 10, offsetof(mavlink_terrain_data_t, data) }, \
  27. { "gridbit", NULL, MAVLINK_TYPE_UINT8_T, 0, 42, offsetof(mavlink_terrain_data_t, gridbit) }, \
  28. } \
  29. }
  30. #else
  31. #define MAVLINK_MESSAGE_INFO_TERRAIN_DATA { \
  32. "TERRAIN_DATA", \
  33. 5, \
  34. { { "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_terrain_data_t, lat) }, \
  35. { "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_terrain_data_t, lon) }, \
  36. { "grid_spacing", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_terrain_data_t, grid_spacing) }, \
  37. { "data", NULL, MAVLINK_TYPE_INT16_T, 16, 10, offsetof(mavlink_terrain_data_t, data) }, \
  38. { "gridbit", NULL, MAVLINK_TYPE_UINT8_T, 0, 42, offsetof(mavlink_terrain_data_t, gridbit) }, \
  39. } \
  40. }
  41. #endif
  42. /**
  43. * @brief Pack a terrain_data message
  44. * @param system_id ID of this system
  45. * @param component_id ID of this component (e.g. 200 for IMU)
  46. * @param msg The MAVLink message to compress the data into
  47. *
  48. * @param lat Latitude of SW corner of first grid (degrees *10^7)
  49. * @param lon Longitude of SW corner of first grid (in degrees *10^7)
  50. * @param grid_spacing Grid spacing in meters
  51. * @param gridbit bit within the terrain request mask
  52. * @param data Terrain data in meters AMSL
  53. * @return length of the message in bytes (excluding serial stream start sign)
  54. */
  55. static inline uint16_t mavlink_msg_terrain_data_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  56. int32_t lat, int32_t lon, uint16_t grid_spacing, uint8_t gridbit, const int16_t *data)
  57. {
  58. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  59. char buf[MAVLINK_MSG_ID_TERRAIN_DATA_LEN];
  60. _mav_put_int32_t(buf, 0, lat);
  61. _mav_put_int32_t(buf, 4, lon);
  62. _mav_put_uint16_t(buf, 8, grid_spacing);
  63. _mav_put_uint8_t(buf, 42, gridbit);
  64. _mav_put_int16_t_array(buf, 10, data, 16);
  65. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TERRAIN_DATA_LEN);
  66. #else
  67. mavlink_terrain_data_t packet;
  68. packet.lat = lat;
  69. packet.lon = lon;
  70. packet.grid_spacing = grid_spacing;
  71. packet.gridbit = gridbit;
  72. mav_array_memcpy(packet.data, data, sizeof(int16_t)*16);
  73. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TERRAIN_DATA_LEN);
  74. #endif
  75. msg->msgid = MAVLINK_MSG_ID_TERRAIN_DATA;
  76. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  77. }
  78. /**
  79. * @brief Pack a terrain_data message on a channel
  80. * @param system_id ID of this system
  81. * @param component_id ID of this component (e.g. 200 for IMU)
  82. * @param chan The MAVLink channel this message will be sent over
  83. * @param msg The MAVLink message to compress the data into
  84. * @param lat Latitude of SW corner of first grid (degrees *10^7)
  85. * @param lon Longitude of SW corner of first grid (in degrees *10^7)
  86. * @param grid_spacing Grid spacing in meters
  87. * @param gridbit bit within the terrain request mask
  88. * @param data Terrain data in meters AMSL
  89. * @return length of the message in bytes (excluding serial stream start sign)
  90. */
  91. static inline uint16_t mavlink_msg_terrain_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  92. mavlink_message_t* msg,
  93. int32_t lat,int32_t lon,uint16_t grid_spacing,uint8_t gridbit,const int16_t *data)
  94. {
  95. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  96. char buf[MAVLINK_MSG_ID_TERRAIN_DATA_LEN];
  97. _mav_put_int32_t(buf, 0, lat);
  98. _mav_put_int32_t(buf, 4, lon);
  99. _mav_put_uint16_t(buf, 8, grid_spacing);
  100. _mav_put_uint8_t(buf, 42, gridbit);
  101. _mav_put_int16_t_array(buf, 10, data, 16);
  102. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TERRAIN_DATA_LEN);
  103. #else
  104. mavlink_terrain_data_t packet;
  105. packet.lat = lat;
  106. packet.lon = lon;
  107. packet.grid_spacing = grid_spacing;
  108. packet.gridbit = gridbit;
  109. mav_array_memcpy(packet.data, data, sizeof(int16_t)*16);
  110. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TERRAIN_DATA_LEN);
  111. #endif
  112. msg->msgid = MAVLINK_MSG_ID_TERRAIN_DATA;
  113. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  114. }
  115. /**
  116. * @brief Encode a terrain_data struct
  117. *
  118. * @param system_id ID of this system
  119. * @param component_id ID of this component (e.g. 200 for IMU)
  120. * @param msg The MAVLink message to compress the data into
  121. * @param terrain_data C-struct to read the message contents from
  122. */
  123. static inline uint16_t mavlink_msg_terrain_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_terrain_data_t* terrain_data)
  124. {
  125. return mavlink_msg_terrain_data_pack(system_id, component_id, msg, terrain_data->lat, terrain_data->lon, terrain_data->grid_spacing, terrain_data->gridbit, terrain_data->data);
  126. }
  127. /**
  128. * @brief Encode a terrain_data struct on a channel
  129. *
  130. * @param system_id ID of this system
  131. * @param component_id ID of this component (e.g. 200 for IMU)
  132. * @param chan The MAVLink channel this message will be sent over
  133. * @param msg The MAVLink message to compress the data into
  134. * @param terrain_data C-struct to read the message contents from
  135. */
  136. static inline uint16_t mavlink_msg_terrain_data_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_terrain_data_t* terrain_data)
  137. {
  138. return mavlink_msg_terrain_data_pack_chan(system_id, component_id, chan, msg, terrain_data->lat, terrain_data->lon, terrain_data->grid_spacing, terrain_data->gridbit, terrain_data->data);
  139. }
  140. /**
  141. * @brief Send a terrain_data message
  142. * @param chan MAVLink channel to send the message
  143. *
  144. * @param lat Latitude of SW corner of first grid (degrees *10^7)
  145. * @param lon Longitude of SW corner of first grid (in degrees *10^7)
  146. * @param grid_spacing Grid spacing in meters
  147. * @param gridbit bit within the terrain request mask
  148. * @param data Terrain data in meters AMSL
  149. */
  150. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  151. static inline void mavlink_msg_terrain_data_send(mavlink_channel_t chan, int32_t lat, int32_t lon, uint16_t grid_spacing, uint8_t gridbit, const int16_t *data)
  152. {
  153. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  154. char buf[MAVLINK_MSG_ID_TERRAIN_DATA_LEN];
  155. _mav_put_int32_t(buf, 0, lat);
  156. _mav_put_int32_t(buf, 4, lon);
  157. _mav_put_uint16_t(buf, 8, grid_spacing);
  158. _mav_put_uint8_t(buf, 42, gridbit);
  159. _mav_put_int16_t_array(buf, 10, data, 16);
  160. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_DATA, buf, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  161. #else
  162. mavlink_terrain_data_t packet;
  163. packet.lat = lat;
  164. packet.lon = lon;
  165. packet.grid_spacing = grid_spacing;
  166. packet.gridbit = gridbit;
  167. mav_array_memcpy(packet.data, data, sizeof(int16_t)*16);
  168. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_DATA, (const char *)&packet, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  169. #endif
  170. }
  171. /**
  172. * @brief Send a terrain_data message
  173. * @param chan MAVLink channel to send the message
  174. * @param struct The MAVLink struct to serialize
  175. */
  176. static inline void mavlink_msg_terrain_data_send_struct(mavlink_channel_t chan, const mavlink_terrain_data_t* terrain_data)
  177. {
  178. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  179. mavlink_msg_terrain_data_send(chan, terrain_data->lat, terrain_data->lon, terrain_data->grid_spacing, terrain_data->gridbit, terrain_data->data);
  180. #else
  181. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_DATA, (const char *)terrain_data, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  182. #endif
  183. }
  184. #if MAVLINK_MSG_ID_TERRAIN_DATA_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  185. /*
  186. This varient of _send() can be used to save stack space by re-using
  187. memory from the receive buffer. The caller provides a
  188. mavlink_message_t which is the size of a full mavlink message. This
  189. is usually the receive buffer for the channel, and allows a reply to an
  190. incoming message with minimum stack space usage.
  191. */
  192. static inline void mavlink_msg_terrain_data_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, int32_t lat, int32_t lon, uint16_t grid_spacing, uint8_t gridbit, const int16_t *data)
  193. {
  194. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  195. char *buf = (char *)msgbuf;
  196. _mav_put_int32_t(buf, 0, lat);
  197. _mav_put_int32_t(buf, 4, lon);
  198. _mav_put_uint16_t(buf, 8, grid_spacing);
  199. _mav_put_uint8_t(buf, 42, gridbit);
  200. _mav_put_int16_t_array(buf, 10, data, 16);
  201. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_DATA, buf, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  202. #else
  203. mavlink_terrain_data_t *packet = (mavlink_terrain_data_t *)msgbuf;
  204. packet->lat = lat;
  205. packet->lon = lon;
  206. packet->grid_spacing = grid_spacing;
  207. packet->gridbit = gridbit;
  208. mav_array_memcpy(packet->data, data, sizeof(int16_t)*16);
  209. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TERRAIN_DATA, (const char *)packet, MAVLINK_MSG_ID_TERRAIN_DATA_MIN_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_LEN, MAVLINK_MSG_ID_TERRAIN_DATA_CRC);
  210. #endif
  211. }
  212. #endif
  213. #endif
  214. // MESSAGE TERRAIN_DATA UNPACKING
  215. /**
  216. * @brief Get field lat from terrain_data message
  217. *
  218. * @return Latitude of SW corner of first grid (degrees *10^7)
  219. */
  220. static inline int32_t mavlink_msg_terrain_data_get_lat(const mavlink_message_t* msg)
  221. {
  222. return _MAV_RETURN_int32_t(msg, 0);
  223. }
  224. /**
  225. * @brief Get field lon from terrain_data message
  226. *
  227. * @return Longitude of SW corner of first grid (in degrees *10^7)
  228. */
  229. static inline int32_t mavlink_msg_terrain_data_get_lon(const mavlink_message_t* msg)
  230. {
  231. return _MAV_RETURN_int32_t(msg, 4);
  232. }
  233. /**
  234. * @brief Get field grid_spacing from terrain_data message
  235. *
  236. * @return Grid spacing in meters
  237. */
  238. static inline uint16_t mavlink_msg_terrain_data_get_grid_spacing(const mavlink_message_t* msg)
  239. {
  240. return _MAV_RETURN_uint16_t(msg, 8);
  241. }
  242. /**
  243. * @brief Get field gridbit from terrain_data message
  244. *
  245. * @return bit within the terrain request mask
  246. */
  247. static inline uint8_t mavlink_msg_terrain_data_get_gridbit(const mavlink_message_t* msg)
  248. {
  249. return _MAV_RETURN_uint8_t(msg, 42);
  250. }
  251. /**
  252. * @brief Get field data from terrain_data message
  253. *
  254. * @return Terrain data in meters AMSL
  255. */
  256. static inline uint16_t mavlink_msg_terrain_data_get_data(const mavlink_message_t* msg, int16_t *data)
  257. {
  258. return _MAV_RETURN_int16_t_array(msg, data, 16, 10);
  259. }
  260. /**
  261. * @brief Decode a terrain_data message into a struct
  262. *
  263. * @param msg The message to decode
  264. * @param terrain_data C-struct to decode the message contents into
  265. */
  266. static inline void mavlink_msg_terrain_data_decode(const mavlink_message_t* msg, mavlink_terrain_data_t* terrain_data)
  267. {
  268. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  269. terrain_data->lat = mavlink_msg_terrain_data_get_lat(msg);
  270. terrain_data->lon = mavlink_msg_terrain_data_get_lon(msg);
  271. terrain_data->grid_spacing = mavlink_msg_terrain_data_get_grid_spacing(msg);
  272. mavlink_msg_terrain_data_get_data(msg, terrain_data->data);
  273. terrain_data->gridbit = mavlink_msg_terrain_data_get_gridbit(msg);
  274. #else
  275. uint8_t len = msg->len < MAVLINK_MSG_ID_TERRAIN_DATA_LEN? msg->len : MAVLINK_MSG_ID_TERRAIN_DATA_LEN;
  276. memset(terrain_data, 0, MAVLINK_MSG_ID_TERRAIN_DATA_LEN);
  277. memcpy(terrain_data, _MAV_PAYLOAD(msg), len);
  278. #endif
  279. }