Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_vibration.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE VIBRATION PACKING
3
4#define MAVLINK_MSG_ID_VIBRATION 241
5
6
7typedef struct __mavlink_vibration_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 of the number.*/
9 float vibration_x; /*< Vibration levels on X-axis*/
10 float vibration_y; /*< Vibration levels on Y-axis*/
11 float vibration_z; /*< Vibration levels on Z-axis*/
12 uint32_t clipping_0; /*< first accelerometer clipping count*/
13 uint32_t clipping_1; /*< second accelerometer clipping count*/
14 uint32_t clipping_2; /*< third accelerometer clipping count*/
15} mavlink_vibration_t;
16
17#define MAVLINK_MSG_ID_VIBRATION_LEN 32
18#define MAVLINK_MSG_ID_VIBRATION_MIN_LEN 32
19#define MAVLINK_MSG_ID_241_LEN 32
20#define MAVLINK_MSG_ID_241_MIN_LEN 32
21
22#define MAVLINK_MSG_ID_VIBRATION_CRC 90
23#define MAVLINK_MSG_ID_241_CRC 90
24
25
26
27#if MAVLINK_COMMAND_24BIT
28#define MAVLINK_MESSAGE_INFO_VIBRATION {
29 241,
30 "VIBRATION",
31 7,
32 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_vibration_t, time_usec) },
33 { "vibration_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vibration_t, vibration_x) },
34 { "vibration_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vibration_t, vibration_y) },
35 { "vibration_z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vibration_t, vibration_z) },
36 { "clipping_0", NULL, MAVLINK_TYPE_UINT32_T, 0, 20, offsetof(mavlink_vibration_t, clipping_0) },
37 { "clipping_1", NULL, MAVLINK_TYPE_UINT32_T, 0, 24, offsetof(mavlink_vibration_t, clipping_1) },
38 { "clipping_2", NULL, MAVLINK_TYPE_UINT32_T, 0, 28, offsetof(mavlink_vibration_t, clipping_2) },
39 } \
40}
41#else
42#define MAVLINK_MESSAGE_INFO_VIBRATION {
43 "VIBRATION",
44 7,
45 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_vibration_t, time_usec) },
46 { "vibration_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vibration_t, vibration_x) },
47 { "vibration_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vibration_t, vibration_y) },
48 { "vibration_z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vibration_t, vibration_z) },
49 { "clipping_0", NULL, MAVLINK_TYPE_UINT32_T, 0, 20, offsetof(mavlink_vibration_t, clipping_0) },
50 { "clipping_1", NULL, MAVLINK_TYPE_UINT32_T, 0, 24, offsetof(mavlink_vibration_t, clipping_1) },
51 { "clipping_2", NULL, MAVLINK_TYPE_UINT32_T, 0, 28, offsetof(mavlink_vibration_t, clipping_2) },
52 } \
53}
54#endif
55
56/**
57 * @brief Pack a vibration message
58 * @param system_id ID of this system
59 * @param component_id ID of this component (e.g. 200 for IMU)
60 * @param msg The MAVLink message to compress the data into
61 *
62 * @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 of the number.
63 * @param vibration_x Vibration levels on X-axis
64 * @param vibration_y Vibration levels on Y-axis
65 * @param vibration_z Vibration levels on Z-axis
66 * @param clipping_0 first accelerometer clipping count
67 * @param clipping_1 second accelerometer clipping count
68 * @param clipping_2 third accelerometer clipping count
69 * @return length of the message in bytes (excluding serial stream start sign)
70 */
71static inline uint16_t mavlink_msg_vibration_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
72 uint64_t time_usec, float vibration_x, float vibration_y, float vibration_z, uint32_t clipping_0, uint32_t clipping_1, uint32_t clipping_2)
73{
74#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
76 _mav_put_uint64_t(buf, 0, time_usec);
77 _mav_put_float(buf, 8, vibration_x);
78 _mav_put_float(buf, 12, vibration_y);
79 _mav_put_float(buf, 16, vibration_z);
80 _mav_put_uint32_t(buf, 20, clipping_0);
81 _mav_put_uint32_t(buf, 24, clipping_1);
82 _mav_put_uint32_t(buf, 28, clipping_2);
83
84 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VIBRATION_LEN);
85#else
86 mavlink_vibration_t packet;
87 packet.time_usec = time_usec;
88 packet.vibration_x = vibration_x;
89 packet.vibration_y = vibration_y;
90 packet.vibration_z = vibration_z;
91 packet.clipping_0 = clipping_0;
92 packet.clipping_1 = clipping_1;
93 packet.clipping_2 = clipping_2;
94
95 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VIBRATION_LEN);
96#endif
97
98 msg->msgid = MAVLINK_MSG_ID_VIBRATION;
99 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
100}
101
102/**
103 * @brief Pack a vibration message
104 * @param system_id ID of this system
105 * @param component_id ID of this component (e.g. 200 for IMU)
106 * @param status MAVLink status structure
107 * @param msg The MAVLink message to compress the data into
108 *
109 * @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 of the number.
110 * @param vibration_x Vibration levels on X-axis
111 * @param vibration_y Vibration levels on Y-axis
112 * @param vibration_z Vibration levels on Z-axis
113 * @param clipping_0 first accelerometer clipping count
114 * @param clipping_1 second accelerometer clipping count
115 * @param clipping_2 third accelerometer clipping count
116 * @return length of the message in bytes (excluding serial stream start sign)
117 */
118static inline uint16_t mavlink_msg_vibration_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
119 uint64_t time_usec, float vibration_x, float vibration_y, float vibration_z, uint32_t clipping_0, uint32_t clipping_1, uint32_t clipping_2)
120{
121#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
123 _mav_put_uint64_t(buf, 0, time_usec);
124 _mav_put_float(buf, 8, vibration_x);
125 _mav_put_float(buf, 12, vibration_y);
126 _mav_put_float(buf, 16, vibration_z);
127 _mav_put_uint32_t(buf, 20, clipping_0);
128 _mav_put_uint32_t(buf, 24, clipping_1);
129 _mav_put_uint32_t(buf, 28, clipping_2);
130
131 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VIBRATION_LEN);
132#else
133 mavlink_vibration_t packet;
134 packet.time_usec = time_usec;
135 packet.vibration_x = vibration_x;
136 packet.vibration_y = vibration_y;
137 packet.vibration_z = vibration_z;
138 packet.clipping_0 = clipping_0;
139 packet.clipping_1 = clipping_1;
140 packet.clipping_2 = clipping_2;
141
142 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VIBRATION_LEN);
143#endif
144
145 msg->msgid = MAVLINK_MSG_ID_VIBRATION;
146#if MAVLINK_CRC_EXTRA
147 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
148#else
149 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN);
150#endif
151}
152
153/**
154 * @brief Pack a vibration message on a channel
155 * @param system_id ID of this system
156 * @param component_id ID of this component (e.g. 200 for IMU)
157 * @param chan The MAVLink channel this message will be sent over
158 * @param msg The MAVLink message to compress the data into
159 * @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 of the number.
160 * @param vibration_x Vibration levels on X-axis
161 * @param vibration_y Vibration levels on Y-axis
162 * @param vibration_z Vibration levels on Z-axis
163 * @param clipping_0 first accelerometer clipping count
164 * @param clipping_1 second accelerometer clipping count
165 * @param clipping_2 third accelerometer clipping count
166 * @return length of the message in bytes (excluding serial stream start sign)
167 */
168static inline uint16_t mavlink_msg_vibration_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
169 mavlink_message_t* msg,
170 uint64_t time_usec,float vibration_x,float vibration_y,float vibration_z,uint32_t clipping_0,uint32_t clipping_1,uint32_t clipping_2)
171{
172#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
174 _mav_put_uint64_t(buf, 0, time_usec);
175 _mav_put_float(buf, 8, vibration_x);
176 _mav_put_float(buf, 12, vibration_y);
177 _mav_put_float(buf, 16, vibration_z);
178 _mav_put_uint32_t(buf, 20, clipping_0);
179 _mav_put_uint32_t(buf, 24, clipping_1);
180 _mav_put_uint32_t(buf, 28, clipping_2);
181
182 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VIBRATION_LEN);
183#else
184 mavlink_vibration_t packet;
185 packet.time_usec = time_usec;
186 packet.vibration_x = vibration_x;
187 packet.vibration_y = vibration_y;
188 packet.vibration_z = vibration_z;
189 packet.clipping_0 = clipping_0;
190 packet.clipping_1 = clipping_1;
191 packet.clipping_2 = clipping_2;
192
193 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VIBRATION_LEN);
194#endif
195
196 msg->msgid = MAVLINK_MSG_ID_VIBRATION;
197 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
198}
199
200/**
201 * @brief Encode a vibration struct
202 *
203 * @param system_id ID of this system
204 * @param component_id ID of this component (e.g. 200 for IMU)
205 * @param msg The MAVLink message to compress the data into
206 * @param vibration C-struct to read the message contents from
207 */
208static inline uint16_t mavlink_msg_vibration_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vibration_t* vibration)
209{
210 return mavlink_msg_vibration_pack(system_id, component_id, msg, vibration->time_usec, vibration->vibration_x, vibration->vibration_y, vibration->vibration_z, vibration->clipping_0, vibration->clipping_1, vibration->clipping_2);
211}
212
213/**
214 * @brief Encode a vibration struct on a channel
215 *
216 * @param system_id ID of this system
217 * @param component_id ID of this component (e.g. 200 for IMU)
218 * @param chan The MAVLink channel this message will be sent over
219 * @param msg The MAVLink message to compress the data into
220 * @param vibration C-struct to read the message contents from
221 */
222static inline uint16_t mavlink_msg_vibration_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_vibration_t* vibration)
223{
224 return mavlink_msg_vibration_pack_chan(system_id, component_id, chan, msg, vibration->time_usec, vibration->vibration_x, vibration->vibration_y, vibration->vibration_z, vibration->clipping_0, vibration->clipping_1, vibration->clipping_2);
225}
226
227/**
228 * @brief Encode a vibration struct with provided status structure
229 *
230 * @param system_id ID of this system
231 * @param component_id ID of this component (e.g. 200 for IMU)
232 * @param status MAVLink status structure
233 * @param msg The MAVLink message to compress the data into
234 * @param vibration C-struct to read the message contents from
235 */
236static inline uint16_t mavlink_msg_vibration_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_vibration_t* vibration)
237{
238 return mavlink_msg_vibration_pack_status(system_id, component_id, _status, msg, vibration->time_usec, vibration->vibration_x, vibration->vibration_y, vibration->vibration_z, vibration->clipping_0, vibration->clipping_1, vibration->clipping_2);
239}
240
241/**
242 * @brief Send a vibration message
243 * @param chan MAVLink channel to send the message
244 *
245 * @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 of the number.
246 * @param vibration_x Vibration levels on X-axis
247 * @param vibration_y Vibration levels on Y-axis
248 * @param vibration_z Vibration levels on Z-axis
249 * @param clipping_0 first accelerometer clipping count
250 * @param clipping_1 second accelerometer clipping count
251 * @param clipping_2 third accelerometer clipping count
252 */
253#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
254
255static inline void mavlink_msg_vibration_send(mavlink_channel_t chan, uint64_t time_usec, float vibration_x, float vibration_y, float vibration_z, uint32_t clipping_0, uint32_t clipping_1, uint32_t clipping_2)
256{
257#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
258 char buf[MAVLINK_MSG_ID_VIBRATION_LEN];
259 _mav_put_uint64_t(buf, 0, time_usec);
260 _mav_put_float(buf, 8, vibration_x);
261 _mav_put_float(buf, 12, vibration_y);
262 _mav_put_float(buf, 16, vibration_z);
263 _mav_put_uint32_t(buf, 20, clipping_0);
264 _mav_put_uint32_t(buf, 24, clipping_1);
265 _mav_put_uint32_t(buf, 28, clipping_2);
266
267 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VIBRATION, buf, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
268#else
269 mavlink_vibration_t packet;
270 packet.time_usec = time_usec;
271 packet.vibration_x = vibration_x;
272 packet.vibration_y = vibration_y;
273 packet.vibration_z = vibration_z;
274 packet.clipping_0 = clipping_0;
275 packet.clipping_1 = clipping_1;
276 packet.clipping_2 = clipping_2;
277
278 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VIBRATION, (const char *)&packet, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
279#endif
280}
281
282/**
283 * @brief Send a vibration message
284 * @param chan MAVLink channel to send the message
285 * @param struct The MAVLink struct to serialize
286 */
287static inline void mavlink_msg_vibration_send_struct(mavlink_channel_t chan, const mavlink_vibration_t* vibration)
288{
289#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
290 mavlink_msg_vibration_send(chan, vibration->time_usec, vibration->vibration_x, vibration->vibration_y, vibration->vibration_z, vibration->clipping_0, vibration->clipping_1, vibration->clipping_2);
291#else
292 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VIBRATION, (const char *)vibration, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
293#endif
294}
295
296#if MAVLINK_MSG_ID_VIBRATION_LEN <= MAVLINK_MAX_PAYLOAD_LEN
297/*
298 This variant of _send() can be used to save stack space by reusing
299 memory from the receive buffer. The caller provides a
300 mavlink_message_t which is the size of a full mavlink message. This
301 is usually the receive buffer for the channel, and allows a reply to an
302 incoming message with minimum stack space usage.
303 */
304static inline void mavlink_msg_vibration_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, float vibration_x, float vibration_y, float vibration_z, uint32_t clipping_0, uint32_t clipping_1, uint32_t clipping_2)
305{
306#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
307 char *buf = (char *)msgbuf;
308 _mav_put_uint64_t(buf, 0, time_usec);
309 _mav_put_float(buf, 8, vibration_x);
310 _mav_put_float(buf, 12, vibration_y);
311 _mav_put_float(buf, 16, vibration_z);
312 _mav_put_uint32_t(buf, 20, clipping_0);
313 _mav_put_uint32_t(buf, 24, clipping_1);
314 _mav_put_uint32_t(buf, 28, clipping_2);
315
316 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VIBRATION, buf, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
317#else
318 mavlink_vibration_t *packet = (mavlink_vibration_t *)msgbuf;
319 packet->time_usec = time_usec;
320 packet->vibration_x = vibration_x;
321 packet->vibration_y = vibration_y;
322 packet->vibration_z = vibration_z;
323 packet->clipping_0 = clipping_0;
324 packet->clipping_1 = clipping_1;
325 packet->clipping_2 = clipping_2;
326
327 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VIBRATION, (const char *)packet, MAVLINK_MSG_ID_VIBRATION_MIN_LEN, MAVLINK_MSG_ID_VIBRATION_LEN, MAVLINK_MSG_ID_VIBRATION_CRC);
328#endif
329}
330#endif
331
332#endif
333
334// MESSAGE VIBRATION UNPACKING
335
336
337/**
338 * @brief Get field time_usec from vibration message
339 *
340 * @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 of the number.
341 */
342static inline uint64_t mavlink_msg_vibration_get_time_usec(const mavlink_message_t* msg)
343{
344 return _MAV_RETURN_uint64_t(msg, 0);
345}
346
347/**
348 * @brief Get field vibration_x from vibration message
349 *
350 * @return Vibration levels on X-axis
351 */
352static inline float mavlink_msg_vibration_get_vibration_x(const mavlink_message_t* msg)
353{
354 return _MAV_RETURN_float(msg, 8);
355}
356
357/**
358 * @brief Get field vibration_y from vibration message
359 *
360 * @return Vibration levels on Y-axis
361 */
362static inline float mavlink_msg_vibration_get_vibration_y(const mavlink_message_t* msg)
363{
364 return _MAV_RETURN_float(msg, 12);
365}
366
367/**
368 * @brief Get field vibration_z from vibration message
369 *
370 * @return Vibration levels on Z-axis
371 */
372static inline float mavlink_msg_vibration_get_vibration_z(const mavlink_message_t* msg)
373{
374 return _MAV_RETURN_float(msg, 16);
375}
376
377/**
378 * @brief Get field clipping_0 from vibration message
379 *
380 * @return first accelerometer clipping count
381 */
382static inline uint32_t mavlink_msg_vibration_get_clipping_0(const mavlink_message_t* msg)
383{
384 return _MAV_RETURN_uint32_t(msg, 20);
385}
386
387/**
388 * @brief Get field clipping_1 from vibration message
389 *
390 * @return second accelerometer clipping count
391 */
392static inline uint32_t mavlink_msg_vibration_get_clipping_1(const mavlink_message_t* msg)
393{
394 return _MAV_RETURN_uint32_t(msg, 24);
395}
396
397/**
398 * @brief Get field clipping_2 from vibration message
399 *
400 * @return third accelerometer clipping count
401 */
402static inline uint32_t mavlink_msg_vibration_get_clipping_2(const mavlink_message_t* msg)
403{
404 return _MAV_RETURN_uint32_t(msg, 28);
405}
406
407/**
408 * @brief Decode a vibration message into a struct
409 *
410 * @param msg The message to decode
411 * @param vibration C-struct to decode the message contents into
412 */
413static inline void mavlink_msg_vibration_decode(const mavlink_message_t* msg, mavlink_vibration_t* vibration)
414{
415#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
416 vibration->time_usec = mavlink_msg_vibration_get_time_usec(msg);
417 vibration->vibration_x = mavlink_msg_vibration_get_vibration_x(msg);
418 vibration->vibration_y = mavlink_msg_vibration_get_vibration_y(msg);
419 vibration->vibration_z = mavlink_msg_vibration_get_vibration_z(msg);
420 vibration->clipping_0 = mavlink_msg_vibration_get_clipping_0(msg);
421 vibration->clipping_1 = mavlink_msg_vibration_get_clipping_1(msg);
422 vibration->clipping_2 = mavlink_msg_vibration_get_clipping_2(msg);
423#else
424 uint8_t len = msg->len < MAVLINK_MSG_ID_VIBRATION_LEN? msg->len : MAVLINK_MSG_ID_VIBRATION_LEN;
425 memset(vibration, 0, MAVLINK_MSG_ID_VIBRATION_LEN);
426 memcpy(vibration, _MAV_PAYLOAD(msg), len);
427#endif
428}