Merge pull request #10476 from radiolinkW/RADIOLINKF722
[inav.git] / lib / main / MAVLink / common / mavlink_msg_timesync.h
bloba9de47dd45747cb8261b877029dca4f7baaf598d
1 #pragma once
2 // MESSAGE TIMESYNC PACKING
4 #define MAVLINK_MSG_ID_TIMESYNC 111
7 typedef struct __mavlink_timesync_t {
8 int64_t tc1; /*< Time sync timestamp 1*/
9 int64_t ts1; /*< Time sync timestamp 2*/
10 } mavlink_timesync_t;
12 #define MAVLINK_MSG_ID_TIMESYNC_LEN 16
13 #define MAVLINK_MSG_ID_TIMESYNC_MIN_LEN 16
14 #define MAVLINK_MSG_ID_111_LEN 16
15 #define MAVLINK_MSG_ID_111_MIN_LEN 16
17 #define MAVLINK_MSG_ID_TIMESYNC_CRC 34
18 #define MAVLINK_MSG_ID_111_CRC 34
22 #if MAVLINK_COMMAND_24BIT
23 #define MAVLINK_MESSAGE_INFO_TIMESYNC { \
24 111, \
25 "TIMESYNC", \
26 2, \
27 { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) }, \
28 { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) }, \
29 } \
31 #else
32 #define MAVLINK_MESSAGE_INFO_TIMESYNC { \
33 "TIMESYNC", \
34 2, \
35 { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) }, \
36 { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) }, \
37 } \
39 #endif
41 /**
42 * @brief Pack a timesync message
43 * @param system_id ID of this system
44 * @param component_id ID of this component (e.g. 200 for IMU)
45 * @param msg The MAVLink message to compress the data into
47 * @param tc1 Time sync timestamp 1
48 * @param ts1 Time sync timestamp 2
49 * @return length of the message in bytes (excluding serial stream start sign)
51 static inline uint16_t mavlink_msg_timesync_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
52 int64_t tc1, int64_t ts1)
54 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
55 char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
56 _mav_put_int64_t(buf, 0, tc1);
57 _mav_put_int64_t(buf, 8, ts1);
59 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
60 #else
61 mavlink_timesync_t packet;
62 packet.tc1 = tc1;
63 packet.ts1 = ts1;
65 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
66 #endif
68 msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
69 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);
72 /**
73 * @brief Pack a timesync message on a channel
74 * @param system_id ID of this system
75 * @param component_id ID of this component (e.g. 200 for IMU)
76 * @param chan The MAVLink channel this message will be sent over
77 * @param msg The MAVLink message to compress the data into
78 * @param tc1 Time sync timestamp 1
79 * @param ts1 Time sync timestamp 2
80 * @return length of the message in bytes (excluding serial stream start sign)
82 static inline uint16_t mavlink_msg_timesync_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
83 mavlink_message_t* msg,
84 int64_t tc1,int64_t ts1)
86 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
87 char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
88 _mav_put_int64_t(buf, 0, tc1);
89 _mav_put_int64_t(buf, 8, ts1);
91 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
92 #else
93 mavlink_timesync_t packet;
94 packet.tc1 = tc1;
95 packet.ts1 = ts1;
97 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
98 #endif
100 msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
101 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);
105 * @brief Encode a timesync struct
107 * @param system_id ID of this system
108 * @param component_id ID of this component (e.g. 200 for IMU)
109 * @param msg The MAVLink message to compress the data into
110 * @param timesync C-struct to read the message contents from
112 static inline uint16_t mavlink_msg_timesync_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_timesync_t* timesync)
114 return mavlink_msg_timesync_pack(system_id, component_id, msg, timesync->tc1, timesync->ts1);
118 * @brief Encode a timesync struct on a channel
120 * @param system_id ID of this system
121 * @param component_id ID of this component (e.g. 200 for IMU)
122 * @param chan The MAVLink channel this message will be sent over
123 * @param msg The MAVLink message to compress the data into
124 * @param timesync C-struct to read the message contents from
126 static 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)
128 return mavlink_msg_timesync_pack_chan(system_id, component_id, chan, msg, timesync->tc1, timesync->ts1);
132 * @brief Send a timesync message
133 * @param chan MAVLink channel to send the message
135 * @param tc1 Time sync timestamp 1
136 * @param ts1 Time sync timestamp 2
138 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
140 static inline void mavlink_msg_timesync_send(mavlink_channel_t chan, int64_t tc1, int64_t ts1)
142 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
143 char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
144 _mav_put_int64_t(buf, 0, tc1);
145 _mav_put_int64_t(buf, 8, ts1);
147 _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);
148 #else
149 mavlink_timesync_t packet;
150 packet.tc1 = tc1;
151 packet.ts1 = ts1;
153 _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);
154 #endif
158 * @brief Send a timesync message
159 * @param chan MAVLink channel to send the message
160 * @param struct The MAVLink struct to serialize
162 static inline void mavlink_msg_timesync_send_struct(mavlink_channel_t chan, const mavlink_timesync_t* timesync)
164 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
165 mavlink_msg_timesync_send(chan, timesync->tc1, timesync->ts1);
166 #else
167 _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);
168 #endif
171 #if MAVLINK_MSG_ID_TIMESYNC_LEN <= MAVLINK_MAX_PAYLOAD_LEN
173 This varient of _send() can be used to save stack space by re-using
174 memory from the receive buffer. The caller provides a
175 mavlink_message_t which is the size of a full mavlink message. This
176 is usually the receive buffer for the channel, and allows a reply to an
177 incoming message with minimum stack space usage.
179 static inline void mavlink_msg_timesync_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, int64_t tc1, int64_t ts1)
181 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
182 char *buf = (char *)msgbuf;
183 _mav_put_int64_t(buf, 0, tc1);
184 _mav_put_int64_t(buf, 8, ts1);
186 _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);
187 #else
188 mavlink_timesync_t *packet = (mavlink_timesync_t *)msgbuf;
189 packet->tc1 = tc1;
190 packet->ts1 = ts1;
192 _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);
193 #endif
195 #endif
197 #endif
199 // MESSAGE TIMESYNC UNPACKING
203 * @brief Get field tc1 from timesync message
205 * @return Time sync timestamp 1
207 static inline int64_t mavlink_msg_timesync_get_tc1(const mavlink_message_t* msg)
209 return _MAV_RETURN_int64_t(msg, 0);
213 * @brief Get field ts1 from timesync message
215 * @return Time sync timestamp 2
217 static inline int64_t mavlink_msg_timesync_get_ts1(const mavlink_message_t* msg)
219 return _MAV_RETURN_int64_t(msg, 8);
223 * @brief Decode a timesync message into a struct
225 * @param msg The message to decode
226 * @param timesync C-struct to decode the message contents into
228 static inline void mavlink_msg_timesync_decode(const mavlink_message_t* msg, mavlink_timesync_t* timesync)
230 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
231 timesync->tc1 = mavlink_msg_timesync_get_tc1(msg);
232 timesync->ts1 = mavlink_msg_timesync_get_ts1(msg);
233 #else
234 uint8_t len = msg->len < MAVLINK_MSG_ID_TIMESYNC_LEN? msg->len : MAVLINK_MSG_ID_TIMESYNC_LEN;
235 memset(timesync, 0, MAVLINK_MSG_ID_TIMESYNC_LEN);
236 memcpy(timesync, _MAV_PAYLOAD(msg), len);
237 #endif