Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
// MESSAGE HEARTBEAT PACKING
2
 
3
#define MAVLINK_MSG_ID_HEARTBEAT 0
4
 
5
typedef struct __mavlink_heartbeat_t
6
{
7
 uint32_t custom_mode; ///< A bitfield for use for autopilot-specific flags.
8
 uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
9
 uint8_t autopilot; ///< Autopilot type / class. defined in MAV_AUTOPILOT ENUM
10
 uint8_t base_mode; ///< System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
11
 uint8_t system_status; ///< System status flag, see MAV_STATE ENUM
12
 uint8_t mavlink_version; ///< MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
13
} mavlink_heartbeat_t;
14
 
15
#define MAVLINK_MSG_ID_HEARTBEAT_LEN 9
16
#define MAVLINK_MSG_ID_0_LEN 9
17
 
18
 
19
 
20
#define MAVLINK_MESSAGE_INFO_HEARTBEAT { \
21
        "HEARTBEAT", \
22
        6, \
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
         } \
30
}
31
 
32
 
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
38
 *
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)
45
 */
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)
48
{
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);
57
 
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
 
68
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9);
69
#endif
70
 
71
        msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
72
        return mavlink_finalize_message(msg, system_id, component_id, 9, 50);
73
}
74
 
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)
87
 */
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)
91
{
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);
100
 
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;
110
 
111
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9);
112
#endif
113
 
114
        msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
115
        return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 9, 50);
116
}
117
 
118
/**
119
 * @brief Encode a heartbeat struct into a message
120
 *
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
125
 */
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)
127
{
128
        return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
129
}
130
 
131
/**
132
 * @brief Send a heartbeat message
133
 * @param chan MAVLink channel to send the message
134
 *
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
140
 */
141
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
142
 
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)
144
{
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);
153
 
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;
163
 
164
        _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, 9, 50);
165
#endif
166
}
167
 
168
#endif
169
 
170
// MESSAGE HEARTBEAT UNPACKING
171
 
172
 
173
/**
174
 * @brief Get field type from heartbeat message
175
 *
176
 * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)
177
 */
178
static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg)
179
{
180
        return _MAV_RETURN_uint8_t(msg,  4);
181
}
182
 
183
/**
184
 * @brief Get field autopilot from heartbeat message
185
 *
186
 * @return Autopilot type / class. defined in MAV_AUTOPILOT ENUM
187
 */
188
static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg)
189
{
190
        return _MAV_RETURN_uint8_t(msg,  5);
191
}
192
 
193
/**
194
 * @brief Get field base_mode from heartbeat message
195
 *
196
 * @return System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h
197
 */
198
static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg)
199
{
200
        return _MAV_RETURN_uint8_t(msg,  6);
201
}
202
 
203
/**
204
 * @brief Get field custom_mode from heartbeat message
205
 *
206
 * @return A bitfield for use for autopilot-specific flags.
207
 */
208
static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg)
209
{
210
        return _MAV_RETURN_uint32_t(msg,  0);
211
}
212
 
213
/**
214
 * @brief Get field system_status from heartbeat message
215
 *
216
 * @return System status flag, see MAV_STATE ENUM
217
 */
218
static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg)
219
{
220
        return _MAV_RETURN_uint8_t(msg,  7);
221
}
222
 
223
/**
224
 * @brief Get field mavlink_version from heartbeat message
225
 *
226
 * @return MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
227
 */
228
static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg)
229
{
230
        return _MAV_RETURN_uint8_t(msg,  8);
231
}
232
 
233
/**
234
 * @brief Decode a heartbeat message into a struct
235
 *
236
 * @param msg The message to decode
237
 * @param heartbeat C-struct to decode the message contents into
238
 */
239
static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat)
240
{
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
251
}