Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_battery_status.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE BATTERY_STATUS PACKING
3
4#define MAVLINK_MSG_ID_BATTERY_STATUS 147
5
6MAVPACKED(
7typedef struct __mavlink_battery_status_t {
8 int32_t current_consumed; /*< [mAh] Consumed charge, -1: autopilot does not provide consumption estimate*/
9 int32_t energy_consumed; /*< [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate*/
10 int16_t temperature; /*< [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.*/
11 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).*/
12 int16_t current_battery; /*< [cA] Battery current, -1: autopilot does not measure the current*/
13 uint8_t id; /*< Battery ID*/
14 uint8_t battery_function; /*< Function of the battery*/
15 uint8_t type; /*< Type (chemistry) of the battery*/
16 int8_t battery_remaining; /*< [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.*/
17 int32_t time_remaining; /*< [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate*/
18 uint8_t charge_state; /*< State for extent of discharge, provided by autopilot for warning or external reactions*/
19 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.*/
20 uint8_t mode; /*< Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.*/
21 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).*/
22}) mavlink_battery_status_t;
23
24#define MAVLINK_MSG_ID_BATTERY_STATUS_LEN 54
25#define MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN 36
26#define MAVLINK_MSG_ID_147_LEN 54
27#define MAVLINK_MSG_ID_147_MIN_LEN 36
28
29#define MAVLINK_MSG_ID_BATTERY_STATUS_CRC 154
30#define MAVLINK_MSG_ID_147_CRC 154
31
32#define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN 10
33#define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_EXT_LEN 4
34
35#if MAVLINK_COMMAND_24BIT
36#define MAVLINK_MESSAGE_INFO_BATTERY_STATUS {
37 147,
38 "BATTERY_STATUS",
39 14,
40 { { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_battery_status_t, id) },
41 { "battery_function", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_battery_status_t, battery_function) },
42 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 34, offsetof(mavlink_battery_status_t, type) },
43 { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) },
44 { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) },
45 { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) },
46 { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) },
47 { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) },
48 { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) },
49 { "time_remaining", NULL, MAVLINK_TYPE_INT32_T, 0, 36, offsetof(mavlink_battery_status_t, time_remaining) },
50 { "charge_state", NULL, MAVLINK_TYPE_UINT8_T, 0, 40, offsetof(mavlink_battery_status_t, charge_state) },
51 { "voltages_ext", NULL, MAVLINK_TYPE_UINT16_T, 4, 41, offsetof(mavlink_battery_status_t, voltages_ext) },
52 { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 49, offsetof(mavlink_battery_status_t, mode) },
53 { "fault_bitmask", NULL, MAVLINK_TYPE_UINT32_T, 0, 50, offsetof(mavlink_battery_status_t, fault_bitmask) },
54 } \
55}
56#else
57#define MAVLINK_MESSAGE_INFO_BATTERY_STATUS {
58 "BATTERY_STATUS",
59 14,
60 { { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_battery_status_t, id) },
61 { "battery_function", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_battery_status_t, battery_function) },
62 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 34, offsetof(mavlink_battery_status_t, type) },
63 { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) },
64 { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) },
65 { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) },
66 { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) },
67 { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) },
68 { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) },
69 { "time_remaining", NULL, MAVLINK_TYPE_INT32_T, 0, 36, offsetof(mavlink_battery_status_t, time_remaining) },
70 { "charge_state", NULL, MAVLINK_TYPE_UINT8_T, 0, 40, offsetof(mavlink_battery_status_t, charge_state) },
71 { "voltages_ext", NULL, MAVLINK_TYPE_UINT16_T, 4, 41, offsetof(mavlink_battery_status_t, voltages_ext) },
72 { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 49, offsetof(mavlink_battery_status_t, mode) },
73 { "fault_bitmask", NULL, MAVLINK_TYPE_UINT32_T, 0, 50, offsetof(mavlink_battery_status_t, fault_bitmask) },
74 } \
75}
76#endif
77
78/**
79 * @brief Pack a battery_status message
80 * @param system_id ID of this system
81 * @param component_id ID of this component (e.g. 200 for IMU)
82 * @param msg The MAVLink message to compress the data into
83 *
84 * @param id Battery ID
85 * @param battery_function Function of the battery
86 * @param type Type (chemistry) of the battery
87 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
88 * @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).
89 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
90 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
91 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
92 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
93 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
94 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
95 * @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.
96 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
97 * @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).
98 * @return length of the message in bytes (excluding serial stream start sign)
99 */
100static inline uint16_t mavlink_msg_battery_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
101 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)
102{
103#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
105 _mav_put_int32_t(buf, 0, current_consumed);
106 _mav_put_int32_t(buf, 4, energy_consumed);
107 _mav_put_int16_t(buf, 8, temperature);
108 _mav_put_int16_t(buf, 30, current_battery);
109 _mav_put_uint8_t(buf, 32, id);
110 _mav_put_uint8_t(buf, 33, battery_function);
111 _mav_put_uint8_t(buf, 34, type);
112 _mav_put_int8_t(buf, 35, battery_remaining);
113 _mav_put_int32_t(buf, 36, time_remaining);
114 _mav_put_uint8_t(buf, 40, charge_state);
115 _mav_put_uint8_t(buf, 49, mode);
116 _mav_put_uint32_t(buf, 50, fault_bitmask);
117 _mav_put_uint16_t_array(buf, 10, voltages, 10);
118 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
119 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
120#else
121 mavlink_battery_status_t packet;
122 packet.current_consumed = current_consumed;
123 packet.energy_consumed = energy_consumed;
124 packet.temperature = temperature;
125 packet.current_battery = current_battery;
126 packet.id = id;
127 packet.battery_function = battery_function;
128 packet.type = type;
129 packet.battery_remaining = battery_remaining;
130 packet.time_remaining = time_remaining;
131 packet.charge_state = charge_state;
132 packet.mode = mode;
133 packet.fault_bitmask = fault_bitmask;
134 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
135 mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
136 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
137#endif
138
140 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);
141}
142
143/**
144 * @brief Pack a battery_status message
145 * @param system_id ID of this system
146 * @param component_id ID of this component (e.g. 200 for IMU)
147 * @param status MAVLink status structure
148 * @param msg The MAVLink message to compress the data into
149 *
150 * @param id Battery ID
151 * @param battery_function Function of the battery
152 * @param type Type (chemistry) of the battery
153 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
154 * @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).
155 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
156 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
157 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
158 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
159 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
160 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
161 * @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.
162 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
163 * @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).
164 * @return length of the message in bytes (excluding serial stream start sign)
165 */
166static 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,
167 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)
168{
169#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
171 _mav_put_int32_t(buf, 0, current_consumed);
172 _mav_put_int32_t(buf, 4, energy_consumed);
173 _mav_put_int16_t(buf, 8, temperature);
174 _mav_put_int16_t(buf, 30, current_battery);
175 _mav_put_uint8_t(buf, 32, id);
176 _mav_put_uint8_t(buf, 33, battery_function);
177 _mav_put_uint8_t(buf, 34, type);
178 _mav_put_int8_t(buf, 35, battery_remaining);
179 _mav_put_int32_t(buf, 36, time_remaining);
180 _mav_put_uint8_t(buf, 40, charge_state);
181 _mav_put_uint8_t(buf, 49, mode);
182 _mav_put_uint32_t(buf, 50, fault_bitmask);
183 _mav_put_uint16_t_array(buf, 10, voltages, 10);
184 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
185 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
186#else
187 mavlink_battery_status_t packet;
188 packet.current_consumed = current_consumed;
189 packet.energy_consumed = energy_consumed;
190 packet.temperature = temperature;
191 packet.current_battery = current_battery;
192 packet.id = id;
193 packet.battery_function = battery_function;
194 packet.type = type;
195 packet.battery_remaining = battery_remaining;
196 packet.time_remaining = time_remaining;
197 packet.charge_state = charge_state;
198 packet.mode = mode;
199 packet.fault_bitmask = fault_bitmask;
200 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
201 mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
202 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
203#endif
204
206#if MAVLINK_CRC_EXTRA
207 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);
208#else
209 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
210#endif
211}
212
213/**
214 * @brief Pack a battery_status message on a channel
215 * @param system_id ID of this system
216 * @param component_id ID of this component (e.g. 200 for IMU)
217 * @param chan The MAVLink channel this message will be sent over
218 * @param msg The MAVLink message to compress the data into
219 * @param id Battery ID
220 * @param battery_function Function of the battery
221 * @param type Type (chemistry) of the battery
222 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
223 * @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).
224 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
225 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
226 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
227 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
228 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
229 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
230 * @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.
231 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
232 * @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).
233 * @return length of the message in bytes (excluding serial stream start sign)
234 */
235static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
236 mavlink_message_t* msg,
237 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)
238{
239#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
241 _mav_put_int32_t(buf, 0, current_consumed);
242 _mav_put_int32_t(buf, 4, energy_consumed);
243 _mav_put_int16_t(buf, 8, temperature);
244 _mav_put_int16_t(buf, 30, current_battery);
245 _mav_put_uint8_t(buf, 32, id);
246 _mav_put_uint8_t(buf, 33, battery_function);
247 _mav_put_uint8_t(buf, 34, type);
248 _mav_put_int8_t(buf, 35, battery_remaining);
249 _mav_put_int32_t(buf, 36, time_remaining);
250 _mav_put_uint8_t(buf, 40, charge_state);
251 _mav_put_uint8_t(buf, 49, mode);
252 _mav_put_uint32_t(buf, 50, fault_bitmask);
253 _mav_put_uint16_t_array(buf, 10, voltages, 10);
254 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
255 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
256#else
257 mavlink_battery_status_t packet;
258 packet.current_consumed = current_consumed;
259 packet.energy_consumed = energy_consumed;
260 packet.temperature = temperature;
261 packet.current_battery = current_battery;
262 packet.id = id;
263 packet.battery_function = battery_function;
264 packet.type = type;
265 packet.battery_remaining = battery_remaining;
266 packet.time_remaining = time_remaining;
267 packet.charge_state = charge_state;
268 packet.mode = mode;
269 packet.fault_bitmask = fault_bitmask;
270 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
271 mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
272 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
273#endif
274
276 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);
277}
278
279/**
280 * @brief Encode a battery_status struct
281 *
282 * @param system_id ID of this system
283 * @param component_id ID of this component (e.g. 200 for IMU)
284 * @param msg The MAVLink message to compress the data into
285 * @param battery_status C-struct to read the message contents from
286 */
287static 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)
288{
289 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);
290}
291
292/**
293 * @brief Encode a battery_status struct on a channel
294 *
295 * @param system_id ID of this system
296 * @param component_id ID of this component (e.g. 200 for IMU)
297 * @param chan The MAVLink channel this message will be sent over
298 * @param msg The MAVLink message to compress the data into
299 * @param battery_status C-struct to read the message contents from
300 */
301static 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)
302{
303 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);
304}
305
306/**
307 * @brief Encode a battery_status struct with provided status structure
308 *
309 * @param system_id ID of this system
310 * @param component_id ID of this component (e.g. 200 for IMU)
311 * @param status MAVLink status structure
312 * @param msg The MAVLink message to compress the data into
313 * @param battery_status C-struct to read the message contents from
314 */
315static 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)
316{
317 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);
318}
319
320/**
321 * @brief Send a battery_status message
322 * @param chan MAVLink channel to send the message
323 *
324 * @param id Battery ID
325 * @param battery_function Function of the battery
326 * @param type Type (chemistry) of the battery
327 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
328 * @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).
329 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
330 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
331 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
332 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
333 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
334 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
335 * @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.
336 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
337 * @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).
338 */
339#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
340
341static 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)
342{
343#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
344 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
345 _mav_put_int32_t(buf, 0, current_consumed);
346 _mav_put_int32_t(buf, 4, energy_consumed);
347 _mav_put_int16_t(buf, 8, temperature);
348 _mav_put_int16_t(buf, 30, current_battery);
349 _mav_put_uint8_t(buf, 32, id);
350 _mav_put_uint8_t(buf, 33, battery_function);
351 _mav_put_uint8_t(buf, 34, type);
352 _mav_put_int8_t(buf, 35, battery_remaining);
353 _mav_put_int32_t(buf, 36, time_remaining);
354 _mav_put_uint8_t(buf, 40, charge_state);
355 _mav_put_uint8_t(buf, 49, mode);
356 _mav_put_uint32_t(buf, 50, fault_bitmask);
357 _mav_put_uint16_t_array(buf, 10, voltages, 10);
358 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
359 _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);
360#else
361 mavlink_battery_status_t packet;
362 packet.current_consumed = current_consumed;
363 packet.energy_consumed = energy_consumed;
364 packet.temperature = temperature;
365 packet.current_battery = current_battery;
366 packet.id = id;
367 packet.battery_function = battery_function;
368 packet.type = type;
369 packet.battery_remaining = battery_remaining;
370 packet.time_remaining = time_remaining;
371 packet.charge_state = charge_state;
372 packet.mode = mode;
373 packet.fault_bitmask = fault_bitmask;
374 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
375 mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
376 _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);
377#endif
378}
379
380/**
381 * @brief Send a battery_status message
382 * @param chan MAVLink channel to send the message
383 * @param struct The MAVLink struct to serialize
384 */
385static inline void mavlink_msg_battery_status_send_struct(mavlink_channel_t chan, const mavlink_battery_status_t* battery_status)
386{
387#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
388 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);
389#else
390 _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);
391#endif
392}
393
394#if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
395/*
396 This variant of _send() can be used to save stack space by reusing
397 memory from the receive buffer. The caller provides a
398 mavlink_message_t which is the size of a full mavlink message. This
399 is usually the receive buffer for the channel, and allows a reply to an
400 incoming message with minimum stack space usage.
401 */
402static 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)
403{
404#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
405 char *buf = (char *)msgbuf;
406 _mav_put_int32_t(buf, 0, current_consumed);
407 _mav_put_int32_t(buf, 4, energy_consumed);
408 _mav_put_int16_t(buf, 8, temperature);
409 _mav_put_int16_t(buf, 30, current_battery);
410 _mav_put_uint8_t(buf, 32, id);
411 _mav_put_uint8_t(buf, 33, battery_function);
412 _mav_put_uint8_t(buf, 34, type);
413 _mav_put_int8_t(buf, 35, battery_remaining);
414 _mav_put_int32_t(buf, 36, time_remaining);
415 _mav_put_uint8_t(buf, 40, charge_state);
416 _mav_put_uint8_t(buf, 49, mode);
417 _mav_put_uint32_t(buf, 50, fault_bitmask);
418 _mav_put_uint16_t_array(buf, 10, voltages, 10);
419 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
420 _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);
421#else
422 mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
423 packet->current_consumed = current_consumed;
424 packet->energy_consumed = energy_consumed;
425 packet->temperature = temperature;
426 packet->current_battery = current_battery;
427 packet->id = id;
428 packet->battery_function = battery_function;
429 packet->type = type;
430 packet->battery_remaining = battery_remaining;
431 packet->time_remaining = time_remaining;
432 packet->charge_state = charge_state;
433 packet->mode = mode;
434 packet->fault_bitmask = fault_bitmask;
435 mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
436 mav_array_memcpy(packet->voltages_ext, voltages_ext, sizeof(uint16_t)*4);
437 _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);
438#endif
439}
440#endif
441
442#endif
443
444// MESSAGE BATTERY_STATUS UNPACKING
445
446
447/**
448 * @brief Get field id from battery_status message
449 *
450 * @return Battery ID
451 */
452static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
453{
454 return _MAV_RETURN_uint8_t(msg, 32);
455}
456
457/**
458 * @brief Get field battery_function from battery_status message
459 *
460 * @return Function of the battery
461 */
462static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
463{
464 return _MAV_RETURN_uint8_t(msg, 33);
465}
466
467/**
468 * @brief Get field type from battery_status message
469 *
470 * @return Type (chemistry) of the battery
471 */
472static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
473{
474 return _MAV_RETURN_uint8_t(msg, 34);
475}
476
477/**
478 * @brief Get field temperature from battery_status message
479 *
480 * @return [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
481 */
482static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
483{
484 return _MAV_RETURN_int16_t(msg, 8);
485}
486
487/**
488 * @brief Get field voltages from battery_status message
489 *
490 * @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).
491 */
492static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
493{
494 return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
495}
496
497/**
498 * @brief Get field current_battery from battery_status message
499 *
500 * @return [cA] Battery current, -1: autopilot does not measure the current
501 */
502static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
503{
504 return _MAV_RETURN_int16_t(msg, 30);
505}
506
507/**
508 * @brief Get field current_consumed from battery_status message
509 *
510 * @return [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
511 */
512static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
513{
514 return _MAV_RETURN_int32_t(msg, 0);
515}
516
517/**
518 * @brief Get field energy_consumed from battery_status message
519 *
520 * @return [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
521 */
522static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
523{
524 return _MAV_RETURN_int32_t(msg, 4);
525}
526
527/**
528 * @brief Get field battery_remaining from battery_status message
529 *
530 * @return [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
531 */
532static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
533{
534 return _MAV_RETURN_int8_t(msg, 35);
535}
536
537/**
538 * @brief Get field time_remaining from battery_status message
539 *
540 * @return [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
541 */
542static inline int32_t mavlink_msg_battery_status_get_time_remaining(const mavlink_message_t* msg)
543{
544 return _MAV_RETURN_int32_t(msg, 36);
545}
546
547/**
548 * @brief Get field charge_state from battery_status message
549 *
550 * @return State for extent of discharge, provided by autopilot for warning or external reactions
551 */
552static inline uint8_t mavlink_msg_battery_status_get_charge_state(const mavlink_message_t* msg)
553{
554 return _MAV_RETURN_uint8_t(msg, 40);
555}
556
557/**
558 * @brief Get field voltages_ext from battery_status message
559 *
560 * @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.
561 */
562static inline uint16_t mavlink_msg_battery_status_get_voltages_ext(const mavlink_message_t* msg, uint16_t *voltages_ext)
563{
564 return _MAV_RETURN_uint16_t_array(msg, voltages_ext, 4, 41);
565}
566
567/**
568 * @brief Get field mode from battery_status message
569 *
570 * @return Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
571 */
572static inline uint8_t mavlink_msg_battery_status_get_mode(const mavlink_message_t* msg)
573{
574 return _MAV_RETURN_uint8_t(msg, 49);
575}
576
577/**
578 * @brief Get field fault_bitmask from battery_status message
579 *
580 * @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).
581 */
582static inline uint32_t mavlink_msg_battery_status_get_fault_bitmask(const mavlink_message_t* msg)
583{
584 return _MAV_RETURN_uint32_t(msg, 50);
585}
586
587/**
588 * @brief Decode a battery_status message into a struct
589 *
590 * @param msg The message to decode
591 * @param battery_status C-struct to decode the message contents into
592 */
593static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
594{
595#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
596 battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
597 battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
598 battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
599 mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
600 battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
601 battery_status->id = mavlink_msg_battery_status_get_id(msg);
602 battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
603 battery_status->type = mavlink_msg_battery_status_get_type(msg);
604 battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
605 battery_status->time_remaining = mavlink_msg_battery_status_get_time_remaining(msg);
606 battery_status->charge_state = mavlink_msg_battery_status_get_charge_state(msg);
607 mavlink_msg_battery_status_get_voltages_ext(msg, battery_status->voltages_ext);
608 battery_status->mode = mavlink_msg_battery_status_get_mode(msg);
609 battery_status->fault_bitmask = mavlink_msg_battery_status_get_fault_bitmask(msg);
610#else
611 uint8_t len = msg->len < MAVLINK_MSG_ID_BATTERY_STATUS_LEN? msg->len : MAVLINK_MSG_ID_BATTERY_STATUS_LEN;
612 memset(battery_status, 0, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
613 memcpy(battery_status, _MAV_PAYLOAD(msg), len);
614#endif
615}