Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_event.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE EVENT PACKING
3
4#define MAVLINK_MSG_ID_EVENT 410
5
6
7typedef struct __mavlink_event_t {
8 uint32_t id; /*< Event ID (as defined in the component metadata)*/
9 uint32_t event_time_boot_ms; /*< [ms] Timestamp (time since system boot when the event happened).*/
10 uint16_t sequence; /*< Sequence number.*/
11 uint8_t destination_component; /*< Component ID*/
12 uint8_t destination_system; /*< System ID*/
13 uint8_t log_levels; /*< Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9*/
14 uint8_t arguments[40]; /*< Arguments (depend on event ID).*/
15} mavlink_event_t;
16
17#define MAVLINK_MSG_ID_EVENT_LEN 53
18#define MAVLINK_MSG_ID_EVENT_MIN_LEN 53
19#define MAVLINK_MSG_ID_410_LEN 53
20#define MAVLINK_MSG_ID_410_MIN_LEN 53
21
22#define MAVLINK_MSG_ID_EVENT_CRC 160
23#define MAVLINK_MSG_ID_410_CRC 160
24
25#define MAVLINK_MSG_EVENT_FIELD_ARGUMENTS_LEN 40
26
27#if MAVLINK_COMMAND_24BIT
28#define MAVLINK_MESSAGE_INFO_EVENT {
29 410,
30 "EVENT",
31 7,
32 { { "destination_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_event_t, destination_component) },
33 { "destination_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_event_t, destination_system) },
34 { "id", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_event_t, id) },
35 { "event_time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_event_t, event_time_boot_ms) },
36 { "sequence", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_event_t, sequence) },
37 { "log_levels", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_event_t, log_levels) },
38 { "arguments", NULL, MAVLINK_TYPE_UINT8_T, 40, 13, offsetof(mavlink_event_t, arguments) },
39 } \
40}
41#else
42#define MAVLINK_MESSAGE_INFO_EVENT {
43 "EVENT",
44 7,
45 { { "destination_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_event_t, destination_component) },
46 { "destination_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_event_t, destination_system) },
47 { "id", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_event_t, id) },
48 { "event_time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_event_t, event_time_boot_ms) },
49 { "sequence", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_event_t, sequence) },
50 { "log_levels", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_event_t, log_levels) },
51 { "arguments", NULL, MAVLINK_TYPE_UINT8_T, 40, 13, offsetof(mavlink_event_t, arguments) },
52 } \
53}
54#endif
55
56/**
57 * @brief Pack a event message
58 * @param system_id ID of this system
59 * @param component_id ID of this component (e.g. 200 for IMU)
60 * @param msg The MAVLink message to compress the data into
61 *
62 * @param destination_component Component ID
63 * @param destination_system System ID
64 * @param id Event ID (as defined in the component metadata)
65 * @param event_time_boot_ms [ms] Timestamp (time since system boot when the event happened).
66 * @param sequence Sequence number.
67 * @param log_levels Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9
68 * @param arguments Arguments (depend on event ID).
69 * @return length of the message in bytes (excluding serial stream start sign)
70 */
71MAVLINK_WIP
72static inline uint16_t mavlink_msg_event_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
73 uint8_t destination_component, uint8_t destination_system, uint32_t id, uint32_t event_time_boot_ms, uint16_t sequence, uint8_t log_levels, const uint8_t *arguments)
74{
75#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
77 _mav_put_uint32_t(buf, 0, id);
78 _mav_put_uint32_t(buf, 4, event_time_boot_ms);
79 _mav_put_uint16_t(buf, 8, sequence);
80 _mav_put_uint8_t(buf, 10, destination_component);
81 _mav_put_uint8_t(buf, 11, destination_system);
82 _mav_put_uint8_t(buf, 12, log_levels);
83 _mav_put_uint8_t_array(buf, 13, arguments, 40);
84 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_EVENT_LEN);
85#else
86 mavlink_event_t packet;
87 packet.id = id;
88 packet.event_time_boot_ms = event_time_boot_ms;
89 packet.sequence = sequence;
90 packet.destination_component = destination_component;
91 packet.destination_system = destination_system;
92 packet.log_levels = log_levels;
93 mav_array_memcpy(packet.arguments, arguments, sizeof(uint8_t)*40);
94 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_EVENT_LEN);
95#endif
96
97 msg->msgid = MAVLINK_MSG_ID_EVENT;
98 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
99}
100
101/**
102 * @brief Pack a event message
103 * @param system_id ID of this system
104 * @param component_id ID of this component (e.g. 200 for IMU)
105 * @param status MAVLink status structure
106 * @param msg The MAVLink message to compress the data into
107 *
108 * @param destination_component Component ID
109 * @param destination_system System ID
110 * @param id Event ID (as defined in the component metadata)
111 * @param event_time_boot_ms [ms] Timestamp (time since system boot when the event happened).
112 * @param sequence Sequence number.
113 * @param log_levels Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9
114 * @param arguments Arguments (depend on event ID).
115 * @return length of the message in bytes (excluding serial stream start sign)
116 */
117static inline uint16_t mavlink_msg_event_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
118 uint8_t destination_component, uint8_t destination_system, uint32_t id, uint32_t event_time_boot_ms, uint16_t sequence, uint8_t log_levels, const uint8_t *arguments)
119{
120#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
121 char buf[MAVLINK_MSG_ID_EVENT_LEN];
122 _mav_put_uint32_t(buf, 0, id);
123 _mav_put_uint32_t(buf, 4, event_time_boot_ms);
124 _mav_put_uint16_t(buf, 8, sequence);
125 _mav_put_uint8_t(buf, 10, destination_component);
126 _mav_put_uint8_t(buf, 11, destination_system);
127 _mav_put_uint8_t(buf, 12, log_levels);
128 _mav_put_uint8_t_array(buf, 13, arguments, 40);
129 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_EVENT_LEN);
130#else
131 mavlink_event_t packet;
132 packet.id = id;
133 packet.event_time_boot_ms = event_time_boot_ms;
134 packet.sequence = sequence;
135 packet.destination_component = destination_component;
136 packet.destination_system = destination_system;
137 packet.log_levels = log_levels;
138 mav_array_memcpy(packet.arguments, arguments, sizeof(uint8_t)*40);
139 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_EVENT_LEN);
140#endif
141
142 msg->msgid = MAVLINK_MSG_ID_EVENT;
143#if MAVLINK_CRC_EXTRA
144 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
145#else
146 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN);
147#endif
148}
149
150/**
151 * @brief Pack a event message on a channel
152 * @param system_id ID of this system
153 * @param component_id ID of this component (e.g. 200 for IMU)
154 * @param chan The MAVLink channel this message will be sent over
155 * @param msg The MAVLink message to compress the data into
156 * @param destination_component Component ID
157 * @param destination_system System ID
158 * @param id Event ID (as defined in the component metadata)
159 * @param event_time_boot_ms [ms] Timestamp (time since system boot when the event happened).
160 * @param sequence Sequence number.
161 * @param log_levels Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9
162 * @param arguments Arguments (depend on event ID).
163 * @return length of the message in bytes (excluding serial stream start sign)
164 */
165MAVLINK_WIP
166static inline uint16_t mavlink_msg_event_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
167 mavlink_message_t* msg,
168 uint8_t destination_component,uint8_t destination_system,uint32_t id,uint32_t event_time_boot_ms,uint16_t sequence,uint8_t log_levels,const uint8_t *arguments)
169{
170#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
171 char buf[MAVLINK_MSG_ID_EVENT_LEN];
172 _mav_put_uint32_t(buf, 0, id);
173 _mav_put_uint32_t(buf, 4, event_time_boot_ms);
174 _mav_put_uint16_t(buf, 8, sequence);
175 _mav_put_uint8_t(buf, 10, destination_component);
176 _mav_put_uint8_t(buf, 11, destination_system);
177 _mav_put_uint8_t(buf, 12, log_levels);
178 _mav_put_uint8_t_array(buf, 13, arguments, 40);
179 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_EVENT_LEN);
180#else
181 mavlink_event_t packet;
182 packet.id = id;
183 packet.event_time_boot_ms = event_time_boot_ms;
184 packet.sequence = sequence;
185 packet.destination_component = destination_component;
186 packet.destination_system = destination_system;
187 packet.log_levels = log_levels;
188 mav_array_memcpy(packet.arguments, arguments, sizeof(uint8_t)*40);
189 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_EVENT_LEN);
190#endif
191
192 msg->msgid = MAVLINK_MSG_ID_EVENT;
193 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
194}
195
196/**
197 * @brief Encode a event struct
198 *
199 * @param system_id ID of this system
200 * @param component_id ID of this component (e.g. 200 for IMU)
201 * @param msg The MAVLink message to compress the data into
202 * @param event C-struct to read the message contents from
203 */
204MAVLINK_WIP
205static inline uint16_t mavlink_msg_event_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_event_t* event)
206{
207 return mavlink_msg_event_pack(system_id, component_id, msg, event->destination_component, event->destination_system, event->id, event->event_time_boot_ms, event->sequence, event->log_levels, event->arguments);
208}
209
210/**
211 * @brief Encode a event struct on a channel
212 *
213 * @param system_id ID of this system
214 * @param component_id ID of this component (e.g. 200 for IMU)
215 * @param chan The MAVLink channel this message will be sent over
216 * @param msg The MAVLink message to compress the data into
217 * @param event C-struct to read the message contents from
218 */
219MAVLINK_WIP
220static inline uint16_t mavlink_msg_event_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_event_t* event)
221{
222 return mavlink_msg_event_pack_chan(system_id, component_id, chan, msg, event->destination_component, event->destination_system, event->id, event->event_time_boot_ms, event->sequence, event->log_levels, event->arguments);
223}
224
225/**
226 * @brief Encode a event struct with provided status structure
227 *
228 * @param system_id ID of this system
229 * @param component_id ID of this component (e.g. 200 for IMU)
230 * @param status MAVLink status structure
231 * @param msg The MAVLink message to compress the data into
232 * @param event C-struct to read the message contents from
233 */
234static inline uint16_t mavlink_msg_event_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_event_t* event)
235{
236 return mavlink_msg_event_pack_status(system_id, component_id, _status, msg, event->destination_component, event->destination_system, event->id, event->event_time_boot_ms, event->sequence, event->log_levels, event->arguments);
237}
238
239/**
240 * @brief Send a event message
241 * @param chan MAVLink channel to send the message
242 *
243 * @param destination_component Component ID
244 * @param destination_system System ID
245 * @param id Event ID (as defined in the component metadata)
246 * @param event_time_boot_ms [ms] Timestamp (time since system boot when the event happened).
247 * @param sequence Sequence number.
248 * @param log_levels Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9
249 * @param arguments Arguments (depend on event ID).
250 */
251#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
252
253MAVLINK_WIP
254static inline void mavlink_msg_event_send(mavlink_channel_t chan, uint8_t destination_component, uint8_t destination_system, uint32_t id, uint32_t event_time_boot_ms, uint16_t sequence, uint8_t log_levels, const uint8_t *arguments)
255{
256#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
257 char buf[MAVLINK_MSG_ID_EVENT_LEN];
258 _mav_put_uint32_t(buf, 0, id);
259 _mav_put_uint32_t(buf, 4, event_time_boot_ms);
260 _mav_put_uint16_t(buf, 8, sequence);
261 _mav_put_uint8_t(buf, 10, destination_component);
262 _mav_put_uint8_t(buf, 11, destination_system);
263 _mav_put_uint8_t(buf, 12, log_levels);
264 _mav_put_uint8_t_array(buf, 13, arguments, 40);
265 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_EVENT, buf, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
266#else
267 mavlink_event_t packet;
268 packet.id = id;
269 packet.event_time_boot_ms = event_time_boot_ms;
270 packet.sequence = sequence;
271 packet.destination_component = destination_component;
272 packet.destination_system = destination_system;
273 packet.log_levels = log_levels;
274 mav_array_memcpy(packet.arguments, arguments, sizeof(uint8_t)*40);
275 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_EVENT, (const char *)&packet, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
276#endif
277}
278
279/**
280 * @brief Send a event message
281 * @param chan MAVLink channel to send the message
282 * @param struct The MAVLink struct to serialize
283 */
284MAVLINK_WIP
285static inline void mavlink_msg_event_send_struct(mavlink_channel_t chan, const mavlink_event_t* event)
286{
287#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
288 mavlink_msg_event_send(chan, event->destination_component, event->destination_system, event->id, event->event_time_boot_ms, event->sequence, event->log_levels, event->arguments);
289#else
290 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_EVENT, (const char *)event, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
291#endif
292}
293
294#if MAVLINK_MSG_ID_EVENT_LEN <= MAVLINK_MAX_PAYLOAD_LEN
295/*
296 This variant of _send() can be used to save stack space by reusing
297 memory from the receive buffer. The caller provides a
298 mavlink_message_t which is the size of a full mavlink message. This
299 is usually the receive buffer for the channel, and allows a reply to an
300 incoming message with minimum stack space usage.
301 */
302MAVLINK_WIP
303static inline void mavlink_msg_event_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t destination_component, uint8_t destination_system, uint32_t id, uint32_t event_time_boot_ms, uint16_t sequence, uint8_t log_levels, const uint8_t *arguments)
304{
305#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
306 char *buf = (char *)msgbuf;
307 _mav_put_uint32_t(buf, 0, id);
308 _mav_put_uint32_t(buf, 4, event_time_boot_ms);
309 _mav_put_uint16_t(buf, 8, sequence);
310 _mav_put_uint8_t(buf, 10, destination_component);
311 _mav_put_uint8_t(buf, 11, destination_system);
312 _mav_put_uint8_t(buf, 12, log_levels);
313 _mav_put_uint8_t_array(buf, 13, arguments, 40);
314 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_EVENT, buf, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
315#else
316 mavlink_event_t *packet = (mavlink_event_t *)msgbuf;
317 packet->id = id;
318 packet->event_time_boot_ms = event_time_boot_ms;
319 packet->sequence = sequence;
320 packet->destination_component = destination_component;
321 packet->destination_system = destination_system;
322 packet->log_levels = log_levels;
323 mav_array_memcpy(packet->arguments, arguments, sizeof(uint8_t)*40);
324 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_EVENT, (const char *)packet, MAVLINK_MSG_ID_EVENT_MIN_LEN, MAVLINK_MSG_ID_EVENT_LEN, MAVLINK_MSG_ID_EVENT_CRC);
325#endif
326}
327#endif
328
329#endif
330
331// MESSAGE EVENT UNPACKING
332
333
334/**
335 * @brief Get field destination_component from event message
336 *
337 * @return Component ID
338 */
339MAVLINK_WIP
340static inline uint8_t mavlink_msg_event_get_destination_component(const mavlink_message_t* msg)
341{
342 return _MAV_RETURN_uint8_t(msg, 10);
343}
344
345/**
346 * @brief Get field destination_system from event message
347 *
348 * @return System ID
349 */
350MAVLINK_WIP
351static inline uint8_t mavlink_msg_event_get_destination_system(const mavlink_message_t* msg)
352{
353 return _MAV_RETURN_uint8_t(msg, 11);
354}
355
356/**
357 * @brief Get field id from event message
358 *
359 * @return Event ID (as defined in the component metadata)
360 */
361MAVLINK_WIP
362static inline uint32_t mavlink_msg_event_get_id(const mavlink_message_t* msg)
363{
364 return _MAV_RETURN_uint32_t(msg, 0);
365}
366
367/**
368 * @brief Get field event_time_boot_ms from event message
369 *
370 * @return [ms] Timestamp (time since system boot when the event happened).
371 */
372MAVLINK_WIP
373static inline uint32_t mavlink_msg_event_get_event_time_boot_ms(const mavlink_message_t* msg)
374{
375 return _MAV_RETURN_uint32_t(msg, 4);
376}
377
378/**
379 * @brief Get field sequence from event message
380 *
381 * @return Sequence number.
382 */
383MAVLINK_WIP
384static inline uint16_t mavlink_msg_event_get_sequence(const mavlink_message_t* msg)
385{
386 return _MAV_RETURN_uint16_t(msg, 8);
387}
388
389/**
390 * @brief Get field log_levels from event message
391 *
392 * @return Log levels: 4 bits MSB: internal (for logging purposes), 4 bits LSB: external. Levels: Emergency = 0, Alert = 1, Critical = 2, Error = 3, Warning = 4, Notice = 5, Info = 6, Debug = 7, Protocol = 8, Disabled = 9
393 */
394MAVLINK_WIP
395static inline uint8_t mavlink_msg_event_get_log_levels(const mavlink_message_t* msg)
396{
397 return _MAV_RETURN_uint8_t(msg, 12);
398}
399
400/**
401 * @brief Get field arguments from event message
402 *
403 * @return Arguments (depend on event ID).
404 */
405MAVLINK_WIP
406static inline uint16_t mavlink_msg_event_get_arguments(const mavlink_message_t* msg, uint8_t *arguments)
407{
408 return _MAV_RETURN_uint8_t_array(msg, arguments, 40, 13);
409}
410
411/**
412 * @brief Decode a event message into a struct
413 *
414 * @param msg The message to decode
415 * @param event C-struct to decode the message contents into
416 */
417MAVLINK_WIP
418static inline void mavlink_msg_event_decode(const mavlink_message_t* msg, mavlink_event_t* event)
419{
420#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
421 event->id = mavlink_msg_event_get_id(msg);
422 event->event_time_boot_ms = mavlink_msg_event_get_event_time_boot_ms(msg);
423 event->sequence = mavlink_msg_event_get_sequence(msg);
424 event->destination_component = mavlink_msg_event_get_destination_component(msg);
425 event->destination_system = mavlink_msg_event_get_destination_system(msg);
426 event->log_levels = mavlink_msg_event_get_log_levels(msg);
427 mavlink_msg_event_get_arguments(msg, event->arguments);
428#else
429 uint8_t len = msg->len < MAVLINK_MSG_ID_EVENT_LEN? msg->len : MAVLINK_MSG_ID_EVENT_LEN;
430 memset(event, 0, MAVLINK_MSG_ID_EVENT_LEN);
431 memcpy(event, _MAV_PAYLOAD(msg), len);
432#endif
433}