Mavio
Minimalistic library for transport-agnostic MAVLink communication. It supports no-std
(and no-alloc) targets.
Currently, we use GitLab as the main project repository and GitHub as official mirror.
We accept issues and pull-requests only at GitLab but will do our best to keep GitHub discussions as alive as possible.
The mirror will always contain latest release tags and is kept up to date automatically.
Intro
Mavio is a building block for more sophisticated tools. It is entirely focused on one thing: to include absolute minimum of functionality required for correct communication with everything that speaks MAVLink protocol.
- Supports both
MAVLink 1andMAVLink 2protocol versions. - Provides intermediate MAVLink packets decoding as "frames" that contain only header, checksum and signature being deserialized. Which means that client don't have to decode the entire message for routing and verification.
- Supports optional high-level message decoding by utilizing MAVLink abstractions generated by MAVSpec.
- Includes standard MAVLink dialects enabled by Cargo features.
- Implements message verification via checksum.
- Includes tools for message signing.
In other words, Mavio implements all stateless features of MAVLink protocol. Which means that it does not provide support for message sequencing, automatic heartbeats, etc. The client is responsible for implementing these parts of the protocol by their own or use a dedicated library. We've decided to keep Mavio as simple and catchy as an 8-bit melody.
At the same time, Mavio is flexible and tries to dictate as few as possible. In particular:
- It supports custom dialects or may work with no dialect at all (for intermediate decoding). The latter is useful if you want to simply route or sign messages.
- Can read and write messages to anything that
implements
std::io::Readandstd::io::Writetraits. - Compatible with
no_stdtargets. For such cases the library provides simplified versions ofReadandWritetraits. - Support asynchronous I/O via Tokio.
- Allows filtering out unnecessary MAVLink entities (i.e. messages, enums, commands) to reduce compilation time.
This library is a part of Mavka toolchain. It is integrated with other projects such as:
- MAVInspect that responsible for MAVLink XML definitions parsing.
- MAVSpec that focused on code generation. Mavio uses this library to generate MAVLink dialects.
- Maviola, is a MAVLink communication library based on
Maviothat provides a high-level interface for MAVLink messaging and takes care about stateful features of the protocol: sequencing, message time-stamping, automatic heartbeats, simplifies message signing, and so on.
This project respects semantic versioning. As allowed by specification, breaking changes may be
introduced in minor releases until version 1.0.0 is reached. However, we will keep unstable features under the
unstable feature flag whenever possible.
Install
Install Mavio with cargo:
cargo add mavio
Usage
For details, please check API section and API documentation.
Receiving MAVLink Frames
Connect as TCP client, receive 10 frames, and decode any received
HEARTBEAT message:
use TcpStream;
use ;
use minimal as dialect;
use Minimal;
A slightly more elaborated use-case can be found in tcp_client.rs example.
Sending MAVLink Frames
Listen to TCP port as a server, send 10 HEARTBEAT messages
to any connected client using MAVLink 2 protocol, then disconnect a client.
use TcpStream;
use minimal as dialect;
use ;
use *;
Check tcp_server.rs for a slightly more elaborated use-case.
API Notes
This section provides a general API overview. For further details, please check API documentation.
I/O
Mavio provides two basic I/O primitives: Sender and
Receiver. These structs send and receive instances of
Frame.
Sender and Receiver are generic over std::io::Write and
std::io::Read accordingly. That means you can communicate MAVLink
messages over various transports which implements these traits including UDP, TCP, Unix sockets, and files. It is also
easy to implement custom transport.
For no-std targets Mavio provides custom implementations of Read and Write traits. You can implement them for
hardware-specific communication (like serial ports).
For asynchronous I/O Mavio provides AsyncSender and
AsyncReceiver which work in the same fashion as their
synchronous counterparts, except using Tokio. To enable asynchronous support, add tokio feature
flag.
Encoding/Decoding
Upon receiving, MAVLink Frames can be validated and decoded
into MAVLink messages. Frames can be routed, signed, or forwarded to another system/component ID without decoding.
Note!
MAVLink checksum validation requires
CRC_EXTRAbyte which in its turn depends on a dialect specification. That means, if you are performing dialect-agnostic routing from a noisy source or from devices which implement outdated message specifications, you may forward junk messages. In case of high-latency channels you might want to enforce compliance with a particular dialect to filter incompatible messages.
To decode a frame into a MAVLink message, you need to use a specific dialect. Standard MAVLink dialects are available
under mavio::dialects and can be enabled by the corresponding
feature flags:
minimalβ minimal dialect required to expose your presence to other MAVLink devices.standardβ a superset ofminimaldialect which expected to be used by almost all flight stack.commonβ minimum viable dialect with most of the features, a building block for other future-rich dialects.ardupilotmegaβ feature-full dialect used by ArduPilot. In most cases this dialect is the go-to choice if you want to recognize almost all MAVLink messages used by existing flight stacks.allβ meta-dialect which includes all other standard dialects including these which were created for testing purposes. It is guaranteed that namespaces of the dialects inallfamily do not collide.- Other dialects from MAVLink
XML definitions:
asluav,avssuas,csairlink,cubepilot,development,icarous,matrixpilot,paparazzi,ualberta,uavionix. These do not includepython_array_testandtestdialects which should be either generated manually or as a part ofallmeta-dialect.
Custom Dialects
Concrete implementations of dialects are generated by MAVSpec check its
documentation for details. You may also found useful to review
build.rs, if you want to generate your custom dialects.
Examples
Examples for synchronous I/O in ./examples/sync/examples:
tcp_server.rsis a simple TCP server that awaits for connections, sends and receives heartbeats:cargo run --package mavio_examples_sync --example tcp_servertcp_client.rsis a TCP client which connects to server, sends and receives heartbeats:cargo run --package mavio_examples_sync --example tcp_clienttcp_ping_pong.rsserver and clients which communicate with each other via TCP:cargo run --package mavio_examples_sync --example tcp_ping_pong
Examples for asynchronous I/O in ./examples/async/examples:
async_tcp_ping_pong.rsserver and clients which communicate with each other via TCP:cargo run --package mavio_examples_async --example async_tcp_ping_pong
Examples for custom dialect generation with filtered MAVLink entities can be found in
./examples/custom/examples:
custom_dialects_usage.rsa basic usage of custom-generated dialect:cargo run --package mavio_examples_custom --example mavio_examples_custom_usagecustom_message.rscreating and using a custom message:cargo run --package mavio_examples_custom --example custom_message
License
Here we simply comply with the suggested dual licensing according to Rust API Guidelines (C-PERMISSIVE).
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.