RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
mavlink_msg_distance_sensor.h
1#pragma once
2// MESSAGE DISTANCE_SENSOR PACKING
3
4#define MAVLINK_MSG_ID_DISTANCE_SENSOR 132
5
6MAVPACKED(
7typedef 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. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270*/
15 uint8_t covariance; /*< Measurement covariance in centimeters, 0 for unknown / invalid readings*/
16}) mavlink_distance_sensor_t;
17
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
22
23#define MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC 85
24#define MAVLINK_MSG_ID_132_CRC 85
25
26
27
28#if MAVLINK_COMMAND_24BIT
29#define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR { \
30 132, \
31 "DISTANCE_SENSOR", \
32 8, \
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) }, \
41 } \
42}
43#else
44#define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR { \
45 "DISTANCE_SENSOR", \
46 8, \
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) }, \
55 } \
56}
57#endif
58
59/**
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
64 *
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. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
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)
74 */
75static 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)
77{
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);
88
89 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
90#else
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;
96 packet.type = type;
97 packet.id = id;
98 packet.orientation = orientation;
99 packet.covariance = covariance;
100
101 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
102#endif
103
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);
106}
107
108/**
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. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
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)
123 */
124static 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)
127{
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);
138
139 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
140#else
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;
146 packet.type = type;
147 packet.id = id;
148 packet.orientation = orientation;
149 packet.covariance = covariance;
150
151 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
152#endif
153
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);
156}
157
158/**
159 * @brief Encode a distance_sensor struct
160 *
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
165 */
166static 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)
167{
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);
169}
170
171/**
172 * @brief Encode a distance_sensor struct on a channel
173 *
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
179 */
180static 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)
181{
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);
183}
184
185/**
186 * @brief Send a distance_sensor message
187 * @param chan MAVLink channel to send the message
188 *
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. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
196 * @param covariance Measurement covariance in centimeters, 0 for unknown / invalid readings
197 */
198#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
199
200static 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)
201{
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);
212
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);
214#else
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;
220 packet.type = type;
221 packet.id = id;
222 packet.orientation = orientation;
223 packet.covariance = covariance;
224
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);
226#endif
227}
228
229/**
230 * @brief Send a distance_sensor message
231 * @param chan MAVLink channel to send the message
232 * @param struct The MAVLink struct to serialize
233 */
234static inline void mavlink_msg_distance_sensor_send_struct(mavlink_channel_t chan, const mavlink_distance_sensor_t* distance_sensor)
235{
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);
238#else
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);
240#endif
241}
242
243#if MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN <= MAVLINK_MAX_PAYLOAD_LEN
244/*
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.
250 */
251static 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)
252{
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);
263
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);
265#else
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;
271 packet->type = type;
272 packet->id = id;
273 packet->orientation = orientation;
274 packet->covariance = covariance;
275
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);
277#endif
278}
279#endif
280
281#endif
282
283// MESSAGE DISTANCE_SENSOR UNPACKING
284
285
286/**
287 * @brief Get field time_boot_ms from distance_sensor message
288 *
289 * @return Time since system boot
290 */
291static inline uint32_t mavlink_msg_distance_sensor_get_time_boot_ms(const mavlink_message_t* msg)
292{
293 return _MAV_RETURN_uint32_t(msg, 0);
294}
295
296/**
297 * @brief Get field min_distance from distance_sensor message
298 *
299 * @return Minimum distance the sensor can measure in centimeters
300 */
301static inline uint16_t mavlink_msg_distance_sensor_get_min_distance(const mavlink_message_t* msg)
302{
303 return _MAV_RETURN_uint16_t(msg, 4);
304}
305
306/**
307 * @brief Get field max_distance from distance_sensor message
308 *
309 * @return Maximum distance the sensor can measure in centimeters
310 */
311static inline uint16_t mavlink_msg_distance_sensor_get_max_distance(const mavlink_message_t* msg)
312{
313 return _MAV_RETURN_uint16_t(msg, 6);
314}
315
316/**
317 * @brief Get field current_distance from distance_sensor message
318 *
319 * @return Current distance reading
320 */
321static inline uint16_t mavlink_msg_distance_sensor_get_current_distance(const mavlink_message_t* msg)
322{
323 return _MAV_RETURN_uint16_t(msg, 8);
324}
325
326/**
327 * @brief Get field type from distance_sensor message
328 *
329 * @return Type from MAV_DISTANCE_SENSOR enum.
330 */
331static inline uint8_t mavlink_msg_distance_sensor_get_type(const mavlink_message_t* msg)
332{
333 return _MAV_RETURN_uint8_t(msg, 10);
334}
335
336/**
337 * @brief Get field id from distance_sensor message
338 *
339 * @return Onboard ID of the sensor
340 */
341static inline uint8_t mavlink_msg_distance_sensor_get_id(const mavlink_message_t* msg)
342{
343 return _MAV_RETURN_uint8_t(msg, 11);
344}
345
346/**
347 * @brief Get field orientation from distance_sensor message
348 *
349 * @return Direction the sensor faces from MAV_SENSOR_ORIENTATION enum. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
350 */
351static inline uint8_t mavlink_msg_distance_sensor_get_orientation(const mavlink_message_t* msg)
352{
353 return _MAV_RETURN_uint8_t(msg, 12);
354}
355
356/**
357 * @brief Get field covariance from distance_sensor message
358 *
359 * @return Measurement covariance in centimeters, 0 for unknown / invalid readings
360 */
361static inline uint8_t mavlink_msg_distance_sensor_get_covariance(const mavlink_message_t* msg)
362{
363 return _MAV_RETURN_uint8_t(msg, 13);
364}
365
366/**
367 * @brief Decode a distance_sensor message into a struct
368 *
369 * @param msg The message to decode
370 * @param distance_sensor C-struct to decode the message contents into
371 */
372static inline void mavlink_msg_distance_sensor_decode(const mavlink_message_t* msg, mavlink_distance_sensor_t* distance_sensor)
373{
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);
383#else
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);
387#endif
388}