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

View Source

CRTP session helpers over a transport.

Owns connection handshake (link probe + protocol version), optional CRTP logging subscription for battery / estimator readiness, and convenience send wrappers used by the Crazyflie adapter.

Lifecycle

{:ok, mod} = Drone.Adapters.Crazyflie.Transport.resolve(uri: "mock://ready")
{:ok, session} = Drone.Adapters.Crazyflie.Session.connect(mod, uri: "mock://ready")
{:ok, _ack, session} =
  Drone.Adapters.Crazyflie.Session.send_packet(
    session,
    Drone.Adapters.Crazyflie.CRTP.null_packet()
  )
:ok = Drone.Adapters.Crazyflie.Session.close(session)

Handshake failures close the transport and return {:error, reason} (for example {:unsupported_protocol, version} or :link_lost).

Logging setup failures close the transport with {:error, {:logging_setup_failed, reason}}.

poll/1 is a thin null-packet helper kept for tests; production code should use send_packet/2 with an explicit CRTP packet.

Summary

Types

t()

Open CRTP session bound to a transport module and its opaque state.

Functions

Closes the underlying transport.

Opens a transport, verifies protocol compatibility, and subscribes to logging.

Sends a CRTP packet through the session transport.

Types

t()

@type t() :: %{
  transport_module: module(),
  transport_state: term(),
  protocol_version: non_neg_integer() | nil,
  log_layout: [Drone.Adapters.Crazyflie.Logging.layout_entry()] | nil
}

Open CRTP session bound to a transport module and its opaque state.

FieldTypeMeaning
:transport_modulemodule()Module implementing Drone.Adapters.Crazyflie.Transport
:transport_stateterm()Opaque state returned by open / send
:protocol_versionnon_neg_integer() | nilNegotiated CRTP protocol version after handshake
:log_layout[map()] | nilActive logging decode layout when subscribed

Example

%{
  transport_module: Drone.Adapters.Crazyflie.Transport.Mock,
  transport_state: %Drone.Adapters.Crazyflie.Transport.Mock{profile: :ready},
  protocol_version: 8,
  log_layout: nil
}

Functions

close(map)

@spec close(t()) :: :ok

Closes the underlying transport.

connect(transport_module, opts)

@spec connect(
  module(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Opens a transport, verifies protocol compatibility, and subscribes to logging.

Sequence:

  1. transport_module.open(opts) (SafeLink enable happens here when requested)
  2. Send Platform.link_probe/0
  3. Send Platform.get_protocol_version/0 and parse the reply
  4. Platform.check_compatibility/1
  5. Reset logging, download TOC, create/start a battery + canfly block

send_packet(session, packet)

@spec send_packet(t(), Drone.Adapters.Crazyflie.CRTP.packet()) ::
  {:ok, map(), t()} | {:error, term(), t()}

Sends a CRTP packet through the session transport.