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:
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?

UserRevisionLine numberNew contents of line
shimniok 0:a6a169de725f 1 // MESSAGE ENCAPSULATED_DATA PACKING
shimniok 0:a6a169de725f 2
shimniok 0:a6a169de725f 3 #define MAVLINK_MSG_ID_ENCAPSULATED_DATA 171
shimniok 0:a6a169de725f 4
shimniok 0:a6a169de725f 5 typedef struct __mavlink_encapsulated_data_t
shimniok 0:a6a169de725f 6 {
shimniok 0:a6a169de725f 7 uint16_t seqnr; ///< sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 8 uint8_t data[253]; ///< image data bytes
shimniok 0:a6a169de725f 9
shimniok 0:a6a169de725f 10 } mavlink_encapsulated_data_t;
shimniok 0:a6a169de725f 11
shimniok 0:a6a169de725f 12 #define MAVLINK_MSG_ENCAPSULATED_DATA_FIELD_DATA_LEN 253
shimniok 0:a6a169de725f 13
shimniok 0:a6a169de725f 14
shimniok 0:a6a169de725f 15 /**
shimniok 0:a6a169de725f 16 * @brief Pack a encapsulated_data message
shimniok 0:a6a169de725f 17 * @param system_id ID of this system
shimniok 0:a6a169de725f 18 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 19 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 20 *
shimniok 0:a6a169de725f 21 * @param seqnr sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 22 * @param data image data bytes
shimniok 0:a6a169de725f 23 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:a6a169de725f 24 */
shimniok 0:a6a169de725f 25 static inline uint16_t mavlink_msg_encapsulated_data_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint16_t seqnr, const uint8_t* data)
shimniok 0:a6a169de725f 26 {
shimniok 0:a6a169de725f 27 uint16_t i = 0;
shimniok 0:a6a169de725f 28 msg->msgid = MAVLINK_MSG_ID_ENCAPSULATED_DATA;
shimniok 0:a6a169de725f 29
shimniok 0:a6a169de725f 30 i += put_uint16_t_by_index(seqnr, i, msg->payload); // sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 31 i += put_array_by_index((const int8_t*)data, sizeof(uint8_t)*253, i, msg->payload); // image data bytes
shimniok 0:a6a169de725f 32
shimniok 0:a6a169de725f 33 return mavlink_finalize_message(msg, system_id, component_id, i);
shimniok 0:a6a169de725f 34 }
shimniok 0:a6a169de725f 35
shimniok 0:a6a169de725f 36 /**
shimniok 0:a6a169de725f 37 * @brief Pack a encapsulated_data message
shimniok 0:a6a169de725f 38 * @param system_id ID of this system
shimniok 0:a6a169de725f 39 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 40 * @param chan The MAVLink channel this message was sent over
shimniok 0:a6a169de725f 41 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 42 * @param seqnr sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 43 * @param data image data bytes
shimniok 0:a6a169de725f 44 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:a6a169de725f 45 */
shimniok 0:a6a169de725f 46 static inline uint16_t mavlink_msg_encapsulated_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint16_t seqnr, const uint8_t* data)
shimniok 0:a6a169de725f 47 {
shimniok 0:a6a169de725f 48 uint16_t i = 0;
shimniok 0:a6a169de725f 49 msg->msgid = MAVLINK_MSG_ID_ENCAPSULATED_DATA;
shimniok 0:a6a169de725f 50
shimniok 0:a6a169de725f 51 i += put_uint16_t_by_index(seqnr, i, msg->payload); // sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 52 i += put_array_by_index((const int8_t*)data, sizeof(uint8_t)*253, i, msg->payload); // image data bytes
shimniok 0:a6a169de725f 53
shimniok 0:a6a169de725f 54 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);
shimniok 0:a6a169de725f 55 }
shimniok 0:a6a169de725f 56
shimniok 0:a6a169de725f 57 /**
shimniok 0:a6a169de725f 58 * @brief Encode a encapsulated_data struct into a message
shimniok 0:a6a169de725f 59 *
shimniok 0:a6a169de725f 60 * @param system_id ID of this system
shimniok 0:a6a169de725f 61 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:a6a169de725f 62 * @param msg The MAVLink message to compress the data into
shimniok 0:a6a169de725f 63 * @param encapsulated_data C-struct to read the message contents from
shimniok 0:a6a169de725f 64 */
shimniok 0:a6a169de725f 65 static inline uint16_t mavlink_msg_encapsulated_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_encapsulated_data_t* encapsulated_data)
shimniok 0:a6a169de725f 66 {
shimniok 0:a6a169de725f 67 return mavlink_msg_encapsulated_data_pack(system_id, component_id, msg, encapsulated_data->seqnr, encapsulated_data->data);
shimniok 0:a6a169de725f 68 }
shimniok 0:a6a169de725f 69
shimniok 0:a6a169de725f 70 /**
shimniok 0:a6a169de725f 71 * @brief Send a encapsulated_data message
shimniok 0:a6a169de725f 72 * @param chan MAVLink channel to send the message
shimniok 0:a6a169de725f 73 *
shimniok 0:a6a169de725f 74 * @param seqnr sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 75 * @param data image data bytes
shimniok 0:a6a169de725f 76 */
shimniok 0:a6a169de725f 77 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
shimniok 0:a6a169de725f 78
shimniok 0:a6a169de725f 79 static inline void mavlink_msg_encapsulated_data_send(mavlink_channel_t chan, uint16_t seqnr, const uint8_t* data)
shimniok 0:a6a169de725f 80 {
shimniok 0:a6a169de725f 81 mavlink_message_t msg;
shimniok 0:a6a169de725f 82 mavlink_msg_encapsulated_data_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, seqnr, data);
shimniok 0:a6a169de725f 83 mavlink_send_uart(chan, &msg);
shimniok 0:a6a169de725f 84 }
shimniok 0:a6a169de725f 85
shimniok 0:a6a169de725f 86 #endif
shimniok 0:a6a169de725f 87 // MESSAGE ENCAPSULATED_DATA UNPACKING
shimniok 0:a6a169de725f 88
shimniok 0:a6a169de725f 89 /**
shimniok 0:a6a169de725f 90 * @brief Get field seqnr from encapsulated_data message
shimniok 0:a6a169de725f 91 *
shimniok 0:a6a169de725f 92 * @return sequence number (starting with 0 on every transmission)
shimniok 0:a6a169de725f 93 */
shimniok 0:a6a169de725f 94 static inline uint16_t mavlink_msg_encapsulated_data_get_seqnr(const mavlink_message_t* msg)
shimniok 0:a6a169de725f 95 {
shimniok 0:a6a169de725f 96 generic_16bit r;
shimniok 0:a6a169de725f 97 r.b[1] = (msg->payload)[0];
shimniok 0:a6a169de725f 98 r.b[0] = (msg->payload)[1];
shimniok 0:a6a169de725f 99 return (uint16_t)r.s;
shimniok 0:a6a169de725f 100 }
shimniok 0:a6a169de725f 101
shimniok 0:a6a169de725f 102 /**
shimniok 0:a6a169de725f 103 * @brief Get field data from encapsulated_data message
shimniok 0:a6a169de725f 104 *
shimniok 0:a6a169de725f 105 * @return image data bytes
shimniok 0:a6a169de725f 106 */
shimniok 0:a6a169de725f 107 static inline uint16_t mavlink_msg_encapsulated_data_get_data(const mavlink_message_t* msg, uint8_t* r_data)
shimniok 0:a6a169de725f 108 {
shimniok 0:a6a169de725f 109
shimniok 0:a6a169de725f 110 memcpy(r_data, msg->payload+sizeof(uint16_t), sizeof(uint8_t)*253);
shimniok 0:a6a169de725f 111 return sizeof(uint8_t)*253;
shimniok 0:a6a169de725f 112 }
shimniok 0:a6a169de725f 113
shimniok 0:a6a169de725f 114 /**
shimniok 0:a6a169de725f 115 * @brief Decode a encapsulated_data message into a struct
shimniok 0:a6a169de725f 116 *
shimniok 0:a6a169de725f 117 * @param msg The message to decode
shimniok 0:a6a169de725f 118 * @param encapsulated_data C-struct to decode the message contents into
shimniok 0:a6a169de725f 119 */
shimniok 0:a6a169de725f 120 static inline void mavlink_msg_encapsulated_data_decode(const mavlink_message_t* msg, mavlink_encapsulated_data_t* encapsulated_data)
shimniok 0:a6a169de725f 121 {
shimniok 0:a6a169de725f 122 encapsulated_data->seqnr = mavlink_msg_encapsulated_data_get_seqnr(msg);
shimniok 0:a6a169de725f 123 mavlink_msg_encapsulated_data_get_data(msg, encapsulated_data->data);
shimniok 0:a6a169de725f 124 }