RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
mavlink_msg_heartbeat.h
1#pragma once
2// MESSAGE HEARTBEAT PACKING
3
4#define MAVLINK_MSG_ID_HEARTBEAT 0
5
6MAVPACKED(
7typedef struct __mavlink_heartbeat_t {
8 uint32_t custom_mode; /*< A bitfield for use for autopilot-specific flags.*/
9 uint8_t type; /*< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)*/
10 uint8_t autopilot; /*< Autopilot type / class. defined in MAV_AUTOPILOT ENUM*/
11 uint8_t base_mode; /*< System mode bitfield, see MAV_MODE_FLAG ENUM in mavlink/include/mavlink_types.h*/
12 uint8_t system_status; /*< System status flag, see MAV_STATE ENUM*/
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
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
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);
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
108static 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)
111{
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);
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 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);
136}
137
146static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
147{
148 return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
149}
150
160static 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)
161{
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);
163}
164
175#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
176
177static 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)
178{
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);
187
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;
197
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
200}
201
207static inline void mavlink_msg_heartbeat_send_struct(mavlink_channel_t chan, const mavlink_heartbeat_t* heartbeat)
208{
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
214}
215
216#if MAVLINK_MSG_ID_HEARTBEAT_LEN <= MAVLINK_MAX_PAYLOAD_LEN
217/*
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.
223 */
224static 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)
225{
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);
234
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;
244
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
247}
248#endif
249
250#endif
251
252// MESSAGE HEARTBEAT UNPACKING
253
254
260static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg)
261{
262 return _MAV_RETURN_uint8_t(msg, 4);
263}
264
270static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg)
271{
272 return _MAV_RETURN_uint8_t(msg, 5);
273}
274
280static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg)
281{
282 return _MAV_RETURN_uint8_t(msg, 6);
283}
284
290static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg)
291{
292 return _MAV_RETURN_uint32_t(msg, 0);
293}
294
300static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg)
301{
302 return _MAV_RETURN_uint8_t(msg, 7);
303}
304
310static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg)
311{
312 return _MAV_RETURN_uint8_t(msg, 8);
313}
314
321static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat)
322{
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
335}