MAV'RIC
mavlink_types.h
1 #ifndef MAVLINK_TYPES_H_
2 #define MAVLINK_TYPES_H_
3 
4 // Visual Studio versions before 2013 don't conform to C99.
5 #if (defined _MSC_VER) && (_MSC_VER < 1800)
6 #include <stdint.h>
7 #else
8 #include <inttypes.h>
9 #endif
10 
11 // Macro to define packed structures
12 #ifdef __GNUC__
13  #define PACKED( __Declaration__ ) __Declaration__ __attribute__((packed))
14 #else
15  #define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
16 #endif
17 
18 #ifndef MAVLINK_MAX_PAYLOAD_LEN
19 // it is possible to override this, but be careful!
20 #define MAVLINK_MAX_PAYLOAD_LEN 255
21 #endif
22 
23 #define MAVLINK_CORE_HEADER_LEN 5
24 #define MAVLINK_NUM_HEADER_BYTES (MAVLINK_CORE_HEADER_LEN + 1)
25 #define MAVLINK_NUM_CHECKSUM_BYTES 2
26 #define MAVLINK_NUM_NON_PAYLOAD_BYTES (MAVLINK_NUM_HEADER_BYTES + MAVLINK_NUM_CHECKSUM_BYTES)
27 
28 #define MAVLINK_MAX_PACKET_LEN (MAVLINK_MAX_PAYLOAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES)
29 
30 #define MAVLINK_MSG_ID_EXTENDED_MESSAGE 255
31 #define MAVLINK_EXTENDED_HEADER_LEN 14
32 
33 #if (defined _MSC_VER) || ((defined __APPLE__) && (defined __MACH__)) || (defined __linux__)
34  /* full fledged 32bit++ OS */
35  #define MAVLINK_MAX_EXTENDED_PACKET_LEN 65507
36 #else
37  /* small microcontrollers */
38  #define MAVLINK_MAX_EXTENDED_PACKET_LEN 2048
39 #endif
40 
41 #define MAVLINK_MAX_EXTENDED_PAYLOAD_LEN (MAVLINK_MAX_EXTENDED_PACKET_LEN - MAVLINK_EXTENDED_HEADER_LEN - MAVLINK_NUM_NON_PAYLOAD_BYTES)
42 
43 
53 PACKED(
54 typedef struct param_union {
55  union {
56  float param_float;
57  int32_t param_int32;
58  uint32_t param_uint32;
59  int16_t param_int16;
60  uint16_t param_uint16;
61  int8_t param_int8;
62  uint8_t param_uint8;
63  uint8_t bytes[4];
64  };
65  uint8_t type;
66 }) mavlink_param_union_t;
67 
68 
82 PACKED(
83 typedef union {
84  struct {
85  uint8_t is_double:1;
86  uint8_t mavlink_type:7;
87  union {
88  char c;
89  uint8_t uint8;
90  int8_t int8;
91  uint16_t uint16;
92  int16_t int16;
93  uint32_t uint32;
94  int32_t int32;
95  float f;
96  uint8_t align[7];
97  };
98  };
99  uint8_t data[8];
100 }) mavlink_param_union_double_t;
101 
102 PACKED(
103 typedef struct __mavlink_system {
104  uint8_t sysid;
105  uint8_t compid;
106  uint8_t type;
107  uint8_t state;
108  uint8_t mode;
109  uint32_t nav_mode;
110 }) mavlink_system_t;
111 
112 PACKED(
113 typedef struct __mavlink_message {
114  uint16_t checksum;
115  uint8_t magic;
116  uint8_t len;
117  uint8_t seq;
118  uint8_t sysid;
119  uint8_t compid;
120  uint8_t msgid;
121  uint64_t payload64[(MAVLINK_MAX_PAYLOAD_LEN+MAVLINK_NUM_CHECKSUM_BYTES+7)/8];
122 }) mavlink_message_t;
123 
124 PACKED(
125 typedef struct __mavlink_extended_message {
126  mavlink_message_t base_msg;
127  int32_t extended_payload_len;
128  uint8_t extended_payload[MAVLINK_MAX_EXTENDED_PAYLOAD_LEN];
129 }) mavlink_extended_message_t;
130 
131 typedef enum {
132  MAVLINK_TYPE_CHAR = 0,
133  MAVLINK_TYPE_UINT8_T = 1,
134  MAVLINK_TYPE_INT8_T = 2,
135  MAVLINK_TYPE_UINT16_T = 3,
136  MAVLINK_TYPE_INT16_T = 4,
137  MAVLINK_TYPE_UINT32_T = 5,
138  MAVLINK_TYPE_INT32_T = 6,
139  MAVLINK_TYPE_UINT64_T = 7,
140  MAVLINK_TYPE_INT64_T = 8,
141  MAVLINK_TYPE_FLOAT = 9,
142  MAVLINK_TYPE_DOUBLE = 10
143 } mavlink_message_type_t;
144 
145 #define MAVLINK_MAX_FIELDS 64
146 
147 typedef struct __mavlink_field_info {
148  const char *name; // name of this field
149  const char *print_format; // printing format hint, or NULL
150  mavlink_message_type_t type; // type of this field
151  unsigned int array_length; // if non-zero, field is an array
152  unsigned int wire_offset; // offset of each field in the payload
153  unsigned int structure_offset; // offset in a C structure
155 
156 // note that in this structure the order of fields is the order
157 // in the XML file, not necessary the wire order
158 typedef struct __mavlink_message_info {
159  const char *name; // name of the message
160  unsigned num_fields; // how many fields in this message
161  mavlink_field_info_t fields[MAVLINK_MAX_FIELDS]; // field information
163 
164 #define _MAV_PAYLOAD(msg) ((const char *)(&((msg)->payload64[0])))
165 #define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0])))
166 
167 // checksum is immediately after the payload bytes
168 #define mavlink_ck_a(msg) *((msg)->len + (uint8_t *)_MAV_PAYLOAD_NON_CONST(msg))
169 #define mavlink_ck_b(msg) *(((msg)->len+(uint16_t)1) + (uint8_t *)_MAV_PAYLOAD_NON_CONST(msg))
170 
171 typedef enum {
172  MAVLINK_COMM_0,
173  MAVLINK_COMM_1,
174  MAVLINK_COMM_2,
175  MAVLINK_COMM_3
176 } mavlink_channel_t;
177 
178 /*
179  * applications can set MAVLINK_COMM_NUM_BUFFERS to the maximum number
180  * of buffers they will use. If more are used, then the result will be
181  * a stack overrun
182  */
183 #ifndef MAVLINK_COMM_NUM_BUFFERS
184 #if (defined linux) | (defined __linux) | (defined __MACH__) | (defined _WIN32)
185 # define MAVLINK_COMM_NUM_BUFFERS 16
186 #else
187 # define MAVLINK_COMM_NUM_BUFFERS 4
188 #endif
189 #endif
190 
191 typedef enum {
192  MAVLINK_PARSE_STATE_UNINIT=0,
193  MAVLINK_PARSE_STATE_IDLE,
194  MAVLINK_PARSE_STATE_GOT_STX,
195  MAVLINK_PARSE_STATE_GOT_SEQ,
196  MAVLINK_PARSE_STATE_GOT_LENGTH,
197  MAVLINK_PARSE_STATE_GOT_SYSID,
198  MAVLINK_PARSE_STATE_GOT_COMPID,
199  MAVLINK_PARSE_STATE_GOT_MSGID,
200  MAVLINK_PARSE_STATE_GOT_PAYLOAD,
201  MAVLINK_PARSE_STATE_GOT_CRC1
202 } mavlink_parse_state_t;
203 
204 typedef struct __mavlink_status {
205  uint8_t msg_received;
206  uint8_t buffer_overrun;
207  uint8_t parse_error;
208  mavlink_parse_state_t parse_state;
209  uint8_t packet_idx;
210  uint8_t current_rx_seq;
211  uint8_t current_tx_seq;
215 
216 #define MAVLINK_BIG_ENDIAN 0
217 #define MAVLINK_LITTLE_ENDIAN 1
218 
219 #endif /* MAVLINK_TYPES_H_ */