Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
MAVlink/include/minimal/mavlink_msg_heartbeat.h@0:826c6171fc1b, 2012-06-20 (annotated)
- Committer:
- shimniok
- Date:
- Wed Jun 20 14:57:48 2012 +0000
- Revision:
- 0:826c6171fc1b
Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:826c6171fc1b | 1 | // MESSAGE HEARTBEAT PACKING |
shimniok | 0:826c6171fc1b | 2 | |
shimniok | 0:826c6171fc1b | 3 | #define MAVLINK_MSG_ID_HEARTBEAT 0 |
shimniok | 0:826c6171fc1b | 4 | |
shimniok | 0:826c6171fc1b | 5 | typedef struct __mavlink_heartbeat_t |
shimniok | 0:826c6171fc1b | 6 | { |
shimniok | 0:826c6171fc1b | 7 | uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 8 | uint8_t autopilot; ///< Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 9 | uint8_t mavlink_version; ///< MAVLink version |
shimniok | 0:826c6171fc1b | 10 | |
shimniok | 0:826c6171fc1b | 11 | } mavlink_heartbeat_t; |
shimniok | 0:826c6171fc1b | 12 | |
shimniok | 0:826c6171fc1b | 13 | |
shimniok | 0:826c6171fc1b | 14 | |
shimniok | 0:826c6171fc1b | 15 | /** |
shimniok | 0:826c6171fc1b | 16 | * @brief Pack a heartbeat message |
shimniok | 0:826c6171fc1b | 17 | * @param system_id ID of this system |
shimniok | 0:826c6171fc1b | 18 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:826c6171fc1b | 19 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:826c6171fc1b | 20 | * |
shimniok | 0:826c6171fc1b | 21 | * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 22 | * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 23 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:826c6171fc1b | 24 | */ |
shimniok | 0:826c6171fc1b | 25 | static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint8_t type, uint8_t autopilot) |
shimniok | 0:826c6171fc1b | 26 | { |
shimniok | 0:826c6171fc1b | 27 | uint16_t i = 0; |
shimniok | 0:826c6171fc1b | 28 | msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; |
shimniok | 0:826c6171fc1b | 29 | |
shimniok | 0:826c6171fc1b | 30 | i += put_uint8_t_by_index(type, i, msg->payload); // Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 31 | i += put_uint8_t_by_index(autopilot, i, msg->payload); // Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 32 | i += put_uint8_t_by_index(2, i, msg->payload); // MAVLink version |
shimniok | 0:826c6171fc1b | 33 | |
shimniok | 0:826c6171fc1b | 34 | return mavlink_finalize_message(msg, system_id, component_id, i); |
shimniok | 0:826c6171fc1b | 35 | } |
shimniok | 0:826c6171fc1b | 36 | |
shimniok | 0:826c6171fc1b | 37 | /** |
shimniok | 0:826c6171fc1b | 38 | * @brief Pack a heartbeat message |
shimniok | 0:826c6171fc1b | 39 | * @param system_id ID of this system |
shimniok | 0:826c6171fc1b | 40 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:826c6171fc1b | 41 | * @param chan The MAVLink channel this message was sent over |
shimniok | 0:826c6171fc1b | 42 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:826c6171fc1b | 43 | * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 44 | * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 45 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:826c6171fc1b | 46 | */ |
shimniok | 0:826c6171fc1b | 47 | static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint8_t type, uint8_t autopilot) |
shimniok | 0:826c6171fc1b | 48 | { |
shimniok | 0:826c6171fc1b | 49 | uint16_t i = 0; |
shimniok | 0:826c6171fc1b | 50 | msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; |
shimniok | 0:826c6171fc1b | 51 | |
shimniok | 0:826c6171fc1b | 52 | i += put_uint8_t_by_index(type, i, msg->payload); // Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 53 | i += put_uint8_t_by_index(autopilot, i, msg->payload); // Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 54 | i += put_uint8_t_by_index(2, i, msg->payload); // MAVLink version |
shimniok | 0:826c6171fc1b | 55 | |
shimniok | 0:826c6171fc1b | 56 | return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i); |
shimniok | 0:826c6171fc1b | 57 | } |
shimniok | 0:826c6171fc1b | 58 | |
shimniok | 0:826c6171fc1b | 59 | /** |
shimniok | 0:826c6171fc1b | 60 | * @brief Encode a heartbeat struct into a message |
shimniok | 0:826c6171fc1b | 61 | * |
shimniok | 0:826c6171fc1b | 62 | * @param system_id ID of this system |
shimniok | 0:826c6171fc1b | 63 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:826c6171fc1b | 64 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:826c6171fc1b | 65 | * @param heartbeat C-struct to read the message contents from |
shimniok | 0:826c6171fc1b | 66 | */ |
shimniok | 0:826c6171fc1b | 67 | static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat) |
shimniok | 0:826c6171fc1b | 68 | { |
shimniok | 0:826c6171fc1b | 69 | return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot); |
shimniok | 0:826c6171fc1b | 70 | } |
shimniok | 0:826c6171fc1b | 71 | |
shimniok | 0:826c6171fc1b | 72 | /** |
shimniok | 0:826c6171fc1b | 73 | * @brief Send a heartbeat message |
shimniok | 0:826c6171fc1b | 74 | * @param chan MAVLink channel to send the message |
shimniok | 0:826c6171fc1b | 75 | * |
shimniok | 0:826c6171fc1b | 76 | * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 77 | * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 78 | */ |
shimniok | 0:826c6171fc1b | 79 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
shimniok | 0:826c6171fc1b | 80 | |
shimniok | 0:826c6171fc1b | 81 | static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot) |
shimniok | 0:826c6171fc1b | 82 | { |
shimniok | 0:826c6171fc1b | 83 | mavlink_message_t msg; |
shimniok | 0:826c6171fc1b | 84 | mavlink_msg_heartbeat_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, type, autopilot); |
shimniok | 0:826c6171fc1b | 85 | mavlink_send_uart(chan, &msg); |
shimniok | 0:826c6171fc1b | 86 | } |
shimniok | 0:826c6171fc1b | 87 | |
shimniok | 0:826c6171fc1b | 88 | #endif |
shimniok | 0:826c6171fc1b | 89 | // MESSAGE HEARTBEAT UNPACKING |
shimniok | 0:826c6171fc1b | 90 | |
shimniok | 0:826c6171fc1b | 91 | /** |
shimniok | 0:826c6171fc1b | 92 | * @brief Get field type from heartbeat message |
shimniok | 0:826c6171fc1b | 93 | * |
shimniok | 0:826c6171fc1b | 94 | * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) |
shimniok | 0:826c6171fc1b | 95 | */ |
shimniok | 0:826c6171fc1b | 96 | static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg) |
shimniok | 0:826c6171fc1b | 97 | { |
shimniok | 0:826c6171fc1b | 98 | return (uint8_t)(msg->payload)[0]; |
shimniok | 0:826c6171fc1b | 99 | } |
shimniok | 0:826c6171fc1b | 100 | |
shimniok | 0:826c6171fc1b | 101 | /** |
shimniok | 0:826c6171fc1b | 102 | * @brief Get field autopilot from heartbeat message |
shimniok | 0:826c6171fc1b | 103 | * |
shimniok | 0:826c6171fc1b | 104 | * @return Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM |
shimniok | 0:826c6171fc1b | 105 | */ |
shimniok | 0:826c6171fc1b | 106 | static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg) |
shimniok | 0:826c6171fc1b | 107 | { |
shimniok | 0:826c6171fc1b | 108 | return (uint8_t)(msg->payload+sizeof(uint8_t))[0]; |
shimniok | 0:826c6171fc1b | 109 | } |
shimniok | 0:826c6171fc1b | 110 | |
shimniok | 0:826c6171fc1b | 111 | /** |
shimniok | 0:826c6171fc1b | 112 | * @brief Get field mavlink_version from heartbeat message |
shimniok | 0:826c6171fc1b | 113 | * |
shimniok | 0:826c6171fc1b | 114 | * @return MAVLink version |
shimniok | 0:826c6171fc1b | 115 | */ |
shimniok | 0:826c6171fc1b | 116 | static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg) |
shimniok | 0:826c6171fc1b | 117 | { |
shimniok | 0:826c6171fc1b | 118 | return (uint8_t)(msg->payload+sizeof(uint8_t)+sizeof(uint8_t))[0]; |
shimniok | 0:826c6171fc1b | 119 | } |
shimniok | 0:826c6171fc1b | 120 | |
shimniok | 0:826c6171fc1b | 121 | /** |
shimniok | 0:826c6171fc1b | 122 | * @brief Decode a heartbeat message into a struct |
shimniok | 0:826c6171fc1b | 123 | * |
shimniok | 0:826c6171fc1b | 124 | * @param msg The message to decode |
shimniok | 0:826c6171fc1b | 125 | * @param heartbeat C-struct to decode the message contents into |
shimniok | 0:826c6171fc1b | 126 | */ |
shimniok | 0:826c6171fc1b | 127 | static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat) |
shimniok | 0:826c6171fc1b | 128 | { |
shimniok | 0:826c6171fc1b | 129 | heartbeat->type = mavlink_msg_heartbeat_get_type(msg); |
shimniok | 0:826c6171fc1b | 130 | heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg); |
shimniok | 0:826c6171fc1b | 131 | heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg); |
shimniok | 0:826c6171fc1b | 132 | } |