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.

455 lines
23 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #pragma once
  2. // MESSAGE BATTERY_STATUS PACKING
  3. #define MAVLINK_MSG_ID_BATTERY_STATUS 147
  4. MAVPACKED(
  5. typedef struct __mavlink_battery_status_t {
  6. int32_t current_consumed; /*< [mAh] Consumed charge, -1: autopilot does not provide consumption estimate*/
  7. int32_t energy_consumed; /*< [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate*/
  8. int16_t temperature; /*< [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.*/
  9. uint16_t voltages[10]; /*< [mV] Battery voltage of cells. Cells above the valid cell count for this battery should have the UINT16_MAX value.*/
  10. int16_t current_battery; /*< [cA] Battery current, -1: autopilot does not measure the current*/
  11. uint8_t id; /*< Battery ID*/
  12. uint8_t battery_function; /*< Function of the battery*/
  13. uint8_t type; /*< Type (chemistry) of the battery*/
  14. int8_t battery_remaining; /*< [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.*/
  15. int32_t time_remaining; /*< [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate*/
  16. uint8_t charge_state; /*< State for extent of discharge, provided by autopilot for warning or external reactions*/
  17. }) mavlink_battery_status_t;
  18. #define MAVLINK_MSG_ID_BATTERY_STATUS_LEN 41
  19. #define MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN 36
  20. #define MAVLINK_MSG_ID_147_LEN 41
  21. #define MAVLINK_MSG_ID_147_MIN_LEN 36
  22. #define MAVLINK_MSG_ID_BATTERY_STATUS_CRC 154
  23. #define MAVLINK_MSG_ID_147_CRC 154
  24. #define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN 10
  25. #if MAVLINK_COMMAND_24BIT
  26. #define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
  27. 147, \
  28. "BATTERY_STATUS", \
  29. 11, \
  30. { { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_battery_status_t, id) }, \
  31. { "battery_function", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_battery_status_t, battery_function) }, \
  32. { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 34, offsetof(mavlink_battery_status_t, type) }, \
  33. { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) }, \
  34. { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) }, \
  35. { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) }, \
  36. { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) }, \
  37. { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) }, \
  38. { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) }, \
  39. { "time_remaining", NULL, MAVLINK_TYPE_INT32_T, 0, 36, offsetof(mavlink_battery_status_t, time_remaining) }, \
  40. { "charge_state", NULL, MAVLINK_TYPE_UINT8_T, 0, 40, offsetof(mavlink_battery_status_t, charge_state) }, \
  41. } \
  42. }
  43. #else
  44. #define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
  45. "BATTERY_STATUS", \
  46. 11, \
  47. { { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_battery_status_t, id) }, \
  48. { "battery_function", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_battery_status_t, battery_function) }, \
  49. { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 34, offsetof(mavlink_battery_status_t, type) }, \
  50. { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) }, \
  51. { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) }, \
  52. { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) }, \
  53. { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) }, \
  54. { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) }, \
  55. { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) }, \
  56. { "time_remaining", NULL, MAVLINK_TYPE_INT32_T, 0, 36, offsetof(mavlink_battery_status_t, time_remaining) }, \
  57. { "charge_state", NULL, MAVLINK_TYPE_UINT8_T, 0, 40, offsetof(mavlink_battery_status_t, charge_state) }, \
  58. } \
  59. }
  60. #endif
  61. /**
  62. * @brief Pack a battery_status message
  63. * @param system_id ID of this system
  64. * @param component_id ID of this component (e.g. 200 for IMU)
  65. * @param msg The MAVLink message to compress the data into
  66. *
  67. * @param id Battery ID
  68. * @param battery_function Function of the battery
  69. * @param type Type (chemistry) of the battery
  70. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  71. * @param voltages [mV] Battery voltage of cells. Cells above the valid cell count for this battery should have the UINT16_MAX value.
  72. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  73. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  74. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  75. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  76. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  77. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  78. * @return length of the message in bytes (excluding serial stream start sign)
  79. */
  80. static inline uint16_t mavlink_msg_battery_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  81. uint8_t id, uint8_t battery_function, uint8_t type, int16_t temperature, const uint16_t *voltages, int16_t current_battery, int32_t current_consumed, int32_t energy_consumed, int8_t battery_remaining, int32_t time_remaining, uint8_t charge_state)
  82. {
  83. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  84. char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
  85. _mav_put_int32_t(buf, 0, current_consumed);
  86. _mav_put_int32_t(buf, 4, energy_consumed);
  87. _mav_put_int16_t(buf, 8, temperature);
  88. _mav_put_int16_t(buf, 30, current_battery);
  89. _mav_put_uint8_t(buf, 32, id);
  90. _mav_put_uint8_t(buf, 33, battery_function);
  91. _mav_put_uint8_t(buf, 34, type);
  92. _mav_put_int8_t(buf, 35, battery_remaining);
  93. _mav_put_int32_t(buf, 36, time_remaining);
  94. _mav_put_uint8_t(buf, 40, charge_state);
  95. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  96. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  97. #else
  98. mavlink_battery_status_t packet;
  99. packet.current_consumed = current_consumed;
  100. packet.energy_consumed = energy_consumed;
  101. packet.temperature = temperature;
  102. packet.current_battery = current_battery;
  103. packet.id = id;
  104. packet.battery_function = battery_function;
  105. packet.type = type;
  106. packet.battery_remaining = battery_remaining;
  107. packet.time_remaining = time_remaining;
  108. packet.charge_state = charge_state;
  109. mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
  110. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  111. #endif
  112. msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
  113. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  114. }
  115. /**
  116. * @brief Pack a battery_status message on a channel
  117. * @param system_id ID of this system
  118. * @param component_id ID of this component (e.g. 200 for IMU)
  119. * @param chan The MAVLink channel this message will be sent over
  120. * @param msg The MAVLink message to compress the data into
  121. * @param id Battery ID
  122. * @param battery_function Function of the battery
  123. * @param type Type (chemistry) of the battery
  124. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  125. * @param voltages [mV] Battery voltage of cells. Cells above the valid cell count for this battery should have the UINT16_MAX value.
  126. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  127. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  128. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  129. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  130. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  131. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  132. * @return length of the message in bytes (excluding serial stream start sign)
  133. */
  134. static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  135. mavlink_message_t* msg,
  136. uint8_t id,uint8_t battery_function,uint8_t type,int16_t temperature,const uint16_t *voltages,int16_t current_battery,int32_t current_consumed,int32_t energy_consumed,int8_t battery_remaining,int32_t time_remaining,uint8_t charge_state)
  137. {
  138. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  139. char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
  140. _mav_put_int32_t(buf, 0, current_consumed);
  141. _mav_put_int32_t(buf, 4, energy_consumed);
  142. _mav_put_int16_t(buf, 8, temperature);
  143. _mav_put_int16_t(buf, 30, current_battery);
  144. _mav_put_uint8_t(buf, 32, id);
  145. _mav_put_uint8_t(buf, 33, battery_function);
  146. _mav_put_uint8_t(buf, 34, type);
  147. _mav_put_int8_t(buf, 35, battery_remaining);
  148. _mav_put_int32_t(buf, 36, time_remaining);
  149. _mav_put_uint8_t(buf, 40, charge_state);
  150. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  151. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  152. #else
  153. mavlink_battery_status_t packet;
  154. packet.current_consumed = current_consumed;
  155. packet.energy_consumed = energy_consumed;
  156. packet.temperature = temperature;
  157. packet.current_battery = current_battery;
  158. packet.id = id;
  159. packet.battery_function = battery_function;
  160. packet.type = type;
  161. packet.battery_remaining = battery_remaining;
  162. packet.time_remaining = time_remaining;
  163. packet.charge_state = charge_state;
  164. mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
  165. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  166. #endif
  167. msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
  168. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  169. }
  170. /**
  171. * @brief Encode a battery_status struct
  172. *
  173. * @param system_id ID of this system
  174. * @param component_id ID of this component (e.g. 200 for IMU)
  175. * @param msg The MAVLink message to compress the data into
  176. * @param battery_status C-struct to read the message contents from
  177. */
  178. 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)
  179. {
  180. return mavlink_msg_battery_status_pack(system_id, component_id, msg, battery_status->id, battery_status->battery_function, battery_status->type, battery_status->temperature, battery_status->voltages, battery_status->current_battery, battery_status->current_consumed, battery_status->energy_consumed, battery_status->battery_remaining, battery_status->time_remaining, battery_status->charge_state);
  181. }
  182. /**
  183. * @brief Encode a battery_status struct on a channel
  184. *
  185. * @param system_id ID of this system
  186. * @param component_id ID of this component (e.g. 200 for IMU)
  187. * @param chan The MAVLink channel this message will be sent over
  188. * @param msg The MAVLink message to compress the data into
  189. * @param battery_status C-struct to read the message contents from
  190. */
  191. static inline uint16_t mavlink_msg_battery_status_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_battery_status_t* battery_status)
  192. {
  193. return mavlink_msg_battery_status_pack_chan(system_id, component_id, chan, msg, battery_status->id, battery_status->battery_function, battery_status->type, battery_status->temperature, battery_status->voltages, battery_status->current_battery, battery_status->current_consumed, battery_status->energy_consumed, battery_status->battery_remaining, battery_status->time_remaining, battery_status->charge_state);
  194. }
  195. /**
  196. * @brief Send a battery_status message
  197. * @param chan MAVLink channel to send the message
  198. *
  199. * @param id Battery ID
  200. * @param battery_function Function of the battery
  201. * @param type Type (chemistry) of the battery
  202. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  203. * @param voltages [mV] Battery voltage of cells. Cells above the valid cell count for this battery should have the UINT16_MAX value.
  204. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  205. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  206. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  207. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  208. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  209. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  210. */
  211. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  212. static inline void mavlink_msg_battery_status_send(mavlink_channel_t chan, uint8_t id, uint8_t battery_function, uint8_t type, int16_t temperature, const uint16_t *voltages, int16_t current_battery, int32_t current_consumed, int32_t energy_consumed, int8_t battery_remaining, int32_t time_remaining, uint8_t charge_state)
  213. {
  214. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  215. char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
  216. _mav_put_int32_t(buf, 0, current_consumed);
  217. _mav_put_int32_t(buf, 4, energy_consumed);
  218. _mav_put_int16_t(buf, 8, temperature);
  219. _mav_put_int16_t(buf, 30, current_battery);
  220. _mav_put_uint8_t(buf, 32, id);
  221. _mav_put_uint8_t(buf, 33, battery_function);
  222. _mav_put_uint8_t(buf, 34, type);
  223. _mav_put_int8_t(buf, 35, battery_remaining);
  224. _mav_put_int32_t(buf, 36, time_remaining);
  225. _mav_put_uint8_t(buf, 40, charge_state);
  226. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  227. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  228. #else
  229. mavlink_battery_status_t packet;
  230. packet.current_consumed = current_consumed;
  231. packet.energy_consumed = energy_consumed;
  232. packet.temperature = temperature;
  233. packet.current_battery = current_battery;
  234. packet.id = id;
  235. packet.battery_function = battery_function;
  236. packet.type = type;
  237. packet.battery_remaining = battery_remaining;
  238. packet.time_remaining = time_remaining;
  239. packet.charge_state = charge_state;
  240. mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
  241. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)&packet, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  242. #endif
  243. }
  244. /**
  245. * @brief Send a battery_status message
  246. * @param chan MAVLink channel to send the message
  247. * @param struct The MAVLink struct to serialize
  248. */
  249. static inline void mavlink_msg_battery_status_send_struct(mavlink_channel_t chan, const mavlink_battery_status_t* battery_status)
  250. {
  251. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  252. mavlink_msg_battery_status_send(chan, battery_status->id, battery_status->battery_function, battery_status->type, battery_status->temperature, battery_status->voltages, battery_status->current_battery, battery_status->current_consumed, battery_status->energy_consumed, battery_status->battery_remaining, battery_status->time_remaining, battery_status->charge_state);
  253. #else
  254. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)battery_status, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  255. #endif
  256. }
  257. #if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  258. /*
  259. This varient of _send() can be used to save stack space by re-using
  260. memory from the receive buffer. The caller provides a
  261. mavlink_message_t which is the size of a full mavlink message. This
  262. is usually the receive buffer for the channel, and allows a reply to an
  263. incoming message with minimum stack space usage.
  264. */
  265. static inline void mavlink_msg_battery_status_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t id, uint8_t battery_function, uint8_t type, int16_t temperature, const uint16_t *voltages, int16_t current_battery, int32_t current_consumed, int32_t energy_consumed, int8_t battery_remaining, int32_t time_remaining, uint8_t charge_state)
  266. {
  267. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  268. char *buf = (char *)msgbuf;
  269. _mav_put_int32_t(buf, 0, current_consumed);
  270. _mav_put_int32_t(buf, 4, energy_consumed);
  271. _mav_put_int16_t(buf, 8, temperature);
  272. _mav_put_int16_t(buf, 30, current_battery);
  273. _mav_put_uint8_t(buf, 32, id);
  274. _mav_put_uint8_t(buf, 33, battery_function);
  275. _mav_put_uint8_t(buf, 34, type);
  276. _mav_put_int8_t(buf, 35, battery_remaining);
  277. _mav_put_int32_t(buf, 36, time_remaining);
  278. _mav_put_uint8_t(buf, 40, charge_state);
  279. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  280. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  281. #else
  282. mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
  283. packet->current_consumed = current_consumed;
  284. packet->energy_consumed = energy_consumed;
  285. packet->temperature = temperature;
  286. packet->current_battery = current_battery;
  287. packet->id = id;
  288. packet->battery_function = battery_function;
  289. packet->type = type;
  290. packet->battery_remaining = battery_remaining;
  291. packet->time_remaining = time_remaining;
  292. packet->charge_state = charge_state;
  293. mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
  294. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)packet, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  295. #endif
  296. }
  297. #endif
  298. #endif
  299. // MESSAGE BATTERY_STATUS UNPACKING
  300. /**
  301. * @brief Get field id from battery_status message
  302. *
  303. * @return Battery ID
  304. */
  305. static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
  306. {
  307. return _MAV_RETURN_uint8_t(msg, 32);
  308. }
  309. /**
  310. * @brief Get field battery_function from battery_status message
  311. *
  312. * @return Function of the battery
  313. */
  314. static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
  315. {
  316. return _MAV_RETURN_uint8_t(msg, 33);
  317. }
  318. /**
  319. * @brief Get field type from battery_status message
  320. *
  321. * @return Type (chemistry) of the battery
  322. */
  323. static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
  324. {
  325. return _MAV_RETURN_uint8_t(msg, 34);
  326. }
  327. /**
  328. * @brief Get field temperature from battery_status message
  329. *
  330. * @return [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  331. */
  332. static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
  333. {
  334. return _MAV_RETURN_int16_t(msg, 8);
  335. }
  336. /**
  337. * @brief Get field voltages from battery_status message
  338. *
  339. * @return [mV] Battery voltage of cells. Cells above the valid cell count for this battery should have the UINT16_MAX value.
  340. */
  341. static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
  342. {
  343. return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
  344. }
  345. /**
  346. * @brief Get field current_battery from battery_status message
  347. *
  348. * @return [cA] Battery current, -1: autopilot does not measure the current
  349. */
  350. static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
  351. {
  352. return _MAV_RETURN_int16_t(msg, 30);
  353. }
  354. /**
  355. * @brief Get field current_consumed from battery_status message
  356. *
  357. * @return [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  358. */
  359. static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
  360. {
  361. return _MAV_RETURN_int32_t(msg, 0);
  362. }
  363. /**
  364. * @brief Get field energy_consumed from battery_status message
  365. *
  366. * @return [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  367. */
  368. static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
  369. {
  370. return _MAV_RETURN_int32_t(msg, 4);
  371. }
  372. /**
  373. * @brief Get field battery_remaining from battery_status message
  374. *
  375. * @return [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  376. */
  377. static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
  378. {
  379. return _MAV_RETURN_int8_t(msg, 35);
  380. }
  381. /**
  382. * @brief Get field time_remaining from battery_status message
  383. *
  384. * @return [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  385. */
  386. static inline int32_t mavlink_msg_battery_status_get_time_remaining(const mavlink_message_t* msg)
  387. {
  388. return _MAV_RETURN_int32_t(msg, 36);
  389. }
  390. /**
  391. * @brief Get field charge_state from battery_status message
  392. *
  393. * @return State for extent of discharge, provided by autopilot for warning or external reactions
  394. */
  395. static inline uint8_t mavlink_msg_battery_status_get_charge_state(const mavlink_message_t* msg)
  396. {
  397. return _MAV_RETURN_uint8_t(msg, 40);
  398. }
  399. /**
  400. * @brief Decode a battery_status message into a struct
  401. *
  402. * @param msg The message to decode
  403. * @param battery_status C-struct to decode the message contents into
  404. */
  405. static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
  406. {
  407. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  408. battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
  409. battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
  410. battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
  411. mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
  412. battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
  413. battery_status->id = mavlink_msg_battery_status_get_id(msg);
  414. battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
  415. battery_status->type = mavlink_msg_battery_status_get_type(msg);
  416. battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
  417. battery_status->time_remaining = mavlink_msg_battery_status_get_time_remaining(msg);
  418. battery_status->charge_state = mavlink_msg_battery_status_get_charge_state(msg);
  419. #else
  420. uint8_t len = msg->len < MAVLINK_MSG_ID_BATTERY_STATUS_LEN? msg->len : MAVLINK_MSG_ID_BATTERY_STATUS_LEN;
  421. memset(battery_status, 0, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  422. memcpy(battery_status, _MAV_PAYLOAD(msg), len);
  423. #endif
  424. }