2 // MESSAGE DISTANCE_SENSOR PACKING
4 #define MAVLINK_MSG_ID_DISTANCE_SENSOR 132
7 typedef struct __mavlink_distance_sensor_t
{
8 uint32_t time_boot_ms
; /*< Time since system boot*/
9 uint16_t min_distance
; /*< Minimum distance the sensor can measure in centimeters*/
10 uint16_t max_distance
; /*< Maximum distance the sensor can measure in centimeters*/
11 uint16_t current_distance
; /*< Current distance reading*/
12 uint8_t type
; /*< Type from MAV_DISTANCE_SENSOR enum.*/
13 uint8_t id
; /*< Onboard ID of the sensor*/
14 uint8_t orientation
; /*< Direction the sensor faces from MAV_SENSOR_ORIENTATION enum.*/
15 uint8_t covariance
; /*< Measurement covariance in centimeters, 0 for unknown / invalid readings*/
16 }) mavlink_distance_sensor_t
;
18 #define MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN 14
19 #define MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN 14
20 #define MAVLINK_MSG_ID_132_LEN 14
21 #define MAVLINK_MSG_ID_132_MIN_LEN 14
23 #define MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC 85
24 #define MAVLINK_MSG_ID_132_CRC 85
28 #if MAVLINK_COMMAND_24BIT
29 #define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR { \
33 { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_distance_sensor_t, time_boot_ms) }, \
34 { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_distance_sensor_t, min_distance) }, \
35 { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_distance_sensor_t, max_distance) }, \
36 { "current_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_distance_sensor_t, current_distance) }, \
37 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_distance_sensor_t, type) }, \
38 { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_distance_sensor_t, id) }, \
39 { "orientation", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_distance_sensor_t, orientation) }, \
40 { "covariance", NULL, MAVLINK_TYPE_UINT8_T, 0, 13, offsetof(mavlink_distance_sensor_t, covariance) }, \
44 #define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR { \
47 { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_distance_sensor_t, time_boot_ms) }, \
48 { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_distance_sensor_t, min_distance) }, \
49 { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_distance_sensor_t, max_distance) }, \
50 { "current_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_distance_sensor_t, current_distance) }, \
51 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_distance_sensor_t, type) }, \
52 { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_distance_sensor_t, id) }, \
53 { "orientation", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_distance_sensor_t, orientation) }, \
54 { "covariance", NULL, MAVLINK_TYPE_UINT8_T, 0, 13, offsetof(mavlink_distance_sensor_t, covariance) }, \
60 * @brief Pack a distance_sensor message
61 * @param system_id ID of this system
62 * @param component_id ID of this component (e.g. 200 for IMU)
63 * @param msg The MAVLink message to compress the data into
65 * @param time_boot_ms Time since system boot
66 * @param min_distance Minimum distance the sensor can measure in centimeters
67 * @param max_distance Maximum distance the sensor can measure in centimeters
68 * @param current_distance Current distance reading
69 * @param type Type from MAV_DISTANCE_SENSOR enum.
70 * @param id Onboard ID of the sensor
71 * @param orientation Direction the sensor faces from MAV_SENSOR_ORIENTATION enum.
72 * @param covariance Measurement covariance in centimeters, 0 for unknown / invalid readings
73 * @return length of the message in bytes (excluding serial stream start sign)
75 static inline uint16_t mavlink_msg_distance_sensor_pack(uint8_t system_id
, uint8_t component_id
, mavlink_message_t
* msg
,
76 uint32_t time_boot_ms
, uint16_t min_distance
, uint16_t max_distance
, uint16_t current_distance
, uint8_t type
, uint8_t id
, uint8_t orientation
, uint8_t covariance
)
78 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
79 char buf
[MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
];
80 _mav_put_uint32_t(buf
, 0, time_boot_ms
);
81 _mav_put_uint16_t(buf
, 4, min_distance
);
82 _mav_put_uint16_t(buf
, 6, max_distance
);
83 _mav_put_uint16_t(buf
, 8, current_distance
);
84 _mav_put_uint8_t(buf
, 10, type
);
85 _mav_put_uint8_t(buf
, 11, id
);
86 _mav_put_uint8_t(buf
, 12, orientation
);
87 _mav_put_uint8_t(buf
, 13, covariance
);
89 memcpy(_MAV_PAYLOAD_NON_CONST(msg
), buf
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
);
91 mavlink_distance_sensor_t packet
;
92 packet
.time_boot_ms
= time_boot_ms
;
93 packet
.min_distance
= min_distance
;
94 packet
.max_distance
= max_distance
;
95 packet
.current_distance
= current_distance
;
98 packet
.orientation
= orientation
;
99 packet
.covariance
= covariance
;
101 memcpy(_MAV_PAYLOAD_NON_CONST(msg
), &packet
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
);
104 msg
->msgid
= MAVLINK_MSG_ID_DISTANCE_SENSOR
;
105 return mavlink_finalize_message(msg
, system_id
, component_id
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
109 * @brief Pack a distance_sensor message on a channel
110 * @param system_id ID of this system
111 * @param component_id ID of this component (e.g. 200 for IMU)
112 * @param chan The MAVLink channel this message will be sent over
113 * @param msg The MAVLink message to compress the data into
114 * @param time_boot_ms Time since system boot
115 * @param min_distance Minimum distance the sensor can measure in centimeters
116 * @param max_distance Maximum distance the sensor can measure in centimeters
117 * @param current_distance Current distance reading
118 * @param type Type from MAV_DISTANCE_SENSOR enum.
119 * @param id Onboard ID of the sensor
120 * @param orientation Direction the sensor faces from MAV_SENSOR_ORIENTATION enum.
121 * @param covariance Measurement covariance in centimeters, 0 for unknown / invalid readings
122 * @return length of the message in bytes (excluding serial stream start sign)
124 static inline uint16_t mavlink_msg_distance_sensor_pack_chan(uint8_t system_id
, uint8_t component_id
, uint8_t chan
,
125 mavlink_message_t
* msg
,
126 uint32_t time_boot_ms
,uint16_t min_distance
,uint16_t max_distance
,uint16_t current_distance
,uint8_t type
,uint8_t id
,uint8_t orientation
,uint8_t covariance
)
128 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
129 char buf
[MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
];
130 _mav_put_uint32_t(buf
, 0, time_boot_ms
);
131 _mav_put_uint16_t(buf
, 4, min_distance
);
132 _mav_put_uint16_t(buf
, 6, max_distance
);
133 _mav_put_uint16_t(buf
, 8, current_distance
);
134 _mav_put_uint8_t(buf
, 10, type
);
135 _mav_put_uint8_t(buf
, 11, id
);
136 _mav_put_uint8_t(buf
, 12, orientation
);
137 _mav_put_uint8_t(buf
, 13, covariance
);
139 memcpy(_MAV_PAYLOAD_NON_CONST(msg
), buf
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
);
141 mavlink_distance_sensor_t packet
;
142 packet
.time_boot_ms
= time_boot_ms
;
143 packet
.min_distance
= min_distance
;
144 packet
.max_distance
= max_distance
;
145 packet
.current_distance
= current_distance
;
148 packet
.orientation
= orientation
;
149 packet
.covariance
= covariance
;
151 memcpy(_MAV_PAYLOAD_NON_CONST(msg
), &packet
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
);
154 msg
->msgid
= MAVLINK_MSG_ID_DISTANCE_SENSOR
;
155 return mavlink_finalize_message_chan(msg
, system_id
, component_id
, chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
159 * @brief Encode a distance_sensor struct
161 * @param system_id ID of this system
162 * @param component_id ID of this component (e.g. 200 for IMU)
163 * @param msg The MAVLink message to compress the data into
164 * @param distance_sensor C-struct to read the message contents from
166 static inline uint16_t mavlink_msg_distance_sensor_encode(uint8_t system_id
, uint8_t component_id
, mavlink_message_t
* msg
, const mavlink_distance_sensor_t
* distance_sensor
)
168 return mavlink_msg_distance_sensor_pack(system_id
, component_id
, msg
, distance_sensor
->time_boot_ms
, distance_sensor
->min_distance
, distance_sensor
->max_distance
, distance_sensor
->current_distance
, distance_sensor
->type
, distance_sensor
->id
, distance_sensor
->orientation
, distance_sensor
->covariance
);
172 * @brief Encode a distance_sensor struct on a channel
174 * @param system_id ID of this system
175 * @param component_id ID of this component (e.g. 200 for IMU)
176 * @param chan The MAVLink channel this message will be sent over
177 * @param msg The MAVLink message to compress the data into
178 * @param distance_sensor C-struct to read the message contents from
180 static inline uint16_t mavlink_msg_distance_sensor_encode_chan(uint8_t system_id
, uint8_t component_id
, uint8_t chan
, mavlink_message_t
* msg
, const mavlink_distance_sensor_t
* distance_sensor
)
182 return mavlink_msg_distance_sensor_pack_chan(system_id
, component_id
, chan
, msg
, distance_sensor
->time_boot_ms
, distance_sensor
->min_distance
, distance_sensor
->max_distance
, distance_sensor
->current_distance
, distance_sensor
->type
, distance_sensor
->id
, distance_sensor
->orientation
, distance_sensor
->covariance
);
186 * @brief Send a distance_sensor message
187 * @param chan MAVLink channel to send the message
189 * @param time_boot_ms Time since system boot
190 * @param min_distance Minimum distance the sensor can measure in centimeters
191 * @param max_distance Maximum distance the sensor can measure in centimeters
192 * @param current_distance Current distance reading
193 * @param type Type from MAV_DISTANCE_SENSOR enum.
194 * @param id Onboard ID of the sensor
195 * @param orientation Direction the sensor faces from MAV_SENSOR_ORIENTATION enum.
196 * @param covariance Measurement covariance in centimeters, 0 for unknown / invalid readings
198 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
200 static inline void mavlink_msg_distance_sensor_send(mavlink_channel_t chan
, uint32_t time_boot_ms
, uint16_t min_distance
, uint16_t max_distance
, uint16_t current_distance
, uint8_t type
, uint8_t id
, uint8_t orientation
, uint8_t covariance
)
202 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
203 char buf
[MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
];
204 _mav_put_uint32_t(buf
, 0, time_boot_ms
);
205 _mav_put_uint16_t(buf
, 4, min_distance
);
206 _mav_put_uint16_t(buf
, 6, max_distance
);
207 _mav_put_uint16_t(buf
, 8, current_distance
);
208 _mav_put_uint8_t(buf
, 10, type
);
209 _mav_put_uint8_t(buf
, 11, id
);
210 _mav_put_uint8_t(buf
, 12, orientation
);
211 _mav_put_uint8_t(buf
, 13, covariance
);
213 _mav_finalize_message_chan_send(chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR
, buf
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
215 mavlink_distance_sensor_t packet
;
216 packet
.time_boot_ms
= time_boot_ms
;
217 packet
.min_distance
= min_distance
;
218 packet
.max_distance
= max_distance
;
219 packet
.current_distance
= current_distance
;
222 packet
.orientation
= orientation
;
223 packet
.covariance
= covariance
;
225 _mav_finalize_message_chan_send(chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR
, (const char *)&packet
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
230 * @brief Send a distance_sensor message
231 * @param chan MAVLink channel to send the message
232 * @param struct The MAVLink struct to serialize
234 static inline void mavlink_msg_distance_sensor_send_struct(mavlink_channel_t chan
, const mavlink_distance_sensor_t
* distance_sensor
)
236 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
237 mavlink_msg_distance_sensor_send(chan
, distance_sensor
->time_boot_ms
, distance_sensor
->min_distance
, distance_sensor
->max_distance
, distance_sensor
->current_distance
, distance_sensor
->type
, distance_sensor
->id
, distance_sensor
->orientation
, distance_sensor
->covariance
);
239 _mav_finalize_message_chan_send(chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR
, (const char *)distance_sensor
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
243 #if MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN <= MAVLINK_MAX_PAYLOAD_LEN
245 This varient of _send() can be used to save stack space by re-using
246 memory from the receive buffer. The caller provides a
247 mavlink_message_t which is the size of a full mavlink message. This
248 is usually the receive buffer for the channel, and allows a reply to an
249 incoming message with minimum stack space usage.
251 static inline void mavlink_msg_distance_sensor_send_buf(mavlink_message_t
*msgbuf
, mavlink_channel_t chan
, uint32_t time_boot_ms
, uint16_t min_distance
, uint16_t max_distance
, uint16_t current_distance
, uint8_t type
, uint8_t id
, uint8_t orientation
, uint8_t covariance
)
253 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
254 char *buf
= (char *)msgbuf
;
255 _mav_put_uint32_t(buf
, 0, time_boot_ms
);
256 _mav_put_uint16_t(buf
, 4, min_distance
);
257 _mav_put_uint16_t(buf
, 6, max_distance
);
258 _mav_put_uint16_t(buf
, 8, current_distance
);
259 _mav_put_uint8_t(buf
, 10, type
);
260 _mav_put_uint8_t(buf
, 11, id
);
261 _mav_put_uint8_t(buf
, 12, orientation
);
262 _mav_put_uint8_t(buf
, 13, covariance
);
264 _mav_finalize_message_chan_send(chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR
, buf
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
266 mavlink_distance_sensor_t
*packet
= (mavlink_distance_sensor_t
*)msgbuf
;
267 packet
->time_boot_ms
= time_boot_ms
;
268 packet
->min_distance
= min_distance
;
269 packet
->max_distance
= max_distance
;
270 packet
->current_distance
= current_distance
;
273 packet
->orientation
= orientation
;
274 packet
->covariance
= covariance
;
276 _mav_finalize_message_chan_send(chan
, MAVLINK_MSG_ID_DISTANCE_SENSOR
, (const char *)packet
, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC
);
283 // MESSAGE DISTANCE_SENSOR UNPACKING
287 * @brief Get field time_boot_ms from distance_sensor message
289 * @return Time since system boot
291 static inline uint32_t mavlink_msg_distance_sensor_get_time_boot_ms(const mavlink_message_t
* msg
)
293 return _MAV_RETURN_uint32_t(msg
, 0);
297 * @brief Get field min_distance from distance_sensor message
299 * @return Minimum distance the sensor can measure in centimeters
301 static inline uint16_t mavlink_msg_distance_sensor_get_min_distance(const mavlink_message_t
* msg
)
303 return _MAV_RETURN_uint16_t(msg
, 4);
307 * @brief Get field max_distance from distance_sensor message
309 * @return Maximum distance the sensor can measure in centimeters
311 static inline uint16_t mavlink_msg_distance_sensor_get_max_distance(const mavlink_message_t
* msg
)
313 return _MAV_RETURN_uint16_t(msg
, 6);
317 * @brief Get field current_distance from distance_sensor message
319 * @return Current distance reading
321 static inline uint16_t mavlink_msg_distance_sensor_get_current_distance(const mavlink_message_t
* msg
)
323 return _MAV_RETURN_uint16_t(msg
, 8);
327 * @brief Get field type from distance_sensor message
329 * @return Type from MAV_DISTANCE_SENSOR enum.
331 static inline uint8_t mavlink_msg_distance_sensor_get_type(const mavlink_message_t
* msg
)
333 return _MAV_RETURN_uint8_t(msg
, 10);
337 * @brief Get field id from distance_sensor message
339 * @return Onboard ID of the sensor
341 static inline uint8_t mavlink_msg_distance_sensor_get_id(const mavlink_message_t
* msg
)
343 return _MAV_RETURN_uint8_t(msg
, 11);
347 * @brief Get field orientation from distance_sensor message
349 * @return Direction the sensor faces from MAV_SENSOR_ORIENTATION enum.
351 static inline uint8_t mavlink_msg_distance_sensor_get_orientation(const mavlink_message_t
* msg
)
353 return _MAV_RETURN_uint8_t(msg
, 12);
357 * @brief Get field covariance from distance_sensor message
359 * @return Measurement covariance in centimeters, 0 for unknown / invalid readings
361 static inline uint8_t mavlink_msg_distance_sensor_get_covariance(const mavlink_message_t
* msg
)
363 return _MAV_RETURN_uint8_t(msg
, 13);
367 * @brief Decode a distance_sensor message into a struct
369 * @param msg The message to decode
370 * @param distance_sensor C-struct to decode the message contents into
372 static inline void mavlink_msg_distance_sensor_decode(const mavlink_message_t
* msg
, mavlink_distance_sensor_t
* distance_sensor
)
374 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
375 distance_sensor
->time_boot_ms
= mavlink_msg_distance_sensor_get_time_boot_ms(msg
);
376 distance_sensor
->min_distance
= mavlink_msg_distance_sensor_get_min_distance(msg
);
377 distance_sensor
->max_distance
= mavlink_msg_distance_sensor_get_max_distance(msg
);
378 distance_sensor
->current_distance
= mavlink_msg_distance_sensor_get_current_distance(msg
);
379 distance_sensor
->type
= mavlink_msg_distance_sensor_get_type(msg
);
380 distance_sensor
->id
= mavlink_msg_distance_sensor_get_id(msg
);
381 distance_sensor
->orientation
= mavlink_msg_distance_sensor_get_orientation(msg
);
382 distance_sensor
->covariance
= mavlink_msg_distance_sensor_get_covariance(msg
);
384 uint8_t len
= msg
->len
< MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
? msg
->len
: MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
;
385 memset(distance_sensor
, 0, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN
);
386 memcpy(distance_sensor
, _MAV_PAYLOAD(msg
), len
);