Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / libraries / mavlink / v1.0 / common / mavlink_msg_heartbeat.h
blob0167f8801112941f08458ffa9a9eb1c6a2bc1c27
1 // MESSAGE HEARTBEAT PACKING
3 #define MAVLINK_MSG_ID_HEARTBEAT 0
5 typedef struct __mavlink_heartbeat_t {
6 uint32_t custom_mode; ///< A bitfield for use for autopilot-specific flags.
7 uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
8 uint8_t autopilot; ///< Autopilot type / class. defined in MAV_AUTOPILOT ENUM
9 uint8_t base_mode; ///< System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
10 uint8_t system_status; ///< System status flag, see MAV_STATE ENUM
11 uint8_t mavlink_version; ///< MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
12 } mavlink_heartbeat_t;
14 #define MAVLINK_MSG_ID_HEARTBEAT_LEN 9
15 #define MAVLINK_MSG_ID_0_LEN 9
18 #define MAVLINK_MESSAGE_INFO_HEARTBEAT \
19 { \
20 "HEARTBEAT", \
21 6, \
22 { \
23 { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) }, \
24 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) }, \
25 { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) }, \
26 { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) }, \
27 { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) }, \
28 { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) }, \
29 } \
33 /**
34 * @brief Pack a heartbeat message
35 * @param system_id ID of this system
36 * @param component_id ID of this component (e.g. 200 for IMU)
37 * @param msg The MAVLink message to compress the data into
39 * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
40 * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM
41 * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
42 * @param custom_mode A bitfield for use for autopilot-specific flags.
43 * @param system_status System status flag, see MAV_STATE ENUM
44 * @return length of the message in bytes (excluding serial stream start sign)
46 static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t *msg,
47 uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
49 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
50 char buf[9];
51 _mav_put_uint32_t(buf, 0, custom_mode);
52 _mav_put_uint8_t(buf, 4, type);
53 _mav_put_uint8_t(buf, 5, autopilot);
54 _mav_put_uint8_t(buf, 6, base_mode);
55 _mav_put_uint8_t(buf, 7, system_status);
56 _mav_put_uint8_t(buf, 8, 3);
58 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9);
59 #else
60 mavlink_heartbeat_t packet;
61 packet.custom_mode = custom_mode;
62 packet.type = type;
63 packet.autopilot = autopilot;
64 packet.base_mode = base_mode;
65 packet.system_status = system_status;
66 packet.mavlink_version = 3;
67 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9);
69 #endif
71 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
72 return mavlink_finalize_message(msg, system_id, component_id, 9, 50);
75 /**
76 * @brief Pack a heartbeat message on a channel
77 * @param system_id ID of this system
78 * @param component_id ID of this component (e.g. 200 for IMU)
79 * @param chan The MAVLink channel this message was sent over
80 * @param msg The MAVLink message to compress the data into
81 * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
82 * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM
83 * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
84 * @param custom_mode A bitfield for use for autopilot-specific flags.
85 * @param system_status System status flag, see MAV_STATE ENUM
86 * @return length of the message in bytes (excluding serial stream start sign)
88 static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
89 mavlink_message_t *msg,
90 uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
92 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
93 char buf[9];
94 _mav_put_uint32_t(buf, 0, custom_mode);
95 _mav_put_uint8_t(buf, 4, type);
96 _mav_put_uint8_t(buf, 5, autopilot);
97 _mav_put_uint8_t(buf, 6, base_mode);
98 _mav_put_uint8_t(buf, 7, system_status);
99 _mav_put_uint8_t(buf, 8, 3);
101 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9);
102 #else
103 mavlink_heartbeat_t packet;
104 packet.custom_mode = custom_mode;
105 packet.type = type;
106 packet.autopilot = autopilot;
107 packet.base_mode = base_mode;
108 packet.system_status = system_status;
109 packet.mavlink_version = 3;
111 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9);
112 #endif
114 msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
115 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 9, 50);
119 * @brief Encode a heartbeat struct into a message
121 * @param system_id ID of this system
122 * @param component_id ID of this component (e.g. 200 for IMU)
123 * @param msg The MAVLink message to compress the data into
124 * @param heartbeat C-struct to read the message contents from
126 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)
128 return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
132 * @brief Send a heartbeat message
133 * @param chan MAVLink channel to send the message
135 * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
136 * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM
137 * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
138 * @param custom_mode A bitfield for use for autopilot-specific flags.
139 * @param system_status System status flag, see MAV_STATE ENUM
141 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
143 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)
145 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
146 char buf[9];
147 _mav_put_uint32_t(buf, 0, custom_mode);
148 _mav_put_uint8_t(buf, 4, type);
149 _mav_put_uint8_t(buf, 5, autopilot);
150 _mav_put_uint8_t(buf, 6, base_mode);
151 _mav_put_uint8_t(buf, 7, system_status);
152 _mav_put_uint8_t(buf, 8, 3);
154 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, 9, 50);
155 #else
156 mavlink_heartbeat_t packet;
157 packet.custom_mode = custom_mode;
158 packet.type = type;
159 packet.autopilot = autopilot;
160 packet.base_mode = base_mode;
161 packet.system_status = system_status;
162 packet.mavlink_version = 3;
164 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, 9, 50);
165 #endif
168 #endif // ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
170 // MESSAGE HEARTBEAT UNPACKING
174 * @brief Get field type from heartbeat message
176 * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
178 static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t *msg)
180 return _MAV_RETURN_uint8_t(msg, 4);
184 * @brief Get field autopilot from heartbeat message
186 * @return Autopilot type / class. defined in MAV_AUTOPILOT ENUM
188 static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t *msg)
190 return _MAV_RETURN_uint8_t(msg, 5);
194 * @brief Get field base_mode from heartbeat message
196 * @return System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
198 static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t *msg)
200 return _MAV_RETURN_uint8_t(msg, 6);
204 * @brief Get field custom_mode from heartbeat message
206 * @return A bitfield for use for autopilot-specific flags.
208 static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t *msg)
210 return _MAV_RETURN_uint32_t(msg, 0);
214 * @brief Get field system_status from heartbeat message
216 * @return System status flag, see MAV_STATE ENUM
218 static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t *msg)
220 return _MAV_RETURN_uint8_t(msg, 7);
224 * @brief Get field mavlink_version from heartbeat message
226 * @return MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
228 static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t *msg)
230 return _MAV_RETURN_uint8_t(msg, 8);
234 * @brief Decode a heartbeat message into a struct
236 * @param msg The message to decode
237 * @param heartbeat C-struct to decode the message contents into
239 static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t *msg, mavlink_heartbeat_t *heartbeat)
241 #if MAVLINK_NEED_BYTE_SWAP
242 heartbeat->custom_mode = mavlink_msg_heartbeat_get_custom_mode(msg);
243 heartbeat->type = mavlink_msg_heartbeat_get_type(msg);
244 heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg);
245 heartbeat->base_mode = mavlink_msg_heartbeat_get_base_mode(msg);
246 heartbeat->system_status = mavlink_msg_heartbeat_get_system_status(msg);
247 heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg);
248 #else
249 memcpy(heartbeat, _MAV_PAYLOAD(msg), 9);
250 #endif