Table of Contents

Class Mesh

Namespace
Pamoja.Mesh
Assembly
Pamoja.Mesh.dll

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

uint

DefaultHopLimit

The hop limit a frame starts with unless one is given.

public const byte DefaultHopLimit = 3

Field Value

byte

HeaderLen

How many bytes of a frame are header, so where its payload starts.

public const int HeaderLen = 12

Field Value

int

MaxFrame

The largest frame, in bytes, including its header and checksum.

public const int MaxFrame = 250

Field Value

int

MaxPayload

The largest payload a single frame can carry, in bytes.

public const int MaxPayload = 236

Field Value

int

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

src uint

The address of this node.

id ushort

The sequence number identifying this packet from this source.

payload ReadOnlySpan<byte>

The bytes to carry.

hopLimit byte?

How many relays the frame may take, defaulting to DefaultHopLimit.

Returns

MeshFrame

The frame, with the bytes to transmit on its Bytes property.

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

data ReadOnlySpan<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

src uint

The address of this node.

dst uint

The address the frame is for, or Broadcast.

id ushort

The sequence number identifying this packet from this source.

payload ReadOnlySpan<byte>

The bytes to carry.

hopLimit byte?

How many relays the frame may take, defaulting to DefaultHopLimit.

Returns

MeshFrame

The frame, with the bytes to transmit on its Bytes property.

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

bytes ReadOnlySpan<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

bytes ReadOnlySpan<byte>

The frame exactly as it arrived.

Returns

MeshFrame

The frame to forward, or null once its hops have run out, which is what stops a flood from circulating forever.

Exceptions

PamojaException

The frame cannot be parsed.