Class Mesh
Mesh packet framing, for radios that give you no addressing of their own.
public static class Mesh
- Inheritance
-
Mesh
- Inherited Members
Remarks
When the fixed infrastructure is gone or was never there, devices carry each other's traffic: every node relays what it hears, so a message crosses an area no single node can reach. This is the packet half of that; driving a radio is the caller's job.
Fields
Broadcast
The destination address that means every node.
public const uint Broadcast = 4294967295
Field Value
DefaultHopLimit
The hop limit a frame starts with unless one is given.
public const byte DefaultHopLimit = 3
Field Value
HeaderLen
How many bytes of a frame are header, so where its payload starts.
public const int HeaderLen = 12
Field Value
MaxFrame
The largest frame, in bytes, including its header and checksum.
public const int MaxFrame = 250
Field Value
MaxPayload
The largest payload a single frame can carry, in bytes.
public const int MaxPayload = 236
Field Value
Methods
BroadcastFrame(uint, ushort, ReadOnlySpan<byte>, byte?)
Builds a frame addressed to every node.
public static MeshFrame BroadcastFrame(uint src, ushort id, ReadOnlySpan<byte> payload, byte? hopLimit = null)
Parameters
srcuintThe address of this node.
idushortThe sequence number identifying this packet from this source.
payloadReadOnlySpan<byte>The bytes to carry.
hopLimitbyte?How many relays the frame may take, defaulting to DefaultHopLimit.
Returns
- MeshFrame
The frame, with the bytes to transmit on its
Bytesproperty.
Exceptions
- PamojaException
The payload is larger than MaxPayload.
Crc16(ReadOnlySpan<byte>)
Computes the CRC-16 a frame carries.
public static ushort Crc16(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The bytes the checksum covers.
Returns
- ushort
The checksum.
Frame(uint, uint, ushort, ReadOnlySpan<byte>, byte?)
Builds a frame addressed to one node.
public static MeshFrame Frame(uint src, uint dst, ushort id, ReadOnlySpan<byte> payload, byte? hopLimit = null)
Parameters
srcuintThe address of this node.
dstuintThe address the frame is for, or Broadcast.
idushortThe sequence number identifying this packet from this source.
payloadReadOnlySpan<byte>The bytes to carry.
hopLimitbyte?How many relays the frame may take, defaulting to DefaultHopLimit.
Returns
- MeshFrame
The frame, with the bytes to transmit on its
Bytesproperty.
Exceptions
- PamojaException
The payload is larger than MaxPayload.
Parse(ReadOnlySpan<byte>)
Parses a frame received off a radio.
public static MeshFrame Parse(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The frame exactly as it arrived.
Returns
- MeshFrame
The parsed frame.
Exceptions
- PamojaException
The frame is truncated, of an unknown version, or fails its checksum, which is what a noisy radio produces.
Relayed(ReadOnlySpan<byte>)
Returns the same frame with one hop spent, ready to forward.
public static MeshFrame? Relayed(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The frame exactly as it arrived.
Returns
- MeshFrame
The frame to forward, or
nullonce its hops have run out, which is what stops a flood from circulating forever.
Exceptions
- PamojaException
The frame cannot be parsed.