Mavlink Messages for Emaxx Nav Board

Dependents:   Madpulse_Speed_Control_temp Madpulse_Speed_Control_Students

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?

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