Move telemetry displayport init and cms device registering
[betaflight.git] / lib / main / MAVLink / common / mavlink_msg_battery_status.h
blob12371e69fa56f700c308914aa8ddde6d6bbbeac0
1 // MESSAGE BATTERY_STATUS PACKING
3 #define MAVLINK_MSG_ID_BATTERY_STATUS 147
5 typedef struct __mavlink_battery_status_t
7 int32_t current_consumed; ///< Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate
8 int32_t energy_consumed; ///< Consumed energy, in 100*Joules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate
9 int16_t temperature; ///< Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.
10 uint16_t voltages[10]; ///< Battery voltage of cells, in millivolts (1 = 1 millivolt)
11 int16_t current_battery; ///< Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
12 uint8_t id; ///< Battery ID
13 uint8_t battery_function; ///< Function of the battery
14 uint8_t type; ///< Type (chemistry) of the battery
15 int8_t battery_remaining; ///< Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
16 } mavlink_battery_status_t;
18 #define MAVLINK_MSG_ID_BATTERY_STATUS_LEN 36
19 #define MAVLINK_MSG_ID_147_LEN 36
21 #define MAVLINK_MSG_ID_BATTERY_STATUS_CRC 154
22 #define MAVLINK_MSG_ID_147_CRC 154
24 #define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN 10
26 #define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
27 "BATTERY_STATUS", \
28 9, \
29 { { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) }, \
30 { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) }, \
31 { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) }, \
32 { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) }, \
33 { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) }, \
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 { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) }, \
38 } \
42 /**
43 * @brief Pack a battery_status message
44 * @param system_id ID of this system
45 * @param component_id ID of this component (e.g. 200 for IMU)
46 * @param msg The MAVLink message to compress the data into
48 * @param id Battery ID
49 * @param battery_function Function of the battery
50 * @param type Type (chemistry) of the battery
51 * @param temperature Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.
52 * @param voltages Battery voltage of cells, in millivolts (1 = 1 millivolt)
53 * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
54 * @param current_consumed Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate
55 * @param energy_consumed Consumed energy, in 100*Joules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate
56 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
57 * @return length of the message in bytes (excluding serial stream start sign)
59 static inline uint16_t mavlink_msg_battery_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
60 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)
62 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
63 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
64 _mav_put_int32_t(buf, 0, current_consumed);
65 _mav_put_int32_t(buf, 4, energy_consumed);
66 _mav_put_int16_t(buf, 8, temperature);
67 _mav_put_int16_t(buf, 30, current_battery);
68 _mav_put_uint8_t(buf, 32, id);
69 _mav_put_uint8_t(buf, 33, battery_function);
70 _mav_put_uint8_t(buf, 34, type);
71 _mav_put_int8_t(buf, 35, battery_remaining);
72 _mav_put_uint16_t_array(buf, 10, voltages, 10);
73 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
74 #else
75 mavlink_battery_status_t packet;
76 packet.current_consumed = current_consumed;
77 packet.energy_consumed = energy_consumed;
78 packet.temperature = temperature;
79 packet.current_battery = current_battery;
80 packet.id = id;
81 packet.battery_function = battery_function;
82 packet.type = type;
83 packet.battery_remaining = battery_remaining;
84 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
85 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
86 #endif
88 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
89 #if MAVLINK_CRC_EXTRA
90 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
91 #else
92 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
93 #endif
96 /**
97 * @brief Pack a battery_status message on a channel
98 * @param system_id ID of this system
99 * @param component_id ID of this component (e.g. 200 for IMU)
100 * @param chan The MAVLink channel this message will be sent over
101 * @param msg The MAVLink message to compress the data into
102 * @param id Battery ID
103 * @param battery_function Function of the battery
104 * @param type Type (chemistry) of the battery
105 * @param temperature Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.
106 * @param voltages Battery voltage of cells, in millivolts (1 = 1 millivolt)
107 * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
108 * @param current_consumed Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate
109 * @param energy_consumed Consumed energy, in 100*Joules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate
110 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
111 * @return length of the message in bytes (excluding serial stream start sign)
113 static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
114 mavlink_message_t* msg,
115 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)
117 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
118 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
119 _mav_put_int32_t(buf, 0, current_consumed);
120 _mav_put_int32_t(buf, 4, energy_consumed);
121 _mav_put_int16_t(buf, 8, temperature);
122 _mav_put_int16_t(buf, 30, current_battery);
123 _mav_put_uint8_t(buf, 32, id);
124 _mav_put_uint8_t(buf, 33, battery_function);
125 _mav_put_uint8_t(buf, 34, type);
126 _mav_put_int8_t(buf, 35, battery_remaining);
127 _mav_put_uint16_t_array(buf, 10, voltages, 10);
128 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
129 #else
130 mavlink_battery_status_t packet;
131 packet.current_consumed = current_consumed;
132 packet.energy_consumed = energy_consumed;
133 packet.temperature = temperature;
134 packet.current_battery = current_battery;
135 packet.id = id;
136 packet.battery_function = battery_function;
137 packet.type = type;
138 packet.battery_remaining = battery_remaining;
139 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
140 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
141 #endif
143 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
144 #if MAVLINK_CRC_EXTRA
145 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
146 #else
147 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
148 #endif
152 * @brief Encode a battery_status struct
154 * @param system_id ID of this system
155 * @param component_id ID of this component (e.g. 200 for IMU)
156 * @param msg The MAVLink message to compress the data into
157 * @param battery_status C-struct to read the message contents from
159 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)
161 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);
165 * @brief Encode a battery_status struct on a channel
167 * @param system_id ID of this system
168 * @param component_id ID of this component (e.g. 200 for IMU)
169 * @param chan The MAVLink channel this message will be sent over
170 * @param msg The MAVLink message to compress the data into
171 * @param battery_status C-struct to read the message contents from
173 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)
175 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);
179 * @brief Send a battery_status message
180 * @param chan MAVLink channel to send the message
182 * @param id Battery ID
183 * @param battery_function Function of the battery
184 * @param type Type (chemistry) of the battery
185 * @param temperature Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.
186 * @param voltages Battery voltage of cells, in millivolts (1 = 1 millivolt)
187 * @param current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
188 * @param current_consumed Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate
189 * @param energy_consumed Consumed energy, in 100*Joules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate
190 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
192 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
194 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)
196 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
197 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
198 _mav_put_int32_t(buf, 0, current_consumed);
199 _mav_put_int32_t(buf, 4, energy_consumed);
200 _mav_put_int16_t(buf, 8, temperature);
201 _mav_put_int16_t(buf, 30, current_battery);
202 _mav_put_uint8_t(buf, 32, id);
203 _mav_put_uint8_t(buf, 33, battery_function);
204 _mav_put_uint8_t(buf, 34, type);
205 _mav_put_int8_t(buf, 35, battery_remaining);
206 _mav_put_uint16_t_array(buf, 10, voltages, 10);
207 #if MAVLINK_CRC_EXTRA
208 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
209 #else
210 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
211 #endif
212 #else
213 mavlink_battery_status_t packet;
214 packet.current_consumed = current_consumed;
215 packet.energy_consumed = energy_consumed;
216 packet.temperature = temperature;
217 packet.current_battery = current_battery;
218 packet.id = id;
219 packet.battery_function = battery_function;
220 packet.type = type;
221 packet.battery_remaining = battery_remaining;
222 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
223 #if MAVLINK_CRC_EXTRA
224 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)&packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
225 #else
226 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)&packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
227 #endif
228 #endif
231 #if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
233 This varient of _send() can be used to save stack space by re-using
234 memory from the receive buffer. The caller provides a
235 mavlink_message_t which is the size of a full mavlink message. This
236 is usually the receive buffer for the channel, and allows a reply to an
237 incoming message with minimum stack space usage.
239 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)
241 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
242 char *buf = (char *)msgbuf;
243 _mav_put_int32_t(buf, 0, current_consumed);
244 _mav_put_int32_t(buf, 4, energy_consumed);
245 _mav_put_int16_t(buf, 8, temperature);
246 _mav_put_int16_t(buf, 30, current_battery);
247 _mav_put_uint8_t(buf, 32, id);
248 _mav_put_uint8_t(buf, 33, battery_function);
249 _mav_put_uint8_t(buf, 34, type);
250 _mav_put_int8_t(buf, 35, battery_remaining);
251 _mav_put_uint16_t_array(buf, 10, voltages, 10);
252 #if MAVLINK_CRC_EXTRA
253 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
254 #else
255 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
256 #endif
257 #else
258 mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
259 packet->current_consumed = current_consumed;
260 packet->energy_consumed = energy_consumed;
261 packet->temperature = temperature;
262 packet->current_battery = current_battery;
263 packet->id = id;
264 packet->battery_function = battery_function;
265 packet->type = type;
266 packet->battery_remaining = battery_remaining;
267 mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
268 #if MAVLINK_CRC_EXTRA
269 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN, MAVLINK_MSG_ID_BATTERY_STATUS_CRC);
270 #else
271 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BATTERY_STATUS, (const char *)packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
272 #endif
273 #endif
275 #endif
277 #endif
279 // MESSAGE BATTERY_STATUS UNPACKING
283 * @brief Get field id from battery_status message
285 * @return Battery ID
287 static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
289 return _MAV_RETURN_uint8_t(msg, 32);
293 * @brief Get field battery_function from battery_status message
295 * @return Function of the battery
297 static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
299 return _MAV_RETURN_uint8_t(msg, 33);
303 * @brief Get field type from battery_status message
305 * @return Type (chemistry) of the battery
307 static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
309 return _MAV_RETURN_uint8_t(msg, 34);
313 * @brief Get field temperature from battery_status message
315 * @return Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.
317 static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
319 return _MAV_RETURN_int16_t(msg, 8);
323 * @brief Get field voltages from battery_status message
325 * @return Battery voltage of cells, in millivolts (1 = 1 millivolt)
327 static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
329 return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
333 * @brief Get field current_battery from battery_status message
335 * @return Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
337 static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
339 return _MAV_RETURN_int16_t(msg, 30);
343 * @brief Get field current_consumed from battery_status message
345 * @return Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate
347 static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
349 return _MAV_RETURN_int32_t(msg, 0);
353 * @brief Get field energy_consumed from battery_status message
355 * @return Consumed energy, in 100*Joules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate
357 static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
359 return _MAV_RETURN_int32_t(msg, 4);
363 * @brief Get field battery_remaining from battery_status message
365 * @return Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery
367 static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
369 return _MAV_RETURN_int8_t(msg, 35);
373 * @brief Decode a battery_status message into a struct
375 * @param msg The message to decode
376 * @param battery_status C-struct to decode the message contents into
378 static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
380 #if MAVLINK_NEED_BYTE_SWAP
381 battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
382 battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
383 battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
384 mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
385 battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
386 battery_status->id = mavlink_msg_battery_status_get_id(msg);
387 battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
388 battery_status->type = mavlink_msg_battery_status_get_type(msg);
389 battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
390 #else
391 memcpy(battery_status, _MAV_PAYLOAD(msg), MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
392 #endif