Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.

Dependencies:   mbed Watchdog SDFileSystem DigoleSerialDisp

Committer:
shimniok
Date:
Mon May 27 13:26:03 2013 +0000
Revision:
0:a6a169de725f
Working version with priorities set and update time display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:a6a169de725f 1 // MESSAGE SYSTEM_TIME PACKING
shimniok 0:a6a169de725f 2
shimniok 0:a6a169de725f 3 #define MAVLINK_MSG_ID_SYSTEM_TIME 2
shimniok 0:a6a169de725f 4
shimniok 0:a6a169de725f 5 typedef struct __mavlink_system_time_t
shimniok 0:a6a169de725f 6 {
shimniok 0:a6a169de725f 7 uint64_t time_usec; ///< Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 8
shimniok 0:a6a169de725f 9 } mavlink_system_time_t;
shimniok 0:a6a169de725f 10
shimniok 0:a6a169de725f 11
shimniok 0:a6a169de725f 12
shimniok 0:a6a169de725f 13 /**
shimniok 0:a6a169de725f 14 * @brief Pack a system_time message
shimniok 0:a6a169de725f 15 * @param system_id ID of this system
shimniok 0:a6a169de725f 16 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 17 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 18 *
shimniok 0:a6a169de725f 19 * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 20 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:a6a169de725f 21 */
shimniok 0:a6a169de725f 22 static inline uint16_t mavlink_msg_system_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint64_t time_usec)
shimniok 0:a6a169de725f 23 {
shimniok 0:a6a169de725f 24 uint16_t i = 0;
shimniok 0:a6a169de725f 25 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
shimniok 0:a6a169de725f 26
shimniok 0:a6a169de725f 27 i += put_uint64_t_by_index(time_usec, i, msg->payload); // Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 28
shimniok 0:a6a169de725f 29 return mavlink_finalize_message(msg, system_id, component_id, i);
shimniok 0:a6a169de725f 30 }
shimniok 0:a6a169de725f 31
shimniok 0:a6a169de725f 32 /**
shimniok 0:a6a169de725f 33 * @brief Pack a system_time message
shimniok 0:a6a169de725f 34 * @param system_id ID of this system
shimniok 0:a6a169de725f 35 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 36 * @param chan The MAVLink channel this message was sent over
shimniok 0:a6a169de725f 37 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 38 * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 39 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:a6a169de725f 40 */
shimniok 0:a6a169de725f 41 static inline uint16_t mavlink_msg_system_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint64_t time_usec)
shimniok 0:a6a169de725f 42 {
shimniok 0:a6a169de725f 43 uint16_t i = 0;
shimniok 0:a6a169de725f 44 msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME;
shimniok 0:a6a169de725f 45
shimniok 0:a6a169de725f 46 i += put_uint64_t_by_index(time_usec, i, msg->payload); // Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 47
shimniok 0:a6a169de725f 48 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);
shimniok 0:a6a169de725f 49 }
shimniok 0:a6a169de725f 50
shimniok 0:a6a169de725f 51 /**
shimniok 0:a6a169de725f 52 * @brief Encode a system_time struct into a message
shimniok 0:a6a169de725f 53 *
shimniok 0:a6a169de725f 54 * @param system_id ID of this system
shimniok 0:a6a169de725f 55 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 56 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 57 * @param system_time C-struct to read the message contents from
shimniok 0:a6a169de725f 58 */
shimniok 0:a6a169de725f 59 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)
shimniok 0:a6a169de725f 60 {
shimniok 0:a6a169de725f 61 return mavlink_msg_system_time_pack(system_id, component_id, msg, system_time->time_usec);
shimniok 0:a6a169de725f 62 }
shimniok 0:a6a169de725f 63
shimniok 0:a6a169de725f 64 /**
shimniok 0:a6a169de725f 65 * @brief Send a system_time message
shimniok 0:a6a169de725f 66 * @param chan MAVLink channel to send the message
shimniok 0:a6a169de725f 67 *
shimniok 0:a6a169de725f 68 * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 69 */
shimniok 0:a6a169de725f 70 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
shimniok 0:a6a169de725f 71
shimniok 0:a6a169de725f 72 static inline void mavlink_msg_system_time_send(mavlink_channel_t chan, uint64_t time_usec)
shimniok 0:a6a169de725f 73 {
shimniok 0:a6a169de725f 74 mavlink_message_t msg;
shimniok 0:a6a169de725f 75 mavlink_msg_system_time_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, time_usec);
shimniok 0:a6a169de725f 76 mavlink_send_uart(chan, &msg);
shimniok 0:a6a169de725f 77 }
shimniok 0:a6a169de725f 78
shimniok 0:a6a169de725f 79 #endif
shimniok 0:a6a169de725f 80 // MESSAGE SYSTEM_TIME UNPACKING
shimniok 0:a6a169de725f 81
shimniok 0:a6a169de725f 82 /**
shimniok 0:a6a169de725f 83 * @brief Get field time_usec from system_time message
shimniok 0:a6a169de725f 84 *
shimniok 0:a6a169de725f 85 * @return Timestamp of the master clock in microseconds since UNIX epoch.
shimniok 0:a6a169de725f 86 */
shimniok 0:a6a169de725f 87 static inline uint64_t mavlink_msg_system_time_get_time_usec(const mavlink_message_t* msg)
shimniok 0:a6a169de725f 88 {
shimniok 0:a6a169de725f 89 generic_64bit r;
shimniok 0:a6a169de725f 90 r.b[7] = (msg->payload)[0];
shimniok 0:a6a169de725f 91 r.b[6] = (msg->payload)[1];
shimniok 0:a6a169de725f 92 r.b[5] = (msg->payload)[2];
shimniok 0:a6a169de725f 93 r.b[4] = (msg->payload)[3];
shimniok 0:a6a169de725f 94 r.b[3] = (msg->payload)[4];
shimniok 0:a6a169de725f 95 r.b[2] = (msg->payload)[5];
shimniok 0:a6a169de725f 96 r.b[1] = (msg->payload)[6];
shimniok 0:a6a169de725f 97 r.b[0] = (msg->payload)[7];
shimniok 0:a6a169de725f 98 return (uint64_t)r.ll;
shimniok 0:a6a169de725f 99 }
shimniok 0:a6a169de725f 100
shimniok 0:a6a169de725f 101 /**
shimniok 0:a6a169de725f 102 * @brief Decode a system_time message into a struct
shimniok 0:a6a169de725f 103 *
shimniok 0:a6a169de725f 104 * @param msg The message to decode
shimniok 0:a6a169de725f 105 * @param system_time C-struct to decode the message contents into
shimniok 0:a6a169de725f 106 */
shimniok 0:a6a169de725f 107 static inline void mavlink_msg_system_time_decode(const mavlink_message_t* msg, mavlink_system_time_t* system_time)
shimniok 0:a6a169de725f 108 {
shimniok 0:a6a169de725f 109 system_time->time_usec = mavlink_msg_system_time_get_time_usec(msg);
shimniok 0:a6a169de725f 110 }