Table of Contents

Class MavlinkMessage

Namespace
Pamoja.Mavlink
Assembly
Pamoja.Mavlink.dll

A message read and written by field name against a MavlinkSchema.

public sealed class MavlinkMessage : IDisposable
Inheritance
MavlinkMessage
Implements
Inherited Members

Properties

The message's bytes as they go on the wire.

public byte[] Payload { get; }

Property Value

byte[]

Methods

Releases the message.

public void Dispose()

Reads a field as a double, whatever its type.

public double Get(string field, int index = 0)

Parameters

field string

The field name.

index int

The element to read, or 0 for a scalar field.

Returns

double

The value.

An integer field wider than 53 bits can exceed what a double holds exactly, so read those with GetInt64(string, int) or GetUInt64(string, int) where the exact value matters.

Exceptions

PamojaException

The message has no such field, or the element is past the end of an array.

Copies the raw bytes of a byte-wide array field out.

public byte[] GetBytes(string field, int length)

Parameters

field string

The field name.

length int

The field's declared length, from its schema.

Returns

byte[]

The bytes, including the zero padding.

Exceptions

PamojaException

The message has no such field, or it is not a byte-wide array.

Reads an integer field exactly, whatever its width or sign.

public long GetInt64(string field, int index = 0)

Parameters

field string

The field name.

index int

The element to read, or 0 for a scalar field.

Returns

long

The value.

Exceptions

PamojaException

The message has no such field, the element is past the end of an array, the field is floating-point, or a uint64_t value is above the signed range.

Reads a char array as text, stopping at the padding.

public string GetText(string field, int length)

Parameters

field string

The field name.

length int

The field's declared length, from its schema.

Returns

string

The text, without its padding.

MAVLink carries a string in a fixed-length array, padded with zeros when the text is shorter and left unterminated when it exactly fills the field.

Exceptions

PamojaException

The message has no such field, or it is not a byte-wide array.

Reads an unsigned integer field exactly.

public ulong GetUInt64(string field, int index = 0)

Parameters

field string

The field name.

index int

The element to read, or 0 for a scalar field.

Returns

ulong

The value.

Exceptions

PamojaException

The message has no such field, the element is past the end of an array, the field is floating-point, or the value is negative.

Writes a double into a field, converting it to the field's type.

public void Set(string field, double value, int index = 0)

Parameters

field string

The field name.

value double

The value to store.

index int

The element to write, or 0 for a scalar field.

A value bound for an integer field must be a whole number within that field's range, so a fractional or oversized value is refused rather than silently truncated.

Exceptions

PamojaException

The message has no such field, the element is past the end of an array, or an integer field cannot hold the value exactly.

Writes the raw bytes of a byte-wide array field, zero-padding the rest.

public void SetBytes(string field, ReadOnlySpan<byte> bytes)

Parameters

field string

The field name.

bytes ReadOnlySpan<byte>

The bytes to store, at most the field's declared length.

Exceptions

PamojaException

The message has no such field, it is not a byte-wide array, or the bytes are longer than the field.

Writes an integer into a field exactly, whatever its width or sign.

public void SetInt64(string field, long value, int index = 0)

Parameters

field string

The field name.

value long

The value to store.

index int

The element to write, or 0 for a scalar field.

Exceptions

PamojaException

The message has no such field, the element is past the end of an array, the field is floating-point, or the value does not fit the field's type.

Writes text into a char array, padding the rest with zeros.

public void SetText(string field, string text)

Parameters

field string

The field name.

text string

The text to store, at most the field's declared length.

Exceptions

PamojaException

The message has no such field, it is not a byte-wide array, or the text is longer than the field.

Writes an unsigned integer into a field exactly.

public void SetUInt64(string field, ulong value, int index = 0)

Parameters

field string

The field name.

value ulong

The value to store.

index int

The element to write, or 0 for a scalar field.

Exceptions

PamojaException

The message has no such field, the element is past the end of an array, the field is floating-point, or the value does not fit the field's type.

Builds a v2 frame carrying this message.

public MavlinkFrame ToFrame(MavlinkHeader header)

Parameters

header MavlinkHeader

The addressing fields to stamp on the frame.

Returns

MavlinkFrame

The frame ready to send.

Exceptions

PamojaException

The message does not fit a frame.