mavlink_dialects/lib.rs
1//! # MAVLink dialects for [MAVSpec](https://crates.io/crates/mavspec)
2//!
3//! <span style="font-size:24px">[πΊπ¦](https://mavka.gitlab.io/home/a_note_on_the_war_in_ukraine/)</span>
4//! [](https://gitlab.com/mavka/libs/mavspec)
5//! [](https://crates.io/crates/mavlink-dialects)
6//! [](https://docs.rs/mavlink-dialects/latest/mavlink-dialects/)
7//! [](https://gitlab.com/mavka/libs/mavspec/-/issues/)
8//!
9//! [MAVLink](https://mavlink.io/en/) messages bindings based on [MAVInspect](https://crates.io/crates/mavinspect).
10//!
11//! This library is a part of [MAVSpec](https://crates.io/crates/mavspec) code-generation
12//! toolchain and is intended to use alongside with it. However, nothing prevents you from using
13//! this crate independently.
14//!
15//! Since [MAVSpec](https://crates.io/crates/mavspec) is I/O agnostic, it and does not provide any
16//! abstractions for transferring MAVLink messages. If you want to communicate with MAVLink devices,
17//! use [Mavio](https://crates.io/crates/mavio) for embedded devices and simple tasks or
18//! [Maviola](https://crates.io/crates/maviola) for advanced I/O in `std` environments (for ground
19//! control stations, communication layers, and so on).
20//!
21//! # Usage
22//!
23//! ```rust
24//! # #[cfg(not(feature = "dlct-minimal"))]
25//! # fn main() {}
26//! # #[cfg(feature = "dlct-minimal")]
27//! # fn main() {
28//! use dialect::enums::{MavAutopilot, MavModeFlag, MavState};
29//! use dialect::messages::Heartbeat;
30//! use dialect::Minimal as DialectMessage;
31//! use mavlink_dialects::dialects::minimal as dialect;
32//! use mavlink_dialects::spec::*;
33//!
34//! let message = Heartbeat {
35//! autopilot: MavAutopilot::Armazila,
36//! base_mode: MavModeFlag::HIL_ENABLED,
37//! system_status: MavState::Active,
38//! ..Default::default()
39//! };
40//!
41//! // Check that this message indeed supports `MAVLink 1`.
42//! assert_eq!(message.min_supported_mavlink_version(), MavLinkVersion::V1);
43//!
44//! // Encode to MAVLink payload.
45//! let payload = message.encode(MavLinkVersion::V2).unwrap();
46//! assert_eq!(payload.version(), MavLinkVersion::V2);
47//! assert_eq!(payload.id(), message.id());
48//!
49//! // Decode from MAVLink payload, now without .
50//! let dialect_message = DialectMessage::decode(&payload).unwrap();
51//! match dialect_message {
52//! DialectMessage::Heartbeat(msg) => {
53//! assert_eq!(msg.id(), Heartbeat::ID);
54//! }
55//! _ => panic!("Unexpected dialect message: {:?}", dialect_message),
56//! }
57//! # }
58//! ```
59//!
60//! # Features
61//!
62//! This library provides MAVLink abstractions to work with MAVLink messages and dialects.
63//!
64//! It also provides a set of additional tools to work with MAVLink
65//! [microservices](https://mavlink.io/en/services/). Basic microservices support involves
66//! generation of sub-dialects which include only required entities. For some microservices, like
67//! mission, additional utilities are provided.
68//!
69//! ## Dialects
70//!
71//! Standard MAVLink dialect can be bundled with MAVSpec. This can be enabled by the corresponding
72//! `dlct-<name>` feature flags.
73//!
74//! * [`minimal`]((https://mavlink.io/en/messages/minimal.html)) β minimal dialect required to
75//! expose your presence to other MAVLink devices.
76//! * [`standard`](https://mavlink.io/en/messages/standard.html) β a superset of `minimal` dialect,
77//! that expected to be used by almost all flight stack.
78//! * [`common`](https://mavlink.io/en/messages/common.html) β minimum viable dialect with most of
79//! the features, a building block for other future-rich dialects.
80//! * [`ardupilotmega`](https://mavlink.io/en/messages/common.html) β feature-full dialect used by
81//! [ArduPilot](http://ardupilot.org). In most cases this dialect is the go-to choice if you want
82//! to recognize almost all MAVLink messages used by existing flight stacks.
83//! * [`all`](https://mavlink.io/en/messages/all.html) β meta-dialect which includes all other
84//! standard dialects including those which were created for testing purposes. It is guaranteed
85//! that namespaces of the dialects in `all` family do not collide.
86//! * Other dialects from MAVLink XML [definitions](https://github.com/mavlink/mavlink/tree/master/message_definitions/v1.0):
87//! `asluav`, `avssuas`, `csairlink`, `cubepilot`, `development`, `icarous`, `matrixpilot`,
88//! `paparazzi`, `ualberta`, `uavionix`. These do not include `python_array_test` and `test`
89//! dialects which should be either generated manually or as a part of `all` meta-dialect.
90//!
91//! ### Default Dialect
92//!
93//! When standard MAVLink dialects are used and at least `dlct-minimal` Cargo feature is enabled,
94//! this library exposes [`default_dialect`] and [`DefaultDialect`] entities that allow to access
95//! the most feature-rich enabled MAVLink dialect.
96//!
97//! ## Microservices
98//!
99//! MAVSpec allows to generate additional structures tailored for MAVLink
100//! [microservices](https://mavlink.io/en/services/). Each microservice is a subdialect with only
101//! those messages and enums which are necessary. To generate microservice subdialects use `msrv-*`
102//! feature flags.
103//!
104//! At the moment, microservices are only generated for the [`default_dialect`] and, if enabled,
105//! are available at [`default_dialect::microservices`] and as `microservices` module of the
106//! corresponding default dialect.
107//!
108//! <section class="warning">
109//! We do not recommend to enable microservices for libraries that perform generic MAVLink
110//! operations as, if not used properly, this may increase compilation time and binary size.
111//! </section>
112//!
113//! ## Fingerprints
114//!
115//! MAVSpec may skip code re-generation if dialects haven't changed. It uses 64-bit CRC fingerprint to monitor
116//! changes. Set `fingerprints` feature flag to enable this behavior.
117//!
118//! This feature is useful for reducing build time during development and CI runs. Make sure that your releases are
119//! clean and do not depend on fingerprints.
120//!
121//! # Caveats
122//!
123//! The API is straightforward and generally stable, however, incorrect use of certain features
124//! may lead to issues during deployment and development.
125//!
126//! ## Binary Size
127//!
128//! For small applications that use only a small subset of messages, avoid using dialect enums as
129//! they contain all message variants. Instead, decode messages directly from frames:
130//!
131//! This will help compiler to throw away unnecessary pieces of code.
132//!
133//! ## Unstable Features
134//!
135//! Certain features are considered unstable and available only when `unstable` feature flag is
136//! enabled. Unstable features are marked with <sup>`β`</sup> and are may be changed in futures
137//! versions.
138//!
139//! ## Incompatible Features
140//!
141//! - [Specta](https://crates.io/crates/specta) requires `std` feature to be enabled.
142//!
143//! # Feature Flags
144//!
145//! In most of the cases you will be interested in `dlct-*` and `msrv-*` feature families, and
146//! `alloc` / `std` target specification. However, a more fine-grained control may be required.
147//!
148#![cfg_attr(feature = "std", doc = document_features::document_features!())]
149//
150#![warn(missing_docs)]
151#![deny(rustdoc::broken_intra_doc_links)]
152#![doc(
153 html_logo_url = "https://gitlab.com/mavka/libs/mavspec/-/raw/main/avatar.png?ref_type=heads",
154 html_favicon_url = "https://gitlab.com/mavka/libs/mavspec/-/raw/main/avatar.png?ref_type=heads"
155)]
156#![cfg_attr(not(feature = "std"), no_std)]
157
158#[cfg(feature = "alloc")]
159extern crate alloc;
160extern crate core;
161
162/// <sup>[`mavspec`](https://crates.io/crates/mavspec)</sup>
163#[doc(inline)]
164pub use mavspec_rust_derive as derive;
165/// <sup>[`mavspec`](https://crates.io/crates/mavspec)</sup>
166#[doc(inline)]
167pub use mavspec_rust_spec as spec;
168
169/// Rust bindings specifications left for compatibility with [MAVSpec](https://crates.io/crates/mavspec).
170pub mod rust {
171 pub use mavspec_rust_derive as derive;
172 pub use mavspec_rust_spec as spec;
173}
174
175mod mavlink {
176 #[cfg(windows)]
177 include!(concat!(env!("OUT_DIR"), "\\mavlink\\mod.rs"));
178 #[cfg(not(windows))]
179 include!(concat!(env!("OUT_DIR"), "/mavlink/mod.rs"));
180}
181pub use mavlink::dialects;
182
183#[cfg(feature = "dlct-minimal")]
184pub use mavlink::{default_dialect, DefaultDialect};
185
186#[cfg(all(feature = "specta", not(feature = "std")))]
187compile_error!("Specta support is currently available only for `std` targets! Add `std` feature.");