Expand description
The MAVLink wire protocol for the pamoja SDK.
MAVLink is the language drones speak: PX4 and ArduPilot autopilots and MAVSDK ground stations all exchange MAVLink frames, so talking to a vehicle means putting exactly the right bytes on the wire and trusting the bytes that come back. This crate is that byte layer, hand-written from the MAVLink specification and pinned to its reference values rather than guessed from memory:
crc16_mcrf4xx- the CRC-16/MCRF4XX every frame carries, the checksum that lets a receiver reject a frame mangled in transit, anchored to the catalogue check value.Frame- the v1 and v2 frame on the wire, which both assembles a frame to send and parses one received, verifying the checksum and the per-messagemessage_crc_extraseed so a corrupt or mismatched frame never reaches the application.Parser- a streaming parser that turns the bytes a link delivers into whole frames, resynchronizing on noise so a serial port or UDP socket just works.signing- MAVLink 2 message signing: the SHA-256 signature and the monotonic timestamp that let a ground station trust a command came from the vehicle it expects and was not replayed.dialect- a broad, typed slice of the common dialect (HEARTBEAT, the command, parameter, and mission protocols, and core telemetry), plus message shapes as data: aMessageDescriptorgives any message’s bytes named fields, and a builder describes one this crate does not type, so a vendor or private dialect is usable at runtime.protocol- the mission, command, and offboard exchanges as pure, allocation-free state machines: the rules of order, matching, and retransmission that turn single messages into a real conversation with an autopilot, with no IO of their own. Each machine also takes aFrameat a time and hands back the frame to send, so a caller holding a link writes no decoding or dispatch of its own.
The protocol core is no_std and allocation-free, so the same framing runs on a
microcontroller flight controller. The default std feature adds the async layer: the
byte-stream link seam and an in-process software-in-the-loop autopilot (link), the
vehicle device model that presents an autopilot as a pamoja Device, and the real
drivers (UDP, TCP, and serial behind the serial feature) that carry MAVLink to a real
or simulated autopilot.
§Examples
use pamoja_mavlink::dialect::{Heartbeat, Message};
use pamoja_mavlink::{Frame, Header};
// Announce this node as an onboard controller.
let heartbeat = Heartbeat {
custom_mode: 0,
type_: 18, // MAV_TYPE_ONBOARD_CONTROLLER
autopilot: 0,
base_mode: 0,
system_status: 4, // MAV_STATE_ACTIVE
mavlink_version: 3,
};
// Encode it into a v2 frame, then read it back the way a peer would.
let mut payload = [0u8; 255];
let len = heartbeat.encode(&mut payload);
let frame = Frame::encode_v2(Header::new(1, 1, 0), Heartbeat::ID, &payload[..len], Heartbeat::CRC_EXTRA)?;
let received = Frame::parse(frame.as_bytes(), Heartbeat::CRC_EXTRA)?;
let decoded = Heartbeat::decode(received.payload())?;
assert_eq!(decoded.system_status, 4);Re-exports§
pub use signing::Signer;pub use signing::Verifier;pub use vehicle::Report;pub use vehicle::Setpoint;pub use vehicle::Vehicle;pub use drivers::TcpLink;pub use drivers::UdpLink;
Modules§
- dialect
- The typed message layer: a broad slice of the MAVLink common dialect, plus the seam that lets any message id be carried and checked.
- drivers
- Real
ByteLinkdrivers over serial ports, UDP, and TCP. - link
- The byte-stream link seam and an in-process autopilot to exercise it with no hardware.
- protocol
- The MAVLink service protocols as pure, allocation-free state machines.
- signing
- MAVLink 2 message signing: the signature a sender appends and the check a receiver makes, so a ground station can trust that a command came from the vehicle it expects and was not replayed.
- vehicle
- A MAVLink vehicle modelled as a pamoja
Device.
Structs§
- Frame
- An encoded MAVLink frame, held in a fixed buffer so encoding never allocates.
- Header
- The addressing fields a sender stamps on every frame.
- Parser
- Accumulates bytes from a link and emits complete frames.
Enums§
- Mavlink
Error - A fault encountered while building, parsing, signing, or verifying a frame.
- Version
- Which MAVLink wire format a frame uses.
Constants§
- IFLAG_
SIGNED - The incompatibility-flag bit that marks a v2 frame as signed.
- MAGIC_
V1 - The start marker of a MAVLink v1 frame.
- MAGIC_
V2 - The start marker of a MAVLink v2 frame.
- MAX_
FRAME - The largest a complete frame can be: a v2 header, the largest payload, the checksum, and a signature.
- MAX_
PAYLOAD - The largest payload, in bytes, a frame can carry.
- SIGNATURE_
LEN - The length of a v2 signature block: a link id, a timestamp, and the signature.
Functions§
- accumulate
- Folds more bytes into a running CRC-16/MCRF4XX.
- checksum
- Computes the checksum a frame carries: the CRC over its bytes with the message’s
CRC_EXTRAfolded in last. - crc16_
mcrf4xx - Computes the CRC-16/MCRF4XX of a byte slice.
- message_
crc_ extra - Derives a message’s
CRC_EXTRAfrom its name and base fields.
Type Aliases§
- Result
- A specialized
core::result::Resultwhose error type isMavlinkError.