You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
12 KiB

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