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.

263 lines
10 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #pragma once
  2. // MESSAGE DATA_STREAM PACKING
  3. #define MAVLINK_MSG_ID_DATA_STREAM 67
  4. MAVPACKED(
  5. typedef struct __mavlink_data_stream_t {
  6. uint16_t message_rate; /*< [Hz] The message rate*/
  7. uint8_t stream_id; /*< The ID of the requested data stream*/
  8. uint8_t on_off; /*< 1 stream is enabled, 0 stream is stopped.*/
  9. }) mavlink_data_stream_t;
  10. #define MAVLINK_MSG_ID_DATA_STREAM_LEN 4
  11. #define MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN 4
  12. #define MAVLINK_MSG_ID_67_LEN 4
  13. #define MAVLINK_MSG_ID_67_MIN_LEN 4
  14. #define MAVLINK_MSG_ID_DATA_STREAM_CRC 21
  15. #define MAVLINK_MSG_ID_67_CRC 21
  16. #if MAVLINK_COMMAND_24BIT
  17. #define MAVLINK_MESSAGE_INFO_DATA_STREAM { \
  18. 67, \
  19. "DATA_STREAM", \
  20. 3, \
  21. { { "stream_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_data_stream_t, stream_id) }, \
  22. { "message_rate", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_data_stream_t, message_rate) }, \
  23. { "on_off", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_data_stream_t, on_off) }, \
  24. } \
  25. }
  26. #else
  27. #define MAVLINK_MESSAGE_INFO_DATA_STREAM { \
  28. "DATA_STREAM", \
  29. 3, \
  30. { { "stream_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_data_stream_t, stream_id) }, \
  31. { "message_rate", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_data_stream_t, message_rate) }, \
  32. { "on_off", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_data_stream_t, on_off) }, \
  33. } \
  34. }
  35. #endif
  36. /**
  37. * @brief Pack a data_stream message
  38. * @param system_id ID of this system
  39. * @param component_id ID of this component (e.g. 200 for IMU)
  40. * @param msg The MAVLink message to compress the data into
  41. *
  42. * @param stream_id The ID of the requested data stream
  43. * @param message_rate [Hz] The message rate
  44. * @param on_off 1 stream is enabled, 0 stream is stopped.
  45. * @return length of the message in bytes (excluding serial stream start sign)
  46. */
  47. static inline uint16_t mavlink_msg_data_stream_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  48. uint8_t stream_id, uint16_t message_rate, uint8_t on_off)
  49. {
  50. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  51. char buf[MAVLINK_MSG_ID_DATA_STREAM_LEN];
  52. _mav_put_uint16_t(buf, 0, message_rate);
  53. _mav_put_uint8_t(buf, 2, stream_id);
  54. _mav_put_uint8_t(buf, 3, on_off);
  55. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DATA_STREAM_LEN);
  56. #else
  57. mavlink_data_stream_t packet;
  58. packet.message_rate = message_rate;
  59. packet.stream_id = stream_id;
  60. packet.on_off = on_off;
  61. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DATA_STREAM_LEN);
  62. #endif
  63. msg->msgid = MAVLINK_MSG_ID_DATA_STREAM;
  64. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  65. }
  66. /**
  67. * @brief Pack a data_stream message on a channel
  68. * @param system_id ID of this system
  69. * @param component_id ID of this component (e.g. 200 for IMU)
  70. * @param chan The MAVLink channel this message will be sent over
  71. * @param msg The MAVLink message to compress the data into
  72. * @param stream_id The ID of the requested data stream
  73. * @param message_rate [Hz] The message rate
  74. * @param on_off 1 stream is enabled, 0 stream is stopped.
  75. * @return length of the message in bytes (excluding serial stream start sign)
  76. */
  77. static inline uint16_t mavlink_msg_data_stream_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  78. mavlink_message_t* msg,
  79. uint8_t stream_id,uint16_t message_rate,uint8_t on_off)
  80. {
  81. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  82. char buf[MAVLINK_MSG_ID_DATA_STREAM_LEN];
  83. _mav_put_uint16_t(buf, 0, message_rate);
  84. _mav_put_uint8_t(buf, 2, stream_id);
  85. _mav_put_uint8_t(buf, 3, on_off);
  86. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DATA_STREAM_LEN);
  87. #else
  88. mavlink_data_stream_t packet;
  89. packet.message_rate = message_rate;
  90. packet.stream_id = stream_id;
  91. packet.on_off = on_off;
  92. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DATA_STREAM_LEN);
  93. #endif
  94. msg->msgid = MAVLINK_MSG_ID_DATA_STREAM;
  95. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  96. }
  97. /**
  98. * @brief Encode a data_stream struct
  99. *
  100. * @param system_id ID of this system
  101. * @param component_id ID of this component (e.g. 200 for IMU)
  102. * @param msg The MAVLink message to compress the data into
  103. * @param data_stream C-struct to read the message contents from
  104. */
  105. static inline uint16_t mavlink_msg_data_stream_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data_stream_t* data_stream)
  106. {
  107. return mavlink_msg_data_stream_pack(system_id, component_id, msg, data_stream->stream_id, data_stream->message_rate, data_stream->on_off);
  108. }
  109. /**
  110. * @brief Encode a data_stream struct on a channel
  111. *
  112. * @param system_id ID of this system
  113. * @param component_id ID of this component (e.g. 200 for IMU)
  114. * @param chan The MAVLink channel this message will be sent over
  115. * @param msg The MAVLink message to compress the data into
  116. * @param data_stream C-struct to read the message contents from
  117. */
  118. static inline uint16_t mavlink_msg_data_stream_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_data_stream_t* data_stream)
  119. {
  120. return mavlink_msg_data_stream_pack_chan(system_id, component_id, chan, msg, data_stream->stream_id, data_stream->message_rate, data_stream->on_off);
  121. }
  122. /**
  123. * @brief Send a data_stream message
  124. * @param chan MAVLink channel to send the message
  125. *
  126. * @param stream_id The ID of the requested data stream
  127. * @param message_rate [Hz] The message rate
  128. * @param on_off 1 stream is enabled, 0 stream is stopped.
  129. */
  130. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  131. static inline void mavlink_msg_data_stream_send(mavlink_channel_t chan, uint8_t stream_id, uint16_t message_rate, uint8_t on_off)
  132. {
  133. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  134. char buf[MAVLINK_MSG_ID_DATA_STREAM_LEN];
  135. _mav_put_uint16_t(buf, 0, message_rate);
  136. _mav_put_uint8_t(buf, 2, stream_id);
  137. _mav_put_uint8_t(buf, 3, on_off);
  138. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_STREAM, buf, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  139. #else
  140. mavlink_data_stream_t packet;
  141. packet.message_rate = message_rate;
  142. packet.stream_id = stream_id;
  143. packet.on_off = on_off;
  144. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_STREAM, (const char *)&packet, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  145. #endif
  146. }
  147. /**
  148. * @brief Send a data_stream message
  149. * @param chan MAVLink channel to send the message
  150. * @param struct The MAVLink struct to serialize
  151. */
  152. static inline void mavlink_msg_data_stream_send_struct(mavlink_channel_t chan, const mavlink_data_stream_t* data_stream)
  153. {
  154. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  155. mavlink_msg_data_stream_send(chan, data_stream->stream_id, data_stream->message_rate, data_stream->on_off);
  156. #else
  157. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_STREAM, (const char *)data_stream, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  158. #endif
  159. }
  160. #if MAVLINK_MSG_ID_DATA_STREAM_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  161. /*
  162. This varient of _send() can be used to save stack space by re-using
  163. memory from the receive buffer. The caller provides a
  164. mavlink_message_t which is the size of a full mavlink message. This
  165. is usually the receive buffer for the channel, and allows a reply to an
  166. incoming message with minimum stack space usage.
  167. */
  168. static inline void mavlink_msg_data_stream_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t stream_id, uint16_t message_rate, uint8_t on_off)
  169. {
  170. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  171. char *buf = (char *)msgbuf;
  172. _mav_put_uint16_t(buf, 0, message_rate);
  173. _mav_put_uint8_t(buf, 2, stream_id);
  174. _mav_put_uint8_t(buf, 3, on_off);
  175. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_STREAM, buf, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  176. #else
  177. mavlink_data_stream_t *packet = (mavlink_data_stream_t *)msgbuf;
  178. packet->message_rate = message_rate;
  179. packet->stream_id = stream_id;
  180. packet->on_off = on_off;
  181. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_STREAM, (const char *)packet, MAVLINK_MSG_ID_DATA_STREAM_MIN_LEN, MAVLINK_MSG_ID_DATA_STREAM_LEN, MAVLINK_MSG_ID_DATA_STREAM_CRC);
  182. #endif
  183. }
  184. #endif
  185. #endif
  186. // MESSAGE DATA_STREAM UNPACKING
  187. /**
  188. * @brief Get field stream_id from data_stream message
  189. *
  190. * @return The ID of the requested data stream
  191. */
  192. static inline uint8_t mavlink_msg_data_stream_get_stream_id(const mavlink_message_t* msg)
  193. {
  194. return _MAV_RETURN_uint8_t(msg, 2);
  195. }
  196. /**
  197. * @brief Get field message_rate from data_stream message
  198. *
  199. * @return [Hz] The message rate
  200. */
  201. static inline uint16_t mavlink_msg_data_stream_get_message_rate(const mavlink_message_t* msg)
  202. {
  203. return _MAV_RETURN_uint16_t(msg, 0);
  204. }
  205. /**
  206. * @brief Get field on_off from data_stream message
  207. *
  208. * @return 1 stream is enabled, 0 stream is stopped.
  209. */
  210. static inline uint8_t mavlink_msg_data_stream_get_on_off(const mavlink_message_t* msg)
  211. {
  212. return _MAV_RETURN_uint8_t(msg, 3);
  213. }
  214. /**
  215. * @brief Decode a data_stream message into a struct
  216. *
  217. * @param msg The message to decode
  218. * @param data_stream C-struct to decode the message contents into
  219. */
  220. static inline void mavlink_msg_data_stream_decode(const mavlink_message_t* msg, mavlink_data_stream_t* data_stream)
  221. {
  222. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  223. data_stream->message_rate = mavlink_msg_data_stream_get_message_rate(msg);
  224. data_stream->stream_id = mavlink_msg_data_stream_get_stream_id(msg);
  225. data_stream->on_off = mavlink_msg_data_stream_get_on_off(msg);
  226. #else
  227. uint8_t len = msg->len < MAVLINK_MSG_ID_DATA_STREAM_LEN? msg->len : MAVLINK_MSG_ID_DATA_STREAM_LEN;
  228. memset(data_stream, 0, MAVLINK_MSG_ID_DATA_STREAM_LEN);
  229. memcpy(data_stream, _MAV_PAYLOAD(msg), len);
  230. #endif
  231. }