mavlink_msg_battery_status.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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
  136. * @param system_id ID of this system
  137. * @param component_id ID of this component (e.g. 200 for IMU)
  138. * @param status MAVLink status structure
  139. * @param msg The MAVLink message to compress the data into
  140. *
  141. * @param id Battery ID
  142. * @param battery_function Function of the battery
  143. * @param type Type (chemistry) of the battery
  144. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  145. * @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).
  146. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  147. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  148. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  149. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  150. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  151. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  152. * @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.
  153. * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
  154. * @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).
  155. * @return length of the message in bytes (excluding serial stream start sign)
  156. */
  157. static inline uint16_t mavlink_msg_battery_status_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, 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. #if MAVLINK_CRC_EXTRA
  197. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
  198. #else
  199. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  200. #endif
  201. }
  202. /**
  203. * @brief Pack a battery_status message on a channel
  204. * @param system_id ID of this system
  205. * @param component_id ID of this component (e.g. 200 for IMU)
  206. * @param chan The MAVLink channel this message will be sent over
  207. * @param msg The MAVLink message to compress the data into
  208. * @param id Battery ID
  209. * @param battery_function Function of the battery
  210. * @param type Type (chemistry) of the battery
  211. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  212. * @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).
  213. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  214. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  215. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  216. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  217. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  218. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  219. * @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.
  220. * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
  221. * @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).
  222. * @return length of the message in bytes (excluding serial stream start sign)
  223. */
  224. static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  225. mavlink_message_t* msg,
  226. 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)
  227. {
  228. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  229. char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
  230. _mav_put_int32_t(buf, 0, current_consumed);
  231. _mav_put_int32_t(buf, 4, energy_consumed);
  232. _mav_put_int16_t(buf, 8, temperature);
  233. _mav_put_int16_t(buf, 30, current_battery);
  234. _mav_put_uint8_t(buf, 32, id);
  235. _mav_put_uint8_t(buf, 33, battery_function);
  236. _mav_put_uint8_t(buf, 34, type);
  237. _mav_put_int8_t(buf, 35, battery_remaining);
  238. _mav_put_int32_t(buf, 36, time_remaining);
  239. _mav_put_uint8_t(buf, 40, charge_state);
  240. _mav_put_uint8_t(buf, 49, mode);
  241. _mav_put_uint32_t(buf, 50, fault_bitmask);
  242. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  243. _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
  244. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  245. #else
  246. mavlink_battery_status_t packet;
  247. packet.current_consumed = current_consumed;
  248. packet.energy_consumed = energy_consumed;
  249. packet.temperature = temperature;
  250. packet.current_battery = current_battery;
  251. packet.id = id;
  252. packet.battery_function = battery_function;
  253. packet.type = type;
  254. packet.battery_remaining = battery_remaining;
  255. packet.time_remaining = time_remaining;
  256. packet.charge_state = charge_state;
  257. packet.mode = mode;
  258. packet.fault_bitmask = fault_bitmask;
  259. mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
  260. mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
  261. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  262. #endif
  263. msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
  264. 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);
  265. }
  266. /**
  267. * @brief Encode a battery_status struct
  268. *
  269. * @param system_id ID of this system
  270. * @param component_id ID of this component (e.g. 200 for IMU)
  271. * @param msg The MAVLink message to compress the data into
  272. * @param battery_status C-struct to read the message contents from
  273. */
  274. 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)
  275. {
  276. 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);
  277. }
  278. /**
  279. * @brief Encode a battery_status struct on a channel
  280. *
  281. * @param system_id ID of this system
  282. * @param component_id ID of this component (e.g. 200 for IMU)
  283. * @param chan The MAVLink channel this message will be sent over
  284. * @param msg The MAVLink message to compress the data into
  285. * @param battery_status C-struct to read the message contents from
  286. */
  287. 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)
  288. {
  289. 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);
  290. }
  291. /**
  292. * @brief Encode a battery_status struct with provided status structure
  293. *
  294. * @param system_id ID of this system
  295. * @param component_id ID of this component (e.g. 200 for IMU)
  296. * @param status MAVLink status structure
  297. * @param msg The MAVLink message to compress the data into
  298. * @param battery_status C-struct to read the message contents from
  299. */
  300. static inline uint16_t mavlink_msg_battery_status_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_battery_status_t* battery_status)
  301. {
  302. return mavlink_msg_battery_status_pack_status(system_id, component_id, _status, 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);
  303. }
  304. /**
  305. * @brief Send a battery_status message
  306. * @param chan MAVLink channel to send the message
  307. *
  308. * @param id Battery ID
  309. * @param battery_function Function of the battery
  310. * @param type Type (chemistry) of the battery
  311. * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  312. * @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).
  313. * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
  314. * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  315. * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  316. * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  317. * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  318. * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
  319. * @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.
  320. * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
  321. * @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).
  322. */
  323. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  324. 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)
  325. {
  326. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  327. char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
  328. _mav_put_int32_t(buf, 0, current_consumed);
  329. _mav_put_int32_t(buf, 4, energy_consumed);
  330. _mav_put_int16_t(buf, 8, temperature);
  331. _mav_put_int16_t(buf, 30, current_battery);
  332. _mav_put_uint8_t(buf, 32, id);
  333. _mav_put_uint8_t(buf, 33, battery_function);
  334. _mav_put_uint8_t(buf, 34, type);
  335. _mav_put_int8_t(buf, 35, battery_remaining);
  336. _mav_put_int32_t(buf, 36, time_remaining);
  337. _mav_put_uint8_t(buf, 40, charge_state);
  338. _mav_put_uint8_t(buf, 49, mode);
  339. _mav_put_uint32_t(buf, 50, fault_bitmask);
  340. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  341. _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
  342. _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);
  343. #else
  344. mavlink_battery_status_t packet;
  345. packet.current_consumed = current_consumed;
  346. packet.energy_consumed = energy_consumed;
  347. packet.temperature = temperature;
  348. packet.current_battery = current_battery;
  349. packet.id = id;
  350. packet.battery_function = battery_function;
  351. packet.type = type;
  352. packet.battery_remaining = battery_remaining;
  353. packet.time_remaining = time_remaining;
  354. packet.charge_state = charge_state;
  355. packet.mode = mode;
  356. packet.fault_bitmask = fault_bitmask;
  357. mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
  358. mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
  359. _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);
  360. #endif
  361. }
  362. /**
  363. * @brief Send a battery_status message
  364. * @param chan MAVLink channel to send the message
  365. * @param struct The MAVLink struct to serialize
  366. */
  367. static inline void mavlink_msg_battery_status_send_struct(mavlink_channel_t chan, const mavlink_battery_status_t* battery_status)
  368. {
  369. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  370. 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);
  371. #else
  372. _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);
  373. #endif
  374. }
  375. #if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  376. /*
  377. This variant of _send() can be used to save stack space by re-using
  378. memory from the receive buffer. The caller provides a
  379. mavlink_message_t which is the size of a full mavlink message. This
  380. is usually the receive buffer for the channel, and allows a reply to an
  381. incoming message with minimum stack space usage.
  382. */
  383. 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)
  384. {
  385. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  386. char *buf = (char *)msgbuf;
  387. _mav_put_int32_t(buf, 0, current_consumed);
  388. _mav_put_int32_t(buf, 4, energy_consumed);
  389. _mav_put_int16_t(buf, 8, temperature);
  390. _mav_put_int16_t(buf, 30, current_battery);
  391. _mav_put_uint8_t(buf, 32, id);
  392. _mav_put_uint8_t(buf, 33, battery_function);
  393. _mav_put_uint8_t(buf, 34, type);
  394. _mav_put_int8_t(buf, 35, battery_remaining);
  395. _mav_put_int32_t(buf, 36, time_remaining);
  396. _mav_put_uint8_t(buf, 40, charge_state);
  397. _mav_put_uint8_t(buf, 49, mode);
  398. _mav_put_uint32_t(buf, 50, fault_bitmask);
  399. _mav_put_uint16_t_array(buf, 10, voltages, 10);
  400. _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
  401. _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);
  402. #else
  403. mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
  404. packet->current_consumed = current_consumed;
  405. packet->energy_consumed = energy_consumed;
  406. packet->temperature = temperature;
  407. packet->current_battery = current_battery;
  408. packet->id = id;
  409. packet->battery_function = battery_function;
  410. packet->type = type;
  411. packet->battery_remaining = battery_remaining;
  412. packet->time_remaining = time_remaining;
  413. packet->charge_state = charge_state;
  414. packet->mode = mode;
  415. packet->fault_bitmask = fault_bitmask;
  416. mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
  417. mav_array_memcpy(packet->voltages_ext, voltages_ext, sizeof(uint16_t)*4);
  418. _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);
  419. #endif
  420. }
  421. #endif
  422. #endif
  423. // MESSAGE BATTERY_STATUS UNPACKING
  424. /**
  425. * @brief Get field id from battery_status message
  426. *
  427. * @return Battery ID
  428. */
  429. static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
  430. {
  431. return _MAV_RETURN_uint8_t(msg, 32);
  432. }
  433. /**
  434. * @brief Get field battery_function from battery_status message
  435. *
  436. * @return Function of the battery
  437. */
  438. static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
  439. {
  440. return _MAV_RETURN_uint8_t(msg, 33);
  441. }
  442. /**
  443. * @brief Get field type from battery_status message
  444. *
  445. * @return Type (chemistry) of the battery
  446. */
  447. static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
  448. {
  449. return _MAV_RETURN_uint8_t(msg, 34);
  450. }
  451. /**
  452. * @brief Get field temperature from battery_status message
  453. *
  454. * @return [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
  455. */
  456. static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
  457. {
  458. return _MAV_RETURN_int16_t(msg, 8);
  459. }
  460. /**
  461. * @brief Get field voltages from battery_status message
  462. *
  463. * @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).
  464. */
  465. static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
  466. {
  467. return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
  468. }
  469. /**
  470. * @brief Get field current_battery from battery_status message
  471. *
  472. * @return [cA] Battery current, -1: autopilot does not measure the current
  473. */
  474. static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
  475. {
  476. return _MAV_RETURN_int16_t(msg, 30);
  477. }
  478. /**
  479. * @brief Get field current_consumed from battery_status message
  480. *
  481. * @return [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
  482. */
  483. static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
  484. {
  485. return _MAV_RETURN_int32_t(msg, 0);
  486. }
  487. /**
  488. * @brief Get field energy_consumed from battery_status message
  489. *
  490. * @return [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
  491. */
  492. static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
  493. {
  494. return _MAV_RETURN_int32_t(msg, 4);
  495. }
  496. /**
  497. * @brief Get field battery_remaining from battery_status message
  498. *
  499. * @return [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
  500. */
  501. static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
  502. {
  503. return _MAV_RETURN_int8_t(msg, 35);
  504. }
  505. /**
  506. * @brief Get field time_remaining from battery_status message
  507. *
  508. * @return [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
  509. */
  510. static inline int32_t mavlink_msg_battery_status_get_time_remaining(const mavlink_message_t* msg)
  511. {
  512. return _MAV_RETURN_int32_t(msg, 36);
  513. }
  514. /**
  515. * @brief Get field charge_state from battery_status message
  516. *
  517. * @return State for extent of discharge, provided by autopilot for warning or external reactions
  518. */
  519. static inline uint8_t mavlink_msg_battery_status_get_charge_state(const mavlink_message_t* msg)
  520. {
  521. return _MAV_RETURN_uint8_t(msg, 40);
  522. }
  523. /**
  524. * @brief Get field voltages_ext from battery_status message
  525. *
  526. * @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.
  527. */
  528. static inline uint16_t mavlink_msg_battery_status_get_voltages_ext(const mavlink_message_t* msg, uint16_t *voltages_ext)
  529. {
  530. return _MAV_RETURN_uint16_t_array(msg, voltages_ext, 4, 41);
  531. }
  532. /**
  533. * @brief Get field mode from battery_status message
  534. *
  535. * @return Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
  536. */
  537. static inline uint8_t mavlink_msg_battery_status_get_mode(const mavlink_message_t* msg)
  538. {
  539. return _MAV_RETURN_uint8_t(msg, 49);
  540. }
  541. /**
  542. * @brief Get field fault_bitmask from battery_status message
  543. *
  544. * @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).
  545. */
  546. static inline uint32_t mavlink_msg_battery_status_get_fault_bitmask(const mavlink_message_t* msg)
  547. {
  548. return _MAV_RETURN_uint32_t(msg, 50);
  549. }
  550. /**
  551. * @brief Decode a battery_status message into a struct
  552. *
  553. * @param msg The message to decode
  554. * @param battery_status C-struct to decode the message contents into
  555. */
  556. static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
  557. {
  558. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  559. battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
  560. battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
  561. battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
  562. mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
  563. battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
  564. battery_status->id = mavlink_msg_battery_status_get_id(msg);
  565. battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
  566. battery_status->type = mavlink_msg_battery_status_get_type(msg);
  567. battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
  568. battery_status->time_remaining = mavlink_msg_battery_status_get_time_remaining(msg);
  569. battery_status->charge_state = mavlink_msg_battery_status_get_charge_state(msg);
  570. mavlink_msg_battery_status_get_voltages_ext(msg, battery_status->voltages_ext);
  571. battery_status->mode = mavlink_msg_battery_status_get_mode(msg);
  572. battery_status->fault_bitmask = mavlink_msg_battery_status_get_fault_bitmask(msg);
  573. #else
  574. uint8_t len = msg->len < MAVLINK_MSG_ID_BATTERY_STATUS_LEN? msg->len : MAVLINK_MSG_ID_BATTERY_STATUS_LEN;
  575. memset(battery_status, 0, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
  576. memcpy(battery_status, _MAV_PAYLOAD(msg), len);
  577. #endif
  578. }