source: flair-src/trunk/tools/Controller/Mavlink/src/include/common/mavlink_msg_raw_imu.h@ 88

Last change on this file since 88 was 88, checked in by Sanahuja Guillaume, 8 years ago

m

File size: 15.9 KB
Line 
1// MESSAGE RAW_IMU PACKING
2
3#define MAVLINK_MSG_ID_RAW_IMU 27
4
5typedef struct MAVLINK_PACKED __mavlink_raw_imu_t
6{
7 uint64_t time_usec; /*< Timestamp (microseconds since UNIX epoch or microseconds since system boot)*/
8 int16_t xacc; /*< X acceleration (raw)*/
9 int16_t yacc; /*< Y acceleration (raw)*/
10 int16_t zacc; /*< Z acceleration (raw)*/
11 int16_t xgyro; /*< Angular speed around X axis (raw)*/
12 int16_t ygyro; /*< Angular speed around Y axis (raw)*/
13 int16_t zgyro; /*< Angular speed around Z axis (raw)*/
14 int16_t xmag; /*< X Magnetic field (raw)*/
15 int16_t ymag; /*< Y Magnetic field (raw)*/
16 int16_t zmag; /*< Z Magnetic field (raw)*/
17} mavlink_raw_imu_t;
18
19#define MAVLINK_MSG_ID_RAW_IMU_LEN 26
20#define MAVLINK_MSG_ID_RAW_IMU_MIN_LEN 26
21#define MAVLINK_MSG_ID_27_LEN 26
22#define MAVLINK_MSG_ID_27_MIN_LEN 26
23
24#define MAVLINK_MSG_ID_RAW_IMU_CRC 144
25#define MAVLINK_MSG_ID_27_CRC 144
26
27
28
29#if MAVLINK_COMMAND_24BIT
30#define MAVLINK_MESSAGE_INFO_RAW_IMU { \
31 27, \
32 "RAW_IMU", \
33 10, \
34 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_raw_imu_t, time_usec) }, \
35 { "xacc", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_raw_imu_t, xacc) }, \
36 { "yacc", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_raw_imu_t, yacc) }, \
37 { "zacc", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_raw_imu_t, zacc) }, \
38 { "xgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_raw_imu_t, xgyro) }, \
39 { "ygyro", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_raw_imu_t, ygyro) }, \
40 { "zgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 18, offsetof(mavlink_raw_imu_t, zgyro) }, \
41 { "xmag", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_raw_imu_t, xmag) }, \
42 { "ymag", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_raw_imu_t, ymag) }, \
43 { "zmag", NULL, MAVLINK_TYPE_INT16_T, 0, 24, offsetof(mavlink_raw_imu_t, zmag) }, \
44 } \
45}
46#else
47#define MAVLINK_MESSAGE_INFO_RAW_IMU { \
48 "RAW_IMU", \
49 10, \
50 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_raw_imu_t, time_usec) }, \
51 { "xacc", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_raw_imu_t, xacc) }, \
52 { "yacc", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_raw_imu_t, yacc) }, \
53 { "zacc", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_raw_imu_t, zacc) }, \
54 { "xgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_raw_imu_t, xgyro) }, \
55 { "ygyro", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_raw_imu_t, ygyro) }, \
56 { "zgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 18, offsetof(mavlink_raw_imu_t, zgyro) }, \
57 { "xmag", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_raw_imu_t, xmag) }, \
58 { "ymag", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_raw_imu_t, ymag) }, \
59 { "zmag", NULL, MAVLINK_TYPE_INT16_T, 0, 24, offsetof(mavlink_raw_imu_t, zmag) }, \
60 } \
61}
62#endif
63
64/**
65 * @brief Pack a raw_imu message
66 * @param system_id ID of this system
67 * @param component_id ID of this component (e.g. 200 for IMU)
68 * @param msg The MAVLink message to compress the data into
69 *
70 * @param time_usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
71 * @param xacc X acceleration (raw)
72 * @param yacc Y acceleration (raw)
73 * @param zacc Z acceleration (raw)
74 * @param xgyro Angular speed around X axis (raw)
75 * @param ygyro Angular speed around Y axis (raw)
76 * @param zgyro Angular speed around Z axis (raw)
77 * @param xmag X Magnetic field (raw)
78 * @param ymag Y Magnetic field (raw)
79 * @param zmag Z Magnetic field (raw)
80 * @return length of the message in bytes (excluding serial stream start sign)
81 */
82static inline uint16_t mavlink_msg_raw_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
83 uint64_t time_usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
84{
85#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
86 char buf[MAVLINK_MSG_ID_RAW_IMU_LEN];
87 _mav_put_uint64_t(buf, 0, time_usec);
88 _mav_put_int16_t(buf, 8, xacc);
89 _mav_put_int16_t(buf, 10, yacc);
90 _mav_put_int16_t(buf, 12, zacc);
91 _mav_put_int16_t(buf, 14, xgyro);
92 _mav_put_int16_t(buf, 16, ygyro);
93 _mav_put_int16_t(buf, 18, zgyro);
94 _mav_put_int16_t(buf, 20, xmag);
95 _mav_put_int16_t(buf, 22, ymag);
96 _mav_put_int16_t(buf, 24, zmag);
97
98 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_RAW_IMU_LEN);
99#else
100 mavlink_raw_imu_t packet;
101 packet.time_usec = time_usec;
102 packet.xacc = xacc;
103 packet.yacc = yacc;
104 packet.zacc = zacc;
105 packet.xgyro = xgyro;
106 packet.ygyro = ygyro;
107 packet.zgyro = zgyro;
108 packet.xmag = xmag;
109 packet.ymag = ymag;
110 packet.zmag = zmag;
111
112 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_RAW_IMU_LEN);
113#endif
114
115 msg->msgid = MAVLINK_MSG_ID_RAW_IMU;
116 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
117}
118
119/**
120 * @brief Pack a raw_imu message on a channel
121 * @param system_id ID of this system
122 * @param component_id ID of this component (e.g. 200 for IMU)
123 * @param chan The MAVLink channel this message will be sent over
124 * @param msg The MAVLink message to compress the data into
125 * @param time_usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
126 * @param xacc X acceleration (raw)
127 * @param yacc Y acceleration (raw)
128 * @param zacc Z acceleration (raw)
129 * @param xgyro Angular speed around X axis (raw)
130 * @param ygyro Angular speed around Y axis (raw)
131 * @param zgyro Angular speed around Z axis (raw)
132 * @param xmag X Magnetic field (raw)
133 * @param ymag Y Magnetic field (raw)
134 * @param zmag Z Magnetic field (raw)
135 * @return length of the message in bytes (excluding serial stream start sign)
136 */
137static inline uint16_t mavlink_msg_raw_imu_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
138 mavlink_message_t* msg,
139 uint64_t time_usec,int16_t xacc,int16_t yacc,int16_t zacc,int16_t xgyro,int16_t ygyro,int16_t zgyro,int16_t xmag,int16_t ymag,int16_t zmag)
140{
141#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
142 char buf[MAVLINK_MSG_ID_RAW_IMU_LEN];
143 _mav_put_uint64_t(buf, 0, time_usec);
144 _mav_put_int16_t(buf, 8, xacc);
145 _mav_put_int16_t(buf, 10, yacc);
146 _mav_put_int16_t(buf, 12, zacc);
147 _mav_put_int16_t(buf, 14, xgyro);
148 _mav_put_int16_t(buf, 16, ygyro);
149 _mav_put_int16_t(buf, 18, zgyro);
150 _mav_put_int16_t(buf, 20, xmag);
151 _mav_put_int16_t(buf, 22, ymag);
152 _mav_put_int16_t(buf, 24, zmag);
153
154 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_RAW_IMU_LEN);
155#else
156 mavlink_raw_imu_t packet;
157 packet.time_usec = time_usec;
158 packet.xacc = xacc;
159 packet.yacc = yacc;
160 packet.zacc = zacc;
161 packet.xgyro = xgyro;
162 packet.ygyro = ygyro;
163 packet.zgyro = zgyro;
164 packet.xmag = xmag;
165 packet.ymag = ymag;
166 packet.zmag = zmag;
167
168 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_RAW_IMU_LEN);
169#endif
170
171 msg->msgid = MAVLINK_MSG_ID_RAW_IMU;
172 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
173}
174
175/**
176 * @brief Encode a raw_imu struct
177 *
178 * @param system_id ID of this system
179 * @param component_id ID of this component (e.g. 200 for IMU)
180 * @param msg The MAVLink message to compress the data into
181 * @param raw_imu C-struct to read the message contents from
182 */
183static inline uint16_t mavlink_msg_raw_imu_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_raw_imu_t* raw_imu)
184{
185 return mavlink_msg_raw_imu_pack(system_id, component_id, msg, raw_imu->time_usec, raw_imu->xacc, raw_imu->yacc, raw_imu->zacc, raw_imu->xgyro, raw_imu->ygyro, raw_imu->zgyro, raw_imu->xmag, raw_imu->ymag, raw_imu->zmag);
186}
187
188/**
189 * @brief Encode a raw_imu struct on a channel
190 *
191 * @param system_id ID of this system
192 * @param component_id ID of this component (e.g. 200 for IMU)
193 * @param chan The MAVLink channel this message will be sent over
194 * @param msg The MAVLink message to compress the data into
195 * @param raw_imu C-struct to read the message contents from
196 */
197static inline uint16_t mavlink_msg_raw_imu_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_raw_imu_t* raw_imu)
198{
199 return mavlink_msg_raw_imu_pack_chan(system_id, component_id, chan, msg, raw_imu->time_usec, raw_imu->xacc, raw_imu->yacc, raw_imu->zacc, raw_imu->xgyro, raw_imu->ygyro, raw_imu->zgyro, raw_imu->xmag, raw_imu->ymag, raw_imu->zmag);
200}
201
202/**
203 * @brief Send a raw_imu message
204 * @param chan MAVLink channel to send the message
205 *
206 * @param time_usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
207 * @param xacc X acceleration (raw)
208 * @param yacc Y acceleration (raw)
209 * @param zacc Z acceleration (raw)
210 * @param xgyro Angular speed around X axis (raw)
211 * @param ygyro Angular speed around Y axis (raw)
212 * @param zgyro Angular speed around Z axis (raw)
213 * @param xmag X Magnetic field (raw)
214 * @param ymag Y Magnetic field (raw)
215 * @param zmag Z Magnetic field (raw)
216 */
217#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
218
219static inline void mavlink_msg_raw_imu_send(mavlink_channel_t chan, uint64_t time_usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
220{
221#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
222 char buf[MAVLINK_MSG_ID_RAW_IMU_LEN];
223 _mav_put_uint64_t(buf, 0, time_usec);
224 _mav_put_int16_t(buf, 8, xacc);
225 _mav_put_int16_t(buf, 10, yacc);
226 _mav_put_int16_t(buf, 12, zacc);
227 _mav_put_int16_t(buf, 14, xgyro);
228 _mav_put_int16_t(buf, 16, ygyro);
229 _mav_put_int16_t(buf, 18, zgyro);
230 _mav_put_int16_t(buf, 20, xmag);
231 _mav_put_int16_t(buf, 22, ymag);
232 _mav_put_int16_t(buf, 24, zmag);
233
234 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, buf, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
235#else
236 mavlink_raw_imu_t packet;
237 packet.time_usec = time_usec;
238 packet.xacc = xacc;
239 packet.yacc = yacc;
240 packet.zacc = zacc;
241 packet.xgyro = xgyro;
242 packet.ygyro = ygyro;
243 packet.zgyro = zgyro;
244 packet.xmag = xmag;
245 packet.ymag = ymag;
246 packet.zmag = zmag;
247
248 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, (const char *)&packet, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
249#endif
250}
251
252/**
253 * @brief Send a raw_imu message
254 * @param chan MAVLink channel to send the message
255 * @param struct The MAVLink struct to serialize
256 */
257static inline void mavlink_msg_raw_imu_send_struct(mavlink_channel_t chan, const mavlink_raw_imu_t* raw_imu)
258{
259#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
260 mavlink_msg_raw_imu_send(chan, raw_imu->time_usec, raw_imu->xacc, raw_imu->yacc, raw_imu->zacc, raw_imu->xgyro, raw_imu->ygyro, raw_imu->zgyro, raw_imu->xmag, raw_imu->ymag, raw_imu->zmag);
261#else
262 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, (const char *)raw_imu, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
263#endif
264}
265
266#if MAVLINK_MSG_ID_RAW_IMU_LEN <= MAVLINK_MAX_PAYLOAD_LEN
267/*
268 This varient of _send() can be used to save stack space by re-using
269 memory from the receive buffer. The caller provides a
270 mavlink_message_t which is the size of a full mavlink message. This
271 is usually the receive buffer for the channel, and allows a reply to an
272 incoming message with minimum stack space usage.
273 */
274static inline void mavlink_msg_raw_imu_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
275{
276#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
277 char *buf = (char *)msgbuf;
278 _mav_put_uint64_t(buf, 0, time_usec);
279 _mav_put_int16_t(buf, 8, xacc);
280 _mav_put_int16_t(buf, 10, yacc);
281 _mav_put_int16_t(buf, 12, zacc);
282 _mav_put_int16_t(buf, 14, xgyro);
283 _mav_put_int16_t(buf, 16, ygyro);
284 _mav_put_int16_t(buf, 18, zgyro);
285 _mav_put_int16_t(buf, 20, xmag);
286 _mav_put_int16_t(buf, 22, ymag);
287 _mav_put_int16_t(buf, 24, zmag);
288
289 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, buf, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
290#else
291 mavlink_raw_imu_t *packet = (mavlink_raw_imu_t *)msgbuf;
292 packet->time_usec = time_usec;
293 packet->xacc = xacc;
294 packet->yacc = yacc;
295 packet->zacc = zacc;
296 packet->xgyro = xgyro;
297 packet->ygyro = ygyro;
298 packet->zgyro = zgyro;
299 packet->xmag = xmag;
300 packet->ymag = ymag;
301 packet->zmag = zmag;
302
303 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, (const char *)packet, MAVLINK_MSG_ID_RAW_IMU_MIN_LEN, MAVLINK_MSG_ID_RAW_IMU_LEN, MAVLINK_MSG_ID_RAW_IMU_CRC);
304#endif
305}
306#endif
307
308#endif
309
310// MESSAGE RAW_IMU UNPACKING
311
312
313/**
314 * @brief Get field time_usec from raw_imu message
315 *
316 * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot)
317 */
318static inline uint64_t mavlink_msg_raw_imu_get_time_usec(const mavlink_message_t* msg)
319{
320 return _MAV_RETURN_uint64_t(msg, 0);
321}
322
323/**
324 * @brief Get field xacc from raw_imu message
325 *
326 * @return X acceleration (raw)
327 */
328static inline int16_t mavlink_msg_raw_imu_get_xacc(const mavlink_message_t* msg)
329{
330 return _MAV_RETURN_int16_t(msg, 8);
331}
332
333/**
334 * @brief Get field yacc from raw_imu message
335 *
336 * @return Y acceleration (raw)
337 */
338static inline int16_t mavlink_msg_raw_imu_get_yacc(const mavlink_message_t* msg)
339{
340 return _MAV_RETURN_int16_t(msg, 10);
341}
342
343/**
344 * @brief Get field zacc from raw_imu message
345 *
346 * @return Z acceleration (raw)
347 */
348static inline int16_t mavlink_msg_raw_imu_get_zacc(const mavlink_message_t* msg)
349{
350 return _MAV_RETURN_int16_t(msg, 12);
351}
352
353/**
354 * @brief Get field xgyro from raw_imu message
355 *
356 * @return Angular speed around X axis (raw)
357 */
358static inline int16_t mavlink_msg_raw_imu_get_xgyro(const mavlink_message_t* msg)
359{
360 return _MAV_RETURN_int16_t(msg, 14);
361}
362
363/**
364 * @brief Get field ygyro from raw_imu message
365 *
366 * @return Angular speed around Y axis (raw)
367 */
368static inline int16_t mavlink_msg_raw_imu_get_ygyro(const mavlink_message_t* msg)
369{
370 return _MAV_RETURN_int16_t(msg, 16);
371}
372
373/**
374 * @brief Get field zgyro from raw_imu message
375 *
376 * @return Angular speed around Z axis (raw)
377 */
378static inline int16_t mavlink_msg_raw_imu_get_zgyro(const mavlink_message_t* msg)
379{
380 return _MAV_RETURN_int16_t(msg, 18);
381}
382
383/**
384 * @brief Get field xmag from raw_imu message
385 *
386 * @return X Magnetic field (raw)
387 */
388static inline int16_t mavlink_msg_raw_imu_get_xmag(const mavlink_message_t* msg)
389{
390 return _MAV_RETURN_int16_t(msg, 20);
391}
392
393/**
394 * @brief Get field ymag from raw_imu message
395 *
396 * @return Y Magnetic field (raw)
397 */
398static inline int16_t mavlink_msg_raw_imu_get_ymag(const mavlink_message_t* msg)
399{
400 return _MAV_RETURN_int16_t(msg, 22);
401}
402
403/**
404 * @brief Get field zmag from raw_imu message
405 *
406 * @return Z Magnetic field (raw)
407 */
408static inline int16_t mavlink_msg_raw_imu_get_zmag(const mavlink_message_t* msg)
409{
410 return _MAV_RETURN_int16_t(msg, 24);
411}
412
413/**
414 * @brief Decode a raw_imu message into a struct
415 *
416 * @param msg The message to decode
417 * @param raw_imu C-struct to decode the message contents into
418 */
419static inline void mavlink_msg_raw_imu_decode(const mavlink_message_t* msg, mavlink_raw_imu_t* raw_imu)
420{
421#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
422 raw_imu->time_usec = mavlink_msg_raw_imu_get_time_usec(msg);
423 raw_imu->xacc = mavlink_msg_raw_imu_get_xacc(msg);
424 raw_imu->yacc = mavlink_msg_raw_imu_get_yacc(msg);
425 raw_imu->zacc = mavlink_msg_raw_imu_get_zacc(msg);
426 raw_imu->xgyro = mavlink_msg_raw_imu_get_xgyro(msg);
427 raw_imu->ygyro = mavlink_msg_raw_imu_get_ygyro(msg);
428 raw_imu->zgyro = mavlink_msg_raw_imu_get_zgyro(msg);
429 raw_imu->xmag = mavlink_msg_raw_imu_get_xmag(msg);
430 raw_imu->ymag = mavlink_msg_raw_imu_get_ymag(msg);
431 raw_imu->zmag = mavlink_msg_raw_imu_get_zmag(msg);
432#else
433 uint8_t len = msg->len < MAVLINK_MSG_ID_RAW_IMU_LEN? msg->len : MAVLINK_MSG_ID_RAW_IMU_LEN;
434 memset(raw_imu, 0, MAVLINK_MSG_ID_RAW_IMU_LEN);
435 memcpy(raw_imu, _MAV_PAYLOAD(msg), len);
436#endif
437}
Note: See TracBrowser for help on using the repository browser.