mavlink_msg_auth_key.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 on a channel
  56. * @param system_id ID of this system
  57. * @param component_id ID of this component (e.g. 200 for IMU)
  58. * @param chan The MAVLink channel this message will be sent over
  59. * @param msg The MAVLink message to compress the data into
  60. * @param key key
  61. * @return length of the message in bytes (excluding serial stream start sign)
  62. */
  63. static inline uint16_t mavlink_msg_auth_key_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  64. 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. 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);
  78. }
  79. /**
  80. * @brief Encode a auth_key struct
  81. *
  82. * @param system_id ID of this system
  83. * @param component_id ID of this component (e.g. 200 for IMU)
  84. * @param msg The MAVLink message to compress the data into
  85. * @param auth_key C-struct to read the message contents from
  86. */
  87. 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)
  88. {
  89. return mavlink_msg_auth_key_pack(system_id, component_id, msg, auth_key->key);
  90. }
  91. /**
  92. * @brief Encode a auth_key struct on a channel
  93. *
  94. * @param system_id ID of this system
  95. * @param component_id ID of this component (e.g. 200 for IMU)
  96. * @param chan The MAVLink channel this message will be sent over
  97. * @param msg The MAVLink message to compress the data into
  98. * @param auth_key C-struct to read the message contents from
  99. */
  100. 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)
  101. {
  102. return mavlink_msg_auth_key_pack_chan(system_id, component_id, chan, msg, auth_key->key);
  103. }
  104. /**
  105. * @brief Send a auth_key message
  106. * @param chan MAVLink channel to send the message
  107. *
  108. * @param key key
  109. */
  110. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  111. static inline void mavlink_msg_auth_key_send(mavlink_channel_t chan, const char *key)
  112. {
  113. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  114. char buf[MAVLINK_MSG_ID_AUTH_KEY_LEN];
  115. _mav_put_char_array(buf, 0, key, 32);
  116. _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);
  117. #else
  118. mavlink_auth_key_t packet;
  119. mav_array_memcpy(packet.key, key, sizeof(char)*32);
  120. _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);
  121. #endif
  122. }
  123. /**
  124. * @brief Send a auth_key message
  125. * @param chan MAVLink channel to send the message
  126. * @param struct The MAVLink struct to serialize
  127. */
  128. static inline void mavlink_msg_auth_key_send_struct(mavlink_channel_t chan, const mavlink_auth_key_t* auth_key)
  129. {
  130. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  131. mavlink_msg_auth_key_send(chan, auth_key->key);
  132. #else
  133. _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);
  134. #endif
  135. }
  136. #if MAVLINK_MSG_ID_AUTH_KEY_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  137. /*
  138. This variant of _send() can be used to save stack space by re-using
  139. memory from the receive buffer. The caller provides a
  140. mavlink_message_t which is the size of a full mavlink message. This
  141. is usually the receive buffer for the channel, and allows a reply to an
  142. incoming message with minimum stack space usage.
  143. */
  144. static inline void mavlink_msg_auth_key_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, const char *key)
  145. {
  146. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  147. char *buf = (char *)msgbuf;
  148. _mav_put_char_array(buf, 0, key, 32);
  149. _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);
  150. #else
  151. mavlink_auth_key_t *packet = (mavlink_auth_key_t *)msgbuf;
  152. mav_array_memcpy(packet->key, key, sizeof(char)*32);
  153. _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);
  154. #endif
  155. }
  156. #endif
  157. #endif
  158. // MESSAGE AUTH_KEY UNPACKING
  159. /**
  160. * @brief Get field key from auth_key message
  161. *
  162. * @return key
  163. */
  164. static inline uint16_t mavlink_msg_auth_key_get_key(const mavlink_message_t* msg, char *key)
  165. {
  166. return _MAV_RETURN_char_array(msg, key, 32, 0);
  167. }
  168. /**
  169. * @brief Decode a auth_key message into a struct
  170. *
  171. * @param msg The message to decode
  172. * @param auth_key C-struct to decode the message contents into
  173. */
  174. static inline void mavlink_msg_auth_key_decode(const mavlink_message_t* msg, mavlink_auth_key_t* auth_key)
  175. {
  176. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  177. mavlink_msg_auth_key_get_key(msg, auth_key->key);
  178. #else
  179. uint8_t len = msg->len < MAVLINK_MSG_ID_AUTH_KEY_LEN? msg->len : MAVLINK_MSG_ID_AUTH_KEY_LEN;
  180. memset(auth_key, 0, MAVLINK_MSG_ID_AUTH_KEY_LEN);
  181. memcpy(auth_key, _MAV_PAYLOAD(msg), len);
  182. #endif
  183. }