Move telemetry displayport init and cms device registering
[betaflight.git] / lib / main / MAVLink / common / mavlink_msg_optical_flow.h
blob6a2efc664f8cfc49ee23f2c56d3594a5814236af
1 // MESSAGE OPTICAL_FLOW PACKING
3 #define MAVLINK_MSG_ID_OPTICAL_FLOW 100
5 typedef struct __mavlink_optical_flow_t
7 uint64_t time_usec; ///< Timestamp (UNIX)
8 float flow_comp_m_x; ///< Flow in meters in x-sensor direction, angular-speed compensated
9 float flow_comp_m_y; ///< Flow in meters in y-sensor direction, angular-speed compensated
10 float ground_distance; ///< Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
11 int16_t flow_x; ///< Flow in pixels * 10 in x-sensor direction (dezi-pixels)
12 int16_t flow_y; ///< Flow in pixels * 10 in y-sensor direction (dezi-pixels)
13 uint8_t sensor_id; ///< Sensor ID
14 uint8_t quality; ///< Optical flow quality / confidence. 0: bad, 255: maximum quality
15 } mavlink_optical_flow_t;
17 #define MAVLINK_MSG_ID_OPTICAL_FLOW_LEN 26
18 #define MAVLINK_MSG_ID_100_LEN 26
20 #define MAVLINK_MSG_ID_OPTICAL_FLOW_CRC 175
21 #define MAVLINK_MSG_ID_100_CRC 175
25 #define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \
26 "OPTICAL_FLOW", \
27 8, \
28 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time_usec) }, \
29 { "flow_comp_m_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_optical_flow_t, flow_comp_m_x) }, \
30 { "flow_comp_m_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_optical_flow_t, flow_comp_m_y) }, \
31 { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_optical_flow_t, ground_distance) }, \
32 { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_optical_flow_t, flow_x) }, \
33 { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_optical_flow_t, flow_y) }, \
34 { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_optical_flow_t, sensor_id) }, \
35 { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_optical_flow_t, quality) }, \
36 } \
40 /**
41 * @brief Pack a optical_flow message
42 * @param system_id ID of this system
43 * @param component_id ID of this component (e.g. 200 for IMU)
44 * @param msg The MAVLink message to compress the data into
46 * @param time_usec Timestamp (UNIX)
47 * @param sensor_id Sensor ID
48 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
49 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
50 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
51 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
52 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
53 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
54 * @return length of the message in bytes (excluding serial stream start sign)
56 static inline uint16_t mavlink_msg_optical_flow_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
57 uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance)
59 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
60 char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
61 _mav_put_uint64_t(buf, 0, time_usec);
62 _mav_put_float(buf, 8, flow_comp_m_x);
63 _mav_put_float(buf, 12, flow_comp_m_y);
64 _mav_put_float(buf, 16, ground_distance);
65 _mav_put_int16_t(buf, 20, flow_x);
66 _mav_put_int16_t(buf, 22, flow_y);
67 _mav_put_uint8_t(buf, 24, sensor_id);
68 _mav_put_uint8_t(buf, 25, quality);
70 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
71 #else
72 mavlink_optical_flow_t packet;
73 packet.time_usec = time_usec;
74 packet.flow_comp_m_x = flow_comp_m_x;
75 packet.flow_comp_m_y = flow_comp_m_y;
76 packet.ground_distance = ground_distance;
77 packet.flow_x = flow_x;
78 packet.flow_y = flow_y;
79 packet.sensor_id = sensor_id;
80 packet.quality = quality;
82 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
83 #endif
85 msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
86 #if MAVLINK_CRC_EXTRA
87 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
88 #else
89 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
90 #endif
93 /**
94 * @brief Pack a optical_flow message on a channel
95 * @param system_id ID of this system
96 * @param component_id ID of this component (e.g. 200 for IMU)
97 * @param chan The MAVLink channel this message will be sent over
98 * @param msg The MAVLink message to compress the data into
99 * @param time_usec Timestamp (UNIX)
100 * @param sensor_id Sensor ID
101 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
102 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
103 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
104 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
105 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
106 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
107 * @return length of the message in bytes (excluding serial stream start sign)
109 static inline uint16_t mavlink_msg_optical_flow_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
110 mavlink_message_t* msg,
111 uint64_t time_usec,uint8_t sensor_id,int16_t flow_x,int16_t flow_y,float flow_comp_m_x,float flow_comp_m_y,uint8_t quality,float ground_distance)
113 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
114 char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
115 _mav_put_uint64_t(buf, 0, time_usec);
116 _mav_put_float(buf, 8, flow_comp_m_x);
117 _mav_put_float(buf, 12, flow_comp_m_y);
118 _mav_put_float(buf, 16, ground_distance);
119 _mav_put_int16_t(buf, 20, flow_x);
120 _mav_put_int16_t(buf, 22, flow_y);
121 _mav_put_uint8_t(buf, 24, sensor_id);
122 _mav_put_uint8_t(buf, 25, quality);
124 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
125 #else
126 mavlink_optical_flow_t packet;
127 packet.time_usec = time_usec;
128 packet.flow_comp_m_x = flow_comp_m_x;
129 packet.flow_comp_m_y = flow_comp_m_y;
130 packet.ground_distance = ground_distance;
131 packet.flow_x = flow_x;
132 packet.flow_y = flow_y;
133 packet.sensor_id = sensor_id;
134 packet.quality = quality;
136 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
137 #endif
139 msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
140 #if MAVLINK_CRC_EXTRA
141 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
142 #else
143 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
144 #endif
148 * @brief Encode a optical_flow struct
150 * @param system_id ID of this system
151 * @param component_id ID of this component (e.g. 200 for IMU)
152 * @param msg The MAVLink message to compress the data into
153 * @param optical_flow C-struct to read the message contents from
155 static inline uint16_t mavlink_msg_optical_flow_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow)
157 return mavlink_msg_optical_flow_pack(system_id, component_id, msg, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance);
161 * @brief Encode a optical_flow struct on a channel
163 * @param system_id ID of this system
164 * @param component_id ID of this component (e.g. 200 for IMU)
165 * @param chan The MAVLink channel this message will be sent over
166 * @param msg The MAVLink message to compress the data into
167 * @param optical_flow C-struct to read the message contents from
169 static inline uint16_t mavlink_msg_optical_flow_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow)
171 return mavlink_msg_optical_flow_pack_chan(system_id, component_id, chan, msg, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance);
175 * @brief Send a optical_flow message
176 * @param chan MAVLink channel to send the message
178 * @param time_usec Timestamp (UNIX)
179 * @param sensor_id Sensor ID
180 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
181 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
182 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
183 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
184 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
185 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
187 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
189 static inline void mavlink_msg_optical_flow_send(mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance)
191 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
192 char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
193 _mav_put_uint64_t(buf, 0, time_usec);
194 _mav_put_float(buf, 8, flow_comp_m_x);
195 _mav_put_float(buf, 12, flow_comp_m_y);
196 _mav_put_float(buf, 16, ground_distance);
197 _mav_put_int16_t(buf, 20, flow_x);
198 _mav_put_int16_t(buf, 22, flow_y);
199 _mav_put_uint8_t(buf, 24, sensor_id);
200 _mav_put_uint8_t(buf, 25, quality);
202 #if MAVLINK_CRC_EXTRA
203 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
204 #else
205 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
206 #endif
207 #else
208 mavlink_optical_flow_t packet;
209 packet.time_usec = time_usec;
210 packet.flow_comp_m_x = flow_comp_m_x;
211 packet.flow_comp_m_y = flow_comp_m_y;
212 packet.ground_distance = ground_distance;
213 packet.flow_x = flow_x;
214 packet.flow_y = flow_y;
215 packet.sensor_id = sensor_id;
216 packet.quality = quality;
218 #if MAVLINK_CRC_EXTRA
219 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)&packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
220 #else
221 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)&packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
222 #endif
223 #endif
226 #if MAVLINK_MSG_ID_OPTICAL_FLOW_LEN <= MAVLINK_MAX_PAYLOAD_LEN
228 This varient of _send() can be used to save stack space by re-using
229 memory from the receive buffer. The caller provides a
230 mavlink_message_t which is the size of a full mavlink message. This
231 is usually the receive buffer for the channel, and allows a reply to an
232 incoming message with minimum stack space usage.
234 static inline void mavlink_msg_optical_flow_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance)
236 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
237 char *buf = (char *)msgbuf;
238 _mav_put_uint64_t(buf, 0, time_usec);
239 _mav_put_float(buf, 8, flow_comp_m_x);
240 _mav_put_float(buf, 12, flow_comp_m_y);
241 _mav_put_float(buf, 16, ground_distance);
242 _mav_put_int16_t(buf, 20, flow_x);
243 _mav_put_int16_t(buf, 22, flow_y);
244 _mav_put_uint8_t(buf, 24, sensor_id);
245 _mav_put_uint8_t(buf, 25, quality);
247 #if MAVLINK_CRC_EXTRA
248 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
249 #else
250 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
251 #endif
252 #else
253 mavlink_optical_flow_t *packet = (mavlink_optical_flow_t *)msgbuf;
254 packet->time_usec = time_usec;
255 packet->flow_comp_m_x = flow_comp_m_x;
256 packet->flow_comp_m_y = flow_comp_m_y;
257 packet->ground_distance = ground_distance;
258 packet->flow_x = flow_x;
259 packet->flow_y = flow_y;
260 packet->sensor_id = sensor_id;
261 packet->quality = quality;
263 #if MAVLINK_CRC_EXTRA
264 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
265 #else
266 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
267 #endif
268 #endif
270 #endif
272 #endif
274 // MESSAGE OPTICAL_FLOW UNPACKING
278 * @brief Get field time_usec from optical_flow message
280 * @return Timestamp (UNIX)
282 static inline uint64_t mavlink_msg_optical_flow_get_time_usec(const mavlink_message_t* msg)
284 return _MAV_RETURN_uint64_t(msg, 0);
288 * @brief Get field sensor_id from optical_flow message
290 * @return Sensor ID
292 static inline uint8_t mavlink_msg_optical_flow_get_sensor_id(const mavlink_message_t* msg)
294 return _MAV_RETURN_uint8_t(msg, 24);
298 * @brief Get field flow_x from optical_flow message
300 * @return Flow in pixels * 10 in x-sensor direction (dezi-pixels)
302 static inline int16_t mavlink_msg_optical_flow_get_flow_x(const mavlink_message_t* msg)
304 return _MAV_RETURN_int16_t(msg, 20);
308 * @brief Get field flow_y from optical_flow message
310 * @return Flow in pixels * 10 in y-sensor direction (dezi-pixels)
312 static inline int16_t mavlink_msg_optical_flow_get_flow_y(const mavlink_message_t* msg)
314 return _MAV_RETURN_int16_t(msg, 22);
318 * @brief Get field flow_comp_m_x from optical_flow message
320 * @return Flow in meters in x-sensor direction, angular-speed compensated
322 static inline float mavlink_msg_optical_flow_get_flow_comp_m_x(const mavlink_message_t* msg)
324 return _MAV_RETURN_float(msg, 8);
328 * @brief Get field flow_comp_m_y from optical_flow message
330 * @return Flow in meters in y-sensor direction, angular-speed compensated
332 static inline float mavlink_msg_optical_flow_get_flow_comp_m_y(const mavlink_message_t* msg)
334 return _MAV_RETURN_float(msg, 12);
338 * @brief Get field quality from optical_flow message
340 * @return Optical flow quality / confidence. 0: bad, 255: maximum quality
342 static inline uint8_t mavlink_msg_optical_flow_get_quality(const mavlink_message_t* msg)
344 return _MAV_RETURN_uint8_t(msg, 25);
348 * @brief Get field ground_distance from optical_flow message
350 * @return Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
352 static inline float mavlink_msg_optical_flow_get_ground_distance(const mavlink_message_t* msg)
354 return _MAV_RETURN_float(msg, 16);
358 * @brief Decode a optical_flow message into a struct
360 * @param msg The message to decode
361 * @param optical_flow C-struct to decode the message contents into
363 static inline void mavlink_msg_optical_flow_decode(const mavlink_message_t* msg, mavlink_optical_flow_t* optical_flow)
365 #if MAVLINK_NEED_BYTE_SWAP
366 optical_flow->time_usec = mavlink_msg_optical_flow_get_time_usec(msg);
367 optical_flow->flow_comp_m_x = mavlink_msg_optical_flow_get_flow_comp_m_x(msg);
368 optical_flow->flow_comp_m_y = mavlink_msg_optical_flow_get_flow_comp_m_y(msg);
369 optical_flow->ground_distance = mavlink_msg_optical_flow_get_ground_distance(msg);
370 optical_flow->flow_x = mavlink_msg_optical_flow_get_flow_x(msg);
371 optical_flow->flow_y = mavlink_msg_optical_flow_get_flow_y(msg);
372 optical_flow->sensor_id = mavlink_msg_optical_flow_get_sensor_id(msg);
373 optical_flow->quality = mavlink_msg_optical_flow_get_quality(msg);
374 #else
375 memcpy(optical_flow, _MAV_PAYLOAD(msg), MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
376 #endif