Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_types.h
Go to the documentation of this file.
1#pragma once
2
3// Visual Studio versions before 2010 don't have stdint.h, so we just error out.
4#if (defined _MSC_VER) && (_MSC_VER < 1600)
5#error "The C-MAVLink implementation requires Visual Studio 2010 or greater"
6#endif
7
8#include <stdbool.h>
9#include <stdint.h>
10
11#ifdef MAVLINK_USE_CXX_NAMESPACE
12namespace mavlink {
13#endif
14
15// Macro to define packed structures
16#ifdef __GNUC__
17 #define MAVPACKED( __Declaration__ ) __Declaration__ __attribute__((packed))
18#else
19 #define MAVPACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
20#endif
21
22#ifndef MAVLINK_MAX_PAYLOAD_LEN
23// it is possible to override this, but be careful!
24#define MAVLINK_MAX_PAYLOAD_LEN 255 ///< Maximum payload length
25#endif
26
27#define MAVLINK_CORE_HEADER_LEN 9 ///< Length of core header (of the comm. layer)
28#define MAVLINK_CORE_HEADER_MAVLINK1_LEN 5 ///< Length of MAVLink1 core header (of the comm. layer)
29#define MAVLINK_NUM_HEADER_BYTES (MAVLINK_CORE_HEADER_LEN + 1) ///< Length of all header bytes, including core and stx
30#define MAVLINK_NUM_CHECKSUM_BYTES 2
31#define MAVLINK_NUM_NON_PAYLOAD_BYTES (MAVLINK_NUM_HEADER_BYTES + MAVLINK_NUM_CHECKSUM_BYTES)
32
33#define MAVLINK_SIGNATURE_BLOCK_LEN 13
34
35#define MAVLINK_MAX_PACKET_LEN (MAVLINK_MAX_PAYLOAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES + MAVLINK_SIGNATURE_BLOCK_LEN) ///< Maximum packet length
36
37/**
38 * Old-style 4 byte param union
39 *
40 * This struct is the data format to be used when sending
41 * parameters. The parameter should be copied to the native
42 * type (without type conversion)
43 * and re-instanted on the receiving side using the
44 * native type as well.
45 */
47typedef struct param_union {
48 union {
49 float param_float;
50 int32_t param_int32;
51 uint32_t param_uint32;
52 int16_t param_int16;
53 uint16_t param_uint16;
54 int8_t param_int8;
55 uint8_t param_uint8;
56 uint8_t bytes[4];
57 };
58 uint8_t type;
59}) mavlink_param_union_t;
60
61
62/**
63 * New-style 8 byte param union
64 * mavlink_param_union_double_t will be 8 bytes long, and treated as needing 8 byte alignment for the purposes of MAVLink 1.0 field ordering.
65 * The mavlink_param_union_double_t will be treated as a little-endian structure.
66 *
67 * If is_double is 1 then the type is a double, and the remaining 63 bits are the double, with the lowest bit of the mantissa zero.
68 * The intention is that by replacing the is_double bit with 0 the type can be directly used as a double (as the is_double bit corresponds to the
69 * lowest mantissa bit of a double). If is_double is 0 then mavlink_type gives the type in the union.
70 * The mavlink_types.h header will also need to have shifts/masks to define the bit boundaries in the above,
71 * as bitfield ordering isn't consistent between platforms. The above is intended to be for gcc on x86,
72 * which should be the same as gcc on little-endian arm. When using shifts/masks the value will be treated as a 64 bit unsigned number,
73 * and the bits pulled out using the shifts/masks.
74*/
76typedef struct param_union_extended {
77 union {
78 struct {
79 uint8_t is_double:1;
80 uint8_t mavlink_type:7;
81 union {
82 char c;
83 uint8_t uint8;
84 int8_t int8;
85 uint16_t uint16;
86 int16_t int16;
87 uint32_t uint32;
88 int32_t int32;
89 float f;
90 uint8_t align[7];
91 };
92 };
93 uint8_t data[8];
94 };
95}) mavlink_param_union_double_t;
96
97/**
98 * This structure is required to make the mavlink_send_xxx convenience functions
99 * work, as it tells the library what the current system and component ID are.
100 */
102typedef struct __mavlink_system {
103 uint8_t sysid; ///< Used by the MAVLink message_xx_send() convenience function
104 uint8_t compid; ///< Used by the MAVLink message_xx_send() convenience function
105}) mavlink_system_t;
106
108typedef struct __mavlink_message {
109 uint16_t checksum; ///< sent at end of packet
110 uint8_t magic; ///< protocol magic marker
111 uint8_t len; ///< Length of payload
112 uint8_t incompat_flags; ///< flags that must be understood
113 uint8_t compat_flags; ///< flags that can be ignored if not understood
114 uint8_t seq; ///< Sequence of packet
115 uint8_t sysid; ///< ID of message sender system/aircraft
116 uint8_t compid; ///< ID of the message sender component
117 uint32_t msgid:24; ///< ID of message in payload
118 uint64_t payload64[(MAVLINK_MAX_PAYLOAD_LEN+MAVLINK_NUM_CHECKSUM_BYTES+7)/8];
119 uint8_t ck[2]; ///< incoming checksum bytes
120 uint8_t signature[MAVLINK_SIGNATURE_BLOCK_LEN];
121}) mavlink_message_t;
122
123typedef enum {
135} mavlink_message_type_t;
136
137#define MAVLINK_MAX_FIELDS 64
138
139typedef struct __mavlink_field_info {
140 const char *name; // name of this field
141 const char *print_format; // printing format hint, or NULL
142 mavlink_message_type_t type; // type of this field
143 unsigned int array_length; // if non-zero, field is an array
144 unsigned int wire_offset; // offset of each field in the payload
145 unsigned int structure_offset; // offset in a C structure
146} mavlink_field_info_t;
147
148// note that in this structure the order of fields is the order
149// in the XML file, not necessary the wire order
151 uint32_t msgid; // message ID
152 const char *name; // name of the message
153 unsigned num_fields; // how many fields in this message
154 mavlink_field_info_t fields[MAVLINK_MAX_FIELDS]; // field information
155} mavlink_message_info_t;
156
157#define _MAV_PAYLOAD(msg) ((const char *)(&((msg)->payload64[0])))
158#define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0])))
159
160// checksum is immediately after the payload bytes
161#define mavlink_ck_a(msg) *((msg)->len + (uint8_t *)_MAV_PAYLOAD_NON_CONST(msg))
162#define mavlink_ck_b(msg) *(((msg)->len+(uint16_t)1) + (uint8_t *)_MAV_PAYLOAD_NON_CONST(msg))
163
164#ifndef HAVE_MAVLINK_CHANNEL_T
165typedef enum {
170} mavlink_channel_t;
171#endif
172
173/*
174 * applications can set MAVLINK_COMM_NUM_BUFFERS to the maximum number
175 * of buffers they will use. If more are used, then the result will be
176 * a stack overrun
177 */
178#ifndef MAVLINK_COMM_NUM_BUFFERS
179#if (defined linux) | (defined __linux) | (defined __MACH__) | (defined _WIN32)
180# define MAVLINK_COMM_NUM_BUFFERS 16
181#else
182# define MAVLINK_COMM_NUM_BUFFERS 4
183#endif
184#endif
185
186typedef enum {
204} mavlink_parse_state_t; ///< The state machine for the comm parser
205
206typedef enum {
211} mavlink_framing_t;
212
213#define MAVLINK_STATUS_FLAG_IN_MAVLINK1 1 // last incoming packet was MAVLink1
214#define MAVLINK_STATUS_FLAG_OUT_MAVLINK1 2 // generate MAVLink1 by default
215#define MAVLINK_STATUS_FLAG_IN_SIGNED 4 // last incoming packet was signed and validated
216#define MAVLINK_STATUS_FLAG_IN_BADSIG 8 // last incoming packet had a bad signature
217
218#define MAVLINK_STX_MAVLINK1 0xFE // marker for old protocol
219
220typedef struct __mavlink_status {
221 uint8_t msg_received; ///< Number of received messages
222 uint8_t buffer_overrun; ///< Number of buffer overruns
223 uint8_t parse_error; ///< Number of parse errors
224 mavlink_parse_state_t parse_state; ///< Parsing state machine
225 uint8_t packet_idx; ///< Index in current packet
226 uint8_t current_rx_seq; ///< Sequence number of last packet received
227 uint8_t current_tx_seq; ///< Sequence number of last packet sent
228 uint16_t packet_rx_success_count; ///< Received packets
229 uint16_t packet_rx_drop_count; ///< Number of packet drops
230 uint8_t flags; ///< MAVLINK_STATUS_FLAG_*
231 uint8_t signature_wait; ///< number of signature bytes left to receive
232 struct __mavlink_signing *signing; ///< optional signing state
233 struct __mavlink_signing_streams *signing_streams; ///< global record of stream timestamps
234} mavlink_status_t;
235
236/*
237 a callback function to allow for accepting unsigned packets
238 */
239typedef bool (*mavlink_accept_unsigned_t)(const mavlink_status_t *status, uint32_t msgid);
240
241/*
242 flags controlling signing
243 */
244#define MAVLINK_SIGNING_FLAG_SIGN_OUTGOING 1 ///< Enable outgoing signing
245
246typedef enum {
254} mavlink_signing_status_t;
255
256/*
257 state of MAVLink signing for this channel
258 */
259typedef struct __mavlink_signing {
260 uint8_t flags; ///< MAVLINK_SIGNING_FLAG_*
261 uint8_t link_id; ///< Same as MAVLINK_CHANNEL
262 uint64_t timestamp; ///< Timestamp, in microseconds since UNIX epoch GMT
263 uint8_t secret_key[32];
265 mavlink_signing_status_t last_status;
266} mavlink_signing_t;
267
268/*
269 timestamp state of each logical signing stream. This needs to be the same structure for all
270 connections in order to be secure
271 */
272#ifndef MAVLINK_MAX_SIGNING_STREAMS
273#define MAVLINK_MAX_SIGNING_STREAMS 16
274#endif
278 uint8_t link_id; ///< ID of the link (MAVLINK_CHANNEL)
279 uint8_t sysid; ///< Remote system ID
280 uint8_t compid; ///< Remote component ID
281 uint8_t timestamp_bytes[6]; ///< Timestamp, in microseconds since UNIX epoch GMT
283} mavlink_signing_streams_t;
284
285
286#define MAVLINK_BIG_ENDIAN 0
287#define MAVLINK_LITTLE_ENDIAN 1
288
289#define MAV_MSG_ENTRY_FLAG_HAVE_TARGET_SYSTEM 1
290#define MAV_MSG_ENTRY_FLAG_HAVE_TARGET_COMPONENT 2
291
292/*
293 entry in table of information about each message type
294 */
295typedef struct __mavlink_msg_entry {
296 uint32_t msgid;
297 uint8_t crc_extra;
298 uint8_t min_msg_len; // minimum message length
299 uint8_t max_msg_len; // maximum message length (e.g. including mavlink2 extensions)
300 uint8_t flags; // MAV_MSG_ENTRY_FLAG_*
301 uint8_t target_system_ofs; // payload offset to target_system, or 0
302 uint8_t target_component_ofs; // payload offset to target_component, or 0
303} mavlink_msg_entry_t;
304
305/*
306 incompat_flags bits
307 */
308#define MAVLINK_IFLAG_SIGNED 0x01
309#define MAVLINK_IFLAG_MASK 0x01 // mask of all understood bits
310
311#ifdef MAVLINK_USE_CXX_NAMESPACE
312} // namespace mavlink
313#endif
Definition: mavlink_types.h:295
uint8_t target_component_ofs
Definition: mavlink_types.h:302
uint8_t target_system_ofs
Definition: mavlink_types.h:301
uint8_t min_msg_len
Definition: mavlink_types.h:298
uint8_t max_msg_len
Definition: mavlink_types.h:299
uint8_t crc_extra
Definition: mavlink_types.h:297
uint8_t flags
Definition: mavlink_types.h:300
uint32_t msgid
Definition: mavlink_types.h:296