Table of Contents

Class Mavlink

Namespace
Pamoja.Mavlink
Assembly
Pamoja.Mavlink.dll

The MAVLink wire protocol: checksums, seeds, and clocks.

public static class Mavlink
Inheritance
Mavlink
Inherited Members

MAVLink is the language drones speak, so talking to a PX4 or ArduPilot autopilot means putting exactly the right bytes on the wire and trusting the bytes that come back.

Nothing here is limited to the messages this build happens to know. The common dialect's seeds are built in, and MavlinkDialect carries any others, derived by MessageCrcExtra(string, IReadOnlyList<MavlinkField>) the way the specification does.

Fields

The default window a verifier accepts a timestamp within.

public const ulong DefaultTimestampWindow = 6000000

Field Value

ulong

The length of a signing key, in bytes.

public const int KeyLength = 32

Field Value

int

The largest frame, in bytes, header, checksum and signature included.

public const int MaxFrame = 280

Field Value

int

The largest payload a frame can carry, in bytes.

public const int MaxPayload = 255

Field Value

int

The length of a v2 signature block, in bytes.

public const int SignatureLength = 13

Field Value

int

Methods

Returns the CRC-16/MCRF4XX checksum of a byte string.

public static ushort Crc16(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The data to checksum.

Returns

ushort

The checksum.

This is the checksum every MAVLink frame carries, exposed because a host that implements part of the protocol itself needs the same arithmetic.

Builds a v2 frame carrying a message the common dialect defines.

public static MavlinkFrame Frame(MavlinkHeader header, uint msgid, ReadOnlySpan<byte> payload)

Parameters

header MavlinkHeader

The addressing fields to stamp on the frame.

msgid uint

The message id.

payload ReadOnlySpan<byte>

The message payload.

Returns

MavlinkFrame

The frame ready to send.

The seed is looked up rather than passed, which is the usual case: a sender emitting a standard message should not have to know its checksum constant.

Exceptions

PamojaException

The id is outside the common dialect, in which case build the frame with Raw(MavlinkHeader, uint, byte, ReadOnlySpan<byte>) and a seed of your own.

Returns the CRC_EXTRA the common dialect publishes for a message id.

public static byte? KnownCrcExtra(uint msgid)

Parameters

msgid uint

The message id to look up.

Returns

byte?

The seed, or null for an id outside the common dialect, which is what a MavlinkDialect is for.

Derives the CRC_EXTRA seed of a message from its definition.

public static byte MessageCrcExtra(string name, IReadOnlyList<MavlinkField> fields)

Parameters

name string

The message name, such as HEARTBEAT.

fields IReadOnlyList<MavlinkField>

The base fields in wire order.

Returns

byte

The seed.

This is what makes a dialect this build has never seen usable: the seed comes out the same as the one the dialect publishes, and a frame carrying that message then checks like any other. Extension fields are excluded from the seed and must not be listed.

Exceptions

PamojaException

A name was not valid UTF-8.

Converts Unix time into the timestamp MAVLink signing counts in.

public static ulong TimestampFromUnixMicros(ulong unixMicros)

Parameters

unixMicros ulong

The time in microseconds since the Unix epoch.

Returns

ulong

The signing timestamp, in units of ten microseconds since 2015.

Returns a signing timestamp for now.

public static ulong TimestampNow()

Returns

ulong

The signing timestamp matching the current clock.