Class MavlinkMessage
A message read and written by field name against a MavlinkSchema.
public sealed class MavlinkMessage : IDisposable
- Inheritance
-
MavlinkMessage
- Implements
- Inherited Members
Properties
Payload
The message's bytes as they go on the wire.
public byte[] Payload { get; }
Property Value
- byte[]
Methods
Dispose()
Releases the message.
public void Dispose()
Get(string, int)
Reads a field as a double, whatever its type.
public double Get(string field, int index = 0)
Parameters
Returns
- double
The value.
Remarks
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.
GetBytes(string, int)
Copies the raw bytes of a byte-wide array field out.
public byte[] GetBytes(string field, int length)
Parameters
Returns
- byte[]
The bytes, including the zero padding.
Exceptions
- PamojaException
The message has no such field, or it is not a byte-wide array.
GetInt64(string, int)
Reads an integer field exactly, whatever its width or sign.
public long GetInt64(string field, int index = 0)
Parameters
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_tvalue is above the signed range.
GetText(string, int)
Reads a char array as text, stopping at the padding.
public string GetText(string field, int length)
Parameters
Returns
- string
The text, without its padding.
Remarks
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.
GetUInt64(string, int)
Reads an unsigned integer field exactly.
public ulong GetUInt64(string field, int index = 0)
Parameters
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.
Set(string, double, int)
Writes a double into a field, converting it to the field's type.
public void Set(string field, double value, int index = 0)
Parameters
fieldstringThe field name.
valuedoubleThe value to store.
indexintThe element to write, or
0for a scalar field.
Remarks
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.
SetBytes(string, ReadOnlySpan<byte>)
Writes the raw bytes of a byte-wide array field, zero-padding the rest.
public void SetBytes(string field, ReadOnlySpan<byte> bytes)
Parameters
fieldstringThe field name.
bytesReadOnlySpan<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.
SetInt64(string, long, int)
Writes an integer into a field exactly, whatever its width or sign.
public void SetInt64(string field, long value, int index = 0)
Parameters
fieldstringThe field name.
valuelongThe value to store.
indexintThe element to write, or
0for 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.
SetText(string, string)
Writes text into a char array, padding the rest with zeros.
public void SetText(string field, string text)
Parameters
Exceptions
- PamojaException
The message has no such field, it is not a byte-wide array, or the text is longer than the field.
SetUInt64(string, ulong, int)
Writes an unsigned integer into a field exactly.
public void SetUInt64(string field, ulong value, int index = 0)
Parameters
fieldstringThe field name.
valueulongThe value to store.
indexintThe element to write, or
0for 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.
ToFrame(MavlinkHeader)
Builds a v2 frame carrying this message.
public MavlinkFrame ToFrame(MavlinkHeader header)
Parameters
headerMavlinkHeaderThe addressing fields to stamp on the frame.
Returns
- MavlinkFrame
The frame ready to send.
Exceptions
- PamojaException
The message does not fit a frame.