mavlink_msg_auth_key.h 9.4 KB

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