pinxian wu / mavlink_bridge

Dependents:   mavlink F429ZI_LCD_demo

Fork of mavlink_bridge by Benjamin Hepp

Committer:
wupinxian
Date:
Mon Jul 23 16:34:26 2018 +0000
Revision:
11:76345550efb4
Parent:
0:28183cc7963f
mavlink for stm32 Nucleo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhepp 0:28183cc7963f 1 // MESSAGE DEBUG PACKING
bhepp 0:28183cc7963f 2
bhepp 0:28183cc7963f 3 #define MAVLINK_MSG_ID_DEBUG 254
bhepp 0:28183cc7963f 4
bhepp 0:28183cc7963f 5 typedef struct __mavlink_debug_t
bhepp 0:28183cc7963f 6 {
bhepp 0:28183cc7963f 7 uint32_t time_boot_ms; /*< Timestamp (milliseconds since system boot)*/
bhepp 0:28183cc7963f 8 float value; /*< DEBUG value*/
bhepp 0:28183cc7963f 9 uint8_t ind; /*< index of debug variable*/
bhepp 0:28183cc7963f 10 } mavlink_debug_t;
bhepp 0:28183cc7963f 11
bhepp 0:28183cc7963f 12 #define MAVLINK_MSG_ID_DEBUG_LEN 9
bhepp 0:28183cc7963f 13 #define MAVLINK_MSG_ID_254_LEN 9
bhepp 0:28183cc7963f 14
bhepp 0:28183cc7963f 15 #define MAVLINK_MSG_ID_DEBUG_CRC 46
bhepp 0:28183cc7963f 16 #define MAVLINK_MSG_ID_254_CRC 46
bhepp 0:28183cc7963f 17
bhepp 0:28183cc7963f 18
bhepp 0:28183cc7963f 19
bhepp 0:28183cc7963f 20 #define MAVLINK_MESSAGE_INFO_DEBUG { \
bhepp 0:28183cc7963f 21 "DEBUG", \
bhepp 0:28183cc7963f 22 3, \
bhepp 0:28183cc7963f 23 { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_debug_t, time_boot_ms) }, \
bhepp 0:28183cc7963f 24 { "value", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_debug_t, value) }, \
bhepp 0:28183cc7963f 25 { "ind", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_debug_t, ind) }, \
bhepp 0:28183cc7963f 26 } \
bhepp 0:28183cc7963f 27 }
bhepp 0:28183cc7963f 28
bhepp 0:28183cc7963f 29
bhepp 0:28183cc7963f 30 /**
bhepp 0:28183cc7963f 31 * @brief Pack a debug message
bhepp 0:28183cc7963f 32 * @param system_id ID of this system
bhepp 0:28183cc7963f 33 * @param component_id ID of this component (e.g. 200 for IMU)
bhepp 0:28183cc7963f 34 * @param msg The MAVLink message to compress the data into
bhepp 0:28183cc7963f 35 *
bhepp 0:28183cc7963f 36 * @param time_boot_ms Timestamp (milliseconds since system boot)
bhepp 0:28183cc7963f 37 * @param ind index of debug variable
bhepp 0:28183cc7963f 38 * @param value DEBUG value
bhepp 0:28183cc7963f 39 * @return length of the message in bytes (excluding serial stream start sign)
bhepp 0:28183cc7963f 40 */
bhepp 0:28183cc7963f 41 static inline uint16_t mavlink_msg_debug_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
bhepp 0:28183cc7963f 42 uint32_t time_boot_ms, uint8_t ind, float value)
bhepp 0:28183cc7963f 43 {
bhepp 0:28183cc7963f 44 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
bhepp 0:28183cc7963f 45 char buf[MAVLINK_MSG_ID_DEBUG_LEN];
bhepp 0:28183cc7963f 46 _mav_put_uint32_t(buf, 0, time_boot_ms);
bhepp 0:28183cc7963f 47 _mav_put_float(buf, 4, value);
bhepp 0:28183cc7963f 48 _mav_put_uint8_t(buf, 8, ind);
bhepp 0:28183cc7963f 49
bhepp 0:28183cc7963f 50 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 51 #else
bhepp 0:28183cc7963f 52 mavlink_debug_t packet;
bhepp 0:28183cc7963f 53 packet.time_boot_ms = time_boot_ms;
bhepp 0:28183cc7963f 54 packet.value = value;
bhepp 0:28183cc7963f 55 packet.ind = ind;
bhepp 0:28183cc7963f 56
bhepp 0:28183cc7963f 57 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 58 #endif
bhepp 0:28183cc7963f 59
bhepp 0:28183cc7963f 60 msg->msgid = MAVLINK_MSG_ID_DEBUG;
bhepp 0:28183cc7963f 61 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 62 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 63 #else
bhepp 0:28183cc7963f 64 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 65 #endif
bhepp 0:28183cc7963f 66 }
bhepp 0:28183cc7963f 67
bhepp 0:28183cc7963f 68 /**
bhepp 0:28183cc7963f 69 * @brief Pack a debug message on a channel
bhepp 0:28183cc7963f 70 * @param system_id ID of this system
bhepp 0:28183cc7963f 71 * @param component_id ID of this component (e.g. 200 for IMU)
bhepp 0:28183cc7963f 72 * @param chan The MAVLink channel this message will be sent over
bhepp 0:28183cc7963f 73 * @param msg The MAVLink message to compress the data into
bhepp 0:28183cc7963f 74 * @param time_boot_ms Timestamp (milliseconds since system boot)
bhepp 0:28183cc7963f 75 * @param ind index of debug variable
bhepp 0:28183cc7963f 76 * @param value DEBUG value
bhepp 0:28183cc7963f 77 * @return length of the message in bytes (excluding serial stream start sign)
bhepp 0:28183cc7963f 78 */
bhepp 0:28183cc7963f 79 static inline uint16_t mavlink_msg_debug_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
bhepp 0:28183cc7963f 80 mavlink_message_t* msg,
bhepp 0:28183cc7963f 81 uint32_t time_boot_ms,uint8_t ind,float value)
bhepp 0:28183cc7963f 82 {
bhepp 0:28183cc7963f 83 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
bhepp 0:28183cc7963f 84 char buf[MAVLINK_MSG_ID_DEBUG_LEN];
bhepp 0:28183cc7963f 85 _mav_put_uint32_t(buf, 0, time_boot_ms);
bhepp 0:28183cc7963f 86 _mav_put_float(buf, 4, value);
bhepp 0:28183cc7963f 87 _mav_put_uint8_t(buf, 8, ind);
bhepp 0:28183cc7963f 88
bhepp 0:28183cc7963f 89 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 90 #else
bhepp 0:28183cc7963f 91 mavlink_debug_t packet;
bhepp 0:28183cc7963f 92 packet.time_boot_ms = time_boot_ms;
bhepp 0:28183cc7963f 93 packet.value = value;
bhepp 0:28183cc7963f 94 packet.ind = ind;
bhepp 0:28183cc7963f 95
bhepp 0:28183cc7963f 96 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 97 #endif
bhepp 0:28183cc7963f 98
bhepp 0:28183cc7963f 99 msg->msgid = MAVLINK_MSG_ID_DEBUG;
bhepp 0:28183cc7963f 100 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 101 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 102 #else
bhepp 0:28183cc7963f 103 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 104 #endif
bhepp 0:28183cc7963f 105 }
bhepp 0:28183cc7963f 106
bhepp 0:28183cc7963f 107 /**
bhepp 0:28183cc7963f 108 * @brief Encode a debug struct
bhepp 0:28183cc7963f 109 *
bhepp 0:28183cc7963f 110 * @param system_id ID of this system
bhepp 0:28183cc7963f 111 * @param component_id ID of this component (e.g. 200 for IMU)
bhepp 0:28183cc7963f 112 * @param msg The MAVLink message to compress the data into
bhepp 0:28183cc7963f 113 * @param debug C-struct to read the message contents from
bhepp 0:28183cc7963f 114 */
bhepp 0:28183cc7963f 115 static inline uint16_t mavlink_msg_debug_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_debug_t* debug)
bhepp 0:28183cc7963f 116 {
bhepp 0:28183cc7963f 117 return mavlink_msg_debug_pack(system_id, component_id, msg, debug->time_boot_ms, debug->ind, debug->value);
bhepp 0:28183cc7963f 118 }
bhepp 0:28183cc7963f 119
bhepp 0:28183cc7963f 120 /**
bhepp 0:28183cc7963f 121 * @brief Encode a debug struct on a channel
bhepp 0:28183cc7963f 122 *
bhepp 0:28183cc7963f 123 * @param system_id ID of this system
bhepp 0:28183cc7963f 124 * @param component_id ID of this component (e.g. 200 for IMU)
bhepp 0:28183cc7963f 125 * @param chan The MAVLink channel this message will be sent over
bhepp 0:28183cc7963f 126 * @param msg The MAVLink message to compress the data into
bhepp 0:28183cc7963f 127 * @param debug C-struct to read the message contents from
bhepp 0:28183cc7963f 128 */
bhepp 0:28183cc7963f 129 static inline uint16_t mavlink_msg_debug_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_debug_t* debug)
bhepp 0:28183cc7963f 130 {
bhepp 0:28183cc7963f 131 return mavlink_msg_debug_pack_chan(system_id, component_id, chan, msg, debug->time_boot_ms, debug->ind, debug->value);
bhepp 0:28183cc7963f 132 }
bhepp 0:28183cc7963f 133
bhepp 0:28183cc7963f 134 /**
bhepp 0:28183cc7963f 135 * @brief Send a debug message
bhepp 0:28183cc7963f 136 * @param chan MAVLink channel to send the message
bhepp 0:28183cc7963f 137 *
bhepp 0:28183cc7963f 138 * @param time_boot_ms Timestamp (milliseconds since system boot)
bhepp 0:28183cc7963f 139 * @param ind index of debug variable
bhepp 0:28183cc7963f 140 * @param value DEBUG value
bhepp 0:28183cc7963f 141 */
bhepp 0:28183cc7963f 142 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
bhepp 0:28183cc7963f 143
bhepp 0:28183cc7963f 144 static inline void mavlink_msg_debug_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint8_t ind, float value)
bhepp 0:28183cc7963f 145 {
bhepp 0:28183cc7963f 146 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
bhepp 0:28183cc7963f 147 char buf[MAVLINK_MSG_ID_DEBUG_LEN];
bhepp 0:28183cc7963f 148 _mav_put_uint32_t(buf, 0, time_boot_ms);
bhepp 0:28183cc7963f 149 _mav_put_float(buf, 4, value);
bhepp 0:28183cc7963f 150 _mav_put_uint8_t(buf, 8, ind);
bhepp 0:28183cc7963f 151
bhepp 0:28183cc7963f 152 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 153 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, buf, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 154 #else
bhepp 0:28183cc7963f 155 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, buf, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 156 #endif
bhepp 0:28183cc7963f 157 #else
bhepp 0:28183cc7963f 158 mavlink_debug_t packet;
bhepp 0:28183cc7963f 159 packet.time_boot_ms = time_boot_ms;
bhepp 0:28183cc7963f 160 packet.value = value;
bhepp 0:28183cc7963f 161 packet.ind = ind;
bhepp 0:28183cc7963f 162
bhepp 0:28183cc7963f 163 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 164 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, (const char *)&packet, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 165 #else
bhepp 0:28183cc7963f 166 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, (const char *)&packet, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 167 #endif
bhepp 0:28183cc7963f 168 #endif
bhepp 0:28183cc7963f 169 }
bhepp 0:28183cc7963f 170
bhepp 0:28183cc7963f 171 #if MAVLINK_MSG_ID_DEBUG_LEN <= MAVLINK_MAX_PAYLOAD_LEN
bhepp 0:28183cc7963f 172 /*
bhepp 0:28183cc7963f 173 This varient of _send() can be used to save stack space by re-using
bhepp 0:28183cc7963f 174 memory from the receive buffer. The caller provides a
bhepp 0:28183cc7963f 175 mavlink_message_t which is the size of a full mavlink message. This
bhepp 0:28183cc7963f 176 is usually the receive buffer for the channel, and allows a reply to an
bhepp 0:28183cc7963f 177 incoming message with minimum stack space usage.
bhepp 0:28183cc7963f 178 */
bhepp 0:28183cc7963f 179 static inline void mavlink_msg_debug_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint32_t time_boot_ms, uint8_t ind, float value)
bhepp 0:28183cc7963f 180 {
bhepp 0:28183cc7963f 181 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
bhepp 0:28183cc7963f 182 char *buf = (char *)msgbuf;
bhepp 0:28183cc7963f 183 _mav_put_uint32_t(buf, 0, time_boot_ms);
bhepp 0:28183cc7963f 184 _mav_put_float(buf, 4, value);
bhepp 0:28183cc7963f 185 _mav_put_uint8_t(buf, 8, ind);
bhepp 0:28183cc7963f 186
bhepp 0:28183cc7963f 187 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 188 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, buf, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 189 #else
bhepp 0:28183cc7963f 190 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, buf, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 191 #endif
bhepp 0:28183cc7963f 192 #else
bhepp 0:28183cc7963f 193 mavlink_debug_t *packet = (mavlink_debug_t *)msgbuf;
bhepp 0:28183cc7963f 194 packet->time_boot_ms = time_boot_ms;
bhepp 0:28183cc7963f 195 packet->value = value;
bhepp 0:28183cc7963f 196 packet->ind = ind;
bhepp 0:28183cc7963f 197
bhepp 0:28183cc7963f 198 #if MAVLINK_CRC_EXTRA
bhepp 0:28183cc7963f 199 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, (const char *)packet, MAVLINK_MSG_ID_DEBUG_LEN, MAVLINK_MSG_ID_DEBUG_CRC);
bhepp 0:28183cc7963f 200 #else
bhepp 0:28183cc7963f 201 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, (const char *)packet, MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 202 #endif
bhepp 0:28183cc7963f 203 #endif
bhepp 0:28183cc7963f 204 }
bhepp 0:28183cc7963f 205 #endif
bhepp 0:28183cc7963f 206
bhepp 0:28183cc7963f 207 #endif
bhepp 0:28183cc7963f 208
bhepp 0:28183cc7963f 209 // MESSAGE DEBUG UNPACKING
bhepp 0:28183cc7963f 210
bhepp 0:28183cc7963f 211
bhepp 0:28183cc7963f 212 /**
bhepp 0:28183cc7963f 213 * @brief Get field time_boot_ms from debug message
bhepp 0:28183cc7963f 214 *
bhepp 0:28183cc7963f 215 * @return Timestamp (milliseconds since system boot)
bhepp 0:28183cc7963f 216 */
bhepp 0:28183cc7963f 217 static inline uint32_t mavlink_msg_debug_get_time_boot_ms(const mavlink_message_t* msg)
bhepp 0:28183cc7963f 218 {
bhepp 0:28183cc7963f 219 return _MAV_RETURN_uint32_t(msg, 0);
bhepp 0:28183cc7963f 220 }
bhepp 0:28183cc7963f 221
bhepp 0:28183cc7963f 222 /**
bhepp 0:28183cc7963f 223 * @brief Get field ind from debug message
bhepp 0:28183cc7963f 224 *
bhepp 0:28183cc7963f 225 * @return index of debug variable
bhepp 0:28183cc7963f 226 */
bhepp 0:28183cc7963f 227 static inline uint8_t mavlink_msg_debug_get_ind(const mavlink_message_t* msg)
bhepp 0:28183cc7963f 228 {
bhepp 0:28183cc7963f 229 return _MAV_RETURN_uint8_t(msg, 8);
bhepp 0:28183cc7963f 230 }
bhepp 0:28183cc7963f 231
bhepp 0:28183cc7963f 232 /**
bhepp 0:28183cc7963f 233 * @brief Get field value from debug message
bhepp 0:28183cc7963f 234 *
bhepp 0:28183cc7963f 235 * @return DEBUG value
bhepp 0:28183cc7963f 236 */
bhepp 0:28183cc7963f 237 static inline float mavlink_msg_debug_get_value(const mavlink_message_t* msg)
bhepp 0:28183cc7963f 238 {
bhepp 0:28183cc7963f 239 return _MAV_RETURN_float(msg, 4);
bhepp 0:28183cc7963f 240 }
bhepp 0:28183cc7963f 241
bhepp 0:28183cc7963f 242 /**
bhepp 0:28183cc7963f 243 * @brief Decode a debug message into a struct
bhepp 0:28183cc7963f 244 *
bhepp 0:28183cc7963f 245 * @param msg The message to decode
bhepp 0:28183cc7963f 246 * @param debug C-struct to decode the message contents into
bhepp 0:28183cc7963f 247 */
bhepp 0:28183cc7963f 248 static inline void mavlink_msg_debug_decode(const mavlink_message_t* msg, mavlink_debug_t* debug)
bhepp 0:28183cc7963f 249 {
bhepp 0:28183cc7963f 250 #if MAVLINK_NEED_BYTE_SWAP
bhepp 0:28183cc7963f 251 debug->time_boot_ms = mavlink_msg_debug_get_time_boot_ms(msg);
bhepp 0:28183cc7963f 252 debug->value = mavlink_msg_debug_get_value(msg);
bhepp 0:28183cc7963f 253 debug->ind = mavlink_msg_debug_get_ind(msg);
bhepp 0:28183cc7963f 254 #else
bhepp 0:28183cc7963f 255 memcpy(debug, _MAV_PAYLOAD(msg), MAVLINK_MSG_ID_DEBUG_LEN);
bhepp 0:28183cc7963f 256 #endif
bhepp 0:28183cc7963f 257 }