Meshcore.Frame (Meshcore v0.1.0)

Copy Markdown View Source

Stream framing used by the serial and TCP transports.

Frames sent to the device are `0x3Clength (u16 LE)payload`; frames
coming from the device are `0x3Elength (u16 LE)payload`. The decoder is

resilient against garbage on the line (some radios interleave console output on the same UART): it resynchronises on the next 0x3E byte and drops frames announcing more than 300 bytes.

Summary

Functions

Feeds a chunk of received bytes; returns the completed frame payloads (in order) and the new decoder state.

Wraps payload into an outgoing frame.

Creates an empty decoder state.

Types

t()

@type t() :: %Meshcore.Frame{buffer: binary()}

Functions

decode(state, chunk)

@spec decode(t(), binary()) :: {[binary()], t()}

Feeds a chunk of received bytes; returns the completed frame payloads (in order) and the new decoder state.

iex> {frames, _} = Meshcore.Frame.decode(Meshcore.Frame.new(), <<0x3E, 2, 0, 0xAA, 0xBB, 0x3E, 1>>)
iex> frames
[<<0xAA, 0xBB>>]

encode(payload)

@spec encode(binary()) :: binary()

Wraps payload into an outgoing frame.

new()

@spec new() :: t()

Creates an empty decoder state.