Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_log_data.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE LOG_DATA PACKING
3
4#define MAVLINK_MSG_ID_LOG_DATA 120
5
6
7typedef struct __mavlink_log_data_t {
8 uint32_t ofs; /*< Offset into the log*/
9 uint16_t id; /*< Log id (from LOG_ENTRY reply)*/
10 uint8_t count; /*< [bytes] Number of bytes (zero for end of log)*/
11 uint8_t data[90]; /*< log data*/
12} mavlink_log_data_t;
13
14#define MAVLINK_MSG_ID_LOG_DATA_LEN 97
15#define MAVLINK_MSG_ID_LOG_DATA_MIN_LEN 97
16#define MAVLINK_MSG_ID_120_LEN 97
17#define MAVLINK_MSG_ID_120_MIN_LEN 97
18
19#define MAVLINK_MSG_ID_LOG_DATA_CRC 134
20#define MAVLINK_MSG_ID_120_CRC 134
21
22#define MAVLINK_MSG_LOG_DATA_FIELD_DATA_LEN 90
23
24#if MAVLINK_COMMAND_24BIT
25#define MAVLINK_MESSAGE_INFO_LOG_DATA {
26 120,
27 "LOG_DATA",
28 4,
29 { { "id", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_log_data_t, id) },
30 { "ofs", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_log_data_t, ofs) },
31 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_log_data_t, count) },
32 { "data", NULL, MAVLINK_TYPE_UINT8_T, 90, 7, offsetof(mavlink_log_data_t, data) },
33 } \
34}
35#else
36#define MAVLINK_MESSAGE_INFO_LOG_DATA {
37 "LOG_DATA",
38 4,
39 { { "id", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_log_data_t, id) },
40 { "ofs", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_log_data_t, ofs) },
41 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_log_data_t, count) },
42 { "data", NULL, MAVLINK_TYPE_UINT8_T, 90, 7, offsetof(mavlink_log_data_t, data) },
43 } \
44}
45#endif
46
47/**
48 * @brief Pack a log_data message
49 * @param system_id ID of this system
50 * @param component_id ID of this component (e.g. 200 for IMU)
51 * @param msg The MAVLink message to compress the data into
52 *
53 * @param id Log id (from LOG_ENTRY reply)
54 * @param ofs Offset into the log
55 * @param count [bytes] Number of bytes (zero for end of log)
56 * @param data log data
57 * @return length of the message in bytes (excluding serial stream start sign)
58 */
59static inline uint16_t mavlink_msg_log_data_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
60 uint16_t id, uint32_t ofs, uint8_t count, const uint8_t *data)
61{
62#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
64 _mav_put_uint32_t(buf, 0, ofs);
65 _mav_put_uint16_t(buf, 4, id);
66 _mav_put_uint8_t(buf, 6, count);
67 _mav_put_uint8_t_array(buf, 7, data, 90);
68 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_LOG_DATA_LEN);
69#else
70 mavlink_log_data_t packet;
71 packet.ofs = ofs;
72 packet.id = id;
73 packet.count = count;
74 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*90);
75 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_LOG_DATA_LEN);
76#endif
77
78 msg->msgid = MAVLINK_MSG_ID_LOG_DATA;
79 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
80}
81
82/**
83 * @brief Pack a log_data message
84 * @param system_id ID of this system
85 * @param component_id ID of this component (e.g. 200 for IMU)
86 * @param status MAVLink status structure
87 * @param msg The MAVLink message to compress the data into
88 *
89 * @param id Log id (from LOG_ENTRY reply)
90 * @param ofs Offset into the log
91 * @param count [bytes] Number of bytes (zero for end of log)
92 * @param data log data
93 * @return length of the message in bytes (excluding serial stream start sign)
94 */
95static inline uint16_t mavlink_msg_log_data_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
96 uint16_t id, uint32_t ofs, uint8_t count, const uint8_t *data)
97{
98#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
100 _mav_put_uint32_t(buf, 0, ofs);
101 _mav_put_uint16_t(buf, 4, id);
102 _mav_put_uint8_t(buf, 6, count);
103 _mav_put_uint8_t_array(buf, 7, data, 90);
104 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_LOG_DATA_LEN);
105#else
106 mavlink_log_data_t packet;
107 packet.ofs = ofs;
108 packet.id = id;
109 packet.count = count;
110 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*90);
111 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_LOG_DATA_LEN);
112#endif
113
114 msg->msgid = MAVLINK_MSG_ID_LOG_DATA;
115#if MAVLINK_CRC_EXTRA
116 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
117#else
118 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN);
119#endif
120}
121
122/**
123 * @brief Pack a log_data message on a channel
124 * @param system_id ID of this system
125 * @param component_id ID of this component (e.g. 200 for IMU)
126 * @param chan The MAVLink channel this message will be sent over
127 * @param msg The MAVLink message to compress the data into
128 * @param id Log id (from LOG_ENTRY reply)
129 * @param ofs Offset into the log
130 * @param count [bytes] Number of bytes (zero for end of log)
131 * @param data log data
132 * @return length of the message in bytes (excluding serial stream start sign)
133 */
134static inline uint16_t mavlink_msg_log_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
135 mavlink_message_t* msg,
136 uint16_t id,uint32_t ofs,uint8_t count,const uint8_t *data)
137{
138#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
140 _mav_put_uint32_t(buf, 0, ofs);
141 _mav_put_uint16_t(buf, 4, id);
142 _mav_put_uint8_t(buf, 6, count);
143 _mav_put_uint8_t_array(buf, 7, data, 90);
144 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_LOG_DATA_LEN);
145#else
146 mavlink_log_data_t packet;
147 packet.ofs = ofs;
148 packet.id = id;
149 packet.count = count;
150 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*90);
151 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_LOG_DATA_LEN);
152#endif
153
154 msg->msgid = MAVLINK_MSG_ID_LOG_DATA;
155 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
156}
157
158/**
159 * @brief Encode a log_data struct
160 *
161 * @param system_id ID of this system
162 * @param component_id ID of this component (e.g. 200 for IMU)
163 * @param msg The MAVLink message to compress the data into
164 * @param log_data C-struct to read the message contents from
165 */
166static inline uint16_t mavlink_msg_log_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_log_data_t* log_data)
167{
168 return mavlink_msg_log_data_pack(system_id, component_id, msg, log_data->id, log_data->ofs, log_data->count, log_data->data);
169}
170
171/**
172 * @brief Encode a log_data struct on a channel
173 *
174 * @param system_id ID of this system
175 * @param component_id ID of this component (e.g. 200 for IMU)
176 * @param chan The MAVLink channel this message will be sent over
177 * @param msg The MAVLink message to compress the data into
178 * @param log_data C-struct to read the message contents from
179 */
180static inline uint16_t mavlink_msg_log_data_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_log_data_t* log_data)
181{
182 return mavlink_msg_log_data_pack_chan(system_id, component_id, chan, msg, log_data->id, log_data->ofs, log_data->count, log_data->data);
183}
184
185/**
186 * @brief Encode a log_data struct with provided status structure
187 *
188 * @param system_id ID of this system
189 * @param component_id ID of this component (e.g. 200 for IMU)
190 * @param status MAVLink status structure
191 * @param msg The MAVLink message to compress the data into
192 * @param log_data C-struct to read the message contents from
193 */
194static inline uint16_t mavlink_msg_log_data_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_log_data_t* log_data)
195{
196 return mavlink_msg_log_data_pack_status(system_id, component_id, _status, msg, log_data->id, log_data->ofs, log_data->count, log_data->data);
197}
198
199/**
200 * @brief Send a log_data message
201 * @param chan MAVLink channel to send the message
202 *
203 * @param id Log id (from LOG_ENTRY reply)
204 * @param ofs Offset into the log
205 * @param count [bytes] Number of bytes (zero for end of log)
206 * @param data log data
207 */
208#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
209
210static inline void mavlink_msg_log_data_send(mavlink_channel_t chan, uint16_t id, uint32_t ofs, uint8_t count, const uint8_t *data)
211{
212#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
213 char buf[MAVLINK_MSG_ID_LOG_DATA_LEN];
214 _mav_put_uint32_t(buf, 0, ofs);
215 _mav_put_uint16_t(buf, 4, id);
216 _mav_put_uint8_t(buf, 6, count);
217 _mav_put_uint8_t_array(buf, 7, data, 90);
218 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOG_DATA, buf, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
219#else
220 mavlink_log_data_t packet;
221 packet.ofs = ofs;
222 packet.id = id;
223 packet.count = count;
224 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*90);
225 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOG_DATA, (const char *)&packet, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
226#endif
227}
228
229/**
230 * @brief Send a log_data message
231 * @param chan MAVLink channel to send the message
232 * @param struct The MAVLink struct to serialize
233 */
234static inline void mavlink_msg_log_data_send_struct(mavlink_channel_t chan, const mavlink_log_data_t* log_data)
235{
236#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
237 mavlink_msg_log_data_send(chan, log_data->id, log_data->ofs, log_data->count, log_data->data);
238#else
239 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOG_DATA, (const char *)log_data, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
240#endif
241}
242
243#if MAVLINK_MSG_ID_LOG_DATA_LEN <= MAVLINK_MAX_PAYLOAD_LEN
244/*
245 This variant of _send() can be used to save stack space by reusing
246 memory from the receive buffer. The caller provides a
247 mavlink_message_t which is the size of a full mavlink message. This
248 is usually the receive buffer for the channel, and allows a reply to an
249 incoming message with minimum stack space usage.
250 */
251static inline void mavlink_msg_log_data_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint16_t id, uint32_t ofs, uint8_t count, const uint8_t *data)
252{
253#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
254 char *buf = (char *)msgbuf;
255 _mav_put_uint32_t(buf, 0, ofs);
256 _mav_put_uint16_t(buf, 4, id);
257 _mav_put_uint8_t(buf, 6, count);
258 _mav_put_uint8_t_array(buf, 7, data, 90);
259 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOG_DATA, buf, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
260#else
261 mavlink_log_data_t *packet = (mavlink_log_data_t *)msgbuf;
262 packet->ofs = ofs;
263 packet->id = id;
264 packet->count = count;
265 mav_array_memcpy(packet->data, data, sizeof(uint8_t)*90);
266 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOG_DATA, (const char *)packet, MAVLINK_MSG_ID_LOG_DATA_MIN_LEN, MAVLINK_MSG_ID_LOG_DATA_LEN, MAVLINK_MSG_ID_LOG_DATA_CRC);
267#endif
268}
269#endif
270
271#endif
272
273// MESSAGE LOG_DATA UNPACKING
274
275
276/**
277 * @brief Get field id from log_data message
278 *
279 * @return Log id (from LOG_ENTRY reply)
280 */
281static inline uint16_t mavlink_msg_log_data_get_id(const mavlink_message_t* msg)
282{
283 return _MAV_RETURN_uint16_t(msg, 4);
284}
285
286/**
287 * @brief Get field ofs from log_data message
288 *
289 * @return Offset into the log
290 */
291static inline uint32_t mavlink_msg_log_data_get_ofs(const mavlink_message_t* msg)
292{
293 return _MAV_RETURN_uint32_t(msg, 0);
294}
295
296/**
297 * @brief Get field count from log_data message
298 *
299 * @return [bytes] Number of bytes (zero for end of log)
300 */
301static inline uint8_t mavlink_msg_log_data_get_count(const mavlink_message_t* msg)
302{
303 return _MAV_RETURN_uint8_t(msg, 6);
304}
305
306/**
307 * @brief Get field data from log_data message
308 *
309 * @return log data
310 */
311static inline uint16_t mavlink_msg_log_data_get_data(const mavlink_message_t* msg, uint8_t *data)
312{
313 return _MAV_RETURN_uint8_t_array(msg, data, 90, 7);
314}
315
316/**
317 * @brief Decode a log_data message into a struct
318 *
319 * @param msg The message to decode
320 * @param log_data C-struct to decode the message contents into
321 */
322static inline void mavlink_msg_log_data_decode(const mavlink_message_t* msg, mavlink_log_data_t* log_data)
323{
324#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
325 log_data->ofs = mavlink_msg_log_data_get_ofs(msg);
326 log_data->id = mavlink_msg_log_data_get_id(msg);
327 log_data->count = mavlink_msg_log_data_get_count(msg);
328 mavlink_msg_log_data_get_data(msg, log_data->data);
329#else
330 uint8_t len = msg->len < MAVLINK_MSG_ID_LOG_DATA_LEN? msg->len : MAVLINK_MSG_ID_LOG_DATA_LEN;
331 memset(log_data, 0, MAVLINK_MSG_ID_LOG_DATA_LEN);
332 memcpy(log_data, _MAV_PAYLOAD(msg), len);
333#endif
334}