Crate mavlink_dialects

Source
Expand description

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

MAVLink messages bindings based on MAVInspect.

This library is a part of MAVSpec code-generation toolchain and is intended to use alongside with it. However, nothing prevents you from using this crate independently.

Since MAVSpec is I/O agnostic, it 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).

Β§Usage

use dialect::enums::{MavAutopilot, MavModeFlag, MavState};
use dialect::messages::Heartbeat;
use dialect::Minimal as DialectMessage;
use mavlink_dialects::dialects::minimal as dialect;
use mavlink_dialects::spec::*;

let message = Heartbeat {
    autopilot: MavAutopilot::Armazila,
    base_mode: MavModeFlag::HIL_ENABLED,
    system_status: MavState::Active,
    ..Default::default()
};

// Check that this message indeed supports `MAVLink 1`.
assert_eq!(message.min_supported_mavlink_version(), MavLinkVersion::V1);

// Encode to MAVLink payload.
let payload = message.encode(MavLinkVersion::V2).unwrap();
assert_eq!(payload.version(), MavLinkVersion::V2);
assert_eq!(payload.id(), message.id());

// Decode from MAVLink payload, now without .
let dialect_message = DialectMessage::decode(&payload).unwrap();
match dialect_message {
    DialectMessage::Heartbeat(msg) => {
        assert_eq!(msg.id(), Heartbeat::ID);
    }
    _ => panic!("Unexpected dialect message: {:?}", dialect_message),
}

Β§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.

Β§Dialects

Standard MAVLink dialect can be bundled with MAVSpec. This can be enabled by the corresponding dlct-<name> 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.

Β§Default Dialect

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

Β§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. To generate microservice subdialects use msrv-* feature flags.

At the moment, microservices are only generated for the default_dialect and, if enabled, are available at default_dialect::microservices and as microservices module of the corresponding default dialect.

We do not recommend to enable microservices for libraries that perform generic MAVLink operations as, if not used properly, this may increase compilation time and binary size.

Β§Fingerprints

MAVSpec 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.

Β§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.

Β§Feature Flags

In most of the cases you will be interested in dlct-* and msrv-* 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

Β§Code generation

Features required for dialects generation.

  • 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

Β§Dialects

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

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.

  • dlct-ardupilotmega β€” Include ardupilotmega dialect

  • dlct-asluav β€” Include ASLUAV dialect

  • dlct-avssuas β€” Include AVSSUAS dialect

  • dlct-common β€” Include common dialect

  • dlct-cs_air_link β€” Include csAirLink dialect

  • dlct-cubepilot β€” Include cubepilot dialect

  • dlct-development β€” Include development dialect

  • dlct-icarous β€” Include icarous dialect

  • dlct-matrixpilot β€” Include matrixpilot dialect

  • dlct-minimal β€” Include minimal dialect

  • dlct-paparazzi β€” Include paparazzi dialect

  • dlct-standard β€” Include standard dialect

  • dlct-ualberta β€” Include ualberta dialect

  • dlct-uavionix β€” Include uAvionix dialect

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

  • 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.

  • msrv-all β€” Support for all MavLink microservices
  • msrv-heartbeat β€” Heartbeat protocol support
  • msrv-mission β€” Mission microservice support
  • msrv-parameter β€” Parameter protocol support
  • msrv-parameter-ext β€” Extended parameter protocol support
  • msrv-command β€” Command protocol support
  • msrv-manual-control β€” Manual control protocol support
  • msrv-camera β€” Camera protocol v2 support
  • msrv-gimbal-v1 β€” Gimbal protocol v1 support
  • msrv-gimbal-v2 β€” Gimbal protocol v2 support
  • msrv-arm-auth β€” Arm authorization protocol support
  • msrv-image-transmission β€” Image transmission protocol support
  • msrv-ftp β€” File transfer protocol support
  • msrv-landing-target β€” Landing target protocol support
  • msrv-ping β€” Ping protocol support
  • msrv-path-planning β€” Path planning protocol support
  • msrv-battery β€” Battery protocol support
  • msrv-terrain β€” Terrain protocol support
  • msrv-tunnel β€” Tunnel protocol support
  • msrv-open-drone-id β€” Open Drone ID protocol support
  • msrv-high-latency β€” High latency protocol support
  • msrv-component-metadata β€” Component metadata protocol support
  • msrv-payload β€” Payload protocol support
  • msrv-traffic-management β€” Traffic management protocol support
  • msrv-events-interface β€” Events interface protocol support
  • msrv-time-sync β€” Time synchronization protocol support

Β§Technical features

These features should not be used directly.

  • 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.

ModulesΒ§

default_dialect
Default standard MAVLink dialect module.
derive
mavspec MAVSpec Rust Procedural Macros
dialects
Autogenerated MAVLink dialects
rust
Rust bindings specifications left for compatibility with MAVSpec.
spec
mavspec

EnumsΒ§

DefaultDialect
Default standard MAVLink dialect. Enum containing all messages within all dialect.