Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_heartbeat.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE HEARTBEAT PACKING
3
4#define MAVLINK_MSG_ID_HEARTBEAT 0
5
6
7typedef struct __mavlink_heartbeat_t {
8 uint32_t custom_mode; /*< A bitfield for use for autopilot-specific flags*/
9 uint8_t type; /*< Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.*/
10 uint8_t autopilot; /*< Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.*/
11 uint8_t base_mode; /*< System mode bitmap.*/
12 uint8_t system_status; /*< System status flag.*/
13 uint8_t mavlink_version; /*< MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version*/
14} mavlink_heartbeat_t;
15
16#define MAVLINK_MSG_ID_HEARTBEAT_LEN 9
17#define MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN 9
18#define MAVLINK_MSG_ID_0_LEN 9
19#define MAVLINK_MSG_ID_0_MIN_LEN 9
20
21#define MAVLINK_MSG_ID_HEARTBEAT_CRC 50
22#define MAVLINK_MSG_ID_0_CRC 50
23
24
25
26#if MAVLINK_COMMAND_24BIT
27#define MAVLINK_MESSAGE_INFO_HEARTBEAT {
28 0,
29 "HEARTBEAT",
30 6,
31 { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) },
32 { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) },
33 { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) },
34 { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) },
35 { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) },
36 { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) },
37 } \
38}
39#else
40#define MAVLINK_MESSAGE_INFO_HEARTBEAT {
41 "HEARTBEAT",
42 6,
43 { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) },
44 { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) },
45 { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) },
46 { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) },
47 { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) },
48 { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) },
49 } \
50}
51#endif
52
53/**
54 * @brief Pack a heartbeat message
55 * @param system_id ID of this system
56 * @param component_id ID of this component (e.g. 200 for IMU)
57 * @param msg The MAVLink message to compress the data into
58 *
59 * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
60 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
61 * @param base_mode System mode bitmap.
62 * @param custom_mode A bitfield for use for autopilot-specific flags
63 * @param system_status System status flag.
64 * @return length of the message in bytes (excluding serial stream start sign)
65 */
66static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
67 uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
68{
69#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
71 _mav_put_uint32_t(buf, 0, custom_mode);
72 _mav_put_uint8_t(buf, 4, type);
73 _mav_put_uint8_t(buf, 5, autopilot);
74 _mav_put_uint8_t(buf, 6, base_mode);
75 _mav_put_uint8_t(buf, 7, system_status);
76 _mav_put_uint8_t(buf, 8, 3);
77
78 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
79#else
80 mavlink_heartbeat_t packet;
81 packet.custom_mode = custom_mode;
82 packet.type = type;
83 packet.autopilot = autopilot;
84 packet.base_mode = base_mode;
85 packet.system_status = system_status;
86 packet.mavlink_version = 3;
87
88 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
89#endif
90
91 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
92 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
93}
94
95/**
96 * @brief Pack a heartbeat message
97 * @param system_id ID of this system
98 * @param component_id ID of this component (e.g. 200 for IMU)
99 * @param status MAVLink status structure
100 * @param msg The MAVLink message to compress the data into
101 *
102 * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
103 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
104 * @param base_mode System mode bitmap.
105 * @param custom_mode A bitfield for use for autopilot-specific flags
106 * @param system_status System status flag.
107 * @return length of the message in bytes (excluding serial stream start sign)
108 */
109static inline uint16_t mavlink_msg_heartbeat_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
110 uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
111{
112#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
114 _mav_put_uint32_t(buf, 0, custom_mode);
115 _mav_put_uint8_t(buf, 4, type);
116 _mav_put_uint8_t(buf, 5, autopilot);
117 _mav_put_uint8_t(buf, 6, base_mode);
118 _mav_put_uint8_t(buf, 7, system_status);
119 _mav_put_uint8_t(buf, 8, 3);
120
121 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
122#else
123 mavlink_heartbeat_t packet;
124 packet.custom_mode = custom_mode;
125 packet.type = type;
126 packet.autopilot = autopilot;
127 packet.base_mode = base_mode;
128 packet.system_status = system_status;
129 packet.mavlink_version = 3;
130
131 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
132#endif
133
134 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
135#if MAVLINK_CRC_EXTRA
136 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
137#else
138 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN);
139#endif
140}
141
142/**
143 * @brief Pack a heartbeat message on a channel
144 * @param system_id ID of this system
145 * @param component_id ID of this component (e.g. 200 for IMU)
146 * @param chan The MAVLink channel this message will be sent over
147 * @param msg The MAVLink message to compress the data into
148 * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
149 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
150 * @param base_mode System mode bitmap.
151 * @param custom_mode A bitfield for use for autopilot-specific flags
152 * @param system_status System status flag.
153 * @return length of the message in bytes (excluding serial stream start sign)
154 */
155static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
156 mavlink_message_t* msg,
157 uint8_t type,uint8_t autopilot,uint8_t base_mode,uint32_t custom_mode,uint8_t system_status)
158{
159#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
161 _mav_put_uint32_t(buf, 0, custom_mode);
162 _mav_put_uint8_t(buf, 4, type);
163 _mav_put_uint8_t(buf, 5, autopilot);
164 _mav_put_uint8_t(buf, 6, base_mode);
165 _mav_put_uint8_t(buf, 7, system_status);
166 _mav_put_uint8_t(buf, 8, 3);
167
168 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
169#else
170 mavlink_heartbeat_t packet;
171 packet.custom_mode = custom_mode;
172 packet.type = type;
173 packet.autopilot = autopilot;
174 packet.base_mode = base_mode;
175 packet.system_status = system_status;
176 packet.mavlink_version = 3;
177
178 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
179#endif
180
181 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
182 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
183}
184
185/**
186 * @brief Encode a heartbeat struct
187 *
188 * @param system_id ID of this system
189 * @param component_id ID of this component (e.g. 200 for IMU)
190 * @param msg The MAVLink message to compress the data into
191 * @param heartbeat C-struct to read the message contents from
192 */
193static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
194{
195 return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
196}
197
198/**
199 * @brief Encode a heartbeat struct on a channel
200 *
201 * @param system_id ID of this system
202 * @param component_id ID of this component (e.g. 200 for IMU)
203 * @param chan The MAVLink channel this message will be sent over
204 * @param msg The MAVLink message to compress the data into
205 * @param heartbeat C-struct to read the message contents from
206 */
207static inline uint16_t mavlink_msg_heartbeat_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
208{
209 return mavlink_msg_heartbeat_pack_chan(system_id, component_id, chan, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
210}
211
212/**
213 * @brief Encode a heartbeat struct with provided status structure
214 *
215 * @param system_id ID of this system
216 * @param component_id ID of this component (e.g. 200 for IMU)
217 * @param status MAVLink status structure
218 * @param msg The MAVLink message to compress the data into
219 * @param heartbeat C-struct to read the message contents from
220 */
221static inline uint16_t mavlink_msg_heartbeat_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
222{
223 return mavlink_msg_heartbeat_pack_status(system_id, component_id, _status, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
224}
225
226/**
227 * @brief Send a heartbeat message
228 * @param chan MAVLink channel to send the message
229 *
230 * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
231 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
232 * @param base_mode System mode bitmap.
233 * @param custom_mode A bitfield for use for autopilot-specific flags
234 * @param system_status System status flag.
235 */
236#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
237
238static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
239{
240#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
241 char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
242 _mav_put_uint32_t(buf, 0, custom_mode);
243 _mav_put_uint8_t(buf, 4, type);
244 _mav_put_uint8_t(buf, 5, autopilot);
245 _mav_put_uint8_t(buf, 6, base_mode);
246 _mav_put_uint8_t(buf, 7, system_status);
247 _mav_put_uint8_t(buf, 8, 3);
248
249 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
250#else
251 mavlink_heartbeat_t packet;
252 packet.custom_mode = custom_mode;
253 packet.type = type;
254 packet.autopilot = autopilot;
255 packet.base_mode = base_mode;
256 packet.system_status = system_status;
257 packet.mavlink_version = 3;
258
259 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
260#endif
261}
262
263/**
264 * @brief Send a heartbeat message
265 * @param chan MAVLink channel to send the message
266 * @param struct The MAVLink struct to serialize
267 */
268static inline void mavlink_msg_heartbeat_send_struct(mavlink_channel_t chan, const mavlink_heartbeat_t* heartbeat)
269{
270#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
271 mavlink_msg_heartbeat_send(chan, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
272#else
273 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)heartbeat, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
274#endif
275}
276
277#if MAVLINK_MSG_ID_HEARTBEAT_LEN <= MAVLINK_MAX_PAYLOAD_LEN
278/*
279 This variant of _send() can be used to save stack space by reusing
280 memory from the receive buffer. The caller provides a
281 mavlink_message_t which is the size of a full mavlink message. This
282 is usually the receive buffer for the channel, and allows a reply to an
283 incoming message with minimum stack space usage.
284 */
285static inline void mavlink_msg_heartbeat_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
286{
287#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
288 char *buf = (char *)msgbuf;
289 _mav_put_uint32_t(buf, 0, custom_mode);
290 _mav_put_uint8_t(buf, 4, type);
291 _mav_put_uint8_t(buf, 5, autopilot);
292 _mav_put_uint8_t(buf, 6, base_mode);
293 _mav_put_uint8_t(buf, 7, system_status);
294 _mav_put_uint8_t(buf, 8, 3);
295
296 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
297#else
298 mavlink_heartbeat_t *packet = (mavlink_heartbeat_t *)msgbuf;
299 packet->custom_mode = custom_mode;
300 packet->type = type;
301 packet->autopilot = autopilot;
302 packet->base_mode = base_mode;
303 packet->system_status = system_status;
304 packet->mavlink_version = 3;
305
306 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)packet, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
307#endif
308}
309#endif
310
311#endif
312
313// MESSAGE HEARTBEAT UNPACKING
314
315
316/**
317 * @brief Get field type from heartbeat message
318 *
319 * @return Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
320 */
321static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg)
322{
323 return _MAV_RETURN_uint8_t(msg, 4);
324}
325
326/**
327 * @brief Get field autopilot from heartbeat message
328 *
329 * @return Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
330 */
331static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg)
332{
333 return _MAV_RETURN_uint8_t(msg, 5);
334}
335
336/**
337 * @brief Get field base_mode from heartbeat message
338 *
339 * @return System mode bitmap.
340 */
341static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg)
342{
343 return _MAV_RETURN_uint8_t(msg, 6);
344}
345
346/**
347 * @brief Get field custom_mode from heartbeat message
348 *
349 * @return A bitfield for use for autopilot-specific flags
350 */
351static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg)
352{
353 return _MAV_RETURN_uint32_t(msg, 0);
354}
355
356/**
357 * @brief Get field system_status from heartbeat message
358 *
359 * @return System status flag.
360 */
361static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg)
362{
363 return _MAV_RETURN_uint8_t(msg, 7);
364}
365
366/**
367 * @brief Get field mavlink_version from heartbeat message
368 *
369 * @return MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
370 */
371static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg)
372{
373 return _MAV_RETURN_uint8_t(msg, 8);
374}
375
376/**
377 * @brief Decode a heartbeat message into a struct
378 *
379 * @param msg The message to decode
380 * @param heartbeat C-struct to decode the message contents into
381 */
382static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat)
383{
384#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
385 heartbeat->custom_mode = mavlink_msg_heartbeat_get_custom_mode(msg);
386 heartbeat->type = mavlink_msg_heartbeat_get_type(msg);
387 heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg);
388 heartbeat->base_mode = mavlink_msg_heartbeat_get_base_mode(msg);
389 heartbeat->system_status = mavlink_msg_heartbeat_get_system_status(msg);
390 heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg);
391#else
392 uint8_t len = msg->len < MAVLINK_MSG_ID_HEARTBEAT_LEN? msg->len : MAVLINK_MSG_ID_HEARTBEAT_LEN;
393 memset(heartbeat, 0, MAVLINK_MSG_ID_HEARTBEAT_LEN);
394 memcpy(heartbeat, _MAV_PAYLOAD(msg), len);
395#endif
396}