Crate mavspec

Source
Expand description

Β§MAVSpec

πŸ‡ΊπŸ‡¦ repository crates.io docs.rs issues

Bindings and code-generation toolchain for MAVLink protocol based on MAVInspect.

This library is I/O agnostic and does not provide any abstractions for transferring MAVLink messages. If you want to communicate with MAVLink devices, use Mavio for embedded devices and simple tasks or Maviola for advanced I/O in std environments (for ground control stations, communication layers, and so on).

MAVSpec is a part of Mavka toolchain

Β§Features

This library provides MAVLink abstractions to work with MAVLink messages and dialects.

It also provides a set of additional tools to work with MAVLink microservices. Basic microservices support involves generation of sub-dialects which include only required entities. For some microservices, like mission, additional utilities are provided.

Β§Rust

All Rust-related bindings can be found in rust module.

This library is mostly focused on Rust bindings. At the moment, we support other languages using specta.

By default, this library pre-builds standard MAVLink dialects. However, when --no-default-features is set, then you should enable one of the dialects Cargo features as described below.

Β§Dialects

Standard MAVLink dialect can be bundled with MAVSpec. This can be enabled by the corresponding feature flags.

  • minimal β€” minimal dialect required to expose your presence to other MAVLink devices.
  • standard β€” a superset of minimal dialect, that 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 those which were created for testing purposes. It is guaranteed that namespaces of the dialects in all family do not collide.
  • Other dialects from MAVLink XML definitions: asluav, avssuas, csairlink, cubepilot, development, icarous, matrixpilot, paparazzi, ualberta, uavionix. These do not include python_array_test and test dialects which should be either generated manually or as a part of all meta-dialect.

To bundle MAVLink entities for Rust, you should enable rust-dialects feature flag.

For example:

use mavspec::rust::dialects::common as dialect;
use dialect::{Common, messages::Heartbeat};

let message = Heartbeat {
    /* construct a message */
};

// Use message with dialect enum:
let dialect_message = Common::Heartbeat(message);

// Dialect message:
match dialect_message {
    Common::Heartbeat(msg) => {
        /* process heartbeat */
    }
    /* process other messages */
};

Β§Default dialect

When standard MAVLink dialects are used and at least minimal Cargo feature is enabled, this library exposes default_dialect and DefaultDialect entities that allow to access the most feature-rich enabled MAVLink dialect.

The sequence of default dialects is the following (in the order of the increased completeness):

  • minimal β€” enabled by dlct-minimal feature flag
  • standard β€” enabled by dlct-standard feature flag
  • common β€” enabled by dlct-common feature flag
  • ardupilotmega β€” enabled by dlct-ardupilotmega feature flag
  • all β€” enabled by dlct-all feature flag

Β§Microservices

MAVSpec allows to generate additional structures tailored for MAVLink microservices. Each microservice is a subdialect with only those messages and enums which are necessary.

Microservices are generated only for a default dialect and available as rust::microservices. To generate microservice subdialects use the corresponding msrv-* feature flag.

MAVSpec also provides additional utils to work with MAVLink microservices. These tools can be enabled by msrv-utils-* feature flags and available in rust::microservices::utils module.

msrv-utils-* are considered unstable for now! Use unstable feature flag to enable them.

Β§Metadata

You may want to add additional metadata to MAVLink entities such as a name of enum or the list of its variants. In that case you may enable metadata feature flag.

use mavspec::rust::default_dialect::enums::MavCmd;

println!("Enum name: {}", MavCmd::name());

for entry in MavCmd::entries() {
  println!("Entry {:?} has a value {}", entry, entry.value());
}

Β§Message definitions

It is possible to bundle message definitions generated by MAVInspect into definitions module. This can be useful for ground control stations that require to present the user with the descriptions of MAVLink entities.

To enable definitions bundling use definitions feature flag.

For example:

 let protocol = mavspec::definitions::protocol();
 let mav_cmd = protocol
     .default_dialect()
     .unwrap()
     .get_enum_by_name("MAV_CMD")
     .unwrap();

 println!("MAV_CMD\n: {}", mav_cmd.description());

Message definitions available only with std feature enabled. Otherwise, this will cause build to fail.

Β§Generation

This library can generate custom dialects from XML definitions.

Check rust::gen for details.

Β§Fingerprints

MAVInspect may skip code re-generation if dialects haven’t changed. It uses 64-bit CRC fingerprint to monitor changes. Set fingerprints feature flag to enable this behavior.

This feature is useful for reducing build time during development and CI runs. Make sure that your releases are clean and do not depend on fingerprints.

Β§Caveats

The API is straightforward and generally stable, however, incorrect use of certain features may lead to issues during deployment and development.

Β§Binary Size

For small applications that use only a small subset of messages, avoid using dialect enums as they contain all message variants. Instead, decode messages directly from frames:

This will help compiler to throw away unnecessary pieces of code.

Additionally, you may use microservices to reduce API surface you are interacting with.

Β§Unstable Features

Certain features are considered unstable and available only when unstable feature flag is enabled. Unstable features are marked with ⍚ and are may be changed in futures versions.

Β§Incompatible Features

  • Specta requires std feature to be enabled.
  • definitions requires std feature to be enabled.

Β§Feature Flags

In most of the cases you will be interested in dialect features, msrv-*, msrv-utils-* feature families, and alloc / std target specification. However, a more fine-grained control may be required.

Β§Generic features

  • default β€” Default features (nothing is enabled)

  • alloc β€” Enable alloc support

  • std β€” Enable standard library support

  • metadata β€” Add additional metadata to MAVLink entities.

  • unstable β€” ⚠️ Enables unstable API features.

    Certain features won’t take effect without this flag.

    Unstable features will be marked with ⍚.

  • rust β€” Enable Rust core interfaces

  • specs β€” Enable all core interfaces

Β§Code generation

Features required for custom dialects generation.

  • rust_gen β€” Enable Rust code-generation tools
  • generators β€” Enable all generators
  • fingerprints β€” Use protocol CRC-fingerprints to avoid re-generating files

Β§Serialization and reflection

These features enable serde and specta support.

  • serde β€” Enable serde support
  • specta β€” Enable specta support

These features control whether and how MAVLink message definitions generated by MAVInspect will be bundled.

⚠️ While being useful for ground control stations, the generated definitions is quite large and may bloat the size of the binary.

  • definitions β€” Bundles MAVLink message definitions.

    Message definitions will be generated only for bundled MAVLink dialects. Microservices will be ignored as they are just subsets of existing dialects.

Β§Dialects

These features control which MAVLink dialects will be considered by MAVSpec.

Enabled dialects can be found under the rust::dialects module.

To enable standard MAVLink dialects as defined in XML message definitions, use dlct-* feature family.

In case you want to patch mavlink-message-definitions, you might be interested in enabling extra-dialects feature.

To bundle Rust bindings for MAVLink dialects, enable rust-dialects. No Rust bindings will be generated otherwise.

The dialect selection will also control which dialect definitions will be bundled if definitions feature is enabled.

  • rust-dialects β€” Bundle MAVLink dialects

    This feature does not generate any dialect by itself unless dlct-* of extra-dialects feature flags enabled.

  • dlct-ardupilotmega β€” Include ardupilotmega dialect

    The dialect can be found in rust::dialects::ardupilotmega module.

  • dlct-asluav β€” Include ASLUAV dialect

    The dialect can be found in rust::dialects::asluav module.

  • dlct-avssuas β€” Include AVSSUAS dialect

    The dialect can be found in rust::dialects::avssuas module.

  • dlct-common β€” Include common dialect

    The dialect can be found in rust::dialects::common module.

  • dlct-cs_air_link β€” Include csAirLink dialect

    The dialect can be found in rust::dialects::cs_air_link module.

  • dlct-cubepilot β€” Include cubepilot dialect

    The dialect can be found in rust::dialects::cubepilot module.

  • dlct-development β€” Include development dialect

    The dialect can be found in rust::dialects::development module.

  • dlct-icarous β€” Include icarous dialect

    The dialect can be found in rust::dialects::icarous module.

  • dlct-matrixpilot β€” Include matrixpilot dialect

    The dialect can be found in rust::dialects::matrixpilot module.

  • dlct-minimal β€” Include minimal dialect

    The dialect can be found in rust::dialects::minimal module.

  • dlct-paparazzi β€” Include paparazzi dialect

    The dialect can be found in rust::dialects::paparazzi module.

  • dlct-standard β€” Include standard dialect

    The dialect can be found in rust::dialects::standard module.

  • dlct-ualberta β€” Include ualberta dialect

    The dialect can be found in rust::dialects::ualberta module.

  • dlct-uavionix β€” Include uAvionix dialect

    The dialect can be found in rust::dialects::u_avionix module.

  • dlct-all β€” Include all meta-dialect

    The dialect can be found in rust::dialects::all module.

  • extra-dialects β€” Enables extra dialects

    Downstream crates can patch mavlink-message-definitions adding extra MAVLink dialects.

  • test-dialects β€” Enables test dialects

    These dialects are useful for checking various test cases.

These features will control generation of MAVLink microservice-specific bindings.

If enabled, microservices can be found in rust::microservices module.

These features will enable additional MAVLink utilities such as *.waypoints files support, mission planninc, etc.

If enabled, additional microservice tools can be found in rust::microservices::utils.

⚠️ All such features require unstable feature to be enabled in order to take effect.

  • msrv-utils-all β€” All MAVLink microservices utils

    ⚠️ Requires unstable feature to take effect.

  • msrv-utils-mission β€” Mission protocol utils

    If enabled, these microservice tools can be found in rust::microservices::utils::mission.

    ⚠️ Requires unstable feature to take effect.

Β§Technical features

These features should not be used directly.

  • cli β€” βŠ› Command-line utilities

    Turned on automatically when CLI tools are built.

  • msrv β€” βŠ› Enable MAVLink microservices support

    Do not use directly as this feature does not give access to any specific functionality by itself. Instead, use one of msrv-* features.

  • msrv-utils β€” βŠ›οΈ Enables MAVLink microservices extra utils

    Do not use directly as this feature does not give access to any specific functionality by itself. Instead, use one of msrv-utils-* features.

ModulesΒ§

definitions
MAVLink message definitions for MAVSpec.
rust
MAVSpec’s code generation toolchain for Rust