Class Mavlink
The MAVLink wire protocol: checksums, seeds, and clocks.
public static class Mavlink
- Inheritance
-
Mavlink
- Inherited Members
Remarks
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
DefaultTimestampWindow
The default window a verifier accepts a timestamp within.
public const ulong DefaultTimestampWindow = 6000000
Field Value
KeyLength
The length of a signing key, in bytes.
public const int KeyLength = 32
Field Value
MaxFrame
The largest frame, in bytes, header, checksum and signature included.
public const int MaxFrame = 280
Field Value
MaxPayload
The largest payload a frame can carry, in bytes.
public const int MaxPayload = 255
Field Value
SignatureLength
The length of a v2 signature block, in bytes.
public const int SignatureLength = 13
Field Value
Methods
Crc16(ReadOnlySpan<byte>)
Returns the CRC-16/MCRF4XX checksum of a byte string.
public static ushort Crc16(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The data to checksum.
Returns
- ushort
The checksum.
Remarks
This is the checksum every MAVLink frame carries, exposed because a host that implements part of the protocol itself needs the same arithmetic.
Frame(MavlinkHeader, uint, ReadOnlySpan<byte>)
Builds a v2 frame carrying a message the common dialect defines.
public static MavlinkFrame Frame(MavlinkHeader header, uint msgid, ReadOnlySpan<byte> payload)
Parameters
headerMavlinkHeaderThe addressing fields to stamp on the frame.
msgiduintThe message id.
payloadReadOnlySpan<byte>The message payload.
Returns
- MavlinkFrame
The frame ready to send.
Remarks
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.
KnownCrcExtra(uint)
Returns the CRC_EXTRA the common dialect publishes for a message id.
public static byte? KnownCrcExtra(uint msgid)
Parameters
msgiduintThe message id to look up.
Returns
- byte?
The seed, or
nullfor an id outside the common dialect, which is what a MavlinkDialect is for.
MessageCrcExtra(string, IReadOnlyList<MavlinkField>)
Derives the CRC_EXTRA seed of a message from its definition.
public static byte MessageCrcExtra(string name, IReadOnlyList<MavlinkField> fields)
Parameters
namestringThe message name, such as
HEARTBEAT.fieldsIReadOnlyList<MavlinkField>The base fields in wire order.
Returns
- byte
The seed.
Remarks
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.
TimestampFromUnixMicros(ulong)
Converts Unix time into the timestamp MAVLink signing counts in.
public static ulong TimestampFromUnixMicros(ulong unixMicros)
Parameters
unixMicrosulongThe time in microseconds since the Unix epoch.
Returns
- ulong
The signing timestamp, in units of ten microseconds since 2015.
TimestampNow()
Returns a signing timestamp for now.
public static ulong TimestampNow()
Returns
- ulong
The signing timestamp matching the current clock.