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.

335 lines
15 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #pragma once
  2. // MESSAGE HEARTBEAT PACKING
  3. #define MAVLINK_MSG_ID_HEARTBEAT 0
  4. MAVPACKED(
  5. typedef struct __mavlink_heartbeat_t {
  6. uint32_t custom_mode; /*< A bitfield for use for autopilot-specific flags*/
  7. uint8_t type; /*< Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.*/
  8. uint8_t autopilot; /*< Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.*/
  9. uint8_t base_mode; /*< System mode bitmap.*/
  10. uint8_t system_status; /*< System status flag.*/
  11. uint8_t mavlink_version; /*< MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version*/
  12. }) mavlink_heartbeat_t;
  13. #define MAVLINK_MSG_ID_HEARTBEAT_LEN 9
  14. #define MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN 9
  15. #define MAVLINK_MSG_ID_0_LEN 9
  16. #define MAVLINK_MSG_ID_0_MIN_LEN 9
  17. #define MAVLINK_MSG_ID_HEARTBEAT_CRC 50
  18. #define MAVLINK_MSG_ID_0_CRC 50
  19. #if MAVLINK_COMMAND_24BIT
  20. #define MAVLINK_MESSAGE_INFO_HEARTBEAT { \
  21. 0, \
  22. "HEARTBEAT", \
  23. 6, \
  24. { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) }, \
  25. { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) }, \
  26. { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) }, \
  27. { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) }, \
  28. { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) }, \
  29. { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) }, \
  30. } \
  31. }
  32. #else
  33. #define MAVLINK_MESSAGE_INFO_HEARTBEAT { \
  34. "HEARTBEAT", \
  35. 6, \
  36. { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) }, \
  37. { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) }, \
  38. { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) }, \
  39. { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) }, \
  40. { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) }, \
  41. { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) }, \
  42. } \
  43. }
  44. #endif
  45. /**
  46. * @brief Pack a heartbeat message
  47. * @param system_id ID of this system
  48. * @param component_id ID of this component (e.g. 200 for IMU)
  49. * @param msg The MAVLink message to compress the data into
  50. *
  51. * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
  52. * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
  53. * @param base_mode System mode bitmap.
  54. * @param custom_mode A bitfield for use for autopilot-specific flags
  55. * @param system_status System status flag.
  56. * @return length of the message in bytes (excluding serial stream start sign)
  57. */
  58. static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  59. uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
  60. {
  61. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  62. char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
  63. _mav_put_uint32_t(buf, 0, custom_mode);
  64. _mav_put_uint8_t(buf, 4, type);
  65. _mav_put_uint8_t(buf, 5, autopilot);
  66. _mav_put_uint8_t(buf, 6, base_mode);
  67. _mav_put_uint8_t(buf, 7, system_status);
  68. _mav_put_uint8_t(buf, 8, 3);
  69. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
  70. #else
  71. mavlink_heartbeat_t packet;
  72. packet.custom_mode = custom_mode;
  73. packet.type = type;
  74. packet.autopilot = autopilot;
  75. packet.base_mode = base_mode;
  76. packet.system_status = system_status;
  77. packet.mavlink_version = 3;
  78. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
  79. #endif
  80. msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
  81. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  82. }
  83. /**
  84. * @brief Pack a heartbeat 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 type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
  90. * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
  91. * @param base_mode System mode bitmap.
  92. * @param custom_mode A bitfield for use for autopilot-specific flags
  93. * @param system_status System status flag.
  94. * @return length of the message in bytes (excluding serial stream start sign)
  95. */
  96. static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  97. mavlink_message_t* msg,
  98. uint8_t type,uint8_t autopilot,uint8_t base_mode,uint32_t custom_mode,uint8_t system_status)
  99. {
  100. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  101. char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
  102. _mav_put_uint32_t(buf, 0, custom_mode);
  103. _mav_put_uint8_t(buf, 4, type);
  104. _mav_put_uint8_t(buf, 5, autopilot);
  105. _mav_put_uint8_t(buf, 6, base_mode);
  106. _mav_put_uint8_t(buf, 7, system_status);
  107. _mav_put_uint8_t(buf, 8, 3);
  108. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
  109. #else
  110. mavlink_heartbeat_t packet;
  111. packet.custom_mode = custom_mode;
  112. packet.type = type;
  113. packet.autopilot = autopilot;
  114. packet.base_mode = base_mode;
  115. packet.system_status = system_status;
  116. packet.mavlink_version = 3;
  117. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
  118. #endif
  119. msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
  120. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  121. }
  122. /**
  123. * @brief Encode a heartbeat struct
  124. *
  125. * @param system_id ID of this system
  126. * @param component_id ID of this component (e.g. 200 for IMU)
  127. * @param msg The MAVLink message to compress the data into
  128. * @param heartbeat C-struct to read the message contents from
  129. */
  130. static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
  131. {
  132. return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
  133. }
  134. /**
  135. * @brief Encode a heartbeat struct on a channel
  136. *
  137. * @param system_id ID of this system
  138. * @param component_id ID of this component (e.g. 200 for IMU)
  139. * @param chan The MAVLink channel this message will be sent over
  140. * @param msg The MAVLink message to compress the data into
  141. * @param heartbeat C-struct to read the message contents from
  142. */
  143. static inline uint16_t mavlink_msg_heartbeat_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat)
  144. {
  145. return mavlink_msg_heartbeat_pack_chan(system_id, component_id, chan, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
  146. }
  147. /**
  148. * @brief Send a heartbeat message
  149. * @param chan MAVLink channel to send the message
  150. *
  151. * @param type Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
  152. * @param autopilot Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
  153. * @param base_mode System mode bitmap.
  154. * @param custom_mode A bitfield for use for autopilot-specific flags
  155. * @param system_status System status flag.
  156. */
  157. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  158. static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
  159. {
  160. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  161. char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
  162. _mav_put_uint32_t(buf, 0, custom_mode);
  163. _mav_put_uint8_t(buf, 4, type);
  164. _mav_put_uint8_t(buf, 5, autopilot);
  165. _mav_put_uint8_t(buf, 6, base_mode);
  166. _mav_put_uint8_t(buf, 7, system_status);
  167. _mav_put_uint8_t(buf, 8, 3);
  168. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  169. #else
  170. mavlink_heartbeat_t packet;
  171. packet.custom_mode = custom_mode;
  172. packet.type = type;
  173. packet.autopilot = autopilot;
  174. packet.base_mode = base_mode;
  175. packet.system_status = system_status;
  176. packet.mavlink_version = 3;
  177. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  178. #endif
  179. }
  180. /**
  181. * @brief Send a heartbeat message
  182. * @param chan MAVLink channel to send the message
  183. * @param struct The MAVLink struct to serialize
  184. */
  185. static inline void mavlink_msg_heartbeat_send_struct(mavlink_channel_t chan, const mavlink_heartbeat_t* heartbeat)
  186. {
  187. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  188. mavlink_msg_heartbeat_send(chan, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status);
  189. #else
  190. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)heartbeat, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  191. #endif
  192. }
  193. #if MAVLINK_MSG_ID_HEARTBEAT_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  194. /*
  195. This varient of _send() can be used to save stack space by re-using
  196. memory from the receive buffer. The caller provides a
  197. mavlink_message_t which is the size of a full mavlink message. This
  198. is usually the receive buffer for the channel, and allows a reply to an
  199. incoming message with minimum stack space usage.
  200. */
  201. static inline void mavlink_msg_heartbeat_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status)
  202. {
  203. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  204. char *buf = (char *)msgbuf;
  205. _mav_put_uint32_t(buf, 0, custom_mode);
  206. _mav_put_uint8_t(buf, 4, type);
  207. _mav_put_uint8_t(buf, 5, autopilot);
  208. _mav_put_uint8_t(buf, 6, base_mode);
  209. _mav_put_uint8_t(buf, 7, system_status);
  210. _mav_put_uint8_t(buf, 8, 3);
  211. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  212. #else
  213. mavlink_heartbeat_t *packet = (mavlink_heartbeat_t *)msgbuf;
  214. packet->custom_mode = custom_mode;
  215. packet->type = type;
  216. packet->autopilot = autopilot;
  217. packet->base_mode = base_mode;
  218. packet->system_status = system_status;
  219. packet->mavlink_version = 3;
  220. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)packet, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
  221. #endif
  222. }
  223. #endif
  224. #endif
  225. // MESSAGE HEARTBEAT UNPACKING
  226. /**
  227. * @brief Get field type from heartbeat message
  228. *
  229. * @return Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.
  230. */
  231. static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg)
  232. {
  233. return _MAV_RETURN_uint8_t(msg, 4);
  234. }
  235. /**
  236. * @brief Get field autopilot from heartbeat message
  237. *
  238. * @return Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.
  239. */
  240. static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg)
  241. {
  242. return _MAV_RETURN_uint8_t(msg, 5);
  243. }
  244. /**
  245. * @brief Get field base_mode from heartbeat message
  246. *
  247. * @return System mode bitmap.
  248. */
  249. static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg)
  250. {
  251. return _MAV_RETURN_uint8_t(msg, 6);
  252. }
  253. /**
  254. * @brief Get field custom_mode from heartbeat message
  255. *
  256. * @return A bitfield for use for autopilot-specific flags
  257. */
  258. static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg)
  259. {
  260. return _MAV_RETURN_uint32_t(msg, 0);
  261. }
  262. /**
  263. * @brief Get field system_status from heartbeat message
  264. *
  265. * @return System status flag.
  266. */
  267. static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg)
  268. {
  269. return _MAV_RETURN_uint8_t(msg, 7);
  270. }
  271. /**
  272. * @brief Get field mavlink_version from heartbeat message
  273. *
  274. * @return MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version
  275. */
  276. static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg)
  277. {
  278. return _MAV_RETURN_uint8_t(msg, 8);
  279. }
  280. /**
  281. * @brief Decode a heartbeat message into a struct
  282. *
  283. * @param msg The message to decode
  284. * @param heartbeat C-struct to decode the message contents into
  285. */
  286. static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat)
  287. {
  288. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  289. heartbeat->custom_mode = mavlink_msg_heartbeat_get_custom_mode(msg);
  290. heartbeat->type = mavlink_msg_heartbeat_get_type(msg);
  291. heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg);
  292. heartbeat->base_mode = mavlink_msg_heartbeat_get_base_mode(msg);
  293. heartbeat->system_status = mavlink_msg_heartbeat_get_system_status(msg);
  294. heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg);
  295. #else
  296. uint8_t len = msg->len < MAVLINK_MSG_ID_HEARTBEAT_LEN? msg->len : MAVLINK_MSG_ID_HEARTBEAT_LEN;
  297. memset(heartbeat, 0, MAVLINK_MSG_ID_HEARTBEAT_LEN);
  298. memcpy(heartbeat, _MAV_PAYLOAD(msg), len);
  299. #endif
  300. }