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

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

m

File size: 13.5 KB
Line 
1// MESSAGE SERIAL_CONTROL PACKING
2
3#define MAVLINK_MSG_ID_SERIAL_CONTROL 126
4
5typedef struct MAVLINK_PACKED __mavlink_serial_control_t
6{
7 uint32_t baudrate; /*< Baudrate of transfer. Zero means no change.*/
8 uint16_t timeout; /*< Timeout for reply data in milliseconds*/
9 uint8_t device; /*< See SERIAL_CONTROL_DEV enum*/
10 uint8_t flags; /*< See SERIAL_CONTROL_FLAG enum*/
11 uint8_t count; /*< how many bytes in this transfer*/
12 uint8_t data[70]; /*< serial data*/
13} mavlink_serial_control_t;
14
15#define MAVLINK_MSG_ID_SERIAL_CONTROL_LEN 79
16#define MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN 79
17#define MAVLINK_MSG_ID_126_LEN 79
18#define MAVLINK_MSG_ID_126_MIN_LEN 79
19
20#define MAVLINK_MSG_ID_SERIAL_CONTROL_CRC 220
21#define MAVLINK_MSG_ID_126_CRC 220
22
23#define MAVLINK_MSG_SERIAL_CONTROL_FIELD_DATA_LEN 70
24
25#if MAVLINK_COMMAND_24BIT
26#define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL { \
27 126, \
28 "SERIAL_CONTROL", \
29 6, \
30 { { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) }, \
31 { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) }, \
32 { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) }, \
33 { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) }, \
34 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) }, \
35 { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) }, \
36 } \
37}
38#else
39#define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL { \
40 "SERIAL_CONTROL", \
41 6, \
42 { { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) }, \
43 { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) }, \
44 { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) }, \
45 { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) }, \
46 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) }, \
47 { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) }, \
48 } \
49}
50#endif
51
52/**
53 * @brief Pack a serial_control message
54 * @param system_id ID of this system
55 * @param component_id ID of this component (e.g. 200 for IMU)
56 * @param msg The MAVLink message to compress the data into
57 *
58 * @param device See SERIAL_CONTROL_DEV enum
59 * @param flags See SERIAL_CONTROL_FLAG enum
60 * @param timeout Timeout for reply data in milliseconds
61 * @param baudrate Baudrate of transfer. Zero means no change.
62 * @param count how many bytes in this transfer
63 * @param data serial data
64 * @return length of the message in bytes (excluding serial stream start sign)
65 */
66static inline uint16_t mavlink_msg_serial_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
67 uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data)
68{
69#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
70 char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
71 _mav_put_uint32_t(buf, 0, baudrate);
72 _mav_put_uint16_t(buf, 4, timeout);
73 _mav_put_uint8_t(buf, 6, device);
74 _mav_put_uint8_t(buf, 7, flags);
75 _mav_put_uint8_t(buf, 8, count);
76 _mav_put_uint8_t_array(buf, 9, data, 70);
77 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
78#else
79 mavlink_serial_control_t packet;
80 packet.baudrate = baudrate;
81 packet.timeout = timeout;
82 packet.device = device;
83 packet.flags = flags;
84 packet.count = count;
85 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
86 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
87#endif
88
89 msg->msgid = MAVLINK_MSG_ID_SERIAL_CONTROL;
90 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
91}
92
93/**
94 * @brief Pack a serial_control message on a channel
95 * @param system_id ID of this system
96 * @param component_id ID of this component (e.g. 200 for IMU)
97 * @param chan The MAVLink channel this message will be sent over
98 * @param msg The MAVLink message to compress the data into
99 * @param device See SERIAL_CONTROL_DEV enum
100 * @param flags See SERIAL_CONTROL_FLAG enum
101 * @param timeout Timeout for reply data in milliseconds
102 * @param baudrate Baudrate of transfer. Zero means no change.
103 * @param count how many bytes in this transfer
104 * @param data serial data
105 * @return length of the message in bytes (excluding serial stream start sign)
106 */
107static inline uint16_t mavlink_msg_serial_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
108 mavlink_message_t* msg,
109 uint8_t device,uint8_t flags,uint16_t timeout,uint32_t baudrate,uint8_t count,const uint8_t *data)
110{
111#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
112 char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
113 _mav_put_uint32_t(buf, 0, baudrate);
114 _mav_put_uint16_t(buf, 4, timeout);
115 _mav_put_uint8_t(buf, 6, device);
116 _mav_put_uint8_t(buf, 7, flags);
117 _mav_put_uint8_t(buf, 8, count);
118 _mav_put_uint8_t_array(buf, 9, data, 70);
119 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
120#else
121 mavlink_serial_control_t packet;
122 packet.baudrate = baudrate;
123 packet.timeout = timeout;
124 packet.device = device;
125 packet.flags = flags;
126 packet.count = count;
127 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
128 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
129#endif
130
131 msg->msgid = MAVLINK_MSG_ID_SERIAL_CONTROL;
132 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
133}
134
135/**
136 * @brief Encode a serial_control struct
137 *
138 * @param system_id ID of this system
139 * @param component_id ID of this component (e.g. 200 for IMU)
140 * @param msg The MAVLink message to compress the data into
141 * @param serial_control C-struct to read the message contents from
142 */
143static inline uint16_t mavlink_msg_serial_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_serial_control_t* serial_control)
144{
145 return mavlink_msg_serial_control_pack(system_id, component_id, msg, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data);
146}
147
148/**
149 * @brief Encode a serial_control struct on a channel
150 *
151 * @param system_id ID of this system
152 * @param component_id ID of this component (e.g. 200 for IMU)
153 * @param chan The MAVLink channel this message will be sent over
154 * @param msg The MAVLink message to compress the data into
155 * @param serial_control C-struct to read the message contents from
156 */
157static inline uint16_t mavlink_msg_serial_control_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_serial_control_t* serial_control)
158{
159 return mavlink_msg_serial_control_pack_chan(system_id, component_id, chan, msg, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data);
160}
161
162/**
163 * @brief Send a serial_control message
164 * @param chan MAVLink channel to send the message
165 *
166 * @param device See SERIAL_CONTROL_DEV enum
167 * @param flags See SERIAL_CONTROL_FLAG enum
168 * @param timeout Timeout for reply data in milliseconds
169 * @param baudrate Baudrate of transfer. Zero means no change.
170 * @param count how many bytes in this transfer
171 * @param data serial data
172 */
173#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
174
175static inline void mavlink_msg_serial_control_send(mavlink_channel_t chan, uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data)
176{
177#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
178 char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
179 _mav_put_uint32_t(buf, 0, baudrate);
180 _mav_put_uint16_t(buf, 4, timeout);
181 _mav_put_uint8_t(buf, 6, device);
182 _mav_put_uint8_t(buf, 7, flags);
183 _mav_put_uint8_t(buf, 8, count);
184 _mav_put_uint8_t_array(buf, 9, data, 70);
185 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, buf, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
186#else
187 mavlink_serial_control_t packet;
188 packet.baudrate = baudrate;
189 packet.timeout = timeout;
190 packet.device = device;
191 packet.flags = flags;
192 packet.count = count;
193 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
194 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)&packet, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
195#endif
196}
197
198/**
199 * @brief Send a serial_control message
200 * @param chan MAVLink channel to send the message
201 * @param struct The MAVLink struct to serialize
202 */
203static inline void mavlink_msg_serial_control_send_struct(mavlink_channel_t chan, const mavlink_serial_control_t* serial_control)
204{
205#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
206 mavlink_msg_serial_control_send(chan, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data);
207#else
208 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)serial_control, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
209#endif
210}
211
212#if MAVLINK_MSG_ID_SERIAL_CONTROL_LEN <= MAVLINK_MAX_PAYLOAD_LEN
213/*
214 This varient of _send() can be used to save stack space by re-using
215 memory from the receive buffer. The caller provides a
216 mavlink_message_t which is the size of a full mavlink message. This
217 is usually the receive buffer for the channel, and allows a reply to an
218 incoming message with minimum stack space usage.
219 */
220static inline void mavlink_msg_serial_control_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data)
221{
222#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
223 char *buf = (char *)msgbuf;
224 _mav_put_uint32_t(buf, 0, baudrate);
225 _mav_put_uint16_t(buf, 4, timeout);
226 _mav_put_uint8_t(buf, 6, device);
227 _mav_put_uint8_t(buf, 7, flags);
228 _mav_put_uint8_t(buf, 8, count);
229 _mav_put_uint8_t_array(buf, 9, data, 70);
230 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, buf, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
231#else
232 mavlink_serial_control_t *packet = (mavlink_serial_control_t *)msgbuf;
233 packet->baudrate = baudrate;
234 packet->timeout = timeout;
235 packet->device = device;
236 packet->flags = flags;
237 packet->count = count;
238 mav_array_memcpy(packet->data, data, sizeof(uint8_t)*70);
239 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)packet, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
240#endif
241}
242#endif
243
244#endif
245
246// MESSAGE SERIAL_CONTROL UNPACKING
247
248
249/**
250 * @brief Get field device from serial_control message
251 *
252 * @return See SERIAL_CONTROL_DEV enum
253 */
254static inline uint8_t mavlink_msg_serial_control_get_device(const mavlink_message_t* msg)
255{
256 return _MAV_RETURN_uint8_t(msg, 6);
257}
258
259/**
260 * @brief Get field flags from serial_control message
261 *
262 * @return See SERIAL_CONTROL_FLAG enum
263 */
264static inline uint8_t mavlink_msg_serial_control_get_flags(const mavlink_message_t* msg)
265{
266 return _MAV_RETURN_uint8_t(msg, 7);
267}
268
269/**
270 * @brief Get field timeout from serial_control message
271 *
272 * @return Timeout for reply data in milliseconds
273 */
274static inline uint16_t mavlink_msg_serial_control_get_timeout(const mavlink_message_t* msg)
275{
276 return _MAV_RETURN_uint16_t(msg, 4);
277}
278
279/**
280 * @brief Get field baudrate from serial_control message
281 *
282 * @return Baudrate of transfer. Zero means no change.
283 */
284static inline uint32_t mavlink_msg_serial_control_get_baudrate(const mavlink_message_t* msg)
285{
286 return _MAV_RETURN_uint32_t(msg, 0);
287}
288
289/**
290 * @brief Get field count from serial_control message
291 *
292 * @return how many bytes in this transfer
293 */
294static inline uint8_t mavlink_msg_serial_control_get_count(const mavlink_message_t* msg)
295{
296 return _MAV_RETURN_uint8_t(msg, 8);
297}
298
299/**
300 * @brief Get field data from serial_control message
301 *
302 * @return serial data
303 */
304static inline uint16_t mavlink_msg_serial_control_get_data(const mavlink_message_t* msg, uint8_t *data)
305{
306 return _MAV_RETURN_uint8_t_array(msg, data, 70, 9);
307}
308
309/**
310 * @brief Decode a serial_control message into a struct
311 *
312 * @param msg The message to decode
313 * @param serial_control C-struct to decode the message contents into
314 */
315static inline void mavlink_msg_serial_control_decode(const mavlink_message_t* msg, mavlink_serial_control_t* serial_control)
316{
317#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
318 serial_control->baudrate = mavlink_msg_serial_control_get_baudrate(msg);
319 serial_control->timeout = mavlink_msg_serial_control_get_timeout(msg);
320 serial_control->device = mavlink_msg_serial_control_get_device(msg);
321 serial_control->flags = mavlink_msg_serial_control_get_flags(msg);
322 serial_control->count = mavlink_msg_serial_control_get_count(msg);
323 mavlink_msg_serial_control_get_data(msg, serial_control->data);
324#else
325 uint8_t len = msg->len < MAVLINK_MSG_ID_SERIAL_CONTROL_LEN? msg->len : MAVLINK_MSG_ID_SERIAL_CONTROL_LEN;
326 memset(serial_control, 0, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
327 memcpy(serial_control, _MAV_PAYLOAD(msg), len);
328#endif
329}
Note: See TracBrowser for help on using the repository browser.