Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_esc_status.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE ESC_STATUS PACKING
3
4#define MAVLINK_MSG_ID_ESC_STATUS 291
5
6
7typedef struct __mavlink_esc_status_t {
8 uint64_t time_usec; /*< [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.*/
9 int32_t rpm[4]; /*< [rpm] Reported motor RPM from each ESC (negative for reverse rotation).*/
10 float voltage[4]; /*< [V] Voltage measured from each ESC.*/
11 float current[4]; /*< [A] Current measured from each ESC.*/
12 uint8_t index; /*< Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.*/
13} mavlink_esc_status_t;
14
15#define MAVLINK_MSG_ID_ESC_STATUS_LEN 57
16#define MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN 57
17#define MAVLINK_MSG_ID_291_LEN 57
18#define MAVLINK_MSG_ID_291_MIN_LEN 57
19
20#define MAVLINK_MSG_ID_ESC_STATUS_CRC 10
21#define MAVLINK_MSG_ID_291_CRC 10
22
23#define MAVLINK_MSG_ESC_STATUS_FIELD_RPM_LEN 4
24#define MAVLINK_MSG_ESC_STATUS_FIELD_VOLTAGE_LEN 4
25#define MAVLINK_MSG_ESC_STATUS_FIELD_CURRENT_LEN 4
26
27#if MAVLINK_COMMAND_24BIT
28#define MAVLINK_MESSAGE_INFO_ESC_STATUS {
29 291,
30 "ESC_STATUS",
31 5,
32 { { "index", NULL, MAVLINK_TYPE_UINT8_T, 0, 56, offsetof(mavlink_esc_status_t, index) },
33 { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_esc_status_t, time_usec) },
34 { "rpm", NULL, MAVLINK_TYPE_INT32_T, 4, 8, offsetof(mavlink_esc_status_t, rpm) },
35 { "voltage", NULL, MAVLINK_TYPE_FLOAT, 4, 24, offsetof(mavlink_esc_status_t, voltage) },
36 { "current", NULL, MAVLINK_TYPE_FLOAT, 4, 40, offsetof(mavlink_esc_status_t, current) },
37 } \
38}
39#else
40#define MAVLINK_MESSAGE_INFO_ESC_STATUS {
41 "ESC_STATUS",
42 5,
43 { { "index", NULL, MAVLINK_TYPE_UINT8_T, 0, 56, offsetof(mavlink_esc_status_t, index) },
44 { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_esc_status_t, time_usec) },
45 { "rpm", NULL, MAVLINK_TYPE_INT32_T, 4, 8, offsetof(mavlink_esc_status_t, rpm) },
46 { "voltage", NULL, MAVLINK_TYPE_FLOAT, 4, 24, offsetof(mavlink_esc_status_t, voltage) },
47 { "current", NULL, MAVLINK_TYPE_FLOAT, 4, 40, offsetof(mavlink_esc_status_t, current) },
48 } \
49}
50#endif
51
52/**
53 * @brief Pack a esc_status message
54 * @param system_id ID of this system
55 * @param component_id ID of this component (e.g. 200 for IMU)
56 * @param msg The MAVLink message to compress the data into
57 *
58 * @param index Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.
59 * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.
60 * @param rpm [rpm] Reported motor RPM from each ESC (negative for reverse rotation).
61 * @param voltage [V] Voltage measured from each ESC.
62 * @param current [A] Current measured from each ESC.
63 * @return length of the message in bytes (excluding serial stream start sign)
64 */
65MAVLINK_WIP
66static inline uint16_t mavlink_msg_esc_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
67 uint8_t index, uint64_t time_usec, const int32_t *rpm, const float *voltage, const float *current)
68{
69#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
71 _mav_put_uint64_t(buf, 0, time_usec);
72 _mav_put_uint8_t(buf, 56, index);
73 _mav_put_int32_t_array(buf, 8, rpm, 4);
74 _mav_put_float_array(buf, 24, voltage, 4);
75 _mav_put_float_array(buf, 40, current, 4);
76 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_ESC_STATUS_LEN);
77#else
78 mavlink_esc_status_t packet;
79 packet.time_usec = time_usec;
80 packet.index = index;
81 mav_array_memcpy(packet.rpm, rpm, sizeof(int32_t)*4);
82 mav_array_memcpy(packet.voltage, voltage, sizeof(float)*4);
83 mav_array_memcpy(packet.current, current, sizeof(float)*4);
84 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_ESC_STATUS_LEN);
85#endif
86
87 msg->msgid = MAVLINK_MSG_ID_ESC_STATUS;
88 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
89}
90
91/**
92 * @brief Pack a esc_status message
93 * @param system_id ID of this system
94 * @param component_id ID of this component (e.g. 200 for IMU)
95 * @param status MAVLink status structure
96 * @param msg The MAVLink message to compress the data into
97 *
98 * @param index Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.
99 * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.
100 * @param rpm [rpm] Reported motor RPM from each ESC (negative for reverse rotation).
101 * @param voltage [V] Voltage measured from each ESC.
102 * @param current [A] Current measured from each ESC.
103 * @return length of the message in bytes (excluding serial stream start sign)
104 */
105static inline uint16_t mavlink_msg_esc_status_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
106 uint8_t index, uint64_t time_usec, const int32_t *rpm, const float *voltage, const float *current)
107{
108#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
110 _mav_put_uint64_t(buf, 0, time_usec);
111 _mav_put_uint8_t(buf, 56, index);
112 _mav_put_int32_t_array(buf, 8, rpm, 4);
113 _mav_put_float_array(buf, 24, voltage, 4);
114 _mav_put_float_array(buf, 40, current, 4);
115 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_ESC_STATUS_LEN);
116#else
117 mavlink_esc_status_t packet;
118 packet.time_usec = time_usec;
119 packet.index = index;
120 mav_array_memcpy(packet.rpm, rpm, sizeof(int32_t)*4);
121 mav_array_memcpy(packet.voltage, voltage, sizeof(float)*4);
122 mav_array_memcpy(packet.current, current, sizeof(float)*4);
123 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_ESC_STATUS_LEN);
124#endif
125
126 msg->msgid = MAVLINK_MSG_ID_ESC_STATUS;
127#if MAVLINK_CRC_EXTRA
128 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
129#else
130 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN);
131#endif
132}
133
134/**
135 * @brief Pack a esc_status message on a channel
136 * @param system_id ID of this system
137 * @param component_id ID of this component (e.g. 200 for IMU)
138 * @param chan The MAVLink channel this message will be sent over
139 * @param msg The MAVLink message to compress the data into
140 * @param index Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.
141 * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.
142 * @param rpm [rpm] Reported motor RPM from each ESC (negative for reverse rotation).
143 * @param voltage [V] Voltage measured from each ESC.
144 * @param current [A] Current measured from each ESC.
145 * @return length of the message in bytes (excluding serial stream start sign)
146 */
147MAVLINK_WIP
148static inline uint16_t mavlink_msg_esc_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
149 mavlink_message_t* msg,
150 uint8_t index,uint64_t time_usec,const int32_t *rpm,const float *voltage,const float *current)
151{
152#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
154 _mav_put_uint64_t(buf, 0, time_usec);
155 _mav_put_uint8_t(buf, 56, index);
156 _mav_put_int32_t_array(buf, 8, rpm, 4);
157 _mav_put_float_array(buf, 24, voltage, 4);
158 _mav_put_float_array(buf, 40, current, 4);
159 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_ESC_STATUS_LEN);
160#else
161 mavlink_esc_status_t packet;
162 packet.time_usec = time_usec;
163 packet.index = index;
164 mav_array_memcpy(packet.rpm, rpm, sizeof(int32_t)*4);
165 mav_array_memcpy(packet.voltage, voltage, sizeof(float)*4);
166 mav_array_memcpy(packet.current, current, sizeof(float)*4);
167 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_ESC_STATUS_LEN);
168#endif
169
170 msg->msgid = MAVLINK_MSG_ID_ESC_STATUS;
171 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
172}
173
174/**
175 * @brief Encode a esc_status struct
176 *
177 * @param system_id ID of this system
178 * @param component_id ID of this component (e.g. 200 for IMU)
179 * @param msg The MAVLink message to compress the data into
180 * @param esc_status C-struct to read the message contents from
181 */
182MAVLINK_WIP
183static inline uint16_t mavlink_msg_esc_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_esc_status_t* esc_status)
184{
185 return mavlink_msg_esc_status_pack(system_id, component_id, msg, esc_status->index, esc_status->time_usec, esc_status->rpm, esc_status->voltage, esc_status->current);
186}
187
188/**
189 * @brief Encode a esc_status struct on a channel
190 *
191 * @param system_id ID of this system
192 * @param component_id ID of this component (e.g. 200 for IMU)
193 * @param chan The MAVLink channel this message will be sent over
194 * @param msg The MAVLink message to compress the data into
195 * @param esc_status C-struct to read the message contents from
196 */
197MAVLINK_WIP
198static inline uint16_t mavlink_msg_esc_status_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_esc_status_t* esc_status)
199{
200 return mavlink_msg_esc_status_pack_chan(system_id, component_id, chan, msg, esc_status->index, esc_status->time_usec, esc_status->rpm, esc_status->voltage, esc_status->current);
201}
202
203/**
204 * @brief Encode a esc_status struct with provided status structure
205 *
206 * @param system_id ID of this system
207 * @param component_id ID of this component (e.g. 200 for IMU)
208 * @param status MAVLink status structure
209 * @param msg The MAVLink message to compress the data into
210 * @param esc_status C-struct to read the message contents from
211 */
212static inline uint16_t mavlink_msg_esc_status_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_esc_status_t* esc_status)
213{
214 return mavlink_msg_esc_status_pack_status(system_id, component_id, _status, msg, esc_status->index, esc_status->time_usec, esc_status->rpm, esc_status->voltage, esc_status->current);
215}
216
217/**
218 * @brief Send a esc_status message
219 * @param chan MAVLink channel to send the message
220 *
221 * @param index Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.
222 * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.
223 * @param rpm [rpm] Reported motor RPM from each ESC (negative for reverse rotation).
224 * @param voltage [V] Voltage measured from each ESC.
225 * @param current [A] Current measured from each ESC.
226 */
227#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
228
229MAVLINK_WIP
230static inline void mavlink_msg_esc_status_send(mavlink_channel_t chan, uint8_t index, uint64_t time_usec, const int32_t *rpm, const float *voltage, const float *current)
231{
232#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
233 char buf[MAVLINK_MSG_ID_ESC_STATUS_LEN];
234 _mav_put_uint64_t(buf, 0, time_usec);
235 _mav_put_uint8_t(buf, 56, index);
236 _mav_put_int32_t_array(buf, 8, rpm, 4);
237 _mav_put_float_array(buf, 24, voltage, 4);
238 _mav_put_float_array(buf, 40, current, 4);
239 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ESC_STATUS, buf, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
240#else
241 mavlink_esc_status_t packet;
242 packet.time_usec = time_usec;
243 packet.index = index;
244 mav_array_memcpy(packet.rpm, rpm, sizeof(int32_t)*4);
245 mav_array_memcpy(packet.voltage, voltage, sizeof(float)*4);
246 mav_array_memcpy(packet.current, current, sizeof(float)*4);
247 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ESC_STATUS, (const char *)&packet, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
248#endif
249}
250
251/**
252 * @brief Send a esc_status message
253 * @param chan MAVLink channel to send the message
254 * @param struct The MAVLink struct to serialize
255 */
256MAVLINK_WIP
257static inline void mavlink_msg_esc_status_send_struct(mavlink_channel_t chan, const mavlink_esc_status_t* esc_status)
258{
259#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
260 mavlink_msg_esc_status_send(chan, esc_status->index, esc_status->time_usec, esc_status->rpm, esc_status->voltage, esc_status->current);
261#else
262 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ESC_STATUS, (const char *)esc_status, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
263#endif
264}
265
266#if MAVLINK_MSG_ID_ESC_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
267/*
268 This variant of _send() can be used to save stack space by reusing
269 memory from the receive buffer. The caller provides a
270 mavlink_message_t which is the size of a full mavlink message. This
271 is usually the receive buffer for the channel, and allows a reply to an
272 incoming message with minimum stack space usage.
273 */
274MAVLINK_WIP
275static inline void mavlink_msg_esc_status_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t index, uint64_t time_usec, const int32_t *rpm, const float *voltage, const float *current)
276{
277#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
278 char *buf = (char *)msgbuf;
279 _mav_put_uint64_t(buf, 0, time_usec);
280 _mav_put_uint8_t(buf, 56, index);
281 _mav_put_int32_t_array(buf, 8, rpm, 4);
282 _mav_put_float_array(buf, 24, voltage, 4);
283 _mav_put_float_array(buf, 40, current, 4);
284 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ESC_STATUS, buf, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
285#else
286 mavlink_esc_status_t *packet = (mavlink_esc_status_t *)msgbuf;
287 packet->time_usec = time_usec;
288 packet->index = index;
289 mav_array_memcpy(packet->rpm, rpm, sizeof(int32_t)*4);
290 mav_array_memcpy(packet->voltage, voltage, sizeof(float)*4);
291 mav_array_memcpy(packet->current, current, sizeof(float)*4);
292 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ESC_STATUS, (const char *)packet, MAVLINK_MSG_ID_ESC_STATUS_MIN_LEN, MAVLINK_MSG_ID_ESC_STATUS_LEN, MAVLINK_MSG_ID_ESC_STATUS_CRC);
293#endif
294}
295#endif
296
297#endif
298
299// MESSAGE ESC_STATUS UNPACKING
300
301
302/**
303 * @brief Get field index from esc_status message
304 *
305 * @return Index of the first ESC in this message (ESC are indexed in motor order). minValue = 0, maxValue = 60, increment = 4.
306 */
307MAVLINK_WIP
308static inline uint8_t mavlink_msg_esc_status_get_index(const mavlink_message_t* msg)
309{
310 return _MAV_RETURN_uint8_t(msg, 56);
311}
312
313/**
314 * @brief Get field time_usec from esc_status message
315 *
316 * @return [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number.
317 */
318MAVLINK_WIP
319static inline uint64_t mavlink_msg_esc_status_get_time_usec(const mavlink_message_t* msg)
320{
321 return _MAV_RETURN_uint64_t(msg, 0);
322}
323
324/**
325 * @brief Get field rpm from esc_status message
326 *
327 * @return [rpm] Reported motor RPM from each ESC (negative for reverse rotation).
328 */
329MAVLINK_WIP
330static inline uint16_t mavlink_msg_esc_status_get_rpm(const mavlink_message_t* msg, int32_t *rpm)
331{
332 return _MAV_RETURN_int32_t_array(msg, rpm, 4, 8);
333}
334
335/**
336 * @brief Get field voltage from esc_status message
337 *
338 * @return [V] Voltage measured from each ESC.
339 */
340MAVLINK_WIP
341static inline uint16_t mavlink_msg_esc_status_get_voltage(const mavlink_message_t* msg, float *voltage)
342{
343 return _MAV_RETURN_float_array(msg, voltage, 4, 24);
344}
345
346/**
347 * @brief Get field current from esc_status message
348 *
349 * @return [A] Current measured from each ESC.
350 */
351MAVLINK_WIP
352static inline uint16_t mavlink_msg_esc_status_get_current(const mavlink_message_t* msg, float *current)
353{
354 return _MAV_RETURN_float_array(msg, current, 4, 40);
355}
356
357/**
358 * @brief Decode a esc_status message into a struct
359 *
360 * @param msg The message to decode
361 * @param esc_status C-struct to decode the message contents into
362 */
363MAVLINK_WIP
364static inline void mavlink_msg_esc_status_decode(const mavlink_message_t* msg, mavlink_esc_status_t* esc_status)
365{
366#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
367 esc_status->time_usec = mavlink_msg_esc_status_get_time_usec(msg);
368 mavlink_msg_esc_status_get_rpm(msg, esc_status->rpm);
369 mavlink_msg_esc_status_get_voltage(msg, esc_status->voltage);
370 mavlink_msg_esc_status_get_current(msg, esc_status->current);
371 esc_status->index = mavlink_msg_esc_status_get_index(msg);
372#else
373 uint8_t len = msg->len < MAVLINK_MSG_ID_ESC_STATUS_LEN? msg->len : MAVLINK_MSG_ID_ESC_STATUS_LEN;
374 memset(esc_status, 0, MAVLINK_MSG_ID_ESC_STATUS_LEN);
375 memcpy(esc_status, _MAV_PAYLOAD(msg), len);
376#endif
377}