mavlink_msg_serial_control.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. #pragma once
  2. // MESSAGE SERIAL_CONTROL PACKING
  3. #define MAVLINK_MSG_ID_SERIAL_CONTROL 126
  4. typedef struct __mavlink_serial_control_t {
  5. uint32_t baudrate; /*< [bits/s] Baudrate of transfer. Zero means no change.*/
  6. uint16_t timeout; /*< [ms] Timeout for reply data*/
  7. uint8_t device; /*< Serial control device type.*/
  8. uint8_t flags; /*< Bitmap of serial control flags.*/
  9. uint8_t count; /*< [bytes] how many bytes in this transfer*/
  10. uint8_t data[70]; /*< serial data*/
  11. uint8_t target_system; /*< System ID*/
  12. uint8_t target_component; /*< Component ID*/
  13. } mavlink_serial_control_t;
  14. #define MAVLINK_MSG_ID_SERIAL_CONTROL_LEN 81
  15. #define MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN 79
  16. #define MAVLINK_MSG_ID_126_LEN 81
  17. #define MAVLINK_MSG_ID_126_MIN_LEN 79
  18. #define MAVLINK_MSG_ID_SERIAL_CONTROL_CRC 220
  19. #define MAVLINK_MSG_ID_126_CRC 220
  20. #define MAVLINK_MSG_SERIAL_CONTROL_FIELD_DATA_LEN 70
  21. #if MAVLINK_COMMAND_24BIT
  22. #define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL { \
  23. 126, \
  24. "SERIAL_CONTROL", \
  25. 8, \
  26. { { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) }, \
  27. { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) }, \
  28. { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) }, \
  29. { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) }, \
  30. { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) }, \
  31. { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) }, \
  32. { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_serial_control_t, target_system) }, \
  33. { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 80, offsetof(mavlink_serial_control_t, target_component) }, \
  34. } \
  35. }
  36. #else
  37. #define MAVLINK_MESSAGE_INFO_SERIAL_CONTROL { \
  38. "SERIAL_CONTROL", \
  39. 8, \
  40. { { "device", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_serial_control_t, device) }, \
  41. { "flags", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_serial_control_t, flags) }, \
  42. { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_serial_control_t, timeout) }, \
  43. { "baudrate", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_serial_control_t, baudrate) }, \
  44. { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_serial_control_t, count) }, \
  45. { "data", NULL, MAVLINK_TYPE_UINT8_T, 70, 9, offsetof(mavlink_serial_control_t, data) }, \
  46. { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_serial_control_t, target_system) }, \
  47. { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 80, offsetof(mavlink_serial_control_t, target_component) }, \
  48. } \
  49. }
  50. #endif
  51. /**
  52. * @brief Pack a serial_control message
  53. * @param system_id ID of this system
  54. * @param component_id ID of this component (e.g. 200 for IMU)
  55. * @param msg The MAVLink message to compress the data into
  56. *
  57. * @param device Serial control device type.
  58. * @param flags Bitmap of serial control flags.
  59. * @param timeout [ms] Timeout for reply data
  60. * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
  61. * @param count [bytes] how many bytes in this transfer
  62. * @param data serial data
  63. * @param target_system System ID
  64. * @param target_component Component ID
  65. * @return length of the message in bytes (excluding serial stream start sign)
  66. */
  67. static inline uint16_t mavlink_msg_serial_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  68. uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data, uint8_t target_system, uint8_t target_component)
  69. {
  70. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  71. char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
  72. _mav_put_uint32_t(buf, 0, baudrate);
  73. _mav_put_uint16_t(buf, 4, timeout);
  74. _mav_put_uint8_t(buf, 6, device);
  75. _mav_put_uint8_t(buf, 7, flags);
  76. _mav_put_uint8_t(buf, 8, count);
  77. _mav_put_uint8_t(buf, 79, target_system);
  78. _mav_put_uint8_t(buf, 80, target_component);
  79. _mav_put_uint8_t_array(buf, 9, data, 70);
  80. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
  81. #else
  82. mavlink_serial_control_t packet;
  83. packet.baudrate = baudrate;
  84. packet.timeout = timeout;
  85. packet.device = device;
  86. packet.flags = flags;
  87. packet.count = count;
  88. packet.target_system = target_system;
  89. packet.target_component = target_component;
  90. mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
  91. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
  92. #endif
  93. msg->msgid = MAVLINK_MSG_ID_SERIAL_CONTROL;
  94. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  95. }
  96. /**
  97. * @brief Pack a serial_control message on a channel
  98. * @param system_id ID of this system
  99. * @param component_id ID of this component (e.g. 200 for IMU)
  100. * @param chan The MAVLink channel this message will be sent over
  101. * @param msg The MAVLink message to compress the data into
  102. * @param device Serial control device type.
  103. * @param flags Bitmap of serial control flags.
  104. * @param timeout [ms] Timeout for reply data
  105. * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
  106. * @param count [bytes] how many bytes in this transfer
  107. * @param data serial data
  108. * @param target_system System ID
  109. * @param target_component Component ID
  110. * @return length of the message in bytes (excluding serial stream start sign)
  111. */
  112. static inline uint16_t mavlink_msg_serial_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  113. mavlink_message_t* msg,
  114. uint8_t device,uint8_t flags,uint16_t timeout,uint32_t baudrate,uint8_t count,const uint8_t *data,uint8_t target_system,uint8_t target_component)
  115. {
  116. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  117. char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
  118. _mav_put_uint32_t(buf, 0, baudrate);
  119. _mav_put_uint16_t(buf, 4, timeout);
  120. _mav_put_uint8_t(buf, 6, device);
  121. _mav_put_uint8_t(buf, 7, flags);
  122. _mav_put_uint8_t(buf, 8, count);
  123. _mav_put_uint8_t(buf, 79, target_system);
  124. _mav_put_uint8_t(buf, 80, target_component);
  125. _mav_put_uint8_t_array(buf, 9, data, 70);
  126. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
  127. #else
  128. mavlink_serial_control_t packet;
  129. packet.baudrate = baudrate;
  130. packet.timeout = timeout;
  131. packet.device = device;
  132. packet.flags = flags;
  133. packet.count = count;
  134. packet.target_system = target_system;
  135. packet.target_component = target_component;
  136. mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
  137. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
  138. #endif
  139. msg->msgid = MAVLINK_MSG_ID_SERIAL_CONTROL;
  140. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  141. }
  142. /**
  143. * @brief Encode a serial_control struct
  144. *
  145. * @param system_id ID of this system
  146. * @param component_id ID of this component (e.g. 200 for IMU)
  147. * @param msg The MAVLink message to compress the data into
  148. * @param serial_control C-struct to read the message contents from
  149. */
  150. static inline uint16_t mavlink_msg_serial_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_serial_control_t* serial_control)
  151. {
  152. return mavlink_msg_serial_control_pack(system_id, component_id, msg, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data, serial_control->target_system, serial_control->target_component);
  153. }
  154. /**
  155. * @brief Encode a serial_control struct on a channel
  156. *
  157. * @param system_id ID of this system
  158. * @param component_id ID of this component (e.g. 200 for IMU)
  159. * @param chan The MAVLink channel this message will be sent over
  160. * @param msg The MAVLink message to compress the data into
  161. * @param serial_control C-struct to read the message contents from
  162. */
  163. static inline uint16_t mavlink_msg_serial_control_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_serial_control_t* serial_control)
  164. {
  165. return mavlink_msg_serial_control_pack_chan(system_id, component_id, chan, msg, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data, serial_control->target_system, serial_control->target_component);
  166. }
  167. /**
  168. * @brief Send a serial_control message
  169. * @param chan MAVLink channel to send the message
  170. *
  171. * @param device Serial control device type.
  172. * @param flags Bitmap of serial control flags.
  173. * @param timeout [ms] Timeout for reply data
  174. * @param baudrate [bits/s] Baudrate of transfer. Zero means no change.
  175. * @param count [bytes] how many bytes in this transfer
  176. * @param data serial data
  177. * @param target_system System ID
  178. * @param target_component Component ID
  179. */
  180. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  181. static inline void mavlink_msg_serial_control_send(mavlink_channel_t chan, uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data, uint8_t target_system, uint8_t target_component)
  182. {
  183. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  184. char buf[MAVLINK_MSG_ID_SERIAL_CONTROL_LEN];
  185. _mav_put_uint32_t(buf, 0, baudrate);
  186. _mav_put_uint16_t(buf, 4, timeout);
  187. _mav_put_uint8_t(buf, 6, device);
  188. _mav_put_uint8_t(buf, 7, flags);
  189. _mav_put_uint8_t(buf, 8, count);
  190. _mav_put_uint8_t(buf, 79, target_system);
  191. _mav_put_uint8_t(buf, 80, target_component);
  192. _mav_put_uint8_t_array(buf, 9, data, 70);
  193. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, buf, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  194. #else
  195. mavlink_serial_control_t packet;
  196. packet.baudrate = baudrate;
  197. packet.timeout = timeout;
  198. packet.device = device;
  199. packet.flags = flags;
  200. packet.count = count;
  201. packet.target_system = target_system;
  202. packet.target_component = target_component;
  203. mav_array_memcpy(packet.data, data, sizeof(uint8_t)*70);
  204. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)&packet, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  205. #endif
  206. }
  207. /**
  208. * @brief Send a serial_control message
  209. * @param chan MAVLink channel to send the message
  210. * @param struct The MAVLink struct to serialize
  211. */
  212. static inline void mavlink_msg_serial_control_send_struct(mavlink_channel_t chan, const mavlink_serial_control_t* serial_control)
  213. {
  214. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  215. mavlink_msg_serial_control_send(chan, serial_control->device, serial_control->flags, serial_control->timeout, serial_control->baudrate, serial_control->count, serial_control->data, serial_control->target_system, serial_control->target_component);
  216. #else
  217. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)serial_control, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  218. #endif
  219. }
  220. #if MAVLINK_MSG_ID_SERIAL_CONTROL_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  221. /*
  222. This variant of _send() can be used to save stack space by re-using
  223. memory from the receive buffer. The caller provides a
  224. mavlink_message_t which is the size of a full mavlink message. This
  225. is usually the receive buffer for the channel, and allows a reply to an
  226. incoming message with minimum stack space usage.
  227. */
  228. static inline void mavlink_msg_serial_control_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, uint8_t count, const uint8_t *data, uint8_t target_system, uint8_t target_component)
  229. {
  230. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  231. char *buf = (char *)msgbuf;
  232. _mav_put_uint32_t(buf, 0, baudrate);
  233. _mav_put_uint16_t(buf, 4, timeout);
  234. _mav_put_uint8_t(buf, 6, device);
  235. _mav_put_uint8_t(buf, 7, flags);
  236. _mav_put_uint8_t(buf, 8, count);
  237. _mav_put_uint8_t(buf, 79, target_system);
  238. _mav_put_uint8_t(buf, 80, target_component);
  239. _mav_put_uint8_t_array(buf, 9, data, 70);
  240. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, buf, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  241. #else
  242. mavlink_serial_control_t *packet = (mavlink_serial_control_t *)msgbuf;
  243. packet->baudrate = baudrate;
  244. packet->timeout = timeout;
  245. packet->device = device;
  246. packet->flags = flags;
  247. packet->count = count;
  248. packet->target_system = target_system;
  249. packet->target_component = target_component;
  250. mav_array_memcpy(packet->data, data, sizeof(uint8_t)*70);
  251. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERIAL_CONTROL, (const char *)packet, MAVLINK_MSG_ID_SERIAL_CONTROL_MIN_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN, MAVLINK_MSG_ID_SERIAL_CONTROL_CRC);
  252. #endif
  253. }
  254. #endif
  255. #endif
  256. // MESSAGE SERIAL_CONTROL UNPACKING
  257. /**
  258. * @brief Get field device from serial_control message
  259. *
  260. * @return Serial control device type.
  261. */
  262. static inline uint8_t mavlink_msg_serial_control_get_device(const mavlink_message_t* msg)
  263. {
  264. return _MAV_RETURN_uint8_t(msg, 6);
  265. }
  266. /**
  267. * @brief Get field flags from serial_control message
  268. *
  269. * @return Bitmap of serial control flags.
  270. */
  271. static inline uint8_t mavlink_msg_serial_control_get_flags(const mavlink_message_t* msg)
  272. {
  273. return _MAV_RETURN_uint8_t(msg, 7);
  274. }
  275. /**
  276. * @brief Get field timeout from serial_control message
  277. *
  278. * @return [ms] Timeout for reply data
  279. */
  280. static inline uint16_t mavlink_msg_serial_control_get_timeout(const mavlink_message_t* msg)
  281. {
  282. return _MAV_RETURN_uint16_t(msg, 4);
  283. }
  284. /**
  285. * @brief Get field baudrate from serial_control message
  286. *
  287. * @return [bits/s] Baudrate of transfer. Zero means no change.
  288. */
  289. static inline uint32_t mavlink_msg_serial_control_get_baudrate(const mavlink_message_t* msg)
  290. {
  291. return _MAV_RETURN_uint32_t(msg, 0);
  292. }
  293. /**
  294. * @brief Get field count from serial_control message
  295. *
  296. * @return [bytes] how many bytes in this transfer
  297. */
  298. static inline uint8_t mavlink_msg_serial_control_get_count(const mavlink_message_t* msg)
  299. {
  300. return _MAV_RETURN_uint8_t(msg, 8);
  301. }
  302. /**
  303. * @brief Get field data from serial_control message
  304. *
  305. * @return serial data
  306. */
  307. static inline uint16_t mavlink_msg_serial_control_get_data(const mavlink_message_t* msg, uint8_t *data)
  308. {
  309. return _MAV_RETURN_uint8_t_array(msg, data, 70, 9);
  310. }
  311. /**
  312. * @brief Get field target_system from serial_control message
  313. *
  314. * @return System ID
  315. */
  316. static inline uint8_t mavlink_msg_serial_control_get_target_system(const mavlink_message_t* msg)
  317. {
  318. return _MAV_RETURN_uint8_t(msg, 79);
  319. }
  320. /**
  321. * @brief Get field target_component from serial_control message
  322. *
  323. * @return Component ID
  324. */
  325. static inline uint8_t mavlink_msg_serial_control_get_target_component(const mavlink_message_t* msg)
  326. {
  327. return _MAV_RETURN_uint8_t(msg, 80);
  328. }
  329. /**
  330. * @brief Decode a serial_control message into a struct
  331. *
  332. * @param msg The message to decode
  333. * @param serial_control C-struct to decode the message contents into
  334. */
  335. static inline void mavlink_msg_serial_control_decode(const mavlink_message_t* msg, mavlink_serial_control_t* serial_control)
  336. {
  337. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  338. serial_control->baudrate = mavlink_msg_serial_control_get_baudrate(msg);
  339. serial_control->timeout = mavlink_msg_serial_control_get_timeout(msg);
  340. serial_control->device = mavlink_msg_serial_control_get_device(msg);
  341. serial_control->flags = mavlink_msg_serial_control_get_flags(msg);
  342. serial_control->count = mavlink_msg_serial_control_get_count(msg);
  343. mavlink_msg_serial_control_get_data(msg, serial_control->data);
  344. serial_control->target_system = mavlink_msg_serial_control_get_target_system(msg);
  345. serial_control->target_component = mavlink_msg_serial_control_get_target_component(msg);
  346. #else
  347. uint8_t len = msg->len < MAVLINK_MSG_ID_SERIAL_CONTROL_LEN? msg->len : MAVLINK_MSG_ID_SERIAL_CONTROL_LEN;
  348. memset(serial_control, 0, MAVLINK_MSG_ID_SERIAL_CONTROL_LEN);
  349. memcpy(serial_control, _MAV_PAYLOAD(msg), len);
  350. #endif
  351. }