Merge pull request #10476 from radiolinkW/RADIOLINKF722
[inav.git] / lib / main / MAVLink / common / mavlink_msg_log_data.h
blob37cd77777016e6ba12be808806c2b4260779ed7e
1 #pragma once
2 // MESSAGE LOG_DATA PACKING
4 #define MAVLINK_MSG_ID_LOG_DATA 120
7 typedef 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;
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
19 #define MAVLINK_MSG_ID_LOG_DATA_CRC 134
20 #define MAVLINK_MSG_ID_120_CRC 134
22 #define MAVLINK_MSG_LOG_DATA_FIELD_DATA_LEN 90
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 } \
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 } \
45 #endif
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
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)
59 static 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)
62 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
63 char buf[MAVLINK_MSG_ID_LOG_DATA_LEN];
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
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);
82 /**
83 * @brief Pack a log_data message on a channel
84 * @param system_id ID of this system
85 * @param component_id ID of this component (e.g. 200 for IMU)
86 * @param chan The MAVLink channel this message will be sent over
87 * @param msg The MAVLink message to compress the data into
88 * @param id Log id (from LOG_ENTRY reply)
89 * @param ofs Offset into the log
90 * @param count [bytes] Number of bytes (zero for end of log)
91 * @param data log data
92 * @return length of the message in bytes (excluding serial stream start sign)
94 static inline uint16_t mavlink_msg_log_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
95 mavlink_message_t* msg,
96 uint16_t id,uint32_t ofs,uint8_t count,const uint8_t *data)
98 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
99 char buf[MAVLINK_MSG_ID_LOG_DATA_LEN];
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
114 msg->msgid = MAVLINK_MSG_ID_LOG_DATA;
115 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);
119 * @brief Encode a log_data struct
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 log_data C-struct to read the message contents from
126 static 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)
128 return mavlink_msg_log_data_pack(system_id, component_id, msg, log_data->id, log_data->ofs, log_data->count, log_data->data);
132 * @brief Encode a log_data struct on a channel
134 * @param system_id ID of this system
135 * @param component_id ID of this component (e.g. 200 for IMU)
136 * @param chan The MAVLink channel this message will be sent over
137 * @param msg The MAVLink message to compress the data into
138 * @param log_data C-struct to read the message contents from
140 static 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)
142 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);
146 * @brief Send a log_data message
147 * @param chan MAVLink channel to send the message
149 * @param id Log id (from LOG_ENTRY reply)
150 * @param ofs Offset into the log
151 * @param count [bytes] Number of bytes (zero for end of log)
152 * @param data log data
154 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
156 static inline void mavlink_msg_log_data_send(mavlink_channel_t chan, uint16_t id, uint32_t ofs, uint8_t count, const uint8_t *data)
158 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
159 char buf[MAVLINK_MSG_ID_LOG_DATA_LEN];
160 _mav_put_uint32_t(buf, 0, ofs);
161 _mav_put_uint16_t(buf, 4, id);
162 _mav_put_uint8_t(buf, 6, count);
163 _mav_put_uint8_t_array(buf, 7, data, 90);
164 _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);
165 #else
166 mavlink_log_data_t packet;
167 packet.ofs = ofs;
168 packet.id = id;
169 packet.count = count;
170 mav_array_memcpy(packet.data, data, sizeof(uint8_t)*90);
171 _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);
172 #endif
176 * @brief Send a log_data message
177 * @param chan MAVLink channel to send the message
178 * @param struct The MAVLink struct to serialize
180 static inline void mavlink_msg_log_data_send_struct(mavlink_channel_t chan, const mavlink_log_data_t* log_data)
182 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
183 mavlink_msg_log_data_send(chan, log_data->id, log_data->ofs, log_data->count, log_data->data);
184 #else
185 _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);
186 #endif
189 #if MAVLINK_MSG_ID_LOG_DATA_LEN <= MAVLINK_MAX_PAYLOAD_LEN
191 This varient of _send() can be used to save stack space by re-using
192 memory from the receive buffer. The caller provides a
193 mavlink_message_t which is the size of a full mavlink message. This
194 is usually the receive buffer for the channel, and allows a reply to an
195 incoming message with minimum stack space usage.
197 static 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)
199 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
200 char *buf = (char *)msgbuf;
201 _mav_put_uint32_t(buf, 0, ofs);
202 _mav_put_uint16_t(buf, 4, id);
203 _mav_put_uint8_t(buf, 6, count);
204 _mav_put_uint8_t_array(buf, 7, data, 90);
205 _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);
206 #else
207 mavlink_log_data_t *packet = (mavlink_log_data_t *)msgbuf;
208 packet->ofs = ofs;
209 packet->id = id;
210 packet->count = count;
211 mav_array_memcpy(packet->data, data, sizeof(uint8_t)*90);
212 _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);
213 #endif
215 #endif
217 #endif
219 // MESSAGE LOG_DATA UNPACKING
223 * @brief Get field id from log_data message
225 * @return Log id (from LOG_ENTRY reply)
227 static inline uint16_t mavlink_msg_log_data_get_id(const mavlink_message_t* msg)
229 return _MAV_RETURN_uint16_t(msg, 4);
233 * @brief Get field ofs from log_data message
235 * @return Offset into the log
237 static inline uint32_t mavlink_msg_log_data_get_ofs(const mavlink_message_t* msg)
239 return _MAV_RETURN_uint32_t(msg, 0);
243 * @brief Get field count from log_data message
245 * @return [bytes] Number of bytes (zero for end of log)
247 static inline uint8_t mavlink_msg_log_data_get_count(const mavlink_message_t* msg)
249 return _MAV_RETURN_uint8_t(msg, 6);
253 * @brief Get field data from log_data message
255 * @return log data
257 static inline uint16_t mavlink_msg_log_data_get_data(const mavlink_message_t* msg, uint8_t *data)
259 return _MAV_RETURN_uint8_t_array(msg, data, 90, 7);
263 * @brief Decode a log_data message into a struct
265 * @param msg The message to decode
266 * @param log_data C-struct to decode the message contents into
268 static inline void mavlink_msg_log_data_decode(const mavlink_message_t* msg, mavlink_log_data_t* log_data)
270 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
271 log_data->ofs = mavlink_msg_log_data_get_ofs(msg);
272 log_data->id = mavlink_msg_log_data_get_id(msg);
273 log_data->count = mavlink_msg_log_data_get_count(msg);
274 mavlink_msg_log_data_get_data(msg, log_data->data);
275 #else
276 uint8_t len = msg->len < MAVLINK_MSG_ID_LOG_DATA_LEN? msg->len : MAVLINK_MSG_ID_LOG_DATA_LEN;
277 memset(log_data, 0, MAVLINK_MSG_ID_LOG_DATA_LEN);
278 memcpy(log_data, _MAV_PAYLOAD(msg), len);
279 #endif