Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 // MESSAGE SYS_STATUS PACKING
shimniok 0:826c6171fc1b 2
shimniok 0:826c6171fc1b 3 #define MAVLINK_MSG_ID_SYS_STATUS 34
shimniok 0:826c6171fc1b 4
shimniok 0:826c6171fc1b 5 typedef struct __mavlink_sys_status_t
shimniok 0:826c6171fc1b 6 {
shimniok 0:826c6171fc1b 7 uint8_t mode; ///< System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 8 uint8_t nav_mode; ///< Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 9 uint8_t status; ///< System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 10 uint16_t load; ///< Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 11 uint16_t vbat; ///< Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 12 uint16_t battery_remaining; ///< Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 13 uint16_t packet_drop; ///< Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 14
shimniok 0:826c6171fc1b 15 } mavlink_sys_status_t;
shimniok 0:826c6171fc1b 16
shimniok 0:826c6171fc1b 17
shimniok 0:826c6171fc1b 18
shimniok 0:826c6171fc1b 19 /**
shimniok 0:826c6171fc1b 20 * @brief Pack a sys_status message
shimniok 0:826c6171fc1b 21 * @param system_id ID of this system
shimniok 0:826c6171fc1b 22 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 23 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 24 *
shimniok 0:826c6171fc1b 25 * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 26 * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 27 * @param status System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 28 * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 29 * @param vbat Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 30 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 31 * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 32 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:826c6171fc1b 33 */
shimniok 0:826c6171fc1b 34 static inline uint16_t mavlink_msg_sys_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint8_t mode, uint8_t nav_mode, uint8_t status, uint16_t load, uint16_t vbat, uint16_t battery_remaining, uint16_t packet_drop)
shimniok 0:826c6171fc1b 35 {
shimniok 0:826c6171fc1b 36 uint16_t i = 0;
shimniok 0:826c6171fc1b 37 msg->msgid = MAVLINK_MSG_ID_SYS_STATUS;
shimniok 0:826c6171fc1b 38
shimniok 0:826c6171fc1b 39 i += put_uint8_t_by_index(mode, i, msg->payload); // System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 40 i += put_uint8_t_by_index(nav_mode, i, msg->payload); // Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 41 i += put_uint8_t_by_index(status, i, msg->payload); // System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 42 i += put_uint16_t_by_index(load, i, msg->payload); // Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 43 i += put_uint16_t_by_index(vbat, i, msg->payload); // Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 44 i += put_uint16_t_by_index(battery_remaining, i, msg->payload); // Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 45 i += put_uint16_t_by_index(packet_drop, i, msg->payload); // Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 46
shimniok 0:826c6171fc1b 47 return mavlink_finalize_message(msg, system_id, component_id, i);
shimniok 0:826c6171fc1b 48 }
shimniok 0:826c6171fc1b 49
shimniok 0:826c6171fc1b 50 /**
shimniok 0:826c6171fc1b 51 * @brief Pack a sys_status message
shimniok 0:826c6171fc1b 52 * @param system_id ID of this system
shimniok 0:826c6171fc1b 53 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 54 * @param chan The MAVLink channel this message was sent over
shimniok 0:826c6171fc1b 55 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 56 * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 57 * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 58 * @param status System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 59 * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 60 * @param vbat Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 61 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 62 * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 63 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:826c6171fc1b 64 */
shimniok 0:826c6171fc1b 65 static inline uint16_t mavlink_msg_sys_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint8_t mode, uint8_t nav_mode, uint8_t status, uint16_t load, uint16_t vbat, uint16_t battery_remaining, uint16_t packet_drop)
shimniok 0:826c6171fc1b 66 {
shimniok 0:826c6171fc1b 67 uint16_t i = 0;
shimniok 0:826c6171fc1b 68 msg->msgid = MAVLINK_MSG_ID_SYS_STATUS;
shimniok 0:826c6171fc1b 69
shimniok 0:826c6171fc1b 70 i += put_uint8_t_by_index(mode, i, msg->payload); // System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 71 i += put_uint8_t_by_index(nav_mode, i, msg->payload); // Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 72 i += put_uint8_t_by_index(status, i, msg->payload); // System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 73 i += put_uint16_t_by_index(load, i, msg->payload); // Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 74 i += put_uint16_t_by_index(vbat, i, msg->payload); // Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 75 i += put_uint16_t_by_index(battery_remaining, i, msg->payload); // Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 76 i += put_uint16_t_by_index(packet_drop, i, msg->payload); // Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 77
shimniok 0:826c6171fc1b 78 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);
shimniok 0:826c6171fc1b 79 }
shimniok 0:826c6171fc1b 80
shimniok 0:826c6171fc1b 81 /**
shimniok 0:826c6171fc1b 82 * @brief Encode a sys_status struct into a message
shimniok 0:826c6171fc1b 83 *
shimniok 0:826c6171fc1b 84 * @param system_id ID of this system
shimniok 0:826c6171fc1b 85 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 86 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 87 * @param sys_status C-struct to read the message contents from
shimniok 0:826c6171fc1b 88 */
shimniok 0:826c6171fc1b 89 static inline uint16_t mavlink_msg_sys_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_sys_status_t* sys_status)
shimniok 0:826c6171fc1b 90 {
shimniok 0:826c6171fc1b 91 return mavlink_msg_sys_status_pack(system_id, component_id, msg, sys_status->mode, sys_status->nav_mode, sys_status->status, sys_status->load, sys_status->vbat, sys_status->battery_remaining, sys_status->packet_drop);
shimniok 0:826c6171fc1b 92 }
shimniok 0:826c6171fc1b 93
shimniok 0:826c6171fc1b 94 /**
shimniok 0:826c6171fc1b 95 * @brief Send a sys_status message
shimniok 0:826c6171fc1b 96 * @param chan MAVLink channel to send the message
shimniok 0:826c6171fc1b 97 *
shimniok 0:826c6171fc1b 98 * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 99 * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 100 * @param status System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 101 * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 102 * @param vbat Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 103 * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 104 * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 105 */
shimniok 0:826c6171fc1b 106 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
shimniok 0:826c6171fc1b 107
shimniok 0:826c6171fc1b 108 static inline void mavlink_msg_sys_status_send(mavlink_channel_t chan, uint8_t mode, uint8_t nav_mode, uint8_t status, uint16_t load, uint16_t vbat, uint16_t battery_remaining, uint16_t packet_drop)
shimniok 0:826c6171fc1b 109 {
shimniok 0:826c6171fc1b 110 mavlink_message_t msg;
shimniok 0:826c6171fc1b 111 mavlink_msg_sys_status_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, mode, nav_mode, status, load, vbat, battery_remaining, packet_drop);
shimniok 0:826c6171fc1b 112 mavlink_send_uart(chan, &msg);
shimniok 0:826c6171fc1b 113 }
shimniok 0:826c6171fc1b 114
shimniok 0:826c6171fc1b 115 #endif
shimniok 0:826c6171fc1b 116 // MESSAGE SYS_STATUS UNPACKING
shimniok 0:826c6171fc1b 117
shimniok 0:826c6171fc1b 118 /**
shimniok 0:826c6171fc1b 119 * @brief Get field mode from sys_status message
shimniok 0:826c6171fc1b 120 *
shimniok 0:826c6171fc1b 121 * @return System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h
shimniok 0:826c6171fc1b 122 */
shimniok 0:826c6171fc1b 123 static inline uint8_t mavlink_msg_sys_status_get_mode(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 124 {
shimniok 0:826c6171fc1b 125 return (uint8_t)(msg->payload)[0];
shimniok 0:826c6171fc1b 126 }
shimniok 0:826c6171fc1b 127
shimniok 0:826c6171fc1b 128 /**
shimniok 0:826c6171fc1b 129 * @brief Get field nav_mode from sys_status message
shimniok 0:826c6171fc1b 130 *
shimniok 0:826c6171fc1b 131 * @return Navigation mode, see MAV_NAV_MODE ENUM
shimniok 0:826c6171fc1b 132 */
shimniok 0:826c6171fc1b 133 static inline uint8_t mavlink_msg_sys_status_get_nav_mode(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 134 {
shimniok 0:826c6171fc1b 135 return (uint8_t)(msg->payload+sizeof(uint8_t))[0];
shimniok 0:826c6171fc1b 136 }
shimniok 0:826c6171fc1b 137
shimniok 0:826c6171fc1b 138 /**
shimniok 0:826c6171fc1b 139 * @brief Get field status from sys_status message
shimniok 0:826c6171fc1b 140 *
shimniok 0:826c6171fc1b 141 * @return System status flag, see MAV_STATUS ENUM
shimniok 0:826c6171fc1b 142 */
shimniok 0:826c6171fc1b 143 static inline uint8_t mavlink_msg_sys_status_get_status(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 144 {
shimniok 0:826c6171fc1b 145 return (uint8_t)(msg->payload+sizeof(uint8_t)+sizeof(uint8_t))[0];
shimniok 0:826c6171fc1b 146 }
shimniok 0:826c6171fc1b 147
shimniok 0:826c6171fc1b 148 /**
shimniok 0:826c6171fc1b 149 * @brief Get field load from sys_status message
shimniok 0:826c6171fc1b 150 *
shimniok 0:826c6171fc1b 151 * @return Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000
shimniok 0:826c6171fc1b 152 */
shimniok 0:826c6171fc1b 153 static inline uint16_t mavlink_msg_sys_status_get_load(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 154 {
shimniok 0:826c6171fc1b 155 generic_16bit r;
shimniok 0:826c6171fc1b 156 r.b[1] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t))[0];
shimniok 0:826c6171fc1b 157 r.b[0] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t))[1];
shimniok 0:826c6171fc1b 158 return (uint16_t)r.s;
shimniok 0:826c6171fc1b 159 }
shimniok 0:826c6171fc1b 160
shimniok 0:826c6171fc1b 161 /**
shimniok 0:826c6171fc1b 162 * @brief Get field vbat from sys_status message
shimniok 0:826c6171fc1b 163 *
shimniok 0:826c6171fc1b 164 * @return Battery voltage, in millivolts (1 = 1 millivolt)
shimniok 0:826c6171fc1b 165 */
shimniok 0:826c6171fc1b 166 static inline uint16_t mavlink_msg_sys_status_get_vbat(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 167 {
shimniok 0:826c6171fc1b 168 generic_16bit r;
shimniok 0:826c6171fc1b 169 r.b[1] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t))[0];
shimniok 0:826c6171fc1b 170 r.b[0] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t))[1];
shimniok 0:826c6171fc1b 171 return (uint16_t)r.s;
shimniok 0:826c6171fc1b 172 }
shimniok 0:826c6171fc1b 173
shimniok 0:826c6171fc1b 174 /**
shimniok 0:826c6171fc1b 175 * @brief Get field battery_remaining from sys_status message
shimniok 0:826c6171fc1b 176 *
shimniok 0:826c6171fc1b 177 * @return Remaining battery energy: (0%: 0, 100%: 1000)
shimniok 0:826c6171fc1b 178 */
shimniok 0:826c6171fc1b 179 static inline uint16_t mavlink_msg_sys_status_get_battery_remaining(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 180 {
shimniok 0:826c6171fc1b 181 generic_16bit r;
shimniok 0:826c6171fc1b 182 r.b[1] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint16_t))[0];
shimniok 0:826c6171fc1b 183 r.b[0] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint16_t))[1];
shimniok 0:826c6171fc1b 184 return (uint16_t)r.s;
shimniok 0:826c6171fc1b 185 }
shimniok 0:826c6171fc1b 186
shimniok 0:826c6171fc1b 187 /**
shimniok 0:826c6171fc1b 188 * @brief Get field packet_drop from sys_status message
shimniok 0:826c6171fc1b 189 *
shimniok 0:826c6171fc1b 190 * @return Dropped packets (packets that were corrupted on reception on the MAV)
shimniok 0:826c6171fc1b 191 */
shimniok 0:826c6171fc1b 192 static inline uint16_t mavlink_msg_sys_status_get_packet_drop(const mavlink_message_t* msg)
shimniok 0:826c6171fc1b 193 {
shimniok 0:826c6171fc1b 194 generic_16bit r;
shimniok 0:826c6171fc1b 195 r.b[1] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(uint16_t))[0];
shimniok 0:826c6171fc1b 196 r.b[0] = (msg->payload+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(uint16_t))[1];
shimniok 0:826c6171fc1b 197 return (uint16_t)r.s;
shimniok 0:826c6171fc1b 198 }
shimniok 0:826c6171fc1b 199
shimniok 0:826c6171fc1b 200 /**
shimniok 0:826c6171fc1b 201 * @brief Decode a sys_status message into a struct
shimniok 0:826c6171fc1b 202 *
shimniok 0:826c6171fc1b 203 * @param msg The message to decode
shimniok 0:826c6171fc1b 204 * @param sys_status C-struct to decode the message contents into
shimniok 0:826c6171fc1b 205 */
shimniok 0:826c6171fc1b 206 static inline void mavlink_msg_sys_status_decode(const mavlink_message_t* msg, mavlink_sys_status_t* sys_status)
shimniok 0:826c6171fc1b 207 {
shimniok 0:826c6171fc1b 208 sys_status->mode = mavlink_msg_sys_status_get_mode(msg);
shimniok 0:826c6171fc1b 209 sys_status->nav_mode = mavlink_msg_sys_status_get_nav_mode(msg);
shimniok 0:826c6171fc1b 210 sys_status->status = mavlink_msg_sys_status_get_status(msg);
shimniok 0:826c6171fc1b 211 sys_status->load = mavlink_msg_sys_status_get_load(msg);
shimniok 0:826c6171fc1b 212 sys_status->vbat = mavlink_msg_sys_status_get_vbat(msg);
shimniok 0:826c6171fc1b 213 sys_status->battery_remaining = mavlink_msg_sys_status_get_battery_remaining(msg);
shimniok 0:826c6171fc1b 214 sys_status->packet_drop = mavlink_msg_sys_status_get_packet_drop(msg);
shimniok 0:826c6171fc1b 215 }