Merge pull request #10476 from radiolinkW/RADIOLINKF722
[inav.git] / lib / main / MAVLink / common / mavlink_msg_battery_status.h
blob084b2a388608e9030c7e083e4c4c97a832e74a73
1 #pragma once
2 // MESSAGE BATTERY_STATUS PACKING
4 #define MAVLINK_MSG_ID_BATTERY_STATUS 147
6 MAVPACKED(
7 typedef 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;
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
29 #define MAVLINK_MSG_ID_BATTERY_STATUS_CRC 154
30 #define MAVLINK_MSG_ID_147_CRC 154
32 #define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN 10
33 #define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_EXT_LEN 4
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 } \
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 } \
76 #endif
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
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)
100 static 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)
103 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
104 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
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
139 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
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);
144 * @brief Pack a battery_status message on a channel
145 * @param system_id ID of this system
146 * @param component_id ID of this component (e.g. 200 for IMU)
147 * @param chan The MAVLink channel this message will be sent over
148 * @param msg The MAVLink message to compress the data into
149 * @param id Battery ID
150 * @param battery_function Function of the battery
151 * @param type Type (chemistry) of the battery
152 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
153 * @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).
154 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
155 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
156 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
157 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
158 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
159 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
160 * @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.
161 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
162 * @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).
163 * @return length of the message in bytes (excluding serial stream start sign)
165 static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
166 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)
169 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
170 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
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
205 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
206 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);
210 * @brief Encode a battery_status struct
212 * @param system_id ID of this system
213 * @param component_id ID of this component (e.g. 200 for IMU)
214 * @param msg The MAVLink message to compress the data into
215 * @param battery_status C-struct to read the message contents from
217 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)
219 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);
223 * @brief Encode a battery_status struct on a channel
225 * @param system_id ID of this system
226 * @param component_id ID of this component (e.g. 200 for IMU)
227 * @param chan The MAVLink channel this message will be sent over
228 * @param msg The MAVLink message to compress the data into
229 * @param battery_status C-struct to read the message contents from
231 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)
233 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);
237 * @brief Send a battery_status message
238 * @param chan MAVLink channel to send the message
240 * @param id Battery ID
241 * @param battery_function Function of the battery
242 * @param type Type (chemistry) of the battery
243 * @param temperature [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
244 * @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).
245 * @param current_battery [cA] Battery current, -1: autopilot does not measure the current
246 * @param current_consumed [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
247 * @param energy_consumed [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
248 * @param battery_remaining [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
249 * @param time_remaining [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
250 * @param charge_state State for extent of discharge, provided by autopilot for warning or external reactions
251 * @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.
252 * @param mode Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
253 * @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).
255 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
257 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)
259 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
260 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
261 _mav_put_int32_t(buf, 0, current_consumed);
262 _mav_put_int32_t(buf, 4, energy_consumed);
263 _mav_put_int16_t(buf, 8, temperature);
264 _mav_put_int16_t(buf, 30, current_battery);
265 _mav_put_uint8_t(buf, 32, id);
266 _mav_put_uint8_t(buf, 33, battery_function);
267 _mav_put_uint8_t(buf, 34, type);
268 _mav_put_int8_t(buf, 35, battery_remaining);
269 _mav_put_int32_t(buf, 36, time_remaining);
270 _mav_put_uint8_t(buf, 40, charge_state);
271 _mav_put_uint8_t(buf, 49, mode);
272 _mav_put_uint32_t(buf, 50, fault_bitmask);
273 _mav_put_uint16_t_array(buf, 10, voltages, 10);
274 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
275 _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);
276 #else
277 mavlink_battery_status_t packet;
278 packet.current_consumed = current_consumed;
279 packet.energy_consumed = energy_consumed;
280 packet.temperature = temperature;
281 packet.current_battery = current_battery;
282 packet.id = id;
283 packet.battery_function = battery_function;
284 packet.type = type;
285 packet.battery_remaining = battery_remaining;
286 packet.time_remaining = time_remaining;
287 packet.charge_state = charge_state;
288 packet.mode = mode;
289 packet.fault_bitmask = fault_bitmask;
290 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
291 mav_array_memcpy(packet.voltages_ext, voltages_ext, sizeof(uint16_t)*4);
292 _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);
293 #endif
297 * @brief Send a battery_status message
298 * @param chan MAVLink channel to send the message
299 * @param struct The MAVLink struct to serialize
301 static inline void mavlink_msg_battery_status_send_struct(mavlink_channel_t chan, const mavlink_battery_status_t* battery_status)
303 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
304 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);
305 #else
306 _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);
307 #endif
310 #if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
312 This varient of _send() can be used to save stack space by re-using
313 memory from the receive buffer. The caller provides a
314 mavlink_message_t which is the size of a full mavlink message. This
315 is usually the receive buffer for the channel, and allows a reply to an
316 incoming message with minimum stack space usage.
318 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)
320 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
321 char *buf = (char *)msgbuf;
322 _mav_put_int32_t(buf, 0, current_consumed);
323 _mav_put_int32_t(buf, 4, energy_consumed);
324 _mav_put_int16_t(buf, 8, temperature);
325 _mav_put_int16_t(buf, 30, current_battery);
326 _mav_put_uint8_t(buf, 32, id);
327 _mav_put_uint8_t(buf, 33, battery_function);
328 _mav_put_uint8_t(buf, 34, type);
329 _mav_put_int8_t(buf, 35, battery_remaining);
330 _mav_put_int32_t(buf, 36, time_remaining);
331 _mav_put_uint8_t(buf, 40, charge_state);
332 _mav_put_uint8_t(buf, 49, mode);
333 _mav_put_uint32_t(buf, 50, fault_bitmask);
334 _mav_put_uint16_t_array(buf, 10, voltages, 10);
335 _mav_put_uint16_t_array(buf, 41, voltages_ext, 4);
336 _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);
337 #else
338 mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
339 packet->current_consumed = current_consumed;
340 packet->energy_consumed = energy_consumed;
341 packet->temperature = temperature;
342 packet->current_battery = current_battery;
343 packet->id = id;
344 packet->battery_function = battery_function;
345 packet->type = type;
346 packet->battery_remaining = battery_remaining;
347 packet->time_remaining = time_remaining;
348 packet->charge_state = charge_state;
349 packet->mode = mode;
350 packet->fault_bitmask = fault_bitmask;
351 mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
352 mav_array_memcpy(packet->voltages_ext, voltages_ext, sizeof(uint16_t)*4);
353 _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);
354 #endif
356 #endif
358 #endif
360 // MESSAGE BATTERY_STATUS UNPACKING
364 * @brief Get field id from battery_status message
366 * @return Battery ID
368 static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
370 return _MAV_RETURN_uint8_t(msg, 32);
374 * @brief Get field battery_function from battery_status message
376 * @return Function of the battery
378 static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
380 return _MAV_RETURN_uint8_t(msg, 33);
384 * @brief Get field type from battery_status message
386 * @return Type (chemistry) of the battery
388 static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
390 return _MAV_RETURN_uint8_t(msg, 34);
394 * @brief Get field temperature from battery_status message
396 * @return [cdegC] Temperature of the battery. INT16_MAX for unknown temperature.
398 static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
400 return _MAV_RETURN_int16_t(msg, 8);
404 * @brief Get field voltages from battery_status message
406 * @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).
408 static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
410 return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
414 * @brief Get field current_battery from battery_status message
416 * @return [cA] Battery current, -1: autopilot does not measure the current
418 static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
420 return _MAV_RETURN_int16_t(msg, 30);
424 * @brief Get field current_consumed from battery_status message
426 * @return [mAh] Consumed charge, -1: autopilot does not provide consumption estimate
428 static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
430 return _MAV_RETURN_int32_t(msg, 0);
434 * @brief Get field energy_consumed from battery_status message
436 * @return [hJ] Consumed energy, -1: autopilot does not provide energy consumption estimate
438 static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
440 return _MAV_RETURN_int32_t(msg, 4);
444 * @brief Get field battery_remaining from battery_status message
446 * @return [%] Remaining battery energy. Values: [0-100], -1: autopilot does not estimate the remaining battery.
448 static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
450 return _MAV_RETURN_int8_t(msg, 35);
454 * @brief Get field time_remaining from battery_status message
456 * @return [s] Remaining battery time, 0: autopilot does not provide remaining battery time estimate
458 static inline int32_t mavlink_msg_battery_status_get_time_remaining(const mavlink_message_t* msg)
460 return _MAV_RETURN_int32_t(msg, 36);
464 * @brief Get field charge_state from battery_status message
466 * @return State for extent of discharge, provided by autopilot for warning or external reactions
468 static inline uint8_t mavlink_msg_battery_status_get_charge_state(const mavlink_message_t* msg)
470 return _MAV_RETURN_uint8_t(msg, 40);
474 * @brief Get field voltages_ext from battery_status message
476 * @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.
478 static inline uint16_t mavlink_msg_battery_status_get_voltages_ext(const mavlink_message_t* msg, uint16_t *voltages_ext)
480 return _MAV_RETURN_uint16_t_array(msg, voltages_ext, 4, 41);
484 * @brief Get field mode from battery_status message
486 * @return Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode.
488 static inline uint8_t mavlink_msg_battery_status_get_mode(const mavlink_message_t* msg)
490 return _MAV_RETURN_uint8_t(msg, 49);
494 * @brief Get field fault_bitmask from battery_status message
496 * @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).
498 static inline uint32_t mavlink_msg_battery_status_get_fault_bitmask(const mavlink_message_t* msg)
500 return _MAV_RETURN_uint32_t(msg, 50);
504 * @brief Decode a battery_status message into a struct
506 * @param msg The message to decode
507 * @param battery_status C-struct to decode the message contents into
509 static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
511 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
512 battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
513 battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
514 battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
515 mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
516 battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
517 battery_status->id = mavlink_msg_battery_status_get_id(msg);
518 battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
519 battery_status->type = mavlink_msg_battery_status_get_type(msg);
520 battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
521 battery_status->time_remaining = mavlink_msg_battery_status_get_time_remaining(msg);
522 battery_status->charge_state = mavlink_msg_battery_status_get_charge_state(msg);
523 mavlink_msg_battery_status_get_voltages_ext(msg, battery_status->voltages_ext);
524 battery_status->mode = mavlink_msg_battery_status_get_mode(msg);
525 battery_status->fault_bitmask = mavlink_msg_battery_status_get_fault_bitmask(msg);
526 #else
527 uint8_t len = msg->len < MAVLINK_MSG_ID_BATTERY_STATUS_LEN? msg->len : MAVLINK_MSG_ID_BATTERY_STATUS_LEN;
528 memset(battery_status, 0, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
529 memcpy(battery_status, _MAV_PAYLOAD(msg), len);
530 #endif