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