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.

255 lines
9.1 KiB

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