Crates.io | maviola |
lib.rs | maviola |
version | |
source | src |
created_at | 2023-12-30 14:33:41.879124 |
updated_at | 2024-12-10 11:14:41.495135 |
description | High-level MAVLink communication library with support for essential micro-services. |
homepage | https://gitlab.com/mavka/libs/maviola |
repository | https://gitlab.com/mavka/libs/maviola |
max_upload_size | |
id | 1084249 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A high-level MAVLink communication library written in Rust.
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.
Maviola provides abstractions such as communication nodes, networks, or devices and implements stateful features of MAVLink protocol: sequencing, message signing, automatic heartbeats, and so on. The key features are:
MAVLink 1
and MAVLink 2
protocol versions are supported, it is also possible to have protocol-agnostic
channels that support both versions.This library is based on Mavio, a low-level library with no-std
support. If you
are looking for a solution for embedded devices, then Mavio probably would be a better option.
If you want to use synchronous API, you can install Maviola with:
cargo add maviola --features sync
And for asynchronous API:
cargo add maviola --features async
π If you want to learn how to use Maviola, start from reading Maviola Playbook. The following section is just a brief introduction.
This library provides both synchronous and asynchronous API. The synchronous API can be enabled by sync
feature flag.
The asynchronous API is based on Tokio, and can be enabled by async
feature flag. The differences
between synchronous and asynchronous APIs are minimal, so you can easily switch between them, if necessary. It is also
possible to use both synchronous and asynchronous APIs in different parts of your project.
Install:
cargo add maviola --features sync
Create a synchronous TCP server that represents a particular MAVLink device:
use maviola::prelude::*;
use maviola::sync::prelude::*;
pub fn main() -> Result<()> {
// Create a synchronous MAVLink node
// with MAVLink 2 protocol version
let server = Node::sync::<V2>()
.id(MavLinkId::new(17, 42)) // Set device system and component IDs
.connection(TcpServer::new("127.0.0.1:5600")?) // Define connection settings
.build()?;
// Handle node events
for event in server.events() {
match event {
// Handle a new peer
Event::NewPeer(peer) => println!("new peer: {peer:?}"),
// Handle a peer that becomes inactive
Event::PeerLost(peer) => {
println!("peer offline: {peer:?}");
// Exit when all peers are disconnected
if !server.has_peers() {
break;
}
}
// Handle incoming MAVLink frame
Event::Frame(frame, callback) => if server.validate_frame(&frame).is_ok() {
// Handle heartbeat message
if let Ok(Minimal::Heartbeat(msg)) = frame.decode::<Minimal>() {
// Respond with the same heartbeat message to all clients,
// except the one that sent this message
callback.respond_others(&server.next_frame(&msg)?)?;
}
}
Event::Invalid(frame, err, callback) => {
/* Handle invalid frame */
}
}
}
}
Install:
cargo add maviola --features async
Create an asynchronous TCP server that represents a particular MAVLink device:
use maviola::prelude::*;
use maviola::asnc::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// Create an asynchronous MAVLink node
// with MAVLink 2 protocol version
let server = Node::asnc::<V2>()
.id(MavLinkId::new(17, 42)) // Set device system and component IDs
.connection(
TcpServer::new("127.0.0.1:5600")? // Define connection settings
)
.build().await?;
// Subscribe to a stream of node events
let mut events = server.events().unwrap();
// Handle node events
while let Some(event) = events.next().await {
match event {
// Handle a new peer
Event::NewPeer(peer) => println!("new peer: {peer:?}"),
// Handle a peer that becomes inactive
Event::PeerLost(peer) => {
println!("peer offline: {peer:?}");
// Exit when all peers are disconnected
if !server.has_peers().await {
break;
}
}
// Handle incoming MAVLink frame
Event::Frame(frame, callback) => if server.validate_frame(&frame).is_ok() {
// Handle heartbeat message
if let Ok(Minimal::Heartbeat(msg)) = frame.decode::<Minimal>() {
// Respond with the same heartbeat message to all clients,
// except the one that sent this message
callback.respond_others(&server.next_frame(&msg)?)?;
}
}
Event::Invalid(frame, err, callback) => {
/* Handle invalid frame */
}
}
}
Ok(())
}
Basic examples can be found here.
Although this library has suspiciously small version number, the most parts of the API are considered stable. All
parts of the API that are still under consideration are hidden under the unstable
Cargo feature flag.
There are few exceptions, namely the Device
entity. We are considering to enrich its API in the near future and
can't guarantee that this operation won't require breaking the existing API. There is a corresponding
issue in the tracker.
Basically, the project reached the state, when our intuition and our engineering experience tells us that further development will be mostly related to adding new functionality, not amending the existing one. The current plan is to create a proper roadmap, so other people won't have to rely on our vaguely expressed gut feeling.
You can track v1 milestone dedicated to API stabilisation.
Here we simply comply with the suggested dual licensing according to Rust API Guidelines (C-PERMISSIVE).
Licensed under either of
at your option.
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.