RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
mavlink_msg_battery_status.h
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; /*< Consumed charge, in milliampere hours (1 = 1 mAh), -1: autopilot does not provide mAh consumption estimate*/
9 int32_t energy_consumed; /*< Consumed energy, in HectoJoules (intergrated U*I*dt) (1 = 100 Joule), -1: autopilot does not provide energy consumption estimate*/
10 int16_t temperature; /*< Temperature of the battery in centi-degrees celsius. INT16_MAX for unknown temperature.*/
11 uint16_t voltages[10]; /*< Battery voltage of cells, in millivolts (1 = 1 millivolt). Cells above the valid cell count for this battery should have the UINT16_MAX value.*/
12 int16_t current_battery; /*< Battery current, in 10*milliamperes (1 = 10 milliampere), -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: (0%: 0, 100%: 100), -1: autopilot does not estimate the remaining battery*/
17}) mavlink_battery_status_t;
18
19#define MAVLINK_MSG_ID_BATTERY_STATUS_LEN 36
20#define MAVLINK_MSG_ID_BATTERY_STATUS_MIN_LEN 36
21#define MAVLINK_MSG_ID_147_LEN 36
22#define MAVLINK_MSG_ID_147_MIN_LEN 36
23
24#define MAVLINK_MSG_ID_BATTERY_STATUS_CRC 154
25#define MAVLINK_MSG_ID_147_CRC 154
26
27#define MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN 10
28
29#if MAVLINK_COMMAND_24BIT
30#define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
31 147, \
32 "BATTERY_STATUS", \
33 9, \
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 } \
44}
45#else
46#define MAVLINK_MESSAGE_INFO_BATTERY_STATUS { \
47 "BATTERY_STATUS", \
48 9, \
49 { { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_battery_status_t, id) }, \
50 { "battery_function", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_battery_status_t, battery_function) }, \
51 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 34, offsetof(mavlink_battery_status_t, type) }, \
52 { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_battery_status_t, temperature) }, \
53 { "voltages", NULL, MAVLINK_TYPE_UINT16_T, 10, 10, offsetof(mavlink_battery_status_t, voltages) }, \
54 { "current_battery", NULL, MAVLINK_TYPE_INT16_T, 0, 30, offsetof(mavlink_battery_status_t, current_battery) }, \
55 { "current_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_battery_status_t, current_consumed) }, \
56 { "energy_consumed", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_battery_status_t, energy_consumed) }, \
57 { "battery_remaining", NULL, MAVLINK_TYPE_INT8_T, 0, 35, offsetof(mavlink_battery_status_t, battery_remaining) }, \
58 } \
59}
60#endif
61
79static inline uint16_t mavlink_msg_battery_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
80 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)
81{
82#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
83 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
84 _mav_put_int32_t(buf, 0, current_consumed);
85 _mav_put_int32_t(buf, 4, energy_consumed);
86 _mav_put_int16_t(buf, 8, temperature);
87 _mav_put_int16_t(buf, 30, current_battery);
88 _mav_put_uint8_t(buf, 32, id);
89 _mav_put_uint8_t(buf, 33, battery_function);
90 _mav_put_uint8_t(buf, 34, type);
91 _mav_put_int8_t(buf, 35, battery_remaining);
92 _mav_put_uint16_t_array(buf, 10, voltages, 10);
93 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
94#else
95 mavlink_battery_status_t packet;
96 packet.current_consumed = current_consumed;
97 packet.energy_consumed = energy_consumed;
98 packet.temperature = temperature;
99 packet.current_battery = current_battery;
100 packet.id = id;
101 packet.battery_function = battery_function;
102 packet.type = type;
103 packet.battery_remaining = battery_remaining;
104 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
105 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
106#endif
107
108 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
109 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);
110}
111
129static inline uint16_t mavlink_msg_battery_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
130 mavlink_message_t* msg,
131 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)
132{
133#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
134 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
135 _mav_put_int32_t(buf, 0, current_consumed);
136 _mav_put_int32_t(buf, 4, energy_consumed);
137 _mav_put_int16_t(buf, 8, temperature);
138 _mav_put_int16_t(buf, 30, current_battery);
139 _mav_put_uint8_t(buf, 32, id);
140 _mav_put_uint8_t(buf, 33, battery_function);
141 _mav_put_uint8_t(buf, 34, type);
142 _mav_put_int8_t(buf, 35, battery_remaining);
143 _mav_put_uint16_t_array(buf, 10, voltages, 10);
144 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
145#else
146 mavlink_battery_status_t packet;
147 packet.current_consumed = current_consumed;
148 packet.energy_consumed = energy_consumed;
149 packet.temperature = temperature;
150 packet.current_battery = current_battery;
151 packet.id = id;
152 packet.battery_function = battery_function;
153 packet.type = type;
154 packet.battery_remaining = battery_remaining;
155 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
156 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
157#endif
158
159 msg->msgid = MAVLINK_MSG_ID_BATTERY_STATUS;
160 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);
161}
162
171static 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)
172{
173 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);
174}
175
185static 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)
186{
187 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);
188}
189
204#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
205
206static 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)
207{
208#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
209 char buf[MAVLINK_MSG_ID_BATTERY_STATUS_LEN];
210 _mav_put_int32_t(buf, 0, current_consumed);
211 _mav_put_int32_t(buf, 4, energy_consumed);
212 _mav_put_int16_t(buf, 8, temperature);
213 _mav_put_int16_t(buf, 30, current_battery);
214 _mav_put_uint8_t(buf, 32, id);
215 _mav_put_uint8_t(buf, 33, battery_function);
216 _mav_put_uint8_t(buf, 34, type);
217 _mav_put_int8_t(buf, 35, battery_remaining);
218 _mav_put_uint16_t_array(buf, 10, voltages, 10);
219 _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);
220#else
221 mavlink_battery_status_t packet;
222 packet.current_consumed = current_consumed;
223 packet.energy_consumed = energy_consumed;
224 packet.temperature = temperature;
225 packet.current_battery = current_battery;
226 packet.id = id;
227 packet.battery_function = battery_function;
228 packet.type = type;
229 packet.battery_remaining = battery_remaining;
230 mav_array_memcpy(packet.voltages, voltages, sizeof(uint16_t)*10);
231 _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);
232#endif
233}
234
240static inline void mavlink_msg_battery_status_send_struct(mavlink_channel_t chan, const mavlink_battery_status_t* battery_status)
241{
242#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
243 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);
244#else
245 _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);
246#endif
247}
248
249#if MAVLINK_MSG_ID_BATTERY_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
250/*
251 This varient of _send() can be used to save stack space by re-using
252 memory from the receive buffer. The caller provides a
253 mavlink_message_t which is the size of a full mavlink message. This
254 is usually the receive buffer for the channel, and allows a reply to an
255 incoming message with minimum stack space usage.
256 */
257static 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)
258{
259#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
260 char *buf = (char *)msgbuf;
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_uint16_t_array(buf, 10, voltages, 10);
270 _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);
271#else
272 mavlink_battery_status_t *packet = (mavlink_battery_status_t *)msgbuf;
273 packet->current_consumed = current_consumed;
274 packet->energy_consumed = energy_consumed;
275 packet->temperature = temperature;
276 packet->current_battery = current_battery;
277 packet->id = id;
278 packet->battery_function = battery_function;
279 packet->type = type;
280 packet->battery_remaining = battery_remaining;
281 mav_array_memcpy(packet->voltages, voltages, sizeof(uint16_t)*10);
282 _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);
283#endif
284}
285#endif
286
287#endif
288
289// MESSAGE BATTERY_STATUS UNPACKING
290
291
297static inline uint8_t mavlink_msg_battery_status_get_id(const mavlink_message_t* msg)
298{
299 return _MAV_RETURN_uint8_t(msg, 32);
300}
301
307static inline uint8_t mavlink_msg_battery_status_get_battery_function(const mavlink_message_t* msg)
308{
309 return _MAV_RETURN_uint8_t(msg, 33);
310}
311
317static inline uint8_t mavlink_msg_battery_status_get_type(const mavlink_message_t* msg)
318{
319 return _MAV_RETURN_uint8_t(msg, 34);
320}
321
327static inline int16_t mavlink_msg_battery_status_get_temperature(const mavlink_message_t* msg)
328{
329 return _MAV_RETURN_int16_t(msg, 8);
330}
331
337static inline uint16_t mavlink_msg_battery_status_get_voltages(const mavlink_message_t* msg, uint16_t *voltages)
338{
339 return _MAV_RETURN_uint16_t_array(msg, voltages, 10, 10);
340}
341
347static inline int16_t mavlink_msg_battery_status_get_current_battery(const mavlink_message_t* msg)
348{
349 return _MAV_RETURN_int16_t(msg, 30);
350}
351
357static inline int32_t mavlink_msg_battery_status_get_current_consumed(const mavlink_message_t* msg)
358{
359 return _MAV_RETURN_int32_t(msg, 0);
360}
361
367static inline int32_t mavlink_msg_battery_status_get_energy_consumed(const mavlink_message_t* msg)
368{
369 return _MAV_RETURN_int32_t(msg, 4);
370}
371
377static inline int8_t mavlink_msg_battery_status_get_battery_remaining(const mavlink_message_t* msg)
378{
379 return _MAV_RETURN_int8_t(msg, 35);
380}
381
388static inline void mavlink_msg_battery_status_decode(const mavlink_message_t* msg, mavlink_battery_status_t* battery_status)
389{
390#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
391 battery_status->current_consumed = mavlink_msg_battery_status_get_current_consumed(msg);
392 battery_status->energy_consumed = mavlink_msg_battery_status_get_energy_consumed(msg);
393 battery_status->temperature = mavlink_msg_battery_status_get_temperature(msg);
394 mavlink_msg_battery_status_get_voltages(msg, battery_status->voltages);
395 battery_status->current_battery = mavlink_msg_battery_status_get_current_battery(msg);
396 battery_status->id = mavlink_msg_battery_status_get_id(msg);
397 battery_status->battery_function = mavlink_msg_battery_status_get_battery_function(msg);
398 battery_status->type = mavlink_msg_battery_status_get_type(msg);
399 battery_status->battery_remaining = mavlink_msg_battery_status_get_battery_remaining(msg);
400#else
401 uint8_t len = msg->len < MAVLINK_MSG_ID_BATTERY_STATUS_LEN? msg->len : MAVLINK_MSG_ID_BATTERY_STATUS_LEN;
402 memset(battery_status, 0, MAVLINK_MSG_ID_BATTERY_STATUS_LEN);
403 memcpy(battery_status, _MAV_PAYLOAD(msg), len);
404#endif
405}