MAVLink Forwarding Driver in Simple SM
This doc is all about how to set up a MAVLink forwarding channel in SSM and how to use it.
IOC config
Key Parameter Setting
The default UART setting works.
The Baud Rate of the UART has to match with the Baud Rate that Pixhawk receives.
Either change the baud rate of UART or serial setting on Mission Planner
DMA Setting
Enable both rx DMA line for the uart used
Keep the DMA to be “Normal“
Enable uart global interrupt in NVIC
Explanation
When passing the mavlink message from one place to the other place. We need to initialize two class objects.
In the actual implementation, we may need to initialize three objects. One for the air side, one for the ground side, one for the jetson.
Struct
All the struct types are included in the MAVLink library.
The output data type – mavlink_message_t
typedef struct __mavlink_message {
uint16_t checksum; ///< sent at end of packet
uint8_t magic; ///< protocol magic marker
uint8_t len; ///< Length of payload
uint8_t incompat_flags; ///< flags that must be understood
uint8_t compat_flags; ///< flags that can be ignored if not understood
uint8_t seq; ///< Sequence of packet
uint8_t sysid; ///< ID of message sender system/aircraft
uint8_t compid; ///< ID of the message sender component
uint32_t msgid:24; ///< ID of message in payload
uint64_t payload64[(MAVLINK_MAX_PAYLOAD_LEN+MAVLINK_NUM_CHECKSUM_BYTES+7)/8];
uint8_t ck[2]; ///< incoming checksum bytes
uint8_t signature[MAVLINK_SIGNATURE_BLOCK_LEN];
}) mavlink_message_t;
Methods
class MAVLink {
public:
uint8_t rx_circular_buffer_ptr_[1000];
CircularBuffer* rx_circular_buffer_;
uint8_t raw_rx_msg_[RAW_MAVLINK_LENGTH];
/* Constructor */
MAVLink(UART_HandleTypeDef* uart_handle);
~MAVLink();
/*
@param - the passby parameter, return the new message
@return - true if new message returned, false means no new message returned
*/
bool readMessage(mavlink_message_t& message);
/*
@param - output mavlink message
@return - none
*/
void writeMessage(const mavlink_message_t output_message);
private:
UART_HandleTypeDef* uart_;
};