Merge remote-tracking branch 'upstream/master' into abo_fw_alt_vel_control
[inav.git] / lib / main / MAVLink / minimal / mavlink_msg_heartbeat.h
blob7774a1006b9da680e8781dc6a905cab5e317a7e2
1 #pragma once
2 // MESSAGE HEARTBEAT PACKING
4 #define MAVLINK_MSG_ID_HEARTBEAT 0
7 typedef 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;
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
21 #define MAVLINK_MSG_ID_HEARTBEAT_CRC 50
22 #define MAVLINK_MSG_ID_0_CRC 50
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 } \
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 } \
51 #endif
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
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)
66 static 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)
69 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
70 char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
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);
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;
88 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
89 #endif
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);
95 /**
96 * @brief Pack a heartbeat message on a channel
97 * @param system_id ID of this system
98 * @param component_id ID of this component (e.g. 200 for IMU)
99 * @param chan The MAVLink channel this message will be sent over
100 * @param msg The MAVLink message to compress the data into
101 * @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.
102 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
103 * @param base_mode System mode bitmap.
104 * @param custom_mode A bitfield for use for autopilot-specific flags
105 * @param system_status System status flag.
106 * @return length of the message in bytes (excluding serial stream start sign)
108 static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
109 mavlink_message_t* msg,
110 uint8_t type,uint8_t autopilot,uint8_t base_mode,uint32_t custom_mode,uint8_t system_status)
112 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
113 char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
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);
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;
131 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
132 #endif
134 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
135 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);
139 * @brief Encode a heartbeat struct
141 * @param system_id ID of this system
142 * @param component_id ID of this component (e.g. 200 for IMU)
143 * @param msg The MAVLink message to compress the data into
144 * @param heartbeat C-struct to read the message contents from
146 static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
148 return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
152 * @brief Encode a heartbeat struct on a channel
154 * @param system_id ID of this system
155 * @param component_id ID of this component (e.g. 200 for IMU)
156 * @param chan The MAVLink channel this message will be sent over
157 * @param msg The MAVLink message to compress the data into
158 * @param heartbeat C-struct to read the message contents from
160 static 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)
162 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);
166 * @brief Send a heartbeat message
167 * @param chan MAVLink channel to send the message
169 * @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.
170 * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
171 * @param base_mode System mode bitmap.
172 * @param custom_mode A bitfield for use for autopilot-specific flags
173 * @param system_status System status flag.
175 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
177 static 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)
179 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
180 char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
181 _mav_put_uint32_t(buf, 0, custom_mode);
182 _mav_put_uint8_t(buf, 4, type);
183 _mav_put_uint8_t(buf, 5, autopilot);
184 _mav_put_uint8_t(buf, 6, base_mode);
185 _mav_put_uint8_t(buf, 7, system_status);
186 _mav_put_uint8_t(buf, 8, 3);
188 _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);
189 #else
190 mavlink_heartbeat_t packet;
191 packet.custom_mode = custom_mode;
192 packet.type = type;
193 packet.autopilot = autopilot;
194 packet.base_mode = base_mode;
195 packet.system_status = system_status;
196 packet.mavlink_version = 3;
198 _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);
199 #endif
203 * @brief Send a heartbeat message
204 * @param chan MAVLink channel to send the message
205 * @param struct The MAVLink struct to serialize
207 static inline void mavlink_msg_heartbeat_send_struct(mavlink_channel_t chan, const mavlink_heartbeat_t* heartbeat)
209 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
210 mavlink_msg_heartbeat_send(chan, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
211 #else
212 _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);
213 #endif
216 #if MAVLINK_MSG_ID_HEARTBEAT_LEN <= MAVLINK_MAX_PAYLOAD_LEN
218 This varient of _send() can be used to save stack space by re-using
219 memory from the receive buffer. The caller provides a
220 mavlink_message_t which is the size of a full mavlink message. This
221 is usually the receive buffer for the channel, and allows a reply to an
222 incoming message with minimum stack space usage.
224 static 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)
226 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
227 char *buf = (char *)msgbuf;
228 _mav_put_uint32_t(buf, 0, custom_mode);
229 _mav_put_uint8_t(buf, 4, type);
230 _mav_put_uint8_t(buf, 5, autopilot);
231 _mav_put_uint8_t(buf, 6, base_mode);
232 _mav_put_uint8_t(buf, 7, system_status);
233 _mav_put_uint8_t(buf, 8, 3);
235 _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);
236 #else
237 mavlink_heartbeat_t *packet = (mavlink_heartbeat_t *)msgbuf;
238 packet->custom_mode = custom_mode;
239 packet->type = type;
240 packet->autopilot = autopilot;
241 packet->base_mode = base_mode;
242 packet->system_status = system_status;
243 packet->mavlink_version = 3;
245 _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);
246 #endif
248 #endif
250 #endif
252 // MESSAGE HEARTBEAT UNPACKING
256 * @brief Get field type from heartbeat message
258 * @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.
260 static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg)
262 return _MAV_RETURN_uint8_t(msg, 4);
266 * @brief Get field autopilot from heartbeat message
268 * @return Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
270 static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg)
272 return _MAV_RETURN_uint8_t(msg, 5);
276 * @brief Get field base_mode from heartbeat message
278 * @return System mode bitmap.
280 static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg)
282 return _MAV_RETURN_uint8_t(msg, 6);
286 * @brief Get field custom_mode from heartbeat message
288 * @return A bitfield for use for autopilot-specific flags
290 static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg)
292 return _MAV_RETURN_uint32_t(msg, 0);
296 * @brief Get field system_status from heartbeat message
298 * @return System status flag.
300 static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg)
302 return _MAV_RETURN_uint8_t(msg, 7);
306 * @brief Get field mavlink_version from heartbeat message
308 * @return MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
310 static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg)
312 return _MAV_RETURN_uint8_t(msg, 8);
316 * @brief Decode a heartbeat message into a struct
318 * @param msg The message to decode
319 * @param heartbeat C-struct to decode the message contents into
321 static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat)
323 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
324 heartbeat->custom_mode = mavlink_msg_heartbeat_get_custom_mode(msg);
325 heartbeat->type = mavlink_msg_heartbeat_get_type(msg);
326 heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg);
327 heartbeat->base_mode = mavlink_msg_heartbeat_get_base_mode(msg);
328 heartbeat->system_status = mavlink_msg_heartbeat_get_system_status(msg);
329 heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg);
330 #else
331 uint8_t len = msg->len < MAVLINK_MSG_ID_HEARTBEAT_LEN? msg->len : MAVLINK_MSG_ID_HEARTBEAT_LEN;
332 memset(heartbeat, 0, MAVLINK_MSG_ID_HEARTBEAT_LEN);
333 memcpy(heartbeat, _MAV_PAYLOAD(msg), len);
334 #endif