before merging master
[inav.git] / lib / main / MAVLink / common / mavlink_msg_wheel_distance.h
blobd506f003601094aa1e4834a67776406efb595e32
1 #pragma once
2 // MESSAGE WHEEL_DISTANCE PACKING
4 #define MAVLINK_MSG_ID_WHEEL_DISTANCE 9000
7 typedef struct __mavlink_wheel_distance_t {
8 uint64_t time_usec; /*< [us] Timestamp (synced to UNIX time or since system boot).*/
9 double distance[16]; /*< [m] Distance reported by individual wheel encoders. Forward rotations increase values, reverse rotations decrease them. Not all wheels will necessarily have wheel encoders; the mapping of encoders to wheel positions must be agreed/understood by the endpoints.*/
10 uint8_t count; /*< Number of wheels reported.*/
11 } mavlink_wheel_distance_t;
13 #define MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN 137
14 #define MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN 137
15 #define MAVLINK_MSG_ID_9000_LEN 137
16 #define MAVLINK_MSG_ID_9000_MIN_LEN 137
18 #define MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC 113
19 #define MAVLINK_MSG_ID_9000_CRC 113
21 #define MAVLINK_MSG_WHEEL_DISTANCE_FIELD_DISTANCE_LEN 16
23 #if MAVLINK_COMMAND_24BIT
24 #define MAVLINK_MESSAGE_INFO_WHEEL_DISTANCE { \
25 9000, \
26 "WHEEL_DISTANCE", \
27 3, \
28 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_wheel_distance_t, time_usec) }, \
29 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 136, offsetof(mavlink_wheel_distance_t, count) }, \
30 { "distance", NULL, MAVLINK_TYPE_DOUBLE, 16, 8, offsetof(mavlink_wheel_distance_t, distance) }, \
31 } \
33 #else
34 #define MAVLINK_MESSAGE_INFO_WHEEL_DISTANCE { \
35 "WHEEL_DISTANCE", \
36 3, \
37 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_wheel_distance_t, time_usec) }, \
38 { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 136, offsetof(mavlink_wheel_distance_t, count) }, \
39 { "distance", NULL, MAVLINK_TYPE_DOUBLE, 16, 8, offsetof(mavlink_wheel_distance_t, distance) }, \
40 } \
42 #endif
44 /**
45 * @brief Pack a wheel_distance message
46 * @param system_id ID of this system
47 * @param component_id ID of this component (e.g. 200 for IMU)
48 * @param msg The MAVLink message to compress the data into
50 * @param time_usec [us] Timestamp (synced to UNIX time or since system boot).
51 * @param count Number of wheels reported.
52 * @param distance [m] Distance reported by individual wheel encoders. Forward rotations increase values, reverse rotations decrease them. Not all wheels will necessarily have wheel encoders; the mapping of encoders to wheel positions must be agreed/understood by the endpoints.
53 * @return length of the message in bytes (excluding serial stream start sign)
55 static inline uint16_t mavlink_msg_wheel_distance_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
56 uint64_t time_usec, uint8_t count, const double *distance)
58 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
59 char buf[MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN];
60 _mav_put_uint64_t(buf, 0, time_usec);
61 _mav_put_uint8_t(buf, 136, count);
62 _mav_put_double_array(buf, 8, distance, 16);
63 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN);
64 #else
65 mavlink_wheel_distance_t packet;
66 packet.time_usec = time_usec;
67 packet.count = count;
68 mav_array_memcpy(packet.distance, distance, sizeof(double)*16);
69 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN);
70 #endif
72 msg->msgid = MAVLINK_MSG_ID_WHEEL_DISTANCE;
73 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
76 /**
77 * @brief Pack a wheel_distance message on a channel
78 * @param system_id ID of this system
79 * @param component_id ID of this component (e.g. 200 for IMU)
80 * @param chan The MAVLink channel this message will be sent over
81 * @param msg The MAVLink message to compress the data into
82 * @param time_usec [us] Timestamp (synced to UNIX time or since system boot).
83 * @param count Number of wheels reported.
84 * @param distance [m] Distance reported by individual wheel encoders. Forward rotations increase values, reverse rotations decrease them. Not all wheels will necessarily have wheel encoders; the mapping of encoders to wheel positions must be agreed/understood by the endpoints.
85 * @return length of the message in bytes (excluding serial stream start sign)
87 static inline uint16_t mavlink_msg_wheel_distance_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
88 mavlink_message_t* msg,
89 uint64_t time_usec,uint8_t count,const double *distance)
91 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
92 char buf[MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN];
93 _mav_put_uint64_t(buf, 0, time_usec);
94 _mav_put_uint8_t(buf, 136, count);
95 _mav_put_double_array(buf, 8, distance, 16);
96 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN);
97 #else
98 mavlink_wheel_distance_t packet;
99 packet.time_usec = time_usec;
100 packet.count = count;
101 mav_array_memcpy(packet.distance, distance, sizeof(double)*16);
102 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN);
103 #endif
105 msg->msgid = MAVLINK_MSG_ID_WHEEL_DISTANCE;
106 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
110 * @brief Encode a wheel_distance struct
112 * @param system_id ID of this system
113 * @param component_id ID of this component (e.g. 200 for IMU)
114 * @param msg The MAVLink message to compress the data into
115 * @param wheel_distance C-struct to read the message contents from
117 static inline uint16_t mavlink_msg_wheel_distance_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_wheel_distance_t* wheel_distance)
119 return mavlink_msg_wheel_distance_pack(system_id, component_id, msg, wheel_distance->time_usec, wheel_distance->count, wheel_distance->distance);
123 * @brief Encode a wheel_distance struct on a channel
125 * @param system_id ID of this system
126 * @param component_id ID of this component (e.g. 200 for IMU)
127 * @param chan The MAVLink channel this message will be sent over
128 * @param msg The MAVLink message to compress the data into
129 * @param wheel_distance C-struct to read the message contents from
131 static inline uint16_t mavlink_msg_wheel_distance_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_wheel_distance_t* wheel_distance)
133 return mavlink_msg_wheel_distance_pack_chan(system_id, component_id, chan, msg, wheel_distance->time_usec, wheel_distance->count, wheel_distance->distance);
137 * @brief Send a wheel_distance message
138 * @param chan MAVLink channel to send the message
140 * @param time_usec [us] Timestamp (synced to UNIX time or since system boot).
141 * @param count Number of wheels reported.
142 * @param distance [m] Distance reported by individual wheel encoders. Forward rotations increase values, reverse rotations decrease them. Not all wheels will necessarily have wheel encoders; the mapping of encoders to wheel positions must be agreed/understood by the endpoints.
144 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
146 static inline void mavlink_msg_wheel_distance_send(mavlink_channel_t chan, uint64_t time_usec, uint8_t count, const double *distance)
148 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
149 char buf[MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN];
150 _mav_put_uint64_t(buf, 0, time_usec);
151 _mav_put_uint8_t(buf, 136, count);
152 _mav_put_double_array(buf, 8, distance, 16);
153 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WHEEL_DISTANCE, buf, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
154 #else
155 mavlink_wheel_distance_t packet;
156 packet.time_usec = time_usec;
157 packet.count = count;
158 mav_array_memcpy(packet.distance, distance, sizeof(double)*16);
159 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WHEEL_DISTANCE, (const char *)&packet, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
160 #endif
164 * @brief Send a wheel_distance message
165 * @param chan MAVLink channel to send the message
166 * @param struct The MAVLink struct to serialize
168 static inline void mavlink_msg_wheel_distance_send_struct(mavlink_channel_t chan, const mavlink_wheel_distance_t* wheel_distance)
170 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
171 mavlink_msg_wheel_distance_send(chan, wheel_distance->time_usec, wheel_distance->count, wheel_distance->distance);
172 #else
173 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WHEEL_DISTANCE, (const char *)wheel_distance, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
174 #endif
177 #if MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN <= MAVLINK_MAX_PAYLOAD_LEN
179 This varient of _send() can be used to save stack space by re-using
180 memory from the receive buffer. The caller provides a
181 mavlink_message_t which is the size of a full mavlink message. This
182 is usually the receive buffer for the channel, and allows a reply to an
183 incoming message with minimum stack space usage.
185 static inline void mavlink_msg_wheel_distance_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, uint8_t count, const double *distance)
187 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
188 char *buf = (char *)msgbuf;
189 _mav_put_uint64_t(buf, 0, time_usec);
190 _mav_put_uint8_t(buf, 136, count);
191 _mav_put_double_array(buf, 8, distance, 16);
192 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WHEEL_DISTANCE, buf, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
193 #else
194 mavlink_wheel_distance_t *packet = (mavlink_wheel_distance_t *)msgbuf;
195 packet->time_usec = time_usec;
196 packet->count = count;
197 mav_array_memcpy(packet->distance, distance, sizeof(double)*16);
198 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WHEEL_DISTANCE, (const char *)packet, MAVLINK_MSG_ID_WHEEL_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN, MAVLINK_MSG_ID_WHEEL_DISTANCE_CRC);
199 #endif
201 #endif
203 #endif
205 // MESSAGE WHEEL_DISTANCE UNPACKING
209 * @brief Get field time_usec from wheel_distance message
211 * @return [us] Timestamp (synced to UNIX time or since system boot).
213 static inline uint64_t mavlink_msg_wheel_distance_get_time_usec(const mavlink_message_t* msg)
215 return _MAV_RETURN_uint64_t(msg, 0);
219 * @brief Get field count from wheel_distance message
221 * @return Number of wheels reported.
223 static inline uint8_t mavlink_msg_wheel_distance_get_count(const mavlink_message_t* msg)
225 return _MAV_RETURN_uint8_t(msg, 136);
229 * @brief Get field distance from wheel_distance message
231 * @return [m] Distance reported by individual wheel encoders. Forward rotations increase values, reverse rotations decrease them. Not all wheels will necessarily have wheel encoders; the mapping of encoders to wheel positions must be agreed/understood by the endpoints.
233 static inline uint16_t mavlink_msg_wheel_distance_get_distance(const mavlink_message_t* msg, double *distance)
235 return _MAV_RETURN_double_array(msg, distance, 16, 8);
239 * @brief Decode a wheel_distance message into a struct
241 * @param msg The message to decode
242 * @param wheel_distance C-struct to decode the message contents into
244 static inline void mavlink_msg_wheel_distance_decode(const mavlink_message_t* msg, mavlink_wheel_distance_t* wheel_distance)
246 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
247 wheel_distance->time_usec = mavlink_msg_wheel_distance_get_time_usec(msg);
248 mavlink_msg_wheel_distance_get_distance(msg, wheel_distance->distance);
249 wheel_distance->count = mavlink_msg_wheel_distance_get_count(msg);
250 #else
251 uint8_t len = msg->len < MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN? msg->len : MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN;
252 memset(wheel_distance, 0, MAVLINK_MSG_ID_WHEEL_DISTANCE_LEN);
253 memcpy(wheel_distance, _MAV_PAYLOAD(msg), len);
254 #endif