Mavlink Messages for Emaxx Nav Board
Dependents: Madpulse_Speed_Control_temp Madpulse_Speed_Control_Students
protocol.h@0:bb2cacd02294, 2017-01-20 (annotated)
- Committer:
- jdawkins
- Date:
- Fri Jan 20 13:20:58 2017 +0000
- Revision:
- 0:bb2cacd02294
Initial Commit of Mavlink Messages for Emaxx Board custom messages for decawave ranging and bno055;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jdawkins | 0:bb2cacd02294 | 1 | #ifndef _MAVLINK_PROTOCOL_H_ |
jdawkins | 0:bb2cacd02294 | 2 | #define _MAVLINK_PROTOCOL_H_ |
jdawkins | 0:bb2cacd02294 | 3 | |
jdawkins | 0:bb2cacd02294 | 4 | #include "string.h" |
jdawkins | 0:bb2cacd02294 | 5 | #include "mavlink_types.h" |
jdawkins | 0:bb2cacd02294 | 6 | |
jdawkins | 0:bb2cacd02294 | 7 | /* |
jdawkins | 0:bb2cacd02294 | 8 | If you want MAVLink on a system that is native big-endian, |
jdawkins | 0:bb2cacd02294 | 9 | you need to define NATIVE_BIG_ENDIAN |
jdawkins | 0:bb2cacd02294 | 10 | */ |
jdawkins | 0:bb2cacd02294 | 11 | #ifdef NATIVE_BIG_ENDIAN |
jdawkins | 0:bb2cacd02294 | 12 | # define MAVLINK_NEED_BYTE_SWAP (MAVLINK_ENDIAN == MAVLINK_LITTLE_ENDIAN) |
jdawkins | 0:bb2cacd02294 | 13 | #else |
jdawkins | 0:bb2cacd02294 | 14 | # define MAVLINK_NEED_BYTE_SWAP (MAVLINK_ENDIAN != MAVLINK_LITTLE_ENDIAN) |
jdawkins | 0:bb2cacd02294 | 15 | #endif |
jdawkins | 0:bb2cacd02294 | 16 | |
jdawkins | 0:bb2cacd02294 | 17 | #ifndef MAVLINK_STACK_BUFFER |
jdawkins | 0:bb2cacd02294 | 18 | #define MAVLINK_STACK_BUFFER 0 |
jdawkins | 0:bb2cacd02294 | 19 | #endif |
jdawkins | 0:bb2cacd02294 | 20 | |
jdawkins | 0:bb2cacd02294 | 21 | #ifndef MAVLINK_AVOID_GCC_STACK_BUG |
jdawkins | 0:bb2cacd02294 | 22 | # define MAVLINK_AVOID_GCC_STACK_BUG defined(__GNUC__) |
jdawkins | 0:bb2cacd02294 | 23 | #endif |
jdawkins | 0:bb2cacd02294 | 24 | |
jdawkins | 0:bb2cacd02294 | 25 | #ifndef MAVLINK_ASSERT |
jdawkins | 0:bb2cacd02294 | 26 | #define MAVLINK_ASSERT(x) |
jdawkins | 0:bb2cacd02294 | 27 | #endif |
jdawkins | 0:bb2cacd02294 | 28 | |
jdawkins | 0:bb2cacd02294 | 29 | #ifndef MAVLINK_START_UART_SEND |
jdawkins | 0:bb2cacd02294 | 30 | #define MAVLINK_START_UART_SEND(chan, length) |
jdawkins | 0:bb2cacd02294 | 31 | #endif |
jdawkins | 0:bb2cacd02294 | 32 | |
jdawkins | 0:bb2cacd02294 | 33 | #ifndef MAVLINK_END_UART_SEND |
jdawkins | 0:bb2cacd02294 | 34 | #define MAVLINK_END_UART_SEND(chan, length) |
jdawkins | 0:bb2cacd02294 | 35 | #endif |
jdawkins | 0:bb2cacd02294 | 36 | |
jdawkins | 0:bb2cacd02294 | 37 | /* option to provide alternative implementation of mavlink_helpers.h */ |
jdawkins | 0:bb2cacd02294 | 38 | #ifdef MAVLINK_SEPARATE_HELPERS |
jdawkins | 0:bb2cacd02294 | 39 | |
jdawkins | 0:bb2cacd02294 | 40 | #define MAVLINK_HELPER |
jdawkins | 0:bb2cacd02294 | 41 | |
jdawkins | 0:bb2cacd02294 | 42 | /* decls in sync with those in mavlink_helpers.h */ |
jdawkins | 0:bb2cacd02294 | 43 | #ifndef MAVLINK_GET_CHANNEL_STATUS |
jdawkins | 0:bb2cacd02294 | 44 | MAVLINK_HELPER mavlink_status_t* mavlink_get_channel_status(uint8_t chan); |
jdawkins | 0:bb2cacd02294 | 45 | #endif |
jdawkins | 0:bb2cacd02294 | 46 | MAVLINK_HELPER void mavlink_reset_channel_status(uint8_t chan); |
jdawkins | 0:bb2cacd02294 | 47 | #if MAVLINK_CRC_EXTRA |
jdawkins | 0:bb2cacd02294 | 48 | MAVLINK_HELPER uint16_t mavlink_finalize_message_chan(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, |
jdawkins | 0:bb2cacd02294 | 49 | uint8_t chan, uint8_t min_length, uint8_t length, uint8_t crc_extra); |
jdawkins | 0:bb2cacd02294 | 50 | MAVLINK_HELPER uint16_t mavlink_finalize_message(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, |
jdawkins | 0:bb2cacd02294 | 51 | uint8_t min_length, uint8_t length, uint8_t crc_extra); |
jdawkins | 0:bb2cacd02294 | 52 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
jdawkins | 0:bb2cacd02294 | 53 | MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint8_t msgid, const char *packet, |
jdawkins | 0:bb2cacd02294 | 54 | uint8_t min_length, uint8_t length, uint8_t crc_extra); |
jdawkins | 0:bb2cacd02294 | 55 | #endif |
jdawkins | 0:bb2cacd02294 | 56 | #else |
jdawkins | 0:bb2cacd02294 | 57 | MAVLINK_HELPER uint16_t mavlink_finalize_message_chan(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, |
jdawkins | 0:bb2cacd02294 | 58 | uint8_t chan, uint8_t length); |
jdawkins | 0:bb2cacd02294 | 59 | MAVLINK_HELPER uint16_t mavlink_finalize_message(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, |
jdawkins | 0:bb2cacd02294 | 60 | uint8_t length); |
jdawkins | 0:bb2cacd02294 | 61 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
jdawkins | 0:bb2cacd02294 | 62 | MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint8_t msgid, const char *packet, uint8_t length); |
jdawkins | 0:bb2cacd02294 | 63 | #endif |
jdawkins | 0:bb2cacd02294 | 64 | #endif // MAVLINK_CRC_EXTRA |
jdawkins | 0:bb2cacd02294 | 65 | MAVLINK_HELPER uint16_t mavlink_msg_to_send_buffer(uint8_t *buffer, const mavlink_message_t *msg); |
jdawkins | 0:bb2cacd02294 | 66 | MAVLINK_HELPER void mavlink_start_checksum(mavlink_message_t* msg); |
jdawkins | 0:bb2cacd02294 | 67 | MAVLINK_HELPER void mavlink_update_checksum(mavlink_message_t* msg, uint8_t c); |
jdawkins | 0:bb2cacd02294 | 68 | MAVLINK_HELPER uint8_t mavlink_frame_char_buffer(mavlink_message_t* rxmsg, |
jdawkins | 0:bb2cacd02294 | 69 | mavlink_status_t* status, |
jdawkins | 0:bb2cacd02294 | 70 | uint8_t c, |
jdawkins | 0:bb2cacd02294 | 71 | mavlink_message_t* r_message, |
jdawkins | 0:bb2cacd02294 | 72 | mavlink_status_t* r_mavlink_status); |
jdawkins | 0:bb2cacd02294 | 73 | MAVLINK_HELPER uint8_t mavlink_frame_char(uint8_t chan, uint8_t c, mavlink_message_t* r_message, mavlink_status_t* r_mavlink_status); |
jdawkins | 0:bb2cacd02294 | 74 | MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_message_t* r_message, mavlink_status_t* r_mavlink_status); |
jdawkins | 0:bb2cacd02294 | 75 | MAVLINK_HELPER uint8_t put_bitfield_n_by_index(int32_t b, uint8_t bits, uint8_t packet_index, uint8_t bit_index, |
jdawkins | 0:bb2cacd02294 | 76 | uint8_t* r_bit_index, uint8_t* buffer); |
jdawkins | 0:bb2cacd02294 | 77 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
jdawkins | 0:bb2cacd02294 | 78 | MAVLINK_HELPER void _mavlink_send_uart(mavlink_channel_t chan, const char *buf, uint16_t len); |
jdawkins | 0:bb2cacd02294 | 79 | MAVLINK_HELPER void _mavlink_resend_uart(mavlink_channel_t chan, const mavlink_message_t *msg); |
jdawkins | 0:bb2cacd02294 | 80 | #endif |
jdawkins | 0:bb2cacd02294 | 81 | |
jdawkins | 0:bb2cacd02294 | 82 | #else |
jdawkins | 0:bb2cacd02294 | 83 | |
jdawkins | 0:bb2cacd02294 | 84 | #define MAVLINK_HELPER static inline |
jdawkins | 0:bb2cacd02294 | 85 | #include "mavlink_helpers.h" |
jdawkins | 0:bb2cacd02294 | 86 | |
jdawkins | 0:bb2cacd02294 | 87 | #endif // MAVLINK_SEPARATE_HELPERS |
jdawkins | 0:bb2cacd02294 | 88 | |
jdawkins | 0:bb2cacd02294 | 89 | /** |
jdawkins | 0:bb2cacd02294 | 90 | * @brief Get the required buffer size for this message |
jdawkins | 0:bb2cacd02294 | 91 | */ |
jdawkins | 0:bb2cacd02294 | 92 | static inline uint16_t mavlink_msg_get_send_buffer_length(const mavlink_message_t* msg) |
jdawkins | 0:bb2cacd02294 | 93 | { |
jdawkins | 0:bb2cacd02294 | 94 | return msg->len + MAVLINK_NUM_NON_PAYLOAD_BYTES; |
jdawkins | 0:bb2cacd02294 | 95 | } |
jdawkins | 0:bb2cacd02294 | 96 | |
jdawkins | 0:bb2cacd02294 | 97 | #if MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 98 | static inline void byte_swap_2(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 99 | { |
jdawkins | 0:bb2cacd02294 | 100 | dst[0] = src[1]; |
jdawkins | 0:bb2cacd02294 | 101 | dst[1] = src[0]; |
jdawkins | 0:bb2cacd02294 | 102 | } |
jdawkins | 0:bb2cacd02294 | 103 | static inline void byte_swap_4(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 104 | { |
jdawkins | 0:bb2cacd02294 | 105 | dst[0] = src[3]; |
jdawkins | 0:bb2cacd02294 | 106 | dst[1] = src[2]; |
jdawkins | 0:bb2cacd02294 | 107 | dst[2] = src[1]; |
jdawkins | 0:bb2cacd02294 | 108 | dst[3] = src[0]; |
jdawkins | 0:bb2cacd02294 | 109 | } |
jdawkins | 0:bb2cacd02294 | 110 | static inline void byte_swap_8(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 111 | { |
jdawkins | 0:bb2cacd02294 | 112 | dst[0] = src[7]; |
jdawkins | 0:bb2cacd02294 | 113 | dst[1] = src[6]; |
jdawkins | 0:bb2cacd02294 | 114 | dst[2] = src[5]; |
jdawkins | 0:bb2cacd02294 | 115 | dst[3] = src[4]; |
jdawkins | 0:bb2cacd02294 | 116 | dst[4] = src[3]; |
jdawkins | 0:bb2cacd02294 | 117 | dst[5] = src[2]; |
jdawkins | 0:bb2cacd02294 | 118 | dst[6] = src[1]; |
jdawkins | 0:bb2cacd02294 | 119 | dst[7] = src[0]; |
jdawkins | 0:bb2cacd02294 | 120 | } |
jdawkins | 0:bb2cacd02294 | 121 | #elif !MAVLINK_ALIGNED_FIELDS |
jdawkins | 0:bb2cacd02294 | 122 | static inline void byte_copy_2(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 123 | { |
jdawkins | 0:bb2cacd02294 | 124 | dst[0] = src[0]; |
jdawkins | 0:bb2cacd02294 | 125 | dst[1] = src[1]; |
jdawkins | 0:bb2cacd02294 | 126 | } |
jdawkins | 0:bb2cacd02294 | 127 | static inline void byte_copy_4(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 128 | { |
jdawkins | 0:bb2cacd02294 | 129 | dst[0] = src[0]; |
jdawkins | 0:bb2cacd02294 | 130 | dst[1] = src[1]; |
jdawkins | 0:bb2cacd02294 | 131 | dst[2] = src[2]; |
jdawkins | 0:bb2cacd02294 | 132 | dst[3] = src[3]; |
jdawkins | 0:bb2cacd02294 | 133 | } |
jdawkins | 0:bb2cacd02294 | 134 | static inline void byte_copy_8(char *dst, const char *src) |
jdawkins | 0:bb2cacd02294 | 135 | { |
jdawkins | 0:bb2cacd02294 | 136 | memcpy(dst, src, 8); |
jdawkins | 0:bb2cacd02294 | 137 | } |
jdawkins | 0:bb2cacd02294 | 138 | #endif |
jdawkins | 0:bb2cacd02294 | 139 | |
jdawkins | 0:bb2cacd02294 | 140 | #define _mav_put_uint8_t(buf, wire_offset, b) buf[wire_offset] = (uint8_t)b |
jdawkins | 0:bb2cacd02294 | 141 | #define _mav_put_int8_t(buf, wire_offset, b) buf[wire_offset] = (int8_t)b |
jdawkins | 0:bb2cacd02294 | 142 | #define _mav_put_char(buf, wire_offset, b) buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 143 | |
jdawkins | 0:bb2cacd02294 | 144 | #if MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 145 | #define _mav_put_uint16_t(buf, wire_offset, b) byte_swap_2(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 146 | #define _mav_put_int16_t(buf, wire_offset, b) byte_swap_2(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 147 | #define _mav_put_uint32_t(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 148 | #define _mav_put_int32_t(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 149 | #define _mav_put_uint64_t(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 150 | #define _mav_put_int64_t(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 151 | #define _mav_put_float(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 152 | #define _mav_put_double(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 153 | #elif !MAVLINK_ALIGNED_FIELDS |
jdawkins | 0:bb2cacd02294 | 154 | #define _mav_put_uint16_t(buf, wire_offset, b) byte_copy_2(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 155 | #define _mav_put_int16_t(buf, wire_offset, b) byte_copy_2(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 156 | #define _mav_put_uint32_t(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 157 | #define _mav_put_int32_t(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 158 | #define _mav_put_uint64_t(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 159 | #define _mav_put_int64_t(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 160 | #define _mav_put_float(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 161 | #define _mav_put_double(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) |
jdawkins | 0:bb2cacd02294 | 162 | #else |
jdawkins | 0:bb2cacd02294 | 163 | #define _mav_put_uint16_t(buf, wire_offset, b) *(uint16_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 164 | #define _mav_put_int16_t(buf, wire_offset, b) *(int16_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 165 | #define _mav_put_uint32_t(buf, wire_offset, b) *(uint32_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 166 | #define _mav_put_int32_t(buf, wire_offset, b) *(int32_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 167 | #define _mav_put_uint64_t(buf, wire_offset, b) *(uint64_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 168 | #define _mav_put_int64_t(buf, wire_offset, b) *(int64_t *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 169 | #define _mav_put_float(buf, wire_offset, b) *(float *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 170 | #define _mav_put_double(buf, wire_offset, b) *(double *)&buf[wire_offset] = b |
jdawkins | 0:bb2cacd02294 | 171 | #endif |
jdawkins | 0:bb2cacd02294 | 172 | |
jdawkins | 0:bb2cacd02294 | 173 | /* |
jdawkins | 0:bb2cacd02294 | 174 | like memcpy(), but if src is NULL, do a memset to zero |
jdawkins | 0:bb2cacd02294 | 175 | */ |
jdawkins | 0:bb2cacd02294 | 176 | static inline void mav_array_memcpy(void *dest, const void *src, size_t n) |
jdawkins | 0:bb2cacd02294 | 177 | { |
jdawkins | 0:bb2cacd02294 | 178 | if (src == NULL) { |
jdawkins | 0:bb2cacd02294 | 179 | memset(dest, 0, n); |
jdawkins | 0:bb2cacd02294 | 180 | } else { |
jdawkins | 0:bb2cacd02294 | 181 | memcpy(dest, src, n); |
jdawkins | 0:bb2cacd02294 | 182 | } |
jdawkins | 0:bb2cacd02294 | 183 | } |
jdawkins | 0:bb2cacd02294 | 184 | |
jdawkins | 0:bb2cacd02294 | 185 | /* |
jdawkins | 0:bb2cacd02294 | 186 | * Place a char array into a buffer |
jdawkins | 0:bb2cacd02294 | 187 | */ |
jdawkins | 0:bb2cacd02294 | 188 | static inline void _mav_put_char_array(char *buf, uint8_t wire_offset, const char *b, uint8_t array_length) |
jdawkins | 0:bb2cacd02294 | 189 | { |
jdawkins | 0:bb2cacd02294 | 190 | mav_array_memcpy(&buf[wire_offset], b, array_length); |
jdawkins | 0:bb2cacd02294 | 191 | |
jdawkins | 0:bb2cacd02294 | 192 | } |
jdawkins | 0:bb2cacd02294 | 193 | |
jdawkins | 0:bb2cacd02294 | 194 | /* |
jdawkins | 0:bb2cacd02294 | 195 | * Place a uint8_t array into a buffer |
jdawkins | 0:bb2cacd02294 | 196 | */ |
jdawkins | 0:bb2cacd02294 | 197 | static inline void _mav_put_uint8_t_array(char *buf, uint8_t wire_offset, const uint8_t *b, uint8_t array_length) |
jdawkins | 0:bb2cacd02294 | 198 | { |
jdawkins | 0:bb2cacd02294 | 199 | mav_array_memcpy(&buf[wire_offset], b, array_length); |
jdawkins | 0:bb2cacd02294 | 200 | |
jdawkins | 0:bb2cacd02294 | 201 | } |
jdawkins | 0:bb2cacd02294 | 202 | |
jdawkins | 0:bb2cacd02294 | 203 | /* |
jdawkins | 0:bb2cacd02294 | 204 | * Place a int8_t array into a buffer |
jdawkins | 0:bb2cacd02294 | 205 | */ |
jdawkins | 0:bb2cacd02294 | 206 | static inline void _mav_put_int8_t_array(char *buf, uint8_t wire_offset, const int8_t *b, uint8_t array_length) |
jdawkins | 0:bb2cacd02294 | 207 | { |
jdawkins | 0:bb2cacd02294 | 208 | mav_array_memcpy(&buf[wire_offset], b, array_length); |
jdawkins | 0:bb2cacd02294 | 209 | |
jdawkins | 0:bb2cacd02294 | 210 | } |
jdawkins | 0:bb2cacd02294 | 211 | |
jdawkins | 0:bb2cacd02294 | 212 | #if MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 213 | #define _MAV_PUT_ARRAY(TYPE, V) \ |
jdawkins | 0:bb2cacd02294 | 214 | static inline void _mav_put_ ## TYPE ##_array(char *buf, uint8_t wire_offset, const TYPE *b, uint8_t array_length) \ |
jdawkins | 0:bb2cacd02294 | 215 | { \ |
jdawkins | 0:bb2cacd02294 | 216 | if (b == NULL) { \ |
jdawkins | 0:bb2cacd02294 | 217 | memset(&buf[wire_offset], 0, array_length*sizeof(TYPE)); \ |
jdawkins | 0:bb2cacd02294 | 218 | } else { \ |
jdawkins | 0:bb2cacd02294 | 219 | uint16_t i; \ |
jdawkins | 0:bb2cacd02294 | 220 | for (i=0; i<array_length; i++) { \ |
jdawkins | 0:bb2cacd02294 | 221 | _mav_put_## TYPE (buf, wire_offset+(i*sizeof(TYPE)), b[i]); \ |
jdawkins | 0:bb2cacd02294 | 222 | } \ |
jdawkins | 0:bb2cacd02294 | 223 | } \ |
jdawkins | 0:bb2cacd02294 | 224 | } |
jdawkins | 0:bb2cacd02294 | 225 | #else |
jdawkins | 0:bb2cacd02294 | 226 | #define _MAV_PUT_ARRAY(TYPE, V) \ |
jdawkins | 0:bb2cacd02294 | 227 | static inline void _mav_put_ ## TYPE ##_array(char *buf, uint8_t wire_offset, const TYPE *b, uint8_t array_length) \ |
jdawkins | 0:bb2cacd02294 | 228 | { \ |
jdawkins | 0:bb2cacd02294 | 229 | mav_array_memcpy(&buf[wire_offset], b, array_length*sizeof(TYPE)); \ |
jdawkins | 0:bb2cacd02294 | 230 | } |
jdawkins | 0:bb2cacd02294 | 231 | #endif |
jdawkins | 0:bb2cacd02294 | 232 | |
jdawkins | 0:bb2cacd02294 | 233 | _MAV_PUT_ARRAY(uint16_t, u16) |
jdawkins | 0:bb2cacd02294 | 234 | _MAV_PUT_ARRAY(uint32_t, u32) |
jdawkins | 0:bb2cacd02294 | 235 | _MAV_PUT_ARRAY(uint64_t, u64) |
jdawkins | 0:bb2cacd02294 | 236 | _MAV_PUT_ARRAY(int16_t, i16) |
jdawkins | 0:bb2cacd02294 | 237 | _MAV_PUT_ARRAY(int32_t, i32) |
jdawkins | 0:bb2cacd02294 | 238 | _MAV_PUT_ARRAY(int64_t, i64) |
jdawkins | 0:bb2cacd02294 | 239 | _MAV_PUT_ARRAY(float, f) |
jdawkins | 0:bb2cacd02294 | 240 | _MAV_PUT_ARRAY(double, d) |
jdawkins | 0:bb2cacd02294 | 241 | |
jdawkins | 0:bb2cacd02294 | 242 | #define _MAV_RETURN_char(msg, wire_offset) (const char)_MAV_PAYLOAD(msg)[wire_offset] |
jdawkins | 0:bb2cacd02294 | 243 | #define _MAV_RETURN_int8_t(msg, wire_offset) (const int8_t)_MAV_PAYLOAD(msg)[wire_offset] |
jdawkins | 0:bb2cacd02294 | 244 | #define _MAV_RETURN_uint8_t(msg, wire_offset) (const uint8_t)_MAV_PAYLOAD(msg)[wire_offset] |
jdawkins | 0:bb2cacd02294 | 245 | |
jdawkins | 0:bb2cacd02294 | 246 | #if MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 247 | #define _MAV_MSG_RETURN_TYPE(TYPE, SIZE) \ |
jdawkins | 0:bb2cacd02294 | 248 | static inline TYPE _MAV_RETURN_## TYPE(const mavlink_message_t *msg, uint8_t ofs) \ |
jdawkins | 0:bb2cacd02294 | 249 | { TYPE r; byte_swap_## SIZE((char*)&r, &_MAV_PAYLOAD(msg)[ofs]); return r; } |
jdawkins | 0:bb2cacd02294 | 250 | |
jdawkins | 0:bb2cacd02294 | 251 | _MAV_MSG_RETURN_TYPE(uint16_t, 2) |
jdawkins | 0:bb2cacd02294 | 252 | _MAV_MSG_RETURN_TYPE(int16_t, 2) |
jdawkins | 0:bb2cacd02294 | 253 | _MAV_MSG_RETURN_TYPE(uint32_t, 4) |
jdawkins | 0:bb2cacd02294 | 254 | _MAV_MSG_RETURN_TYPE(int32_t, 4) |
jdawkins | 0:bb2cacd02294 | 255 | _MAV_MSG_RETURN_TYPE(uint64_t, 8) |
jdawkins | 0:bb2cacd02294 | 256 | _MAV_MSG_RETURN_TYPE(int64_t, 8) |
jdawkins | 0:bb2cacd02294 | 257 | _MAV_MSG_RETURN_TYPE(float, 4) |
jdawkins | 0:bb2cacd02294 | 258 | _MAV_MSG_RETURN_TYPE(double, 8) |
jdawkins | 0:bb2cacd02294 | 259 | |
jdawkins | 0:bb2cacd02294 | 260 | #elif !MAVLINK_ALIGNED_FIELDS |
jdawkins | 0:bb2cacd02294 | 261 | #define _MAV_MSG_RETURN_TYPE(TYPE, SIZE) \ |
jdawkins | 0:bb2cacd02294 | 262 | static inline TYPE _MAV_RETURN_## TYPE(const mavlink_message_t *msg, uint8_t ofs) \ |
jdawkins | 0:bb2cacd02294 | 263 | { TYPE r; byte_copy_## SIZE((char*)&r, &_MAV_PAYLOAD(msg)[ofs]); return r; } |
jdawkins | 0:bb2cacd02294 | 264 | |
jdawkins | 0:bb2cacd02294 | 265 | _MAV_MSG_RETURN_TYPE(uint16_t, 2) |
jdawkins | 0:bb2cacd02294 | 266 | _MAV_MSG_RETURN_TYPE(int16_t, 2) |
jdawkins | 0:bb2cacd02294 | 267 | _MAV_MSG_RETURN_TYPE(uint32_t, 4) |
jdawkins | 0:bb2cacd02294 | 268 | _MAV_MSG_RETURN_TYPE(int32_t, 4) |
jdawkins | 0:bb2cacd02294 | 269 | _MAV_MSG_RETURN_TYPE(uint64_t, 8) |
jdawkins | 0:bb2cacd02294 | 270 | _MAV_MSG_RETURN_TYPE(int64_t, 8) |
jdawkins | 0:bb2cacd02294 | 271 | _MAV_MSG_RETURN_TYPE(float, 4) |
jdawkins | 0:bb2cacd02294 | 272 | _MAV_MSG_RETURN_TYPE(double, 8) |
jdawkins | 0:bb2cacd02294 | 273 | #else // nicely aligned, no swap |
jdawkins | 0:bb2cacd02294 | 274 | #define _MAV_MSG_RETURN_TYPE(TYPE) \ |
jdawkins | 0:bb2cacd02294 | 275 | static inline TYPE _MAV_RETURN_## TYPE(const mavlink_message_t *msg, uint8_t ofs) \ |
jdawkins | 0:bb2cacd02294 | 276 | { return *(const TYPE *)(&_MAV_PAYLOAD(msg)[ofs]);} |
jdawkins | 0:bb2cacd02294 | 277 | |
jdawkins | 0:bb2cacd02294 | 278 | _MAV_MSG_RETURN_TYPE(uint16_t) |
jdawkins | 0:bb2cacd02294 | 279 | _MAV_MSG_RETURN_TYPE(int16_t) |
jdawkins | 0:bb2cacd02294 | 280 | _MAV_MSG_RETURN_TYPE(uint32_t) |
jdawkins | 0:bb2cacd02294 | 281 | _MAV_MSG_RETURN_TYPE(int32_t) |
jdawkins | 0:bb2cacd02294 | 282 | _MAV_MSG_RETURN_TYPE(uint64_t) |
jdawkins | 0:bb2cacd02294 | 283 | _MAV_MSG_RETURN_TYPE(int64_t) |
jdawkins | 0:bb2cacd02294 | 284 | _MAV_MSG_RETURN_TYPE(float) |
jdawkins | 0:bb2cacd02294 | 285 | _MAV_MSG_RETURN_TYPE(double) |
jdawkins | 0:bb2cacd02294 | 286 | #endif // MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 287 | |
jdawkins | 0:bb2cacd02294 | 288 | static inline uint16_t _MAV_RETURN_char_array(const mavlink_message_t *msg, char *value, |
jdawkins | 0:bb2cacd02294 | 289 | uint8_t array_length, uint8_t wire_offset) |
jdawkins | 0:bb2cacd02294 | 290 | { |
jdawkins | 0:bb2cacd02294 | 291 | memcpy(value, &_MAV_PAYLOAD(msg)[wire_offset], array_length); |
jdawkins | 0:bb2cacd02294 | 292 | return array_length; |
jdawkins | 0:bb2cacd02294 | 293 | } |
jdawkins | 0:bb2cacd02294 | 294 | |
jdawkins | 0:bb2cacd02294 | 295 | static inline uint16_t _MAV_RETURN_uint8_t_array(const mavlink_message_t *msg, uint8_t *value, |
jdawkins | 0:bb2cacd02294 | 296 | uint8_t array_length, uint8_t wire_offset) |
jdawkins | 0:bb2cacd02294 | 297 | { |
jdawkins | 0:bb2cacd02294 | 298 | memcpy(value, &_MAV_PAYLOAD(msg)[wire_offset], array_length); |
jdawkins | 0:bb2cacd02294 | 299 | return array_length; |
jdawkins | 0:bb2cacd02294 | 300 | } |
jdawkins | 0:bb2cacd02294 | 301 | |
jdawkins | 0:bb2cacd02294 | 302 | static inline uint16_t _MAV_RETURN_int8_t_array(const mavlink_message_t *msg, int8_t *value, |
jdawkins | 0:bb2cacd02294 | 303 | uint8_t array_length, uint8_t wire_offset) |
jdawkins | 0:bb2cacd02294 | 304 | { |
jdawkins | 0:bb2cacd02294 | 305 | memcpy(value, &_MAV_PAYLOAD(msg)[wire_offset], array_length); |
jdawkins | 0:bb2cacd02294 | 306 | return array_length; |
jdawkins | 0:bb2cacd02294 | 307 | } |
jdawkins | 0:bb2cacd02294 | 308 | |
jdawkins | 0:bb2cacd02294 | 309 | #if MAVLINK_NEED_BYTE_SWAP |
jdawkins | 0:bb2cacd02294 | 310 | #define _MAV_RETURN_ARRAY(TYPE, V) \ |
jdawkins | 0:bb2cacd02294 | 311 | static inline uint16_t _MAV_RETURN_## TYPE ##_array(const mavlink_message_t *msg, TYPE *value, \ |
jdawkins | 0:bb2cacd02294 | 312 | uint8_t array_length, uint8_t wire_offset) \ |
jdawkins | 0:bb2cacd02294 | 313 | { \ |
jdawkins | 0:bb2cacd02294 | 314 | uint16_t i; \ |
jdawkins | 0:bb2cacd02294 | 315 | for (i=0; i<array_length; i++) { \ |
jdawkins | 0:bb2cacd02294 | 316 | value[i] = _MAV_RETURN_## TYPE (msg, wire_offset+(i*sizeof(value[0]))); \ |
jdawkins | 0:bb2cacd02294 | 317 | } \ |
jdawkins | 0:bb2cacd02294 | 318 | return array_length*sizeof(value[0]); \ |
jdawkins | 0:bb2cacd02294 | 319 | } |
jdawkins | 0:bb2cacd02294 | 320 | #else |
jdawkins | 0:bb2cacd02294 | 321 | #define _MAV_RETURN_ARRAY(TYPE, V) \ |
jdawkins | 0:bb2cacd02294 | 322 | static inline uint16_t _MAV_RETURN_## TYPE ##_array(const mavlink_message_t *msg, TYPE *value, \ |
jdawkins | 0:bb2cacd02294 | 323 | uint8_t array_length, uint8_t wire_offset) \ |
jdawkins | 0:bb2cacd02294 | 324 | { \ |
jdawkins | 0:bb2cacd02294 | 325 | memcpy(value, &_MAV_PAYLOAD(msg)[wire_offset], array_length*sizeof(TYPE)); \ |
jdawkins | 0:bb2cacd02294 | 326 | return array_length*sizeof(TYPE); \ |
jdawkins | 0:bb2cacd02294 | 327 | } |
jdawkins | 0:bb2cacd02294 | 328 | #endif |
jdawkins | 0:bb2cacd02294 | 329 | |
jdawkins | 0:bb2cacd02294 | 330 | _MAV_RETURN_ARRAY(uint16_t, u16) |
jdawkins | 0:bb2cacd02294 | 331 | _MAV_RETURN_ARRAY(uint32_t, u32) |
jdawkins | 0:bb2cacd02294 | 332 | _MAV_RETURN_ARRAY(uint64_t, u64) |
jdawkins | 0:bb2cacd02294 | 333 | _MAV_RETURN_ARRAY(int16_t, i16) |
jdawkins | 0:bb2cacd02294 | 334 | _MAV_RETURN_ARRAY(int32_t, i32) |
jdawkins | 0:bb2cacd02294 | 335 | _MAV_RETURN_ARRAY(int64_t, i64) |
jdawkins | 0:bb2cacd02294 | 336 | _MAV_RETURN_ARRAY(float, f) |
jdawkins | 0:bb2cacd02294 | 337 | _MAV_RETURN_ARRAY(double, d) |
jdawkins | 0:bb2cacd02294 | 338 | |
jdawkins | 0:bb2cacd02294 | 339 | #endif // _MAVLINK_PROTOCOL_H_ |
jdawkins | 0:bb2cacd02294 | 340 |