Merge pull request #10476 from radiolinkW/RADIOLINKF722
[inav.git] / lib / main / MAVLink / common / mavlink_msg_system_time.h
bloba3848c74190a943a2468efa66e44493b6c4949f8
1 #pragma once
2 // MESSAGE SYSTEM_TIME PACKING
4 #define MAVLINK_MSG_ID_SYSTEM_TIME 2
7 typedef struct __mavlink_system_time_t {
8 uint64_t time_unix_usec; /*< [us] Timestamp (UNIX epoch time).*/
9 uint32_t time_boot_ms; /*< [ms] Timestamp (time since system boot).*/
10 } mavlink_system_time_t;
12 #define MAVLINK_MSG_ID_SYSTEM_TIME_LEN 12
13 #define MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN 12
14 #define MAVLINK_MSG_ID_2_LEN 12
15 #define MAVLINK_MSG_ID_2_MIN_LEN 12
17 #define MAVLINK_MSG_ID_SYSTEM_TIME_CRC 137
18 #define MAVLINK_MSG_ID_2_CRC 137
22 #if MAVLINK_COMMAND_24BIT
23 #define MAVLINK_MESSAGE_INFO_SYSTEM_TIME { \
24 2, \
25 "SYSTEM_TIME", \
26 2, \
27 { { "time_unix_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_system_time_t, time_unix_usec) }, \
28 { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_system_time_t, time_boot_ms) }, \
29 } \
31 #else
32 #define MAVLINK_MESSAGE_INFO_SYSTEM_TIME { \
33 "SYSTEM_TIME", \
34 2, \
35 { { "time_unix_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_system_time_t, time_unix_usec) }, \
36 { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_system_time_t, time_boot_ms) }, \
37 } \
39 #endif
41 /**
42 * @brief Pack a system_time 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 time_unix_usec [us] Timestamp (UNIX epoch time).
48 * @param time_boot_ms [ms] Timestamp (time since system boot).
49 * @return length of the message in bytes (excluding serial stream start sign)
51 static inline uint16_t mavlink_msg_system_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
52 uint64_t time_unix_usec, uint32_t time_boot_ms)
54 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
55 char buf[MAVLINK_MSG_ID_SYSTEM_TIME_LEN];
56 _mav_put_uint64_t(buf, 0, time_unix_usec);
57 _mav_put_uint32_t(buf, 8, time_boot_ms);
59 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SYSTEM_TIME_LEN);
60 #else
61 mavlink_system_time_t packet;
62 packet.time_unix_usec = time_unix_usec;
63 packet.time_boot_ms = time_boot_ms;
65 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SYSTEM_TIME_LEN);
66 #endif
68 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
69 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
72 /**
73 * @brief Pack a system_time 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 time_unix_usec [us] Timestamp (UNIX epoch time).
79 * @param time_boot_ms [ms] Timestamp (time since system boot).
80 * @return length of the message in bytes (excluding serial stream start sign)
82 static inline uint16_t mavlink_msg_system_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
83 mavlink_message_t* msg,
84 uint64_t time_unix_usec,uint32_t time_boot_ms)
86 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
87 char buf[MAVLINK_MSG_ID_SYSTEM_TIME_LEN];
88 _mav_put_uint64_t(buf, 0, time_unix_usec);
89 _mav_put_uint32_t(buf, 8, time_boot_ms);
91 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SYSTEM_TIME_LEN);
92 #else
93 mavlink_system_time_t packet;
94 packet.time_unix_usec = time_unix_usec;
95 packet.time_boot_ms = time_boot_ms;
97 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SYSTEM_TIME_LEN);
98 #endif
100 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
101 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
105 * @brief Encode a system_time 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 system_time C-struct to read the message contents from
112 static inline uint16_t mavlink_msg_system_time_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_system_time_t* system_time)
114 return mavlink_msg_system_time_pack(system_id, component_id, msg, system_time->time_unix_usec, system_time->time_boot_ms);
118 * @brief Encode a system_time 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 system_time C-struct to read the message contents from
126 static inline uint16_t mavlink_msg_system_time_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_system_time_t* system_time)
128 return mavlink_msg_system_time_pack_chan(system_id, component_id, chan, msg, system_time->time_unix_usec, system_time->time_boot_ms);
132 * @brief Send a system_time message
133 * @param chan MAVLink channel to send the message
135 * @param time_unix_usec [us] Timestamp (UNIX epoch time).
136 * @param time_boot_ms [ms] Timestamp (time since system boot).
138 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
140 static inline void mavlink_msg_system_time_send(mavlink_channel_t chan, uint64_t time_unix_usec, uint32_t time_boot_ms)
142 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
143 char buf[MAVLINK_MSG_ID_SYSTEM_TIME_LEN];
144 _mav_put_uint64_t(buf, 0, time_unix_usec);
145 _mav_put_uint32_t(buf, 8, time_boot_ms);
147 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, buf, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
148 #else
149 mavlink_system_time_t packet;
150 packet.time_unix_usec = time_unix_usec;
151 packet.time_boot_ms = time_boot_ms;
153 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, (const char *)&packet, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
154 #endif
158 * @brief Send a system_time message
159 * @param chan MAVLink channel to send the message
160 * @param struct The MAVLink struct to serialize
162 static inline void mavlink_msg_system_time_send_struct(mavlink_channel_t chan, const mavlink_system_time_t* system_time)
164 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
165 mavlink_msg_system_time_send(chan, system_time->time_unix_usec, system_time->time_boot_ms);
166 #else
167 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, (const char *)system_time, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
168 #endif
171 #if MAVLINK_MSG_ID_SYSTEM_TIME_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_system_time_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_unix_usec, uint32_t time_boot_ms)
181 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
182 char *buf = (char *)msgbuf;
183 _mav_put_uint64_t(buf, 0, time_unix_usec);
184 _mav_put_uint32_t(buf, 8, time_boot_ms);
186 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, buf, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
187 #else
188 mavlink_system_time_t *packet = (mavlink_system_time_t *)msgbuf;
189 packet->time_unix_usec = time_unix_usec;
190 packet->time_boot_ms = time_boot_ms;
192 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, (const char *)packet, MAVLINK_MSG_ID_SYSTEM_TIME_MIN_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_LEN, MAVLINK_MSG_ID_SYSTEM_TIME_CRC);
193 #endif
195 #endif
197 #endif
199 // MESSAGE SYSTEM_TIME UNPACKING
203 * @brief Get field time_unix_usec from system_time message
205 * @return [us] Timestamp (UNIX epoch time).
207 static inline uint64_t mavlink_msg_system_time_get_time_unix_usec(const mavlink_message_t* msg)
209 return _MAV_RETURN_uint64_t(msg, 0);
213 * @brief Get field time_boot_ms from system_time message
215 * @return [ms] Timestamp (time since system boot).
217 static inline uint32_t mavlink_msg_system_time_get_time_boot_ms(const mavlink_message_t* msg)
219 return _MAV_RETURN_uint32_t(msg, 8);
223 * @brief Decode a system_time message into a struct
225 * @param msg The message to decode
226 * @param system_time C-struct to decode the message contents into
228 static inline void mavlink_msg_system_time_decode(const mavlink_message_t* msg, mavlink_system_time_t* system_time)
230 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
231 system_time->time_unix_usec = mavlink_msg_system_time_get_time_unix_usec(msg);
232 system_time->time_boot_ms = mavlink_msg_system_time_get_time_boot_ms(msg);
233 #else
234 uint8_t len = msg->len < MAVLINK_MSG_ID_SYSTEM_TIME_LEN? msg->len : MAVLINK_MSG_ID_SYSTEM_TIME_LEN;
235 memset(system_time, 0, MAVLINK_MSG_ID_SYSTEM_TIME_LEN);
236 memcpy(system_time, _MAV_PAYLOAD(msg), len);
237 #endif