RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
mavlink_msg_data32.h
1#pragma once
2// MESSAGE DATA32 PACKING
3
4#define MAVLINK_MSG_ID_DATA32 170
5
6MAVPACKED(
7typedef struct __mavlink_data32_t {
8 uint8_t type; /*< data type*/
9 uint8_t len; /*< data length*/
10 uint8_t data[32]; /*< raw data*/
11}) mavlink_data32_t;
12
13#define MAVLINK_MSG_ID_DATA32_LEN 34
14#define MAVLINK_MSG_ID_DATA32_MIN_LEN 34
15#define MAVLINK_MSG_ID_170_LEN 34
16#define MAVLINK_MSG_ID_170_MIN_LEN 34
17
18#define MAVLINK_MSG_ID_DATA32_CRC 73
19#define MAVLINK_MSG_ID_170_CRC 73
20
21#define MAVLINK_MSG_DATA32_FIELD_DATA_LEN 32
22
23#if MAVLINK_COMMAND_24BIT
24#define MAVLINK_MESSAGE_INFO_DATA32 { \
25 170, \
26 "DATA32", \
27 3, \
28 { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data32_t, type) }, \
29 { "len", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_data32_t, len) }, \
30 { "data", NULL, MAVLINK_TYPE_UINT8_T, 32, 2, offsetof(mavlink_data32_t, data) }, \
31 } \
32}
33#else
34#define MAVLINK_MESSAGE_INFO_DATA32 { \
35 "DATA32", \
36 3, \
37 { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data32_t, type) }, \
38 { "len", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_data32_t, len) }, \
39 { "data", NULL, MAVLINK_TYPE_UINT8_T, 32, 2, offsetof(mavlink_data32_t, data) }, \
40 } \
41}
42#endif
43
44/**
45 * @brief Pack a data32 message
46 * @param system_id ID of this system
47 * @param component_id ID of this component (e.g. 200 for IMU)
48 * @param msg The MAVLink message to compress the data into
49 *
50 * @param type data type
51 * @param len data length
52 * @param data raw data
53 * @return length of the message in bytes (excluding serial stream start sign)
54 */
55static inline uint16_t mavlink_msg_data32_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
56 uint8_t type, uint8_t len, const uint8_t *data)
57{
58#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
59 char buf[MAVLINK_MSG_ID_DATA32_LEN];
60 _mav_put_uint8_t(buf, 0, type);
61 _mav_put_uint8_t(buf, 1, len);
62 _mav_put_uint8_t_array(buf, 2, data, 32);
63 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DATA32_LEN);
64#else
65 mavlink_data32_t packet;
66 packet.type = type;
67 packet.len = len;
68 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32);
69 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DATA32_LEN);
70#endif
71
72 msg->msgid = MAVLINK_MSG_ID_DATA32;
73 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
74}
75
76/**
77 * @brief Pack a data32 message on a channel
78 * @param system_id ID of this system
79 * @param component_id ID of this component (e.g. 200 for IMU)
80 * @param chan The MAVLink channel this message will be sent over
81 * @param msg The MAVLink message to compress the data into
82 * @param type data type
83 * @param len data length
84 * @param data raw data
85 * @return length of the message in bytes (excluding serial stream start sign)
86 */
87static inline uint16_t mavlink_msg_data32_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
88 mavlink_message_t* msg,
89 uint8_t type,uint8_t len,const uint8_t *data)
90{
91#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
92 char buf[MAVLINK_MSG_ID_DATA32_LEN];
93 _mav_put_uint8_t(buf, 0, type);
94 _mav_put_uint8_t(buf, 1, len);
95 _mav_put_uint8_t_array(buf, 2, data, 32);
96 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DATA32_LEN);
97#else
98 mavlink_data32_t packet;
99 packet.type = type;
100 packet.len = len;
101 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32);
102 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DATA32_LEN);
103#endif
104
105 msg->msgid = MAVLINK_MSG_ID_DATA32;
106 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
107}
108
109/**
110 * @brief Encode a data32 struct
111 *
112 * @param system_id ID of this system
113 * @param component_id ID of this component (e.g. 200 for IMU)
114 * @param msg The MAVLink message to compress the data into
115 * @param data32 C-struct to read the message contents from
116 */
117static inline uint16_t mavlink_msg_data32_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data32_t* data32)
118{
119 return mavlink_msg_data32_pack(system_id, component_id, msg, data32->type, data32->len, data32->data);
120}
121
122/**
123 * @brief Encode a data32 struct on a channel
124 *
125 * @param system_id ID of this system
126 * @param component_id ID of this component (e.g. 200 for IMU)
127 * @param chan The MAVLink channel this message will be sent over
128 * @param msg The MAVLink message to compress the data into
129 * @param data32 C-struct to read the message contents from
130 */
131static inline uint16_t mavlink_msg_data32_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_data32_t* data32)
132{
133 return mavlink_msg_data32_pack_chan(system_id, component_id, chan, msg, data32->type, data32->len, data32->data);
134}
135
136/**
137 * @brief Send a data32 message
138 * @param chan MAVLink channel to send the message
139 *
140 * @param type data type
141 * @param len data length
142 * @param data raw data
143 */
144#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
145
146static inline void mavlink_msg_data32_send(mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data)
147{
148#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
149 char buf[MAVLINK_MSG_ID_DATA32_LEN];
150 _mav_put_uint8_t(buf, 0, type);
151 _mav_put_uint8_t(buf, 1, len);
152 _mav_put_uint8_t_array(buf, 2, data, 32);
153 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, buf, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
154#else
155 mavlink_data32_t packet;
156 packet.type = type;
157 packet.len = len;
158 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32);
159 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, (const char *)&packet, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
160#endif
161}
162
163/**
164 * @brief Send a data32 message
165 * @param chan MAVLink channel to send the message
166 * @param struct The MAVLink struct to serialize
167 */
168static inline void mavlink_msg_data32_send_struct(mavlink_channel_t chan, const mavlink_data32_t* data32)
169{
170#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
171 mavlink_msg_data32_send(chan, data32->type, data32->len, data32->data);
172#else
173 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, (const char *)data32, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
174#endif
175}
176
177#if MAVLINK_MSG_ID_DATA32_LEN <= MAVLINK_MAX_PAYLOAD_LEN
178/*
179 This varient of _send() can be used to save stack space by re-using
180 memory from the receive buffer. The caller provides a
181 mavlink_message_t which is the size of a full mavlink message. This
182 is usually the receive buffer for the channel, and allows a reply to an
183 incoming message with minimum stack space usage.
184 */
185static inline void mavlink_msg_data32_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data)
186{
187#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
188 char *buf = (char *)msgbuf;
189 _mav_put_uint8_t(buf, 0, type);
190 _mav_put_uint8_t(buf, 1, len);
191 _mav_put_uint8_t_array(buf, 2, data, 32);
192 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, buf, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
193#else
194 mavlink_data32_t *packet = (mavlink_data32_t *)msgbuf;
195 packet->type = type;
196 packet->len = len;
197 mav_array_memcpy(packet->data, data, sizeof(uint8_t)*32);
198 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, (const char *)packet, MAVLINK_MSG_ID_DATA32_MIN_LEN, MAVLINK_MSG_ID_DATA32_LEN, MAVLINK_MSG_ID_DATA32_CRC);
199#endif
200}
201#endif
202
203#endif
204
205// MESSAGE DATA32 UNPACKING
206
207
208/**
209 * @brief Get field type from data32 message
210 *
211 * @return data type
212 */
213static inline uint8_t mavlink_msg_data32_get_type(const mavlink_message_t* msg)
214{
215 return _MAV_RETURN_uint8_t(msg, 0);
216}
217
218/**
219 * @brief Get field len from data32 message
220 *
221 * @return data length
222 */
223static inline uint8_t mavlink_msg_data32_get_len(const mavlink_message_t* msg)
224{
225 return _MAV_RETURN_uint8_t(msg, 1);
226}
227
228/**
229 * @brief Get field data from data32 message
230 *
231 * @return raw data
232 */
233static inline uint16_t mavlink_msg_data32_get_data(const mavlink_message_t* msg, uint8_t *data)
234{
235 return _MAV_RETURN_uint8_t_array(msg, data, 32, 2);
236}
237
238/**
239 * @brief Decode a data32 message into a struct
240 *
241 * @param msg The message to decode
242 * @param data32 C-struct to decode the message contents into
243 */
244static inline void mavlink_msg_data32_decode(const mavlink_message_t* msg, mavlink_data32_t* data32)
245{
246#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
247 data32->type = mavlink_msg_data32_get_type(msg);
248 data32->len = mavlink_msg_data32_get_len(msg);
249 mavlink_msg_data32_get_data(msg, data32->data);
250#else
251 uint8_t len = msg->len < MAVLINK_MSG_ID_DATA32_LEN? msg->len : MAVLINK_MSG_ID_DATA32_LEN;
252 memset(data32, 0, MAVLINK_MSG_ID_DATA32_LEN);
253 memcpy(data32, _MAV_PAYLOAD(msg), len);
254#endif
255}