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"
11 #ifdef MAVLINK_USE_CXX_NAMESPACE
15 // Macro to define packed structures
17 #define MAVPACKED( __Declaration__ ) __Declaration__ __attribute__((packed))
19 #define MAVPACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
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
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)
33 #define MAVLINK_SIGNATURE_BLOCK_LEN 13
35 #define MAVLINK_MAX_PACKET_LEN (MAVLINK_MAX_PAYLOAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES + MAVLINK_SIGNATURE_BLOCK_LEN) ///< Maximum packet length
38 * Old-style 4 byte param union
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.
47 typedef struct param_union
{
51 uint32_t param_uint32
;
53 uint16_t param_uint16
;
59 }) mavlink_param_union_t
;
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.
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.
76 typedef struct param_union_extended
{
80 uint8_t mavlink_type
:7;
95 }) mavlink_param_union_double_t
;
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.
102 typedef 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
108 typedef 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
;
124 MAVLINK_TYPE_CHAR
= 0,
125 MAVLINK_TYPE_UINT8_T
= 1,
126 MAVLINK_TYPE_INT8_T
= 2,
127 MAVLINK_TYPE_UINT16_T
= 3,
128 MAVLINK_TYPE_INT16_T
= 4,
129 MAVLINK_TYPE_UINT32_T
= 5,
130 MAVLINK_TYPE_INT32_T
= 6,
131 MAVLINK_TYPE_UINT64_T
= 7,
132 MAVLINK_TYPE_INT64_T
= 8,
133 MAVLINK_TYPE_FLOAT
= 9,
134 MAVLINK_TYPE_DOUBLE
= 10
135 } mavlink_message_type_t
;
137 #define MAVLINK_MAX_FIELDS 64
139 typedef 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
;
148 // note that in this structure the order of fields is the order
149 // in the XML file, not necessary the wire order
150 typedef struct __mavlink_message_info
{
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
;
157 #define _MAV_PAYLOAD(msg) ((const char *)(&((msg)->payload64[0])))
158 #define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0])))
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))
164 #ifndef HAVE_MAVLINK_CHANNEL_T
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
178 #ifndef MAVLINK_COMM_NUM_BUFFERS
179 #if (defined linux) | (defined __linux) | (defined __MACH__) | (defined _WIN32)
180 # define MAVLINK_COMM_NUM_BUFFERS 16
182 # define MAVLINK_COMM_NUM_BUFFERS 4
187 MAVLINK_PARSE_STATE_UNINIT
=0,
188 MAVLINK_PARSE_STATE_IDLE
,
189 MAVLINK_PARSE_STATE_GOT_STX
,
190 MAVLINK_PARSE_STATE_GOT_LENGTH
,
191 MAVLINK_PARSE_STATE_GOT_INCOMPAT_FLAGS
,
192 MAVLINK_PARSE_STATE_GOT_COMPAT_FLAGS
,
193 MAVLINK_PARSE_STATE_GOT_SEQ
,
194 MAVLINK_PARSE_STATE_GOT_SYSID
,
195 MAVLINK_PARSE_STATE_GOT_COMPID
,
196 MAVLINK_PARSE_STATE_GOT_MSGID1
,
197 MAVLINK_PARSE_STATE_GOT_MSGID2
,
198 MAVLINK_PARSE_STATE_GOT_MSGID3
,
199 MAVLINK_PARSE_STATE_GOT_PAYLOAD
,
200 MAVLINK_PARSE_STATE_GOT_CRC1
,
201 MAVLINK_PARSE_STATE_GOT_BAD_CRC1
,
202 MAVLINK_PARSE_STATE_SIGNATURE_WAIT
203 } mavlink_parse_state_t
; ///< The state machine for the comm parser
206 MAVLINK_FRAMING_INCOMPLETE
=0,
207 MAVLINK_FRAMING_OK
=1,
208 MAVLINK_FRAMING_BAD_CRC
=2,
209 MAVLINK_FRAMING_BAD_SIGNATURE
=3
212 #define MAVLINK_STATUS_FLAG_IN_MAVLINK1 1 // last incoming packet was MAVLink1
213 #define MAVLINK_STATUS_FLAG_OUT_MAVLINK1 2 // generate MAVLink1 by default
214 #define MAVLINK_STATUS_FLAG_IN_SIGNED 4 // last incoming packet was signed and validated
215 #define MAVLINK_STATUS_FLAG_IN_BADSIG 8 // last incoming packet had a bad signature
217 #define MAVLINK_STX_MAVLINK1 0xFE // marker for old protocol
219 typedef struct __mavlink_status
{
220 uint8_t msg_received
; ///< Number of received messages
221 uint8_t buffer_overrun
; ///< Number of buffer overruns
222 uint8_t parse_error
; ///< Number of parse errors
223 mavlink_parse_state_t parse_state
; ///< Parsing state machine
224 uint8_t packet_idx
; ///< Index in current packet
225 uint8_t current_rx_seq
; ///< Sequence number of last packet received
226 uint8_t current_tx_seq
; ///< Sequence number of last packet sent
227 uint16_t packet_rx_success_count
; ///< Received packets
228 uint16_t packet_rx_drop_count
; ///< Number of packet drops
229 uint8_t flags
; ///< MAVLINK_STATUS_FLAG_*
230 uint8_t signature_wait
; ///< number of signature bytes left to receive
231 struct __mavlink_signing
*signing
; ///< optional signing state
232 struct __mavlink_signing_streams
*signing_streams
; ///< global record of stream timestamps
236 a callback function to allow for accepting unsigned packets
238 typedef bool (*mavlink_accept_unsigned_t
)(const mavlink_status_t
*status
, uint32_t msgid
);
241 flags controlling signing
243 #define MAVLINK_SIGNING_FLAG_SIGN_OUTGOING 1 ///< Enable outgoing signing
246 state of MAVLink signing for this channel
248 typedef struct __mavlink_signing
{
249 uint8_t flags
; ///< MAVLINK_SIGNING_FLAG_*
250 uint8_t link_id
; ///< Same as MAVLINK_CHANNEL
251 uint64_t timestamp
; ///< Timestamp, in microseconds since UNIX epoch GMT
252 uint8_t secret_key
[32];
253 mavlink_accept_unsigned_t accept_unsigned_callback
;
257 timestamp state of each logical signing stream. This needs to be the same structure for all
258 connections in order to be secure
260 #ifndef MAVLINK_MAX_SIGNING_STREAMS
261 #define MAVLINK_MAX_SIGNING_STREAMS 16
263 typedef struct __mavlink_signing_streams
{
264 uint16_t num_signing_streams
;
265 struct __mavlink_signing_stream
{
266 uint8_t link_id
; ///< ID of the link (MAVLINK_CHANNEL)
267 uint8_t sysid
; ///< Remote system ID
268 uint8_t compid
; ///< Remote component ID
269 uint8_t timestamp_bytes
[6]; ///< Timestamp, in microseconds since UNIX epoch GMT
270 } stream
[MAVLINK_MAX_SIGNING_STREAMS
];
271 } mavlink_signing_streams_t
;
274 #define MAVLINK_BIG_ENDIAN 0
275 #define MAVLINK_LITTLE_ENDIAN 1
277 #define MAV_MSG_ENTRY_FLAG_HAVE_TARGET_SYSTEM 1
278 #define MAV_MSG_ENTRY_FLAG_HAVE_TARGET_COMPONENT 2
281 entry in table of information about each message type
283 typedef struct __mavlink_msg_entry
{
286 uint8_t min_msg_len
; // minimum message length
287 uint8_t max_msg_len
; // maximum message length (e.g. including mavlink2 extensions)
288 uint8_t flags
; // MAV_MSG_ENTRY_FLAG_*
289 uint8_t target_system_ofs
; // payload offset to target_system, or 0
290 uint8_t target_component_ofs
; // payload offset to target_component, or 0
291 } mavlink_msg_entry_t
;
296 #define MAVLINK_IFLAG_SIGNED 0x01
297 #define MAVLINK_IFLAG_MASK 0x01 // mask of all understood bits
299 #ifdef MAVLINK_USE_CXX_NAMESPACE
300 } // namespace mavlink