mavlink_msg_battery_status.h 32 KB

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