Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / libraries / mavlink / v1.0 / common / mavlink_msg_system_time.h
blobcf213773b15889858a08b1d410b569b8cc27e8f9
1 // MESSAGE SYSTEM_TIME PACKING
3 #define MAVLINK_MSG_ID_SYSTEM_TIME 2
5 typedef struct __mavlink_system_time_t {
6 uint64_t time_unix_usec; ///< Timestamp of the master clock in microseconds since UNIX epoch.
7 uint32_t time_boot_ms; ///< Timestamp of the component clock since boot time in milliseconds.
8 } mavlink_system_time_t;
10 #define MAVLINK_MSG_ID_SYSTEM_TIME_LEN 12
11 #define MAVLINK_MSG_ID_2_LEN 12
14 #define MAVLINK_MESSAGE_INFO_SYSTEM_TIME \
15 { \
16 "SYSTEM_TIME", \
17 2, \
18 { \
19 { "time_unix_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_system_time_t, time_unix_usec) }, \
20 { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_system_time_t, time_boot_ms) }, \
21 } \
25 /**
26 * @brief Pack a system_time message
27 * @param system_id ID of this system
28 * @param component_id ID of this component (e.g. 200 for IMU)
29 * @param msg The MAVLink message to compress the data into
31 * @param time_unix_usec Timestamp of the master clock in microseconds since UNIX epoch.
32 * @param time_boot_ms Timestamp of the component clock since boot time in milliseconds.
33 * @return length of the message in bytes (excluding serial stream start sign)
35 static inline uint16_t mavlink_msg_system_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t *msg,
36 uint64_t time_unix_usec, uint32_t time_boot_ms)
38 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
39 char buf[12];
40 _mav_put_uint64_t(buf, 0, time_unix_usec);
41 _mav_put_uint32_t(buf, 8, time_boot_ms);
43 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12);
44 #else
45 mavlink_system_time_t packet;
46 packet.time_unix_usec = time_unix_usec;
47 packet.time_boot_ms = time_boot_ms;
49 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12);
50 #endif
52 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
53 return mavlink_finalize_message(msg, system_id, component_id, 12, 137);
56 /**
57 * @brief Pack a system_time message on a channel
58 * @param system_id ID of this system
59 * @param component_id ID of this component (e.g. 200 for IMU)
60 * @param chan The MAVLink channel this message was sent over
61 * @param msg The MAVLink message to compress the data into
62 * @param time_unix_usec Timestamp of the master clock in microseconds since UNIX epoch.
63 * @param time_boot_ms Timestamp of the component clock since boot time in milliseconds.
64 * @return length of the message in bytes (excluding serial stream start sign)
66 static inline uint16_t mavlink_msg_system_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
67 mavlink_message_t *msg,
68 uint64_t time_unix_usec, uint32_t time_boot_ms)
70 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
71 char buf[12];
72 _mav_put_uint64_t(buf, 0, time_unix_usec);
73 _mav_put_uint32_t(buf, 8, time_boot_ms);
75 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12);
76 #else
77 mavlink_system_time_t packet;
78 packet.time_unix_usec = time_unix_usec;
79 packet.time_boot_ms = time_boot_ms;
81 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12);
82 #endif
84 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
85 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12, 137);
88 /**
89 * @brief Encode a system_time struct into a message
91 * @param system_id ID of this system
92 * @param component_id ID of this component (e.g. 200 for IMU)
93 * @param msg The MAVLink message to compress the data into
94 * @param system_time C-struct to read the message contents from
96 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)
98 return mavlink_msg_system_time_pack(system_id, component_id, msg, system_time->time_unix_usec, system_time->time_boot_ms);
102 * @brief Send a system_time message
103 * @param chan MAVLink channel to send the message
105 * @param time_unix_usec Timestamp of the master clock in microseconds since UNIX epoch.
106 * @param time_boot_ms Timestamp of the component clock since boot time in milliseconds.
108 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
110 static inline void mavlink_msg_system_time_send(mavlink_channel_t chan, uint64_t time_unix_usec, uint32_t time_boot_ms)
112 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
113 char buf[12];
114 _mav_put_uint64_t(buf, 0, time_unix_usec);
115 _mav_put_uint32_t(buf, 8, time_boot_ms);
117 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, buf, 12, 137);
118 #else
119 mavlink_system_time_t packet;
120 packet.time_unix_usec = time_unix_usec;
121 packet.time_boot_ms = time_boot_ms;
123 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, (const char *)&packet, 12, 137);
124 #endif
127 #endif
129 // MESSAGE SYSTEM_TIME UNPACKING
133 * @brief Get field time_unix_usec from system_time message
135 * @return Timestamp of the master clock in microseconds since UNIX epoch.
137 static inline uint64_t mavlink_msg_system_time_get_time_unix_usec(const mavlink_message_t *msg)
139 return _MAV_RETURN_uint64_t(msg, 0);
143 * @brief Get field time_boot_ms from system_time message
145 * @return Timestamp of the component clock since boot time in milliseconds.
147 static inline uint32_t mavlink_msg_system_time_get_time_boot_ms(const mavlink_message_t *msg)
149 return _MAV_RETURN_uint32_t(msg, 8);
153 * @brief Decode a system_time message into a struct
155 * @param msg The message to decode
156 * @param system_time C-struct to decode the message contents into
158 static inline void mavlink_msg_system_time_decode(const mavlink_message_t *msg, mavlink_system_time_t *system_time)
160 #if MAVLINK_NEED_BYTE_SWAP
161 system_time->time_unix_usec = mavlink_msg_system_time_get_time_unix_usec(msg);
162 system_time->time_boot_ms = mavlink_msg_system_time_get_time_boot_ms(msg);
163 #else
164 memcpy(system_time, _MAV_PAYLOAD(msg), 12);
165 #endif