Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_serial_control.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE SERIAL_CONTROL PACKING
3
4#define MAVLINK_MSG_ID_SERIAL_CONTROL 126
5
6
8 uint32_t baudrate; /*< [bits/s] Baudrate of transfer. Zero means no change.*/
9 uint16_t timeout; /*< [ms] Timeout for reply data*/
10 uint8_t device; /*< Serial control device type.*/
11 uint8_t flags; /*< Bitmap of serial control flags.*/
12 uint8_t count; /*< [bytes] how many bytes in this transfer*/
13 uint8_t data[70]; /*< serial data*/
14 uint8_t target_system; /*< System ID*/
15 uint8_t target_component; /*< Component ID*/
16} mavlink_serial_control_t;
17
18#define MAVLINK_MSG_ID_SERIAL_CONTROL_LEN 81
19#define MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN 79
20#define MAVLINK_MSG_ID_126_LEN 81
21#define MAVLINK_MSG_ID_126_MIN_LEN 79
22
23#define MAVLINK_MSG_ID_SERIAL_CONTROL_CRC 220
24#define MAVLINK_MSG_ID_126_CRC 220
25
26#define MAVLINK_MSG_SERIAL_CONTROL_FIELD_DATA_LEN 70
27
28#if MAVLINK_COMMAND_24BIT
29#define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL {
30 126,
31 "SERIAL_CONTROL",
32 8,
33 { { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) },
34 { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) },
35 { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) },
36 { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) },
37 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) },
38 { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) },
39 { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_serial_control_t, target_system) },
40 { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 80, offsetof(mavlink_serial_control_t, target_component) },
41 } \
42}
43#else
44#define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL {
45 "SERIAL_CONTROL",
46 8,
47 { { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) },
48 { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) },
49 { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) },
50 { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) },
51 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) },
52 { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) },
53 { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_serial_control_t, target_system) },
54 { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 80, offsetof(mavlink_serial_control_t, target_component) },
55 } \
56}
57#endif
58
59/**
60 * @brief Pack a serial_control 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 device Serial control device type.
66 * @param flags Bitmap of serial control flags.
67 * @param timeout [ms] Timeout for reply data
68 * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
69 * @param count [bytes] how many bytes in this transfer
70 * @param data serial data
71 * @param target_system System ID
72 * @param target_component Component ID
73 * @return length of the message in bytes (excluding serial stream start sign)
74 */
75static inline uint16_t mavlink_msg_serial_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
76 uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data, uint8_t target_system, uint8_t target_component)
77{
78#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
80 _mav_put_uint32_t(buf, 0, baudrate);
81 _mav_put_uint16_t(buf, 4, timeout);
82 _mav_put_uint8_t(buf, 6, device);
83 _mav_put_uint8_t(buf, 7, flags);
84 _mav_put_uint8_t(buf, 8, count);
85 _mav_put_uint8_t(buf, 79, target_system);
86 _mav_put_uint8_t(buf, 80, target_component);
87 _mav_put_uint8_t_array(buf, 9, data, 70);
88 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
89#else
90 mavlink_serial_control_t packet;
91 packet.baudrate = baudrate;
92 packet.timeout = timeout;
93 packet.device = device;
94 packet.flags = flags;
95 packet.count = count;
96 packet.target_system = target_system;
97 packet.target_component = target_component;
98 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
99 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
100#endif
101
103 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);
104}
105
106/**
107 * @brief Pack a serial_control message
108 * @param system_id ID of this system
109 * @param component_id ID of this component (e.g. 200 for IMU)
110 * @param status MAVLink status structure
111 * @param msg The MAVLink message to compress the data into
112 *
113 * @param device Serial control device type.
114 * @param flags Bitmap of serial control flags.
115 * @param timeout [ms] Timeout for reply data
116 * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
117 * @param count [bytes] how many bytes in this transfer
118 * @param data serial data
119 * @param target_system System ID
120 * @param target_component Component ID
121 * @return length of the message in bytes (excluding serial stream start sign)
122 */
123static inline uint16_t mavlink_msg_serial_control_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
124 uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data, uint8_t target_system, uint8_t target_component)
125{
126#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
128 _mav_put_uint32_t(buf, 0, baudrate);
129 _mav_put_uint16_t(buf, 4, timeout);
130 _mav_put_uint8_t(buf, 6, device);
131 _mav_put_uint8_t(buf, 7, flags);
132 _mav_put_uint8_t(buf, 8, count);
133 _mav_put_uint8_t(buf, 79, target_system);
134 _mav_put_uint8_t(buf, 80, target_component);
135 _mav_put_uint8_t_array(buf, 9, data, 70);
136 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
137#else
138 mavlink_serial_control_t packet;
139 packet.baudrate = baudrate;
140 packet.timeout = timeout;
141 packet.device = device;
142 packet.flags = flags;
143 packet.count = count;
144 packet.target_system = target_system;
145 packet.target_component = target_component;
146 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
147 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
148#endif
149
151#if MAVLINK_CRC_EXTRA
152 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
153#else
154 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
155#endif
156}
157
158/**
159 * @brief Pack a serial_control message on a channel
160 * @param system_id ID of this system
161 * @param component_id ID of this component (e.g. 200 for IMU)
162 * @param chan The MAVLink channel this message will be sent over
163 * @param msg The MAVLink message to compress the data into
164 * @param device Serial control device type.
165 * @param flags Bitmap of serial control flags.
166 * @param timeout [ms] Timeout for reply data
167 * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
168 * @param count [bytes] how many bytes in this transfer
169 * @param data serial data
170 * @param target_system System ID
171 * @param target_component Component ID
172 * @return length of the message in bytes (excluding serial stream start sign)
173 */
174static inline uint16_t mavlink_msg_serial_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
175 mavlink_message_t* msg,
176 uint8_t device,uint8_t flags,uint16_t timeout,uint32_t baudrate,uint8_t count,const uint8_t *data,uint8_t target_system,uint8_t target_component)
177{
178#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
180 _mav_put_uint32_t(buf, 0, baudrate);
181 _mav_put_uint16_t(buf, 4, timeout);
182 _mav_put_uint8_t(buf, 6, device);
183 _mav_put_uint8_t(buf, 7, flags);
184 _mav_put_uint8_t(buf, 8, count);
185 _mav_put_uint8_t(buf, 79, target_system);
186 _mav_put_uint8_t(buf, 80, target_component);
187 _mav_put_uint8_t_array(buf, 9, data, 70);
188 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
189#else
190 mavlink_serial_control_t packet;
191 packet.baudrate = baudrate;
192 packet.timeout = timeout;
193 packet.device = device;
194 packet.flags = flags;
195 packet.count = count;
196 packet.target_system = target_system;
197 packet.target_component = target_component;
198 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
199 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
200#endif
201
203 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);
204}
205
206/**
207 * @brief Encode a serial_control struct
208 *
209 * @param system_id ID of this system
210 * @param component_id ID of this component (e.g. 200 for IMU)
211 * @param msg The MAVLink message to compress the data into
212 * @param serial_control C-struct to read the message contents from
213 */
214static 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)
215{
216 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, serial_control->target_system, serial_control->target_component);
217}
218
219/**
220 * @brief Encode a serial_control struct on a channel
221 *
222 * @param system_id ID of this system
223 * @param component_id ID of this component (e.g. 200 for IMU)
224 * @param chan The MAVLink channel this message will be sent over
225 * @param msg The MAVLink message to compress the data into
226 * @param serial_control C-struct to read the message contents from
227 */
228static 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)
229{
230 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, serial_control->target_system, serial_control->target_component);
231}
232
233/**
234 * @brief Encode a serial_control struct with provided status structure
235 *
236 * @param system_id ID of this system
237 * @param component_id ID of this component (e.g. 200 for IMU)
238 * @param status MAVLink status structure
239 * @param msg The MAVLink message to compress the data into
240 * @param serial_control C-struct to read the message contents from
241 */
242static inline uint16_t mavlink_msg_serial_control_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_serial_control_t* serial_control)
243{
244 return mavlink_msg_serial_control_pack_status(system_id, component_id, _status, msg, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data, serial_control->target_system, serial_control->target_component);
245}
246
247/**
248 * @brief Send a serial_control message
249 * @param chan MAVLink channel to send the message
250 *
251 * @param device Serial control device type.
252 * @param flags Bitmap of serial control flags.
253 * @param timeout [ms] Timeout for reply data
254 * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
255 * @param count [bytes] how many bytes in this transfer
256 * @param data serial data
257 * @param target_system System ID
258 * @param target_component Component ID
259 */
260#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
261
262static 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, uint8_t target_system, uint8_t target_component)
263{
264#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
265 char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
266 _mav_put_uint32_t(buf, 0, baudrate);
267 _mav_put_uint16_t(buf, 4, timeout);
268 _mav_put_uint8_t(buf, 6, device);
269 _mav_put_uint8_t(buf, 7, flags);
270 _mav_put_uint8_t(buf, 8, count);
271 _mav_put_uint8_t(buf, 79, target_system);
272 _mav_put_uint8_t(buf, 80, target_component);
273 _mav_put_uint8_t_array(buf, 9, data, 70);
274 _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);
275#else
276 mavlink_serial_control_t packet;
277 packet.baudrate = baudrate;
278 packet.timeout = timeout;
279 packet.device = device;
280 packet.flags = flags;
281 packet.count = count;
282 packet.target_system = target_system;
283 packet.target_component = target_component;
284 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
285 _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);
286#endif
287}
288
289/**
290 * @brief Send a serial_control message
291 * @param chan MAVLink channel to send the message
292 * @param struct The MAVLink struct to serialize
293 */
294static inline void mavlink_msg_serial_control_send_struct(mavlink_channel_t chan, const mavlink_serial_control_t* serial_control)
295{
296#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
297 mavlink_msg_serial_control_send(chan, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data, serial_control->target_system, serial_control->target_component);
298#else
299 _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);
300#endif
301}
302
303#if MAVLINK_MSG_ID_SERIAL_CONTROL_LEN <= MAVLINK_MAX_PAYLOAD_LEN
304/*
305 This variant of _send() can be used to save stack space by reusing
306 memory from the receive buffer. The caller provides a
307 mavlink_message_t which is the size of a full mavlink message. This
308 is usually the receive buffer for the channel, and allows a reply to an
309 incoming message with minimum stack space usage.
310 */
311static 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, uint8_t target_system, uint8_t target_component)
312{
313#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
314 char *buf = (char *)msgbuf;
315 _mav_put_uint32_t(buf, 0, baudrate);
316 _mav_put_uint16_t(buf, 4, timeout);
317 _mav_put_uint8_t(buf, 6, device);
318 _mav_put_uint8_t(buf, 7, flags);
319 _mav_put_uint8_t(buf, 8, count);
320 _mav_put_uint8_t(buf, 79, target_system);
321 _mav_put_uint8_t(buf, 80, target_component);
322 _mav_put_uint8_t_array(buf, 9, data, 70);
323 _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);
324#else
325 mavlink_serial_control_t *packet = (mavlink_serial_control_t *)msgbuf;
326 packet->baudrate = baudrate;
327 packet->timeout = timeout;
328 packet->device = device;
329 packet->flags = flags;
330 packet->count = count;
331 packet->target_system = target_system;
332 packet->target_component = target_component;
333 mav_array_memcpy(packet->data, data, sizeof(uint8_t)*70);
334 _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);
335#endif
336}
337#endif
338
339#endif
340
341// MESSAGE SERIAL_CONTROL UNPACKING
342
343
344/**
345 * @brief Get field device from serial_control message
346 *
347 * @return Serial control device type.
348 */
349static inline uint8_t mavlink_msg_serial_control_get_device(const mavlink_message_t* msg)
350{
351 return _MAV_RETURN_uint8_t(msg, 6);
352}
353
354/**
355 * @brief Get field flags from serial_control message
356 *
357 * @return Bitmap of serial control flags.
358 */
359static inline uint8_t mavlink_msg_serial_control_get_flags(const mavlink_message_t* msg)
360{
361 return _MAV_RETURN_uint8_t(msg, 7);
362}
363
364/**
365 * @brief Get field timeout from serial_control message
366 *
367 * @return [ms] Timeout for reply data
368 */
369static inline uint16_t mavlink_msg_serial_control_get_timeout(const mavlink_message_t* msg)
370{
371 return _MAV_RETURN_uint16_t(msg, 4);
372}
373
374/**
375 * @brief Get field baudrate from serial_control message
376 *
377 * @return [bits/s] Baudrate of transfer. Zero means no change.
378 */
379static inline uint32_t mavlink_msg_serial_control_get_baudrate(const mavlink_message_t* msg)
380{
381 return _MAV_RETURN_uint32_t(msg, 0);
382}
383
384/**
385 * @brief Get field count from serial_control message
386 *
387 * @return [bytes] how many bytes in this transfer
388 */
389static inline uint8_t mavlink_msg_serial_control_get_count(const mavlink_message_t* msg)
390{
391 return _MAV_RETURN_uint8_t(msg, 8);
392}
393
394/**
395 * @brief Get field data from serial_control message
396 *
397 * @return serial data
398 */
399static inline uint16_t mavlink_msg_serial_control_get_data(const mavlink_message_t* msg, uint8_t *data)
400{
401 return _MAV_RETURN_uint8_t_array(msg, data, 70, 9);
402}
403
404/**
405 * @brief Get field target_system from serial_control message
406 *
407 * @return System ID
408 */
409static inline uint8_t mavlink_msg_serial_control_get_target_system(const mavlink_message_t* msg)
410{
411 return _MAV_RETURN_uint8_t(msg, 79);
412}
413
414/**
415 * @brief Get field target_component from serial_control message
416 *
417 * @return Component ID
418 */
419static inline uint8_t mavlink_msg_serial_control_get_target_component(const mavlink_message_t* msg)
420{
421 return _MAV_RETURN_uint8_t(msg, 80);
422}
423
424/**
425 * @brief Decode a serial_control message into a struct
426 *
427 * @param msg The message to decode
428 * @param serial_control C-struct to decode the message contents into
429 */
430static inline void mavlink_msg_serial_control_decode(const mavlink_message_t* msg, mavlink_serial_control_t* serial_control)
431{
432#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
433 serial_control->baudrate = mavlink_msg_serial_control_get_baudrate(msg);
434 serial_control->timeout = mavlink_msg_serial_control_get_timeout(msg);
435 serial_control->device = mavlink_msg_serial_control_get_device(msg);
436 serial_control->flags = mavlink_msg_serial_control_get_flags(msg);
437 serial_control->count = mavlink_msg_serial_control_get_count(msg);
438 mavlink_msg_serial_control_get_data(msg, serial_control->data);
439 serial_control->target_system = mavlink_msg_serial_control_get_target_system(msg);
440 serial_control->target_component = mavlink_msg_serial_control_get_target_component(msg);
441#else
442 uint8_t len = msg->len < MAVLINK_MSG_ID_SERIAL_CONTROL_LEN? msg->len : MAVLINK_MSG_ID_SERIAL_CONTROL_LEN;
443 memset(serial_control, 0, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
444 memcpy(serial_control, _MAV_PAYLOAD(msg), len);
445#endif
446}