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_command_ack.h@25:bb5356402687, 2018-11-30 (annotated)
- Committer:
- shimniok
- Date:
- Fri Nov 30 16:11:53 2018 +0000
- Revision:
- 25:bb5356402687
- Parent:
- 0:a6a169de725f
Initial publish of revised version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | // MESSAGE COMMAND_ACK PACKING |
shimniok | 0:a6a169de725f | 2 | |
shimniok | 0:a6a169de725f | 3 | #define MAVLINK_MSG_ID_COMMAND_ACK 76 |
shimniok | 0:a6a169de725f | 4 | |
shimniok | 0:a6a169de725f | 5 | typedef struct __mavlink_command_ack_t |
shimniok | 0:a6a169de725f | 6 | { |
shimniok | 0:a6a169de725f | 7 | float command; ///< Current airspeed in m/s |
shimniok | 0:a6a169de725f | 8 | float result; ///< 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 9 | |
shimniok | 0:a6a169de725f | 10 | } mavlink_command_ack_t; |
shimniok | 0:a6a169de725f | 11 | |
shimniok | 0:a6a169de725f | 12 | |
shimniok | 0:a6a169de725f | 13 | |
shimniok | 0:a6a169de725f | 14 | /** |
shimniok | 0:a6a169de725f | 15 | * @brief Pack a command_ack message |
shimniok | 0:a6a169de725f | 16 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 17 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 18 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 19 | * |
shimniok | 0:a6a169de725f | 20 | * @param command Current airspeed in m/s |
shimniok | 0:a6a169de725f | 21 | * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 22 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 23 | */ |
shimniok | 0:a6a169de725f | 24 | static inline uint16_t mavlink_msg_command_ack_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, float command, float result) |
shimniok | 0:a6a169de725f | 25 | { |
shimniok | 0:a6a169de725f | 26 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 27 | msg->msgid = MAVLINK_MSG_ID_COMMAND_ACK; |
shimniok | 0:a6a169de725f | 28 | |
shimniok | 0:a6a169de725f | 29 | i += put_float_by_index(command, i, msg->payload); // Current airspeed in m/s |
shimniok | 0:a6a169de725f | 30 | i += put_float_by_index(result, i, msg->payload); // 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 31 | |
shimniok | 0:a6a169de725f | 32 | return mavlink_finalize_message(msg, system_id, component_id, i); |
shimniok | 0:a6a169de725f | 33 | } |
shimniok | 0:a6a169de725f | 34 | |
shimniok | 0:a6a169de725f | 35 | /** |
shimniok | 0:a6a169de725f | 36 | * @brief Pack a command_ack message |
shimniok | 0:a6a169de725f | 37 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 38 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 39 | * @param chan The MAVLink channel this message was sent over |
shimniok | 0:a6a169de725f | 40 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 41 | * @param command Current airspeed in m/s |
shimniok | 0:a6a169de725f | 42 | * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 43 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 44 | */ |
shimniok | 0:a6a169de725f | 45 | static inline uint16_t mavlink_msg_command_ack_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, float command, float result) |
shimniok | 0:a6a169de725f | 46 | { |
shimniok | 0:a6a169de725f | 47 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 48 | msg->msgid = MAVLINK_MSG_ID_COMMAND_ACK; |
shimniok | 0:a6a169de725f | 49 | |
shimniok | 0:a6a169de725f | 50 | i += put_float_by_index(command, i, msg->payload); // Current airspeed in m/s |
shimniok | 0:a6a169de725f | 51 | i += put_float_by_index(result, i, msg->payload); // 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 52 | |
shimniok | 0:a6a169de725f | 53 | return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i); |
shimniok | 0:a6a169de725f | 54 | } |
shimniok | 0:a6a169de725f | 55 | |
shimniok | 0:a6a169de725f | 56 | /** |
shimniok | 0:a6a169de725f | 57 | * @brief Encode a command_ack struct into a message |
shimniok | 0:a6a169de725f | 58 | * |
shimniok | 0:a6a169de725f | 59 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 60 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 61 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 62 | * @param command_ack C-struct to read the message contents from |
shimniok | 0:a6a169de725f | 63 | */ |
shimniok | 0:a6a169de725f | 64 | static inline uint16_t mavlink_msg_command_ack_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_command_ack_t* command_ack) |
shimniok | 0:a6a169de725f | 65 | { |
shimniok | 0:a6a169de725f | 66 | return mavlink_msg_command_ack_pack(system_id, component_id, msg, command_ack->command, command_ack->result); |
shimniok | 0:a6a169de725f | 67 | } |
shimniok | 0:a6a169de725f | 68 | |
shimniok | 0:a6a169de725f | 69 | /** |
shimniok | 0:a6a169de725f | 70 | * @brief Send a command_ack message |
shimniok | 0:a6a169de725f | 71 | * @param chan MAVLink channel to send the message |
shimniok | 0:a6a169de725f | 72 | * |
shimniok | 0:a6a169de725f | 73 | * @param command Current airspeed in m/s |
shimniok | 0:a6a169de725f | 74 | * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 75 | */ |
shimniok | 0:a6a169de725f | 76 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
shimniok | 0:a6a169de725f | 77 | |
shimniok | 0:a6a169de725f | 78 | static inline void mavlink_msg_command_ack_send(mavlink_channel_t chan, float command, float result) |
shimniok | 0:a6a169de725f | 79 | { |
shimniok | 0:a6a169de725f | 80 | mavlink_message_t msg; |
shimniok | 0:a6a169de725f | 81 | mavlink_msg_command_ack_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, command, result); |
shimniok | 0:a6a169de725f | 82 | mavlink_send_uart(chan, &msg); |
shimniok | 0:a6a169de725f | 83 | } |
shimniok | 0:a6a169de725f | 84 | |
shimniok | 0:a6a169de725f | 85 | #endif |
shimniok | 0:a6a169de725f | 86 | // MESSAGE COMMAND_ACK UNPACKING |
shimniok | 0:a6a169de725f | 87 | |
shimniok | 0:a6a169de725f | 88 | /** |
shimniok | 0:a6a169de725f | 89 | * @brief Get field command from command_ack message |
shimniok | 0:a6a169de725f | 90 | * |
shimniok | 0:a6a169de725f | 91 | * @return Current airspeed in m/s |
shimniok | 0:a6a169de725f | 92 | */ |
shimniok | 0:a6a169de725f | 93 | static inline float mavlink_msg_command_ack_get_command(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 94 | { |
shimniok | 0:a6a169de725f | 95 | generic_32bit r; |
shimniok | 0:a6a169de725f | 96 | r.b[3] = (msg->payload)[0]; |
shimniok | 0:a6a169de725f | 97 | r.b[2] = (msg->payload)[1]; |
shimniok | 0:a6a169de725f | 98 | r.b[1] = (msg->payload)[2]; |
shimniok | 0:a6a169de725f | 99 | r.b[0] = (msg->payload)[3]; |
shimniok | 0:a6a169de725f | 100 | return (float)r.f; |
shimniok | 0:a6a169de725f | 101 | } |
shimniok | 0:a6a169de725f | 102 | |
shimniok | 0:a6a169de725f | 103 | /** |
shimniok | 0:a6a169de725f | 104 | * @brief Get field result from command_ack message |
shimniok | 0:a6a169de725f | 105 | * |
shimniok | 0:a6a169de725f | 106 | * @return 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION |
shimniok | 0:a6a169de725f | 107 | */ |
shimniok | 0:a6a169de725f | 108 | static inline float mavlink_msg_command_ack_get_result(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 109 | { |
shimniok | 0:a6a169de725f | 110 | generic_32bit r; |
shimniok | 0:a6a169de725f | 111 | r.b[3] = (msg->payload+sizeof(float))[0]; |
shimniok | 0:a6a169de725f | 112 | r.b[2] = (msg->payload+sizeof(float))[1]; |
shimniok | 0:a6a169de725f | 113 | r.b[1] = (msg->payload+sizeof(float))[2]; |
shimniok | 0:a6a169de725f | 114 | r.b[0] = (msg->payload+sizeof(float))[3]; |
shimniok | 0:a6a169de725f | 115 | return (float)r.f; |
shimniok | 0:a6a169de725f | 116 | } |
shimniok | 0:a6a169de725f | 117 | |
shimniok | 0:a6a169de725f | 118 | /** |
shimniok | 0:a6a169de725f | 119 | * @brief Decode a command_ack message into a struct |
shimniok | 0:a6a169de725f | 120 | * |
shimniok | 0:a6a169de725f | 121 | * @param msg The message to decode |
shimniok | 0:a6a169de725f | 122 | * @param command_ack C-struct to decode the message contents into |
shimniok | 0:a6a169de725f | 123 | */ |
shimniok | 0:a6a169de725f | 124 | static inline void mavlink_msg_command_ack_decode(const mavlink_message_t* msg, mavlink_command_ack_t* command_ack) |
shimniok | 0:a6a169de725f | 125 | { |
shimniok | 0:a6a169de725f | 126 | command_ack->command = mavlink_msg_command_ack_get_command(msg); |
shimniok | 0:a6a169de725f | 127 | command_ack->result = mavlink_msg_command_ack_get_result(msg); |
shimniok | 0:a6a169de725f | 128 | } |