/libs/mavlink/include/mavlink/v1.0/common/mavlink_msg_battery_status.h

https://bitbucket.org/nikhil/qgc · C Header · 320 lines · 178 code · 33 blank · 109 comment · 3 complexity · e53ccb8616ad3c2866fd758d4114ae10 MD5 · raw file

  1. // MESSAGE BATTERY_STATUS PACKING
  2. #define MAVLINK_MSG_ID_BATTERY_STATUS 147
  3. typedef struct __mavlink_battery_status_t
  4. {
  5. uint16_t voltage_cell_1; ///< Battery voltage of cell 1, in millivolts (1 = 1 millivolt)
  6. uint16_t voltage_cell_2; ///< Battery voltage of cell 2, in millivolts (1 = 1 millivolt), -1: no cell
  7. uint16_t voltage_cell_3; ///< Battery voltage of cell 3, in millivolts (1 = 1 millivolt), -1: no cell
  8. uint16_t voltage_cell_4; ///< Battery voltage of cell 4, in millivolts (1 = 1 millivolt), -1: no cell
  9. uint16_t voltage_cell_5; ///< Battery voltage of cell 5, in millivolts (1 = 1 millivolt), -1: no cell
  10. uint16_t voltage_cell_6; ///< Battery voltage of cell 6, in millivolts (1 = 1 millivolt), -1: no cell
  11. int16_t current_battery; ///< Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
  12. uint8_t accu_id; ///< Accupack ID
  13. int8_t battery_remaining; ///< Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
  14. } mavlink_battery_status_t;
  15. #define MAVLINK_MSG_ID_BATTERY_STATUS_LEN 16
  16. #define MAVLINK_MSG_ID_147_LEN 16
  17. #define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
  18. "BATTERY_STATUS", \
  19. 9, \
  20. { { "voltage_cell_1", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_battery_status_t, voltage_cell_1) }, \
  21. { "voltage_cell_2", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_battery_status_t, voltage_cell_2) }, \
  22. { "voltage_cell_3", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_battery_status_t, voltage_cell_3) }, \
  23. { "voltage_cell_4", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_battery_status_t, voltage_cell_4) }, \
  24. { "voltage_cell_5", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_battery_status_t, voltage_cell_5) }, \
  25. { "voltage_cell_6", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_battery_status_t, voltage_cell_6) }, \
  26. { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_battery_status_t, current_battery) }, \
  27. { "accu_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 14, offsetof(mavlink_battery_status_t, accu_id) }, \
  28. { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 15, offsetof(mavlink_battery_status_t, battery_remaining) }, \
  29. } \
  30. }
  31. /**
  32. * @brief Pack a battery_status message
  33. * @param system_id ID of this system
  34. * @param component_id ID of this component (e.g. 200 for IMU)
  35. * @param msg The MAVLink message to compress the data into
  36. *
  37. * @param accu_id Accupack ID
  38. * @param voltage_cell_1 Battery voltage of cell 1, in millivolts (1 = 1 millivolt)
  39. * @param voltage_cell_2 Battery voltage of cell 2, in millivolts (1 = 1 millivolt), -1: no cell
  40. * @param voltage_cell_3 Battery voltage of cell 3, in millivolts (1 = 1 millivolt), -1: no cell
  41. * @param voltage_cell_4 Battery voltage of cell 4, in millivolts (1 = 1 millivolt), -1: no cell
  42. * @param voltage_cell_5 Battery voltage of cell 5, in millivolts (1 = 1 millivolt), -1: no cell
  43. * @param voltage_cell_6 Battery voltage of cell 6, in millivolts (1 = 1 millivolt), -1: no cell
  44. * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
  45. * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
  46. * @return length of the message in bytes (excluding serial stream start sign)
  47. */
  48. static inline uint16_t mavlink_msg_battery_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  49. uint8_t accu_id, uint16_t voltage_cell_1, uint16_t voltage_cell_2, uint16_t voltage_cell_3, uint16_t voltage_cell_4, uint16_t voltage_cell_5, uint16_t voltage_cell_6, int16_t current_battery, int8_t battery_remaining)
  50. {
  51. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  52. char buf[16];
  53. _mav_put_uint16_t(buf, 0, voltage_cell_1);
  54. _mav_put_uint16_t(buf, 2, voltage_cell_2);
  55. _mav_put_uint16_t(buf, 4, voltage_cell_3);
  56. _mav_put_uint16_t(buf, 6, voltage_cell_4);
  57. _mav_put_uint16_t(buf, 8, voltage_cell_5);
  58. _mav_put_uint16_t(buf, 10, voltage_cell_6);
  59. _mav_put_int16_t(buf, 12, current_battery);
  60. _mav_put_uint8_t(buf, 14, accu_id);
  61. _mav_put_int8_t(buf, 15, battery_remaining);
  62. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16);
  63. #else
  64. mavlink_battery_status_t packet;
  65. packet.voltage_cell_1 = voltage_cell_1;
  66. packet.voltage_cell_2 = voltage_cell_2;
  67. packet.voltage_cell_3 = voltage_cell_3;
  68. packet.voltage_cell_4 = voltage_cell_4;
  69. packet.voltage_cell_5 = voltage_cell_5;
  70. packet.voltage_cell_6 = voltage_cell_6;
  71. packet.current_battery = current_battery;
  72. packet.accu_id = accu_id;
  73. packet.battery_remaining = battery_remaining;
  74. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16);
  75. #endif
  76. msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
  77. return mavlink_finalize_message(msg, system_id, component_id, 16, 42);
  78. }
  79. /**
  80. * @brief Pack a battery_status message on a channel
  81. * @param system_id ID of this system
  82. * @param component_id ID of this component (e.g. 200 for IMU)
  83. * @param chan The MAVLink channel this message was sent over
  84. * @param msg The MAVLink message to compress the data into
  85. * @param accu_id Accupack ID
  86. * @param voltage_cell_1 Battery voltage of cell 1, in millivolts (1 = 1 millivolt)
  87. * @param voltage_cell_2 Battery voltage of cell 2, in millivolts (1 = 1 millivolt), -1: no cell
  88. * @param voltage_cell_3 Battery voltage of cell 3, in millivolts (1 = 1 millivolt), -1: no cell
  89. * @param voltage_cell_4 Battery voltage of cell 4, in millivolts (1 = 1 millivolt), -1: no cell
  90. * @param voltage_cell_5 Battery voltage of cell 5, in millivolts (1 = 1 millivolt), -1: no cell
  91. * @param voltage_cell_6 Battery voltage of cell 6, in millivolts (1 = 1 millivolt), -1: no cell
  92. * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
  93. * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
  94. * @return length of the message in bytes (excluding serial stream start sign)
  95. */
  96. static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  97. mavlink_message_t* msg,
  98. uint8_t accu_id,uint16_t voltage_cell_1,uint16_t voltage_cell_2,uint16_t voltage_cell_3,uint16_t voltage_cell_4,uint16_t voltage_cell_5,uint16_t voltage_cell_6,int16_t current_battery,int8_t battery_remaining)
  99. {
  100. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  101. char buf[16];
  102. _mav_put_uint16_t(buf, 0, voltage_cell_1);
  103. _mav_put_uint16_t(buf, 2, voltage_cell_2);
  104. _mav_put_uint16_t(buf, 4, voltage_cell_3);
  105. _mav_put_uint16_t(buf, 6, voltage_cell_4);
  106. _mav_put_uint16_t(buf, 8, voltage_cell_5);
  107. _mav_put_uint16_t(buf, 10, voltage_cell_6);
  108. _mav_put_int16_t(buf, 12, current_battery);
  109. _mav_put_uint8_t(buf, 14, accu_id);
  110. _mav_put_int8_t(buf, 15, battery_remaining);
  111. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16);
  112. #else
  113. mavlink_battery_status_t packet;
  114. packet.voltage_cell_1 = voltage_cell_1;
  115. packet.voltage_cell_2 = voltage_cell_2;
  116. packet.voltage_cell_3 = voltage_cell_3;
  117. packet.voltage_cell_4 = voltage_cell_4;
  118. packet.voltage_cell_5 = voltage_cell_5;
  119. packet.voltage_cell_6 = voltage_cell_6;
  120. packet.current_battery = current_battery;
  121. packet.accu_id = accu_id;
  122. packet.battery_remaining = battery_remaining;
  123. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16);
  124. #endif
  125. msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
  126. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16, 42);
  127. }
  128. /**
  129. * @brief Encode a battery_status struct into a message
  130. *
  131. * @param system_id ID of this system
  132. * @param component_id ID of this component (e.g. 200 for IMU)
  133. * @param msg The MAVLink message to compress the data into
  134. * @param battery_status C-struct to read the message contents from
  135. */
  136. static inline uint16_t mavlink_msg_battery_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_battery_status_t* battery_status)
  137. {
  138. return mavlink_msg_battery_status_pack(system_id, component_id, msg, battery_status->accu_id, battery_status->voltage_cell_1, battery_status->voltage_cell_2, battery_status->voltage_cell_3, battery_status->voltage_cell_4, battery_status->voltage_cell_5, battery_status->voltage_cell_6, battery_status->current_battery, battery_status->battery_remaining);
  139. }
  140. /**
  141. * @brief Send a battery_status message
  142. * @param chan MAVLink channel to send the message
  143. *
  144. * @param accu_id Accupack ID
  145. * @param voltage_cell_1 Battery voltage of cell 1, in millivolts (1 = 1 millivolt)
  146. * @param voltage_cell_2 Battery voltage of cell 2, in millivolts (1 = 1 millivolt), -1: no cell
  147. * @param voltage_cell_3 Battery voltage of cell 3, in millivolts (1 = 1 millivolt), -1: no cell
  148. * @param voltage_cell_4 Battery voltage of cell 4, in millivolts (1 = 1 millivolt), -1: no cell
  149. * @param voltage_cell_5 Battery voltage of cell 5, in millivolts (1 = 1 millivolt), -1: no cell
  150. * @param voltage_cell_6 Battery voltage of cell 6, in millivolts (1 = 1 millivolt), -1: no cell
  151. * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
  152. * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
  153. */
  154. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  155. static inline void mavlink_msg_battery_status_send(mavlink_channel_t chan, uint8_t accu_id, uint16_t voltage_cell_1, uint16_t voltage_cell_2, uint16_t voltage_cell_3, uint16_t voltage_cell_4, uint16_t voltage_cell_5, uint16_t voltage_cell_6, int16_t current_battery, int8_t battery_remaining)
  156. {
  157. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  158. char buf[16];
  159. _mav_put_uint16_t(buf, 0, voltage_cell_1);
  160. _mav_put_uint16_t(buf, 2, voltage_cell_2);
  161. _mav_put_uint16_t(buf, 4, voltage_cell_3);
  162. _mav_put_uint16_t(buf, 6, voltage_cell_4);
  163. _mav_put_uint16_t(buf, 8, voltage_cell_5);
  164. _mav_put_uint16_t(buf, 10, voltage_cell_6);
  165. _mav_put_int16_t(buf, 12, current_battery);
  166. _mav_put_uint8_t(buf, 14, accu_id);
  167. _mav_put_int8_t(buf, 15, battery_remaining);
  168. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, 16, 42);
  169. #else
  170. mavlink_battery_status_t packet;
  171. packet.voltage_cell_1 = voltage_cell_1;
  172. packet.voltage_cell_2 = voltage_cell_2;
  173. packet.voltage_cell_3 = voltage_cell_3;
  174. packet.voltage_cell_4 = voltage_cell_4;
  175. packet.voltage_cell_5 = voltage_cell_5;
  176. packet.voltage_cell_6 = voltage_cell_6;
  177. packet.current_battery = current_battery;
  178. packet.accu_id = accu_id;
  179. packet.battery_remaining = battery_remaining;
  180. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)&packet, 16, 42);
  181. #endif
  182. }
  183. #endif
  184. // MESSAGE BATTERY_STATUS UNPACKING
  185. /**
  186. * @brief Get field accu_id from battery_status message
  187. *
  188. * @return Accupack ID
  189. */
  190. static inline uint8_t mavlink_msg_battery_status_get_accu_id(const mavlink_message_t* msg)
  191. {
  192. return _MAV_RETURN_uint8_t(msg, 14);
  193. }
  194. /**
  195. * @brief Get field voltage_cell_1 from battery_status message
  196. *
  197. * @return Battery voltage of cell 1, in millivolts (1 = 1 millivolt)
  198. */
  199. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_1(const mavlink_message_t* msg)
  200. {
  201. return _MAV_RETURN_uint16_t(msg, 0);
  202. }
  203. /**
  204. * @brief Get field voltage_cell_2 from battery_status message
  205. *
  206. * @return Battery voltage of cell 2, in millivolts (1 = 1 millivolt), -1: no cell
  207. */
  208. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_2(const mavlink_message_t* msg)
  209. {
  210. return _MAV_RETURN_uint16_t(msg, 2);
  211. }
  212. /**
  213. * @brief Get field voltage_cell_3 from battery_status message
  214. *
  215. * @return Battery voltage of cell 3, in millivolts (1 = 1 millivolt), -1: no cell
  216. */
  217. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_3(const mavlink_message_t* msg)
  218. {
  219. return _MAV_RETURN_uint16_t(msg, 4);
  220. }
  221. /**
  222. * @brief Get field voltage_cell_4 from battery_status message
  223. *
  224. * @return Battery voltage of cell 4, in millivolts (1 = 1 millivolt), -1: no cell
  225. */
  226. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_4(const mavlink_message_t* msg)
  227. {
  228. return _MAV_RETURN_uint16_t(msg, 6);
  229. }
  230. /**
  231. * @brief Get field voltage_cell_5 from battery_status message
  232. *
  233. * @return Battery voltage of cell 5, in millivolts (1 = 1 millivolt), -1: no cell
  234. */
  235. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_5(const mavlink_message_t* msg)
  236. {
  237. return _MAV_RETURN_uint16_t(msg, 8);
  238. }
  239. /**
  240. * @brief Get field voltage_cell_6 from battery_status message
  241. *
  242. * @return Battery voltage of cell 6, in millivolts (1 = 1 millivolt), -1: no cell
  243. */
  244. static inline uint16_t mavlink_msg_battery_status_get_voltage_cell_6(const mavlink_message_t* msg)
  245. {
  246. return _MAV_RETURN_uint16_t(msg, 10);
  247. }
  248. /**
  249. * @brief Get field current_battery from battery_status message
  250. *
  251. * @return Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
  252. */
  253. static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
  254. {
  255. return _MAV_RETURN_int16_t(msg, 12);
  256. }
  257. /**
  258. * @brief Get field battery_remaining from battery_status message
  259. *
  260. * @return Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
  261. */
  262. static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
  263. {
  264. return _MAV_RETURN_int8_t(msg, 15);
  265. }
  266. /**
  267. * @brief Decode a battery_status message into a struct
  268. *
  269. * @param msg The message to decode
  270. * @param battery_status C-struct to decode the message contents into
  271. */
  272. static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
  273. {
  274. #if MAVLINK_NEED_BYTE_SWAP
  275. battery_status->voltage_cell_1 = mavlink_msg_battery_status_get_voltage_cell_1(msg);
  276. battery_status->voltage_cell_2 = mavlink_msg_battery_status_get_voltage_cell_2(msg);
  277. battery_status->voltage_cell_3 = mavlink_msg_battery_status_get_voltage_cell_3(msg);
  278. battery_status->voltage_cell_4 = mavlink_msg_battery_status_get_voltage_cell_4(msg);
  279. battery_status->voltage_cell_5 = mavlink_msg_battery_status_get_voltage_cell_5(msg);
  280. battery_status->voltage_cell_6 = mavlink_msg_battery_status_get_voltage_cell_6(msg);
  281. battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
  282. battery_status->accu_id = mavlink_msg_battery_status_get_accu_id(msg);
  283. battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
  284. #else
  285. memcpy(battery_status, _MAV_PAYLOAD(msg), 16);
  286. #endif
  287. }