You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
8.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #pragma once
  2. // MESSAGE TIMESYNC PACKING
  3. #define MAVLINK_MSG_ID_TIMESYNC 111
  4. MAVPACKED(
  5. typedef struct __mavlink_timesync_t {
  6. int64_t tc1; /*< Time sync timestamp 1*/
  7. int64_t ts1; /*< Time sync timestamp 2*/
  8. }) mavlink_timesync_t;
  9. #define MAVLINK_MSG_ID_TIMESYNC_LEN 16
  10. #define MAVLINK_MSG_ID_TIMESYNC_MIN_LEN 16
  11. #define MAVLINK_MSG_ID_111_LEN 16
  12. #define MAVLINK_MSG_ID_111_MIN_LEN 16
  13. #define MAVLINK_MSG_ID_TIMESYNC_CRC 34
  14. #define MAVLINK_MSG_ID_111_CRC 34
  15. #if MAVLINK_COMMAND_24BIT
  16. #define MAVLINK_MESSAGE_INFO_TIMESYNC { \
  17. 111, \
  18. "TIMESYNC", \
  19. 2, \
  20. { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) }, \
  21. { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) }, \
  22. } \
  23. }
  24. #else
  25. #define MAVLINK_MESSAGE_INFO_TIMESYNC { \
  26. "TIMESYNC", \
  27. 2, \
  28. { { "tc1", NULL, MAVLINK_TYPE_INT64_T, 0, 0, offsetof(mavlink_timesync_t, tc1) }, \
  29. { "ts1", NULL, MAVLINK_TYPE_INT64_T, 0, 8, offsetof(mavlink_timesync_t, ts1) }, \
  30. } \
  31. }
  32. #endif
  33. /**
  34. * @brief Pack a timesync message
  35. * @param system_id ID of this system
  36. * @param component_id ID of this component (e.g. 200 for IMU)
  37. * @param msg The MAVLink message to compress the data into
  38. *
  39. * @param tc1 Time sync timestamp 1
  40. * @param ts1 Time sync timestamp 2
  41. * @return length of the message in bytes (excluding serial stream start sign)
  42. */
  43. static inline uint16_t mavlink_msg_timesync_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  44. int64_t tc1, int64_t ts1)
  45. {
  46. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  47. char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
  48. _mav_put_int64_t(buf, 0, tc1);
  49. _mav_put_int64_t(buf, 8, ts1);
  50. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
  51. #else
  52. mavlink_timesync_t packet;
  53. packet.tc1 = tc1;
  54. packet.ts1 = ts1;
  55. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
  56. #endif
  57. msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
  58. 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);
  59. }
  60. /**
  61. * @brief Pack a timesync message on a channel
  62. * @param system_id ID of this system
  63. * @param component_id ID of this component (e.g. 200 for IMU)
  64. * @param chan The MAVLink channel this message will be sent over
  65. * @param msg The MAVLink message to compress the data into
  66. * @param tc1 Time sync timestamp 1
  67. * @param ts1 Time sync timestamp 2
  68. * @return length of the message in bytes (excluding serial stream start sign)
  69. */
  70. static inline uint16_t mavlink_msg_timesync_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  71. mavlink_message_t* msg,
  72. int64_t tc1,int64_t ts1)
  73. {
  74. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  75. char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
  76. _mav_put_int64_t(buf, 0, tc1);
  77. _mav_put_int64_t(buf, 8, ts1);
  78. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_TIMESYNC_LEN);
  79. #else
  80. mavlink_timesync_t packet;
  81. packet.tc1 = tc1;
  82. packet.ts1 = ts1;
  83. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_TIMESYNC_LEN);
  84. #endif
  85. msg->msgid = MAVLINK_MSG_ID_TIMESYNC;
  86. 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);
  87. }
  88. /**
  89. * @brief Encode a timesync struct
  90. *
  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 timesync C-struct to read the message contents from
  95. */
  96. 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)
  97. {
  98. return mavlink_msg_timesync_pack(system_id, component_id, msg, timesync->tc1, timesync->ts1);
  99. }
  100. /**
  101. * @brief Encode a timesync struct on a channel
  102. *
  103. * @param system_id ID of this system
  104. * @param component_id ID of this component (e.g. 200 for IMU)
  105. * @param chan The MAVLink channel this message will be sent over
  106. * @param msg The MAVLink message to compress the data into
  107. * @param timesync C-struct to read the message contents from
  108. */
  109. 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)
  110. {
  111. return mavlink_msg_timesync_pack_chan(system_id, component_id, chan, msg, timesync->tc1, timesync->ts1);
  112. }
  113. /**
  114. * @brief Send a timesync message
  115. * @param chan MAVLink channel to send the message
  116. *
  117. * @param tc1 Time sync timestamp 1
  118. * @param ts1 Time sync timestamp 2
  119. */
  120. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  121. static inline void mavlink_msg_timesync_send(mavlink_channel_t chan, int64_t tc1, int64_t ts1)
  122. {
  123. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  124. char buf[MAVLINK_MSG_ID_TIMESYNC_LEN];
  125. _mav_put_int64_t(buf, 0, tc1);
  126. _mav_put_int64_t(buf, 8, ts1);
  127. _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);
  128. #else
  129. mavlink_timesync_t packet;
  130. packet.tc1 = tc1;
  131. packet.ts1 = ts1;
  132. _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);
  133. #endif
  134. }
  135. /**
  136. * @brief Send a timesync message
  137. * @param chan MAVLink channel to send the message
  138. * @param struct The MAVLink struct to serialize
  139. */
  140. static inline void mavlink_msg_timesync_send_struct(mavlink_channel_t chan, const mavlink_timesync_t* timesync)
  141. {
  142. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  143. mavlink_msg_timesync_send(chan, timesync->tc1, timesync->ts1);
  144. #else
  145. _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);
  146. #endif
  147. }
  148. #if MAVLINK_MSG_ID_TIMESYNC_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  149. /*
  150. This varient of _send() can be used to save stack space by re-using
  151. memory from the receive buffer. The caller provides a
  152. mavlink_message_t which is the size of a full mavlink message. This
  153. is usually the receive buffer for the channel, and allows a reply to an
  154. incoming message with minimum stack space usage.
  155. */
  156. static inline void mavlink_msg_timesync_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, int64_t tc1, int64_t ts1)
  157. {
  158. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  159. char *buf = (char *)msgbuf;
  160. _mav_put_int64_t(buf, 0, tc1);
  161. _mav_put_int64_t(buf, 8, ts1);
  162. _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);
  163. #else
  164. mavlink_timesync_t *packet = (mavlink_timesync_t *)msgbuf;
  165. packet->tc1 = tc1;
  166. packet->ts1 = ts1;
  167. _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);
  168. #endif
  169. }
  170. #endif
  171. #endif
  172. // MESSAGE TIMESYNC UNPACKING
  173. /**
  174. * @brief Get field tc1 from timesync message
  175. *
  176. * @return Time sync timestamp 1
  177. */
  178. static inline int64_t mavlink_msg_timesync_get_tc1(const mavlink_message_t* msg)
  179. {
  180. return _MAV_RETURN_int64_t(msg, 0);
  181. }
  182. /**
  183. * @brief Get field ts1 from timesync message
  184. *
  185. * @return Time sync timestamp 2
  186. */
  187. static inline int64_t mavlink_msg_timesync_get_ts1(const mavlink_message_t* msg)
  188. {
  189. return _MAV_RETURN_int64_t(msg, 8);
  190. }
  191. /**
  192. * @brief Decode a timesync message into a struct
  193. *
  194. * @param msg The message to decode
  195. * @param timesync C-struct to decode the message contents into
  196. */
  197. static inline void mavlink_msg_timesync_decode(const mavlink_message_t* msg, mavlink_timesync_t* timesync)
  198. {
  199. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  200. timesync->tc1 = mavlink_msg_timesync_get_tc1(msg);
  201. timesync->ts1 = mavlink_msg_timesync_get_ts1(msg);
  202. #else
  203. uint8_t len = msg->len < MAVLINK_MSG_ID_TIMESYNC_LEN? msg->len : MAVLINK_MSG_ID_TIMESYNC_LEN;
  204. memset(timesync, 0, MAVLINK_MSG_ID_TIMESYNC_LEN);
  205. memcpy(timesync, _MAV_PAYLOAD(msg), len);
  206. #endif
  207. }