Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_timesync.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE TIMESYNC PACKING
3
4#define MAVLINK_MSG_ID_TIMESYNC 111
5
6
7typedef struct __mavlink_timesync_t {
8 int64_t tc1; /*< [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.*/
9 int64_t ts1; /*< [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).*/
10 uint8_t target_system; /*< Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.*/
11 uint8_t target_component; /*< Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.*/
12} mavlink_timesync_t;
13
14#define MAVLINK_MSG_ID_TIMESYNC_LEN 18
15#define MAVLINK_MSG_ID_TIMESYNC_MIN_LEN 16
16#define MAVLINK_MSG_ID_111_LEN 18
17#define MAVLINK_MSG_ID_111_MIN_LEN 16
18
19#define MAVLINK_MSG_ID_TIMESYNC_CRC 34
20#define MAVLINK_MSG_ID_111_CRC 34
21
22
23
24#if MAVLINK_COMMAND_24BIT
25#define MAVLINK_MESSAGE_INFO_TIMESYNC {
26 111,
27 "TIMESYNC",
28 4,
29 { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) },
30 { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) },
31 { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_timesync_t, target_system) },
32 { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_timesync_t, target_component) },
33 } \
34}
35#else
36#define MAVLINK_MESSAGE_INFO_TIMESYNC {
37 "TIMESYNC",
38 4,
39 { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) },
40 { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) },
41 { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_timesync_t, target_system) },
42 { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_timesync_t, target_component) },
43 } \
44}
45#endif
46
47/**
48 * @brief Pack a timesync 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 tc1 [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.
54 * @param ts1 [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).
55 * @param target_system Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.
56 * @param target_component Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.
57 * @return length of the message in bytes (excluding serial stream start sign)
58 */
59static inline uint16_t mavlink_msg_timesync_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
60 int64_t tc1, int64_t ts1, uint8_t target_system, uint8_t target_component)
61{
62#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
64 _mav_put_int64_t(buf, 0, tc1);
65 _mav_put_int64_t(buf, 8, ts1);
66 _mav_put_uint8_t(buf, 16, target_system);
67 _mav_put_uint8_t(buf, 17, target_component);
68
69 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
70#else
71 mavlink_timesync_t packet;
72 packet.tc1 = tc1;
73 packet.ts1 = ts1;
74 packet.target_system = target_system;
75 packet.target_component = target_component;
76
77 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
78#endif
79
80 msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
81 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
82}
83
84/**
85 * @brief Pack a timesync message
86 * @param system_id ID of this system
87 * @param component_id ID of this component (e.g. 200 for IMU)
88 * @param status MAVLink status structure
89 * @param msg The MAVLink message to compress the data into
90 *
91 * @param tc1 [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.
92 * @param ts1 [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).
93 * @param target_system Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.
94 * @param target_component Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.
95 * @return length of the message in bytes (excluding serial stream start sign)
96 */
97static inline uint16_t mavlink_msg_timesync_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
98 int64_t tc1, int64_t ts1, uint8_t target_system, uint8_t target_component)
99{
100#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
102 _mav_put_int64_t(buf, 0, tc1);
103 _mav_put_int64_t(buf, 8, ts1);
104 _mav_put_uint8_t(buf, 16, target_system);
105 _mav_put_uint8_t(buf, 17, target_component);
106
107 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
108#else
109 mavlink_timesync_t packet;
110 packet.tc1 = tc1;
111 packet.ts1 = ts1;
112 packet.target_system = target_system;
113 packet.target_component = target_component;
114
115 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
116#endif
117
118 msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
119#if MAVLINK_CRC_EXTRA
120 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
121#else
122 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN);
123#endif
124}
125
126/**
127 * @brief Pack a timesync message on a channel
128 * @param system_id ID of this system
129 * @param component_id ID of this component (e.g. 200 for IMU)
130 * @param chan The MAVLink channel this message will be sent over
131 * @param msg The MAVLink message to compress the data into
132 * @param tc1 [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.
133 * @param ts1 [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).
134 * @param target_system Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.
135 * @param target_component Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.
136 * @return length of the message in bytes (excluding serial stream start sign)
137 */
138static inline uint16_t mavlink_msg_timesync_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
139 mavlink_message_t* msg,
140 int64_t tc1,int64_t ts1,uint8_t target_system,uint8_t target_component)
141{
142#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
144 _mav_put_int64_t(buf, 0, tc1);
145 _mav_put_int64_t(buf, 8, ts1);
146 _mav_put_uint8_t(buf, 16, target_system);
147 _mav_put_uint8_t(buf, 17, target_component);
148
149 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
150#else
151 mavlink_timesync_t packet;
152 packet.tc1 = tc1;
153 packet.ts1 = ts1;
154 packet.target_system = target_system;
155 packet.target_component = target_component;
156
157 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
158#endif
159
160 msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
161 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
162}
163
164/**
165 * @brief Encode a timesync struct
166 *
167 * @param system_id ID of this system
168 * @param component_id ID of this component (e.g. 200 for IMU)
169 * @param msg The MAVLink message to compress the data into
170 * @param timesync C-struct to read the message contents from
171 */
172static inline uint16_t mavlink_msg_timesync_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_timesync_t* timesync)
173{
174 return mavlink_msg_timesync_pack(system_id, component_id, msg, timesync->tc1, timesync->ts1, timesync->target_system, timesync->target_component);
175}
176
177/**
178 * @brief Encode a timesync struct on a channel
179 *
180 * @param system_id ID of this system
181 * @param component_id ID of this component (e.g. 200 for IMU)
182 * @param chan The MAVLink channel this message will be sent over
183 * @param msg The MAVLink message to compress the data into
184 * @param timesync C-struct to read the message contents from
185 */
186static inline uint16_t mavlink_msg_timesync_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_timesync_t* timesync)
187{
188 return mavlink_msg_timesync_pack_chan(system_id, component_id, chan, msg, timesync->tc1, timesync->ts1, timesync->target_system, timesync->target_component);
189}
190
191/**
192 * @brief Encode a timesync struct with provided status structure
193 *
194 * @param system_id ID of this system
195 * @param component_id ID of this component (e.g. 200 for IMU)
196 * @param status MAVLink status structure
197 * @param msg The MAVLink message to compress the data into
198 * @param timesync C-struct to read the message contents from
199 */
200static inline uint16_t mavlink_msg_timesync_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_timesync_t* timesync)
201{
202 return mavlink_msg_timesync_pack_status(system_id, component_id, _status, msg, timesync->tc1, timesync->ts1, timesync->target_system, timesync->target_component);
203}
204
205/**
206 * @brief Send a timesync message
207 * @param chan MAVLink channel to send the message
208 *
209 * @param tc1 [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.
210 * @param ts1 [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).
211 * @param target_system Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.
212 * @param target_component Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.
213 */
214#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
215
216static inline void mavlink_msg_timesync_send(mavlink_channel_t chan, int64_t tc1, int64_t ts1, uint8_t target_system, uint8_t target_component)
217{
218#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
219 char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
220 _mav_put_int64_t(buf, 0, tc1);
221 _mav_put_int64_t(buf, 8, ts1);
222 _mav_put_uint8_t(buf, 16, target_system);
223 _mav_put_uint8_t(buf, 17, target_component);
224
225 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TIMESYNC, buf, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
226#else
227 mavlink_timesync_t packet;
228 packet.tc1 = tc1;
229 packet.ts1 = ts1;
230 packet.target_system = target_system;
231 packet.target_component = target_component;
232
233 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TIMESYNC, (const char *)&packet, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
234#endif
235}
236
237/**
238 * @brief Send a timesync message
239 * @param chan MAVLink channel to send the message
240 * @param struct The MAVLink struct to serialize
241 */
242static inline void mavlink_msg_timesync_send_struct(mavlink_channel_t chan, const mavlink_timesync_t* timesync)
243{
244#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
245 mavlink_msg_timesync_send(chan, timesync->tc1, timesync->ts1, timesync->target_system, timesync->target_component);
246#else
247 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TIMESYNC, (const char *)timesync, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
248#endif
249}
250
251#if MAVLINK_MSG_ID_TIMESYNC_LEN <= MAVLINK_MAX_PAYLOAD_LEN
252/*
253 This variant of _send() can be used to save stack space by reusing
254 memory from the receive buffer. The caller provides a
255 mavlink_message_t which is the size of a full mavlink message. This
256 is usually the receive buffer for the channel, and allows a reply to an
257 incoming message with minimum stack space usage.
258 */
259static inline void mavlink_msg_timesync_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, int64_t tc1, int64_t ts1, uint8_t target_system, uint8_t target_component)
260{
261#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
262 char *buf = (char *)msgbuf;
263 _mav_put_int64_t(buf, 0, tc1);
264 _mav_put_int64_t(buf, 8, ts1);
265 _mav_put_uint8_t(buf, 16, target_system);
266 _mav_put_uint8_t(buf, 17, target_component);
267
268 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TIMESYNC, buf, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
269#else
270 mavlink_timesync_t *packet = (mavlink_timesync_t *)msgbuf;
271 packet->tc1 = tc1;
272 packet->ts1 = ts1;
273 packet->target_system = target_system;
274 packet->target_component = target_component;
275
276 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TIMESYNC, (const char *)packet, MAVLINK_MSG_ID_TIMESYNC_MIN_LEN, MAVLINK_MSG_ID_TIMESYNC_LEN, MAVLINK_MSG_ID_TIMESYNC_CRC);
277#endif
278}
279#endif
280
281#endif
282
283// MESSAGE TIMESYNC UNPACKING
284
285
286/**
287 * @brief Get field tc1 from timesync message
288 *
289 * @return [ns] Time sync timestamp 1. Syncing: 0. Responding: Timestamp of responding component.
290 */
291static inline int64_t mavlink_msg_timesync_get_tc1(const mavlink_message_t* msg)
292{
293 return _MAV_RETURN_int64_t(msg, 0);
294}
295
296/**
297 * @brief Get field ts1 from timesync message
298 *
299 * @return [ns] Time sync timestamp 2. Timestamp of syncing component (mirrored in response).
300 */
301static inline int64_t mavlink_msg_timesync_get_ts1(const mavlink_message_t* msg)
302{
303 return _MAV_RETURN_int64_t(msg, 8);
304}
305
306/**
307 * @brief Get field target_system from timesync message
308 *
309 * @return Target system id. Request: 0 (broadcast) or id of specific system. Response must contain system id of the requesting component.
310 */
311static inline uint8_t mavlink_msg_timesync_get_target_system(const mavlink_message_t* msg)
312{
313 return _MAV_RETURN_uint8_t(msg, 16);
314}
315
316/**
317 * @brief Get field target_component from timesync message
318 *
319 * @return Target component id. Request: 0 (broadcast) or id of specific component. Response must contain component id of the requesting component.
320 */
321static inline uint8_t mavlink_msg_timesync_get_target_component(const mavlink_message_t* msg)
322{
323 return _MAV_RETURN_uint8_t(msg, 17);
324}
325
326/**
327 * @brief Decode a timesync message into a struct
328 *
329 * @param msg The message to decode
330 * @param timesync C-struct to decode the message contents into
331 */
332static inline void mavlink_msg_timesync_decode(const mavlink_message_t* msg, mavlink_timesync_t* timesync)
333{
334#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
335 timesync->tc1 = mavlink_msg_timesync_get_tc1(msg);
336 timesync->ts1 = mavlink_msg_timesync_get_ts1(msg);
337 timesync->target_system = mavlink_msg_timesync_get_target_system(msg);
338 timesync->target_component = mavlink_msg_timesync_get_target_component(msg);
339#else
340 uint8_t len = msg->len < MAVLINK_MSG_ID_TIMESYNC_LEN? msg->len : MAVLINK_MSG_ID_TIMESYNC_LEN;
341 memset(timesync, 0, MAVLINK_MSG_ID_TIMESYNC_LEN);
342 memcpy(timesync, _MAV_PAYLOAD(msg), len);
343#endif
344}