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

View Source

Platform / link-control packets for protocol identity.

Connection sequence (documented CRTP connection procedure):

  1. Probe link with a LINKCTRL source packet.
  2. Request protocol version on PLATFORM channel 1.
  3. Parse the reply and call check_compatibility/1.

Examples

probe = Drone.Adapters.Crazyflie.Platform.link_probe()
req = Drone.Adapters.Crazyflie.Platform.get_protocol_version()
{:ok, 8} = Drone.Adapters.Crazyflie.Platform.parse_protocol_version(<<0, 8>>)
:ok = Drone.Adapters.Crazyflie.Platform.check_compatibility(8)

Summary

Functions

Returns :ok when version is in the supported range.

PLATFORM request for the CRTP protocol version.

LINKCTRL probe packet used during connection.

Maximum accepted CRTP protocol version for this adapter.

Minimum accepted CRTP protocol version for this adapter.

Parses a protocol-version response payload.

Functions

check_compatibility(version)

@spec check_compatibility(integer()) ::
  :ok | {:error, {:unsupported_protocol, integer()}}

Returns :ok when version is in the supported range.

Parameters

Returns

Examples

:ok = Drone.Adapters.Crazyflie.Platform.check_compatibility(8)

{:error, {:unsupported_protocol, 99}} =
  Drone.Adapters.Crazyflie.Platform.check_compatibility(99)

get_protocol_version()

@spec get_protocol_version() :: Drone.Adapters.Crazyflie.CRTP.packet()

PLATFORM request for the CRTP protocol version.

Returns

Drone.Adapters.Crazyflie.CRTP.packet() on port :platform, channel 1, payload <<0>> (VERSION_GET_PROTOCOL).

Examples

%{port: 13, channel: 1, payload: <<0>>} =
  Drone.Adapters.Crazyflie.Platform.get_protocol_version()

max_supported()

@spec max_supported() :: pos_integer()

Maximum accepted CRTP protocol version for this adapter.

Returns

pos_integer() (currently 12).

Examples

12 = Drone.Adapters.Crazyflie.Platform.max_supported()

min_supported()

@spec min_supported() :: pos_integer()

Minimum accepted CRTP protocol version for this adapter.

Returns

pos_integer() (currently 4).

Examples

4 = Drone.Adapters.Crazyflie.Platform.min_supported()

parse_protocol_version(arg1)

@spec parse_protocol_version(binary()) ::
  {:ok, non_neg_integer()} | {:error, :invalid_version_response}

Parses a protocol-version response payload.

Expected shape: <<0, version>> where the first byte echoes VERSION_GET_PROTOCOL.

Parameters

  • payload (binary()) — ACK payload from the version request

Returns

  • {:ok, non_neg_integer()} — protocol version byte
  • {:error, :invalid_version_response} — unexpected shape

Examples

{:ok, 8} = Drone.Adapters.Crazyflie.Platform.parse_protocol_version(<<0, 8>>)
{:error, :invalid_version_response} =
  Drone.Adapters.Crazyflie.Platform.parse_protocol_version(<<1, 8>>)