Drone.Adapters.Crazyflie.SafeLink (ex_drone v0.3.0)

View Source

Bitcraze SafeLink helpers for Crazyradio CRTP framing.

SafeLink uses the two reserved link bits in the CRTP header as alternating uplink / downlink counters so neither side silently drops ACK payloads.

Enable negotiation (raw USB bytes, not a normal CRTP encode):

<<0xFF, 0x05, 0x01>>

Success when the ACK data echoes the same three bytes. Framing then stamps:

header = (header &&& 0xF3) ||| (up <<< 3) ||| (down <<< 2)

Counters advance only on ACK: uplink always flips; downlink flips when the ACK payload header carries the expected downlink bit.

Summary

Functions

Advances counters after a successful ACK.

Raw USB disable packet (<<0xFF, 0x05, 0x00>>).

Raw USB enable packet (<<0xFF, 0x05, 0x01>>).

True when ACK downlink data echoes the enable packet.

Applies SafeLink framing to an encoded CRTP binary.

Stamps SafeLink uplink/downlink bits into a CRTP header byte.

Functions

advance(up, down, downlink_header)

@spec advance(0 | 1, 0 | 1, byte() | nil) :: {0 | 1, 0 | 1}

Advances counters after a successful ACK.

downlink_header is the first byte of ACK data when present, otherwise nil (empty ACK payload — uplink still flips).

disable_packet()

@spec disable_packet() :: <<_::24>>

Raw USB disable packet (<<0xFF, 0x05, 0x00>>).

enable_packet()

@spec enable_packet() :: <<_::24>>

Raw USB enable packet (<<0xFF, 0x05, 0x01>>).

enabled_echo?(arg1)

@spec enabled_echo?(binary()) :: boolean()

True when ACK downlink data echoes the enable packet.

stamp_frame(arg1, up, down)

@spec stamp_frame(binary(), 0 | 1, 0 | 1) :: {:ok, binary()} | {:error, :empty_frame}

Applies SafeLink framing to an encoded CRTP binary.

stamp_header(header, up, down)

@spec stamp_header(byte(), 0 | 1, 0 | 1) :: byte()

Stamps SafeLink uplink/downlink bits into a CRTP header byte.