Merge remote-tracking branch 'upstream/master' into abo_fw_alt_vel_control
[inav.git] / lib / main / MAVLink / common / mavlink_msg_collision.h
blobb7d8a07f25753534784cee5b3142a6f6f22c76a8
1 #pragma once
2 // MESSAGE COLLISION PACKING
4 #define MAVLINK_MSG_ID_COLLISION 247
7 typedef struct __mavlink_collision_t {
8 uint32_t id; /*< Unique identifier, domain based on src field*/
9 float time_to_minimum_delta; /*< [s] Estimated time until collision occurs*/
10 float altitude_minimum_delta; /*< [m] Closest vertical distance between vehicle and object*/
11 float horizontal_minimum_delta; /*< [m] Closest horizontal distance between vehicle and object*/
12 uint8_t src; /*< Collision data source*/
13 uint8_t action; /*< Action that is being taken to avoid this collision*/
14 uint8_t threat_level; /*< How concerned the aircraft is about this collision*/
15 } mavlink_collision_t;
17 #define MAVLINK_MSG_ID_COLLISION_LEN 19
18 #define MAVLINK_MSG_ID_COLLISION_MIN_LEN 19
19 #define MAVLINK_MSG_ID_247_LEN 19
20 #define MAVLINK_MSG_ID_247_MIN_LEN 19
22 #define MAVLINK_MSG_ID_COLLISION_CRC 81
23 #define MAVLINK_MSG_ID_247_CRC 81
27 #if MAVLINK_COMMAND_24BIT
28 #define MAVLINK_MESSAGE_INFO_COLLISION { \
29 247, \
30 "COLLISION", \
31 7, \
32 { { "src", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_collision_t, src) }, \
33 { "id", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_collision_t, id) }, \
34 { "action", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_collision_t, action) }, \
35 { "threat_level", NULL, MAVLINK_TYPE_UINT8_T, 0, 18, offsetof(mavlink_collision_t, threat_level) }, \
36 { "time_to_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_collision_t, time_to_minimum_delta) }, \
37 { "altitude_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_collision_t, altitude_minimum_delta) }, \
38 { "horizontal_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_collision_t, horizontal_minimum_delta) }, \
39 } \
41 #else
42 #define MAVLINK_MESSAGE_INFO_COLLISION { \
43 "COLLISION", \
44 7, \
45 { { "src", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_collision_t, src) }, \
46 { "id", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_collision_t, id) }, \
47 { "action", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_collision_t, action) }, \
48 { "threat_level", NULL, MAVLINK_TYPE_UINT8_T, 0, 18, offsetof(mavlink_collision_t, threat_level) }, \
49 { "time_to_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_collision_t, time_to_minimum_delta) }, \
50 { "altitude_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_collision_t, altitude_minimum_delta) }, \
51 { "horizontal_minimum_delta", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_collision_t, horizontal_minimum_delta) }, \
52 } \
54 #endif
56 /**
57 * @brief Pack a collision 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
62 * @param src Collision data source
63 * @param id Unique identifier, domain based on src field
64 * @param action Action that is being taken to avoid this collision
65 * @param threat_level How concerned the aircraft is about this collision
66 * @param time_to_minimum_delta [s] Estimated time until collision occurs
67 * @param altitude_minimum_delta [m] Closest vertical distance between vehicle and object
68 * @param horizontal_minimum_delta [m] Closest horizontal distance between vehicle and object
69 * @return length of the message in bytes (excluding serial stream start sign)
71 static inline uint16_t mavlink_msg_collision_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
72 uint8_t src, uint32_t id, uint8_t action, uint8_t threat_level, float time_to_minimum_delta, float altitude_minimum_delta, float horizontal_minimum_delta)
74 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
75 char buf[MAVLINK_MSG_ID_COLLISION_LEN];
76 _mav_put_uint32_t(buf, 0, id);
77 _mav_put_float(buf, 4, time_to_minimum_delta);
78 _mav_put_float(buf, 8, altitude_minimum_delta);
79 _mav_put_float(buf, 12, horizontal_minimum_delta);
80 _mav_put_uint8_t(buf, 16, src);
81 _mav_put_uint8_t(buf, 17, action);
82 _mav_put_uint8_t(buf, 18, threat_level);
84 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_COLLISION_LEN);
85 #else
86 mavlink_collision_t packet;
87 packet.id = id;
88 packet.time_to_minimum_delta = time_to_minimum_delta;
89 packet.altitude_minimum_delta = altitude_minimum_delta;
90 packet.horizontal_minimum_delta = horizontal_minimum_delta;
91 packet.src = src;
92 packet.action = action;
93 packet.threat_level = threat_level;
95 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_COLLISION_LEN);
96 #endif
98 msg->msgid = MAVLINK_MSG_ID_COLLISION;
99 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
103 * @brief Pack a collision message on a channel
104 * @param system_id ID of this system
105 * @param component_id ID of this component (e.g. 200 for IMU)
106 * @param chan The MAVLink channel this message will be sent over
107 * @param msg The MAVLink message to compress the data into
108 * @param src Collision data source
109 * @param id Unique identifier, domain based on src field
110 * @param action Action that is being taken to avoid this collision
111 * @param threat_level How concerned the aircraft is about this collision
112 * @param time_to_minimum_delta [s] Estimated time until collision occurs
113 * @param altitude_minimum_delta [m] Closest vertical distance between vehicle and object
114 * @param horizontal_minimum_delta [m] Closest horizontal distance between vehicle and object
115 * @return length of the message in bytes (excluding serial stream start sign)
117 static inline uint16_t mavlink_msg_collision_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
118 mavlink_message_t* msg,
119 uint8_t src,uint32_t id,uint8_t action,uint8_t threat_level,float time_to_minimum_delta,float altitude_minimum_delta,float horizontal_minimum_delta)
121 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
122 char buf[MAVLINK_MSG_ID_COLLISION_LEN];
123 _mav_put_uint32_t(buf, 0, id);
124 _mav_put_float(buf, 4, time_to_minimum_delta);
125 _mav_put_float(buf, 8, altitude_minimum_delta);
126 _mav_put_float(buf, 12, horizontal_minimum_delta);
127 _mav_put_uint8_t(buf, 16, src);
128 _mav_put_uint8_t(buf, 17, action);
129 _mav_put_uint8_t(buf, 18, threat_level);
131 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_COLLISION_LEN);
132 #else
133 mavlink_collision_t packet;
134 packet.id = id;
135 packet.time_to_minimum_delta = time_to_minimum_delta;
136 packet.altitude_minimum_delta = altitude_minimum_delta;
137 packet.horizontal_minimum_delta = horizontal_minimum_delta;
138 packet.src = src;
139 packet.action = action;
140 packet.threat_level = threat_level;
142 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_COLLISION_LEN);
143 #endif
145 msg->msgid = MAVLINK_MSG_ID_COLLISION;
146 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
150 * @brief Encode a collision struct
152 * @param system_id ID of this system
153 * @param component_id ID of this component (e.g. 200 for IMU)
154 * @param msg The MAVLink message to compress the data into
155 * @param collision C-struct to read the message contents from
157 static inline uint16_t mavlink_msg_collision_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_collision_t* collision)
159 return mavlink_msg_collision_pack(system_id, component_id, msg, collision->src, collision->id, collision->action, collision->threat_level, collision->time_to_minimum_delta, collision->altitude_minimum_delta, collision->horizontal_minimum_delta);
163 * @brief Encode a collision struct on a channel
165 * @param system_id ID of this system
166 * @param component_id ID of this component (e.g. 200 for IMU)
167 * @param chan The MAVLink channel this message will be sent over
168 * @param msg The MAVLink message to compress the data into
169 * @param collision C-struct to read the message contents from
171 static inline uint16_t mavlink_msg_collision_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_collision_t* collision)
173 return mavlink_msg_collision_pack_chan(system_id, component_id, chan, msg, collision->src, collision->id, collision->action, collision->threat_level, collision->time_to_minimum_delta, collision->altitude_minimum_delta, collision->horizontal_minimum_delta);
177 * @brief Send a collision message
178 * @param chan MAVLink channel to send the message
180 * @param src Collision data source
181 * @param id Unique identifier, domain based on src field
182 * @param action Action that is being taken to avoid this collision
183 * @param threat_level How concerned the aircraft is about this collision
184 * @param time_to_minimum_delta [s] Estimated time until collision occurs
185 * @param altitude_minimum_delta [m] Closest vertical distance between vehicle and object
186 * @param horizontal_minimum_delta [m] Closest horizontal distance between vehicle and object
188 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
190 static inline void mavlink_msg_collision_send(mavlink_channel_t chan, uint8_t src, uint32_t id, uint8_t action, uint8_t threat_level, float time_to_minimum_delta, float altitude_minimum_delta, float horizontal_minimum_delta)
192 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
193 char buf[MAVLINK_MSG_ID_COLLISION_LEN];
194 _mav_put_uint32_t(buf, 0, id);
195 _mav_put_float(buf, 4, time_to_minimum_delta);
196 _mav_put_float(buf, 8, altitude_minimum_delta);
197 _mav_put_float(buf, 12, horizontal_minimum_delta);
198 _mav_put_uint8_t(buf, 16, src);
199 _mav_put_uint8_t(buf, 17, action);
200 _mav_put_uint8_t(buf, 18, threat_level);
202 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COLLISION, buf, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
203 #else
204 mavlink_collision_t packet;
205 packet.id = id;
206 packet.time_to_minimum_delta = time_to_minimum_delta;
207 packet.altitude_minimum_delta = altitude_minimum_delta;
208 packet.horizontal_minimum_delta = horizontal_minimum_delta;
209 packet.src = src;
210 packet.action = action;
211 packet.threat_level = threat_level;
213 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COLLISION, (const char *)&packet, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
214 #endif
218 * @brief Send a collision message
219 * @param chan MAVLink channel to send the message
220 * @param struct The MAVLink struct to serialize
222 static inline void mavlink_msg_collision_send_struct(mavlink_channel_t chan, const mavlink_collision_t* collision)
224 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
225 mavlink_msg_collision_send(chan, collision->src, collision->id, collision->action, collision->threat_level, collision->time_to_minimum_delta, collision->altitude_minimum_delta, collision->horizontal_minimum_delta);
226 #else
227 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COLLISION, (const char *)collision, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
228 #endif
231 #if MAVLINK_MSG_ID_COLLISION_LEN <= MAVLINK_MAX_PAYLOAD_LEN
233 This varient of _send() can be used to save stack space by re-using
234 memory from the receive buffer. The caller provides a
235 mavlink_message_t which is the size of a full mavlink message. This
236 is usually the receive buffer for the channel, and allows a reply to an
237 incoming message with minimum stack space usage.
239 static inline void mavlink_msg_collision_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint8_t src, uint32_t id, uint8_t action, uint8_t threat_level, float time_to_minimum_delta, float altitude_minimum_delta, float horizontal_minimum_delta)
241 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
242 char *buf = (char *)msgbuf;
243 _mav_put_uint32_t(buf, 0, id);
244 _mav_put_float(buf, 4, time_to_minimum_delta);
245 _mav_put_float(buf, 8, altitude_minimum_delta);
246 _mav_put_float(buf, 12, horizontal_minimum_delta);
247 _mav_put_uint8_t(buf, 16, src);
248 _mav_put_uint8_t(buf, 17, action);
249 _mav_put_uint8_t(buf, 18, threat_level);
251 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COLLISION, buf, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
252 #else
253 mavlink_collision_t *packet = (mavlink_collision_t *)msgbuf;
254 packet->id = id;
255 packet->time_to_minimum_delta = time_to_minimum_delta;
256 packet->altitude_minimum_delta = altitude_minimum_delta;
257 packet->horizontal_minimum_delta = horizontal_minimum_delta;
258 packet->src = src;
259 packet->action = action;
260 packet->threat_level = threat_level;
262 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COLLISION, (const char *)packet, MAVLINK_MSG_ID_COLLISION_MIN_LEN, MAVLINK_MSG_ID_COLLISION_LEN, MAVLINK_MSG_ID_COLLISION_CRC);
263 #endif
265 #endif
267 #endif
269 // MESSAGE COLLISION UNPACKING
273 * @brief Get field src from collision message
275 * @return Collision data source
277 static inline uint8_t mavlink_msg_collision_get_src(const mavlink_message_t* msg)
279 return _MAV_RETURN_uint8_t(msg, 16);
283 * @brief Get field id from collision message
285 * @return Unique identifier, domain based on src field
287 static inline uint32_t mavlink_msg_collision_get_id(const mavlink_message_t* msg)
289 return _MAV_RETURN_uint32_t(msg, 0);
293 * @brief Get field action from collision message
295 * @return Action that is being taken to avoid this collision
297 static inline uint8_t mavlink_msg_collision_get_action(const mavlink_message_t* msg)
299 return _MAV_RETURN_uint8_t(msg, 17);
303 * @brief Get field threat_level from collision message
305 * @return How concerned the aircraft is about this collision
307 static inline uint8_t mavlink_msg_collision_get_threat_level(const mavlink_message_t* msg)
309 return _MAV_RETURN_uint8_t(msg, 18);
313 * @brief Get field time_to_minimum_delta from collision message
315 * @return [s] Estimated time until collision occurs
317 static inline float mavlink_msg_collision_get_time_to_minimum_delta(const mavlink_message_t* msg)
319 return _MAV_RETURN_float(msg, 4);
323 * @brief Get field altitude_minimum_delta from collision message
325 * @return [m] Closest vertical distance between vehicle and object
327 static inline float mavlink_msg_collision_get_altitude_minimum_delta(const mavlink_message_t* msg)
329 return _MAV_RETURN_float(msg, 8);
333 * @brief Get field horizontal_minimum_delta from collision message
335 * @return [m] Closest horizontal distance between vehicle and object
337 static inline float mavlink_msg_collision_get_horizontal_minimum_delta(const mavlink_message_t* msg)
339 return _MAV_RETURN_float(msg, 12);
343 * @brief Decode a collision message into a struct
345 * @param msg The message to decode
346 * @param collision C-struct to decode the message contents into
348 static inline void mavlink_msg_collision_decode(const mavlink_message_t* msg, mavlink_collision_t* collision)
350 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
351 collision->id = mavlink_msg_collision_get_id(msg);
352 collision->time_to_minimum_delta = mavlink_msg_collision_get_time_to_minimum_delta(msg);
353 collision->altitude_minimum_delta = mavlink_msg_collision_get_altitude_minimum_delta(msg);
354 collision->horizontal_minimum_delta = mavlink_msg_collision_get_horizontal_minimum_delta(msg);
355 collision->src = mavlink_msg_collision_get_src(msg);
356 collision->action = mavlink_msg_collision_get_action(msg);
357 collision->threat_level = mavlink_msg_collision_get_threat_level(msg);
358 #else
359 uint8_t len = msg->len < MAVLINK_MSG_ID_COLLISION_LEN? msg->len : MAVLINK_MSG_ID_COLLISION_LEN;
360 memset(collision, 0, MAVLINK_MSG_ID_COLLISION_LEN);
361 memcpy(collision, _MAV_PAYLOAD(msg), len);
362 #endif