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
MAVlink/include/common/mavlink_msg_ping.h@0:a6a169de725f, 2013-05-27 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | // MESSAGE PING PACKING |
shimniok | 0:a6a169de725f | 2 | |
shimniok | 0:a6a169de725f | 3 | #define MAVLINK_MSG_ID_PING 3 |
shimniok | 0:a6a169de725f | 4 | |
shimniok | 0:a6a169de725f | 5 | typedef struct __mavlink_ping_t |
shimniok | 0:a6a169de725f | 6 | { |
shimniok | 0:a6a169de725f | 7 | uint32_t seq; ///< PING sequence |
shimniok | 0:a6a169de725f | 8 | uint8_t target_system; ///< 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 9 | uint8_t target_component; ///< 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 10 | uint64_t time; ///< Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 11 | |
shimniok | 0:a6a169de725f | 12 | } mavlink_ping_t; |
shimniok | 0:a6a169de725f | 13 | |
shimniok | 0:a6a169de725f | 14 | |
shimniok | 0:a6a169de725f | 15 | |
shimniok | 0:a6a169de725f | 16 | /** |
shimniok | 0:a6a169de725f | 17 | * @brief Pack a ping message |
shimniok | 0:a6a169de725f | 18 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 19 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 20 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 21 | * |
shimniok | 0:a6a169de725f | 22 | * @param seq PING sequence |
shimniok | 0:a6a169de725f | 23 | * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 24 | * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 25 | * @param time Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 26 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 27 | */ |
shimniok | 0:a6a169de725f | 28 | static inline uint16_t mavlink_msg_ping_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint32_t seq, uint8_t target_system, uint8_t target_component, uint64_t time) |
shimniok | 0:a6a169de725f | 29 | { |
shimniok | 0:a6a169de725f | 30 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 31 | msg->msgid = MAVLINK_MSG_ID_PING; |
shimniok | 0:a6a169de725f | 32 | |
shimniok | 0:a6a169de725f | 33 | i += put_uint32_t_by_index(seq, i, msg->payload); // PING sequence |
shimniok | 0:a6a169de725f | 34 | i += put_uint8_t_by_index(target_system, i, msg->payload); // 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 35 | i += put_uint8_t_by_index(target_component, i, msg->payload); // 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 36 | i += put_uint64_t_by_index(time, i, msg->payload); // Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 37 | |
shimniok | 0:a6a169de725f | 38 | return mavlink_finalize_message(msg, system_id, component_id, i); |
shimniok | 0:a6a169de725f | 39 | } |
shimniok | 0:a6a169de725f | 40 | |
shimniok | 0:a6a169de725f | 41 | /** |
shimniok | 0:a6a169de725f | 42 | * @brief Pack a ping message |
shimniok | 0:a6a169de725f | 43 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 44 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 45 | * @param chan The MAVLink channel this message was sent over |
shimniok | 0:a6a169de725f | 46 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 47 | * @param seq PING sequence |
shimniok | 0:a6a169de725f | 48 | * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 49 | * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 50 | * @param time Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 51 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 52 | */ |
shimniok | 0:a6a169de725f | 53 | static inline uint16_t mavlink_msg_ping_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint32_t seq, uint8_t target_system, uint8_t target_component, uint64_t time) |
shimniok | 0:a6a169de725f | 54 | { |
shimniok | 0:a6a169de725f | 55 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 56 | msg->msgid = MAVLINK_MSG_ID_PING; |
shimniok | 0:a6a169de725f | 57 | |
shimniok | 0:a6a169de725f | 58 | i += put_uint32_t_by_index(seq, i, msg->payload); // PING sequence |
shimniok | 0:a6a169de725f | 59 | i += put_uint8_t_by_index(target_system, i, msg->payload); // 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 60 | i += put_uint8_t_by_index(target_component, i, msg->payload); // 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 61 | i += put_uint64_t_by_index(time, i, msg->payload); // Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 62 | |
shimniok | 0:a6a169de725f | 63 | return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i); |
shimniok | 0:a6a169de725f | 64 | } |
shimniok | 0:a6a169de725f | 65 | |
shimniok | 0:a6a169de725f | 66 | /** |
shimniok | 0:a6a169de725f | 67 | * @brief Encode a ping struct into a message |
shimniok | 0:a6a169de725f | 68 | * |
shimniok | 0:a6a169de725f | 69 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 70 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 71 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 72 | * @param ping C-struct to read the message contents from |
shimniok | 0:a6a169de725f | 73 | */ |
shimniok | 0:a6a169de725f | 74 | static inline uint16_t mavlink_msg_ping_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ping_t* ping) |
shimniok | 0:a6a169de725f | 75 | { |
shimniok | 0:a6a169de725f | 76 | return mavlink_msg_ping_pack(system_id, component_id, msg, ping->seq, ping->target_system, ping->target_component, ping->time); |
shimniok | 0:a6a169de725f | 77 | } |
shimniok | 0:a6a169de725f | 78 | |
shimniok | 0:a6a169de725f | 79 | /** |
shimniok | 0:a6a169de725f | 80 | * @brief Send a ping message |
shimniok | 0:a6a169de725f | 81 | * @param chan MAVLink channel to send the message |
shimniok | 0:a6a169de725f | 82 | * |
shimniok | 0:a6a169de725f | 83 | * @param seq PING sequence |
shimniok | 0:a6a169de725f | 84 | * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 85 | * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 86 | * @param time Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 87 | */ |
shimniok | 0:a6a169de725f | 88 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
shimniok | 0:a6a169de725f | 89 | |
shimniok | 0:a6a169de725f | 90 | static inline void mavlink_msg_ping_send(mavlink_channel_t chan, uint32_t seq, uint8_t target_system, uint8_t target_component, uint64_t time) |
shimniok | 0:a6a169de725f | 91 | { |
shimniok | 0:a6a169de725f | 92 | mavlink_message_t msg; |
shimniok | 0:a6a169de725f | 93 | mavlink_msg_ping_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, seq, target_system, target_component, time); |
shimniok | 0:a6a169de725f | 94 | mavlink_send_uart(chan, &msg); |
shimniok | 0:a6a169de725f | 95 | } |
shimniok | 0:a6a169de725f | 96 | |
shimniok | 0:a6a169de725f | 97 | #endif |
shimniok | 0:a6a169de725f | 98 | // MESSAGE PING UNPACKING |
shimniok | 0:a6a169de725f | 99 | |
shimniok | 0:a6a169de725f | 100 | /** |
shimniok | 0:a6a169de725f | 101 | * @brief Get field seq from ping message |
shimniok | 0:a6a169de725f | 102 | * |
shimniok | 0:a6a169de725f | 103 | * @return PING sequence |
shimniok | 0:a6a169de725f | 104 | */ |
shimniok | 0:a6a169de725f | 105 | static inline uint32_t mavlink_msg_ping_get_seq(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 106 | { |
shimniok | 0:a6a169de725f | 107 | generic_32bit r; |
shimniok | 0:a6a169de725f | 108 | r.b[3] = (msg->payload)[0]; |
shimniok | 0:a6a169de725f | 109 | r.b[2] = (msg->payload)[1]; |
shimniok | 0:a6a169de725f | 110 | r.b[1] = (msg->payload)[2]; |
shimniok | 0:a6a169de725f | 111 | r.b[0] = (msg->payload)[3]; |
shimniok | 0:a6a169de725f | 112 | return (uint32_t)r.i; |
shimniok | 0:a6a169de725f | 113 | } |
shimniok | 0:a6a169de725f | 114 | |
shimniok | 0:a6a169de725f | 115 | /** |
shimniok | 0:a6a169de725f | 116 | * @brief Get field target_system from ping message |
shimniok | 0:a6a169de725f | 117 | * |
shimniok | 0:a6a169de725f | 118 | * @return 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 119 | */ |
shimniok | 0:a6a169de725f | 120 | static inline uint8_t mavlink_msg_ping_get_target_system(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 121 | { |
shimniok | 0:a6a169de725f | 122 | return (uint8_t)(msg->payload+sizeof(uint32_t))[0]; |
shimniok | 0:a6a169de725f | 123 | } |
shimniok | 0:a6a169de725f | 124 | |
shimniok | 0:a6a169de725f | 125 | /** |
shimniok | 0:a6a169de725f | 126 | * @brief Get field target_component from ping message |
shimniok | 0:a6a169de725f | 127 | * |
shimniok | 0:a6a169de725f | 128 | * @return 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system |
shimniok | 0:a6a169de725f | 129 | */ |
shimniok | 0:a6a169de725f | 130 | static inline uint8_t mavlink_msg_ping_get_target_component(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 131 | { |
shimniok | 0:a6a169de725f | 132 | return (uint8_t)(msg->payload+sizeof(uint32_t)+sizeof(uint8_t))[0]; |
shimniok | 0:a6a169de725f | 133 | } |
shimniok | 0:a6a169de725f | 134 | |
shimniok | 0:a6a169de725f | 135 | /** |
shimniok | 0:a6a169de725f | 136 | * @brief Get field time from ping message |
shimniok | 0:a6a169de725f | 137 | * |
shimniok | 0:a6a169de725f | 138 | * @return Unix timestamp in microseconds |
shimniok | 0:a6a169de725f | 139 | */ |
shimniok | 0:a6a169de725f | 140 | static inline uint64_t mavlink_msg_ping_get_time(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 141 | { |
shimniok | 0:a6a169de725f | 142 | generic_64bit r; |
shimniok | 0:a6a169de725f | 143 | r.b[7] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[0]; |
shimniok | 0:a6a169de725f | 144 | r.b[6] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[1]; |
shimniok | 0:a6a169de725f | 145 | r.b[5] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[2]; |
shimniok | 0:a6a169de725f | 146 | r.b[4] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[3]; |
shimniok | 0:a6a169de725f | 147 | r.b[3] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[4]; |
shimniok | 0:a6a169de725f | 148 | r.b[2] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[5]; |
shimniok | 0:a6a169de725f | 149 | r.b[1] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[6]; |
shimniok | 0:a6a169de725f | 150 | r.b[0] = (msg->payload+sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t))[7]; |
shimniok | 0:a6a169de725f | 151 | return (uint64_t)r.ll; |
shimniok | 0:a6a169de725f | 152 | } |
shimniok | 0:a6a169de725f | 153 | |
shimniok | 0:a6a169de725f | 154 | /** |
shimniok | 0:a6a169de725f | 155 | * @brief Decode a ping message into a struct |
shimniok | 0:a6a169de725f | 156 | * |
shimniok | 0:a6a169de725f | 157 | * @param msg The message to decode |
shimniok | 0:a6a169de725f | 158 | * @param ping C-struct to decode the message contents into |
shimniok | 0:a6a169de725f | 159 | */ |
shimniok | 0:a6a169de725f | 160 | static inline void mavlink_msg_ping_decode(const mavlink_message_t* msg, mavlink_ping_t* ping) |
shimniok | 0:a6a169de725f | 161 | { |
shimniok | 0:a6a169de725f | 162 | ping->seq = mavlink_msg_ping_get_seq(msg); |
shimniok | 0:a6a169de725f | 163 | ping->target_system = mavlink_msg_ping_get_target_system(msg); |
shimniok | 0:a6a169de725f | 164 | ping->target_component = mavlink_msg_ping_get_target_component(msg); |
shimniok | 0:a6a169de725f | 165 | ping->time = mavlink_msg_ping_get_time(msg); |
shimniok | 0:a6a169de725f | 166 | } |