mavlink_msg_vfr_hud.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #pragma once
  2. // MESSAGE VFR_HUD PACKING
  3. #define MAVLINK_MSG_ID_VFR_HUD 74
  4. typedef struct __mavlink_vfr_hud_t {
  5. float airspeed; /*< [m/s] Vehicle speed in form appropriate for vehicle type. For standard aircraft this is typically calibrated airspeed (CAS) or indicated airspeed (IAS) - either of which can be used by a pilot to estimate stall speed.*/
  6. float groundspeed; /*< [m/s] Current ground speed.*/
  7. float alt; /*< [m] Current altitude (MSL).*/
  8. float climb; /*< [m/s] Current climb rate.*/
  9. int16_t heading; /*< [deg] Current heading in compass units (0-360, 0=north).*/
  10. uint16_t throttle; /*< [%] Current throttle setting (0 to 100).*/
  11. } mavlink_vfr_hud_t;
  12. #define MAVLINK_MSG_ID_VFR_HUD_LEN 20
  13. #define MAVLINK_MSG_ID_VFR_HUD_MIN_LEN 20
  14. #define MAVLINK_MSG_ID_74_LEN 20
  15. #define MAVLINK_MSG_ID_74_MIN_LEN 20
  16. #define MAVLINK_MSG_ID_VFR_HUD_CRC 20
  17. #define MAVLINK_MSG_ID_74_CRC 20
  18. #if MAVLINK_COMMAND_24BIT
  19. #define MAVLINK_MESSAGE_INFO_VFR_HUD { \
  20. 74, \
  21. "VFR_HUD", \
  22. 6, \
  23. { { "airspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_vfr_hud_t, airspeed) }, \
  24. { "groundspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_vfr_hud_t, groundspeed) }, \
  25. { "heading", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_vfr_hud_t, heading) }, \
  26. { "throttle", NULL, MAVLINK_TYPE_UINT16_T, 0, 18, offsetof(mavlink_vfr_hud_t, throttle) }, \
  27. { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vfr_hud_t, alt) }, \
  28. { "climb", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vfr_hud_t, climb) }, \
  29. } \
  30. }
  31. #else
  32. #define MAVLINK_MESSAGE_INFO_VFR_HUD { \
  33. "VFR_HUD", \
  34. 6, \
  35. { { "airspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_vfr_hud_t, airspeed) }, \
  36. { "groundspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_vfr_hud_t, groundspeed) }, \
  37. { "heading", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_vfr_hud_t, heading) }, \
  38. { "throttle", NULL, MAVLINK_TYPE_UINT16_T, 0, 18, offsetof(mavlink_vfr_hud_t, throttle) }, \
  39. { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vfr_hud_t, alt) }, \
  40. { "climb", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vfr_hud_t, climb) }, \
  41. } \
  42. }
  43. #endif
  44. /**
  45. * @brief Pack a vfr_hud message
  46. * @param system_id ID of this system
  47. * @param component_id ID of this component (e.g. 200 for IMU)
  48. * @param msg The MAVLink message to compress the data into
  49. *
  50. * @param airspeed [m/s] Vehicle speed in form appropriate for vehicle type. For standard aircraft this is typically calibrated airspeed (CAS) or indicated airspeed (IAS) - either of which can be used by a pilot to estimate stall speed.
  51. * @param groundspeed [m/s] Current ground speed.
  52. * @param heading [deg] Current heading in compass units (0-360, 0=north).
  53. * @param throttle [%] Current throttle setting (0 to 100).
  54. * @param alt [m] Current altitude (MSL).
  55. * @param climb [m/s] Current climb rate.
  56. * @return length of the message in bytes (excluding serial stream start sign)
  57. */
  58. static inline uint16_t mavlink_msg_vfr_hud_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  59. float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb)
  60. {
  61. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  62. char buf[MAVLINK_MSG_ID_VFR_HUD_LEN];
  63. _mav_put_float(buf, 0, airspeed);
  64. _mav_put_float(buf, 4, groundspeed);
  65. _mav_put_float(buf, 8, alt);
  66. _mav_put_float(buf, 12, climb);
  67. _mav_put_int16_t(buf, 16, heading);
  68. _mav_put_uint16_t(buf, 18, throttle);
  69. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VFR_HUD_LEN);
  70. #else
  71. mavlink_vfr_hud_t packet;
  72. packet.airspeed = airspeed;
  73. packet.groundspeed = groundspeed;
  74. packet.alt = alt;
  75. packet.climb = climb;
  76. packet.heading = heading;
  77. packet.throttle = throttle;
  78. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VFR_HUD_LEN);
  79. #endif
  80. msg->msgid = MAVLINK_MSG_ID_VFR_HUD;
  81. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  82. }
  83. /**
  84. * @brief Pack a vfr_hud 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 airspeed [m/s] Vehicle speed in form appropriate for vehicle type. For standard aircraft this is typically calibrated airspeed (CAS) or indicated airspeed (IAS) - either of which can be used by a pilot to estimate stall speed.
  90. * @param groundspeed [m/s] Current ground speed.
  91. * @param heading [deg] Current heading in compass units (0-360, 0=north).
  92. * @param throttle [%] Current throttle setting (0 to 100).
  93. * @param alt [m] Current altitude (MSL).
  94. * @param climb [m/s] Current climb rate.
  95. * @return length of the message in bytes (excluding serial stream start sign)
  96. */
  97. static inline uint16_t mavlink_msg_vfr_hud_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  98. mavlink_message_t* msg,
  99. float airspeed,float groundspeed,int16_t heading,uint16_t throttle,float alt,float climb)
  100. {
  101. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  102. char buf[MAVLINK_MSG_ID_VFR_HUD_LEN];
  103. _mav_put_float(buf, 0, airspeed);
  104. _mav_put_float(buf, 4, groundspeed);
  105. _mav_put_float(buf, 8, alt);
  106. _mav_put_float(buf, 12, climb);
  107. _mav_put_int16_t(buf, 16, heading);
  108. _mav_put_uint16_t(buf, 18, throttle);
  109. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VFR_HUD_LEN);
  110. #else
  111. mavlink_vfr_hud_t packet;
  112. packet.airspeed = airspeed;
  113. packet.groundspeed = groundspeed;
  114. packet.alt = alt;
  115. packet.climb = climb;
  116. packet.heading = heading;
  117. packet.throttle = throttle;
  118. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VFR_HUD_LEN);
  119. #endif
  120. msg->msgid = MAVLINK_MSG_ID_VFR_HUD;
  121. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  122. }
  123. /**
  124. * @brief Encode a vfr_hud struct
  125. *
  126. * @param system_id ID of this system
  127. * @param component_id ID of this component (e.g. 200 for IMU)
  128. * @param msg The MAVLink message to compress the data into
  129. * @param vfr_hud C-struct to read the message contents from
  130. */
  131. static inline uint16_t mavlink_msg_vfr_hud_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vfr_hud_t* vfr_hud)
  132. {
  133. return mavlink_msg_vfr_hud_pack(system_id, component_id, msg, vfr_hud->airspeed, vfr_hud->groundspeed, vfr_hud->heading, vfr_hud->throttle, vfr_hud->alt, vfr_hud->climb);
  134. }
  135. /**
  136. * @brief Encode a vfr_hud struct on a channel
  137. *
  138. * @param system_id ID of this system
  139. * @param component_id ID of this component (e.g. 200 for IMU)
  140. * @param chan The MAVLink channel this message will be sent over
  141. * @param msg The MAVLink message to compress the data into
  142. * @param vfr_hud C-struct to read the message contents from
  143. */
  144. static inline uint16_t mavlink_msg_vfr_hud_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_vfr_hud_t* vfr_hud)
  145. {
  146. return mavlink_msg_vfr_hud_pack_chan(system_id, component_id, chan, msg, vfr_hud->airspeed, vfr_hud->groundspeed, vfr_hud->heading, vfr_hud->throttle, vfr_hud->alt, vfr_hud->climb);
  147. }
  148. /**
  149. * @brief Send a vfr_hud message
  150. * @param chan MAVLink channel to send the message
  151. *
  152. * @param airspeed [m/s] Vehicle speed in form appropriate for vehicle type. For standard aircraft this is typically calibrated airspeed (CAS) or indicated airspeed (IAS) - either of which can be used by a pilot to estimate stall speed.
  153. * @param groundspeed [m/s] Current ground speed.
  154. * @param heading [deg] Current heading in compass units (0-360, 0=north).
  155. * @param throttle [%] Current throttle setting (0 to 100).
  156. * @param alt [m] Current altitude (MSL).
  157. * @param climb [m/s] Current climb rate.
  158. */
  159. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  160. static inline void mavlink_msg_vfr_hud_send(mavlink_channel_t chan, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb)
  161. {
  162. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  163. char buf[MAVLINK_MSG_ID_VFR_HUD_LEN];
  164. _mav_put_float(buf, 0, airspeed);
  165. _mav_put_float(buf, 4, groundspeed);
  166. _mav_put_float(buf, 8, alt);
  167. _mav_put_float(buf, 12, climb);
  168. _mav_put_int16_t(buf, 16, heading);
  169. _mav_put_uint16_t(buf, 18, throttle);
  170. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, buf, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  171. #else
  172. mavlink_vfr_hud_t packet;
  173. packet.airspeed = airspeed;
  174. packet.groundspeed = groundspeed;
  175. packet.alt = alt;
  176. packet.climb = climb;
  177. packet.heading = heading;
  178. packet.throttle = throttle;
  179. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, (const char *)&packet, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  180. #endif
  181. }
  182. /**
  183. * @brief Send a vfr_hud message
  184. * @param chan MAVLink channel to send the message
  185. * @param struct The MAVLink struct to serialize
  186. */
  187. static inline void mavlink_msg_vfr_hud_send_struct(mavlink_channel_t chan, const mavlink_vfr_hud_t* vfr_hud)
  188. {
  189. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  190. mavlink_msg_vfr_hud_send(chan, vfr_hud->airspeed, vfr_hud->groundspeed, vfr_hud->heading, vfr_hud->throttle, vfr_hud->alt, vfr_hud->climb);
  191. #else
  192. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, (const char *)vfr_hud, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  193. #endif
  194. }
  195. #if MAVLINK_MSG_ID_VFR_HUD_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  196. /*
  197. This variant of _send() can be used to save stack space by re-using
  198. memory from the receive buffer. The caller provides a
  199. mavlink_message_t which is the size of a full mavlink message. This
  200. is usually the receive buffer for the channel, and allows a reply to an
  201. incoming message with minimum stack space usage.
  202. */
  203. static inline void mavlink_msg_vfr_hud_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb)
  204. {
  205. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  206. char *buf = (char *)msgbuf;
  207. _mav_put_float(buf, 0, airspeed);
  208. _mav_put_float(buf, 4, groundspeed);
  209. _mav_put_float(buf, 8, alt);
  210. _mav_put_float(buf, 12, climb);
  211. _mav_put_int16_t(buf, 16, heading);
  212. _mav_put_uint16_t(buf, 18, throttle);
  213. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, buf, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  214. #else
  215. mavlink_vfr_hud_t *packet = (mavlink_vfr_hud_t *)msgbuf;
  216. packet->airspeed = airspeed;
  217. packet->groundspeed = groundspeed;
  218. packet->alt = alt;
  219. packet->climb = climb;
  220. packet->heading = heading;
  221. packet->throttle = throttle;
  222. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, (const char *)packet, MAVLINK_MSG_ID_VFR_HUD_MIN_LEN, MAVLINK_MSG_ID_VFR_HUD_LEN, MAVLINK_MSG_ID_VFR_HUD_CRC);
  223. #endif
  224. }
  225. #endif
  226. #endif
  227. // MESSAGE VFR_HUD UNPACKING
  228. /**
  229. * @brief Get field airspeed from vfr_hud message
  230. *
  231. * @return [m/s] Vehicle speed in form appropriate for vehicle type. For standard aircraft this is typically calibrated airspeed (CAS) or indicated airspeed (IAS) - either of which can be used by a pilot to estimate stall speed.
  232. */
  233. static inline float mavlink_msg_vfr_hud_get_airspeed(const mavlink_message_t* msg)
  234. {
  235. return _MAV_RETURN_float(msg, 0);
  236. }
  237. /**
  238. * @brief Get field groundspeed from vfr_hud message
  239. *
  240. * @return [m/s] Current ground speed.
  241. */
  242. static inline float mavlink_msg_vfr_hud_get_groundspeed(const mavlink_message_t* msg)
  243. {
  244. return _MAV_RETURN_float(msg, 4);
  245. }
  246. /**
  247. * @brief Get field heading from vfr_hud message
  248. *
  249. * @return [deg] Current heading in compass units (0-360, 0=north).
  250. */
  251. static inline int16_t mavlink_msg_vfr_hud_get_heading(const mavlink_message_t* msg)
  252. {
  253. return _MAV_RETURN_int16_t(msg, 16);
  254. }
  255. /**
  256. * @brief Get field throttle from vfr_hud message
  257. *
  258. * @return [%] Current throttle setting (0 to 100).
  259. */
  260. static inline uint16_t mavlink_msg_vfr_hud_get_throttle(const mavlink_message_t* msg)
  261. {
  262. return _MAV_RETURN_uint16_t(msg, 18);
  263. }
  264. /**
  265. * @brief Get field alt from vfr_hud message
  266. *
  267. * @return [m] Current altitude (MSL).
  268. */
  269. static inline float mavlink_msg_vfr_hud_get_alt(const mavlink_message_t* msg)
  270. {
  271. return _MAV_RETURN_float(msg, 8);
  272. }
  273. /**
  274. * @brief Get field climb from vfr_hud message
  275. *
  276. * @return [m/s] Current climb rate.
  277. */
  278. static inline float mavlink_msg_vfr_hud_get_climb(const mavlink_message_t* msg)
  279. {
  280. return _MAV_RETURN_float(msg, 12);
  281. }
  282. /**
  283. * @brief Decode a vfr_hud message into a struct
  284. *
  285. * @param msg The message to decode
  286. * @param vfr_hud C-struct to decode the message contents into
  287. */
  288. static inline void mavlink_msg_vfr_hud_decode(const mavlink_message_t* msg, mavlink_vfr_hud_t* vfr_hud)
  289. {
  290. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  291. vfr_hud->airspeed = mavlink_msg_vfr_hud_get_airspeed(msg);
  292. vfr_hud->groundspeed = mavlink_msg_vfr_hud_get_groundspeed(msg);
  293. vfr_hud->alt = mavlink_msg_vfr_hud_get_alt(msg);
  294. vfr_hud->climb = mavlink_msg_vfr_hud_get_climb(msg);
  295. vfr_hud->heading = mavlink_msg_vfr_hud_get_heading(msg);
  296. vfr_hud->throttle = mavlink_msg_vfr_hud_get_throttle(msg);
  297. #else
  298. uint8_t len = msg->len < MAVLINK_MSG_ID_VFR_HUD_LEN? msg->len : MAVLINK_MSG_ID_VFR_HUD_LEN;
  299. memset(vfr_hud, 0, MAVLINK_MSG_ID_VFR_HUD_LEN);
  300. memcpy(vfr_hud, _MAV_PAYLOAD(msg), len);
  301. #endif
  302. }