Zigbee.EZSP.ASH.Connection (zigbee v0.1.0)

Copy Markdown View Source

Stateful ASH link over a serial port (Circuits.UART).

Responsibilities:

  • open the UART and stream raw bytes in and out;
  • perform the RST → RSTACK reset handshake with the NCP;
  • split the incoming byte stream into ASH frames (honouring Cancel and flow-control bytes);
  • track frame/ack sequence numbers, ACK inbound DATA frames, and retransmit unacknowledged outbound DATA frames.

This layer is transport for EZSP: it delivers de-randomized EZSP payloads to a subscriber process and accepts EZSP payloads to send. It knows nothing about EZSP frame contents.

Send model

A window of one outstanding DATA frame. send_data/2 blocks until the NCP ACKs (or the retransmit budget is exhausted). EZSP is request/response, so a window of one costs nothing in practice and keeps the state machine small.

Usage

{:ok, conn} = Zigbee.EZSP.ASH.Connection.start_link(device: "/dev/cu.usbmodem2101")
:ok = Zigbee.EZSP.ASH.Connection.reset(conn)        # RST/RSTACK handshake
:ok = Zigbee.EZSP.ASH.Connection.subscribe(conn)    # receive {:ash_data, payload}
:ok = Zigbee.EZSP.ASH.Connection.send_data(conn, ezsp_payload)

Summary

Functions

Returns a specification to start this module under a supervisor.

Perform the RST/RSTACK reset handshake. Resets sequence numbers.

Send an EZSP payload as a DATA frame; blocks until ACKed or it fails.

Register the calling process to receive {:ash_data, payload} messages.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

reset(conn, timeout \\ 3000)

Perform the RST/RSTACK reset handshake. Resets sequence numbers.

send_data(conn, payload)

Send an EZSP payload as a DATA frame; blocks until ACKed or it fails.

start_link(opts)

subscribe(conn)

Register the calling process to receive {:ash_data, payload} messages.