Drone. Adapter behaviour
(ex_drone v0.1.0)
View Source
Behaviour definition for drone adapters.
Every drone adapter must implement this behaviour. The adapter is responsible
for all communication with the physical (or simulated) drone. The Drone.Vehicle
GenServer calls adapter callbacks, passing in opaque adapter state.
Implementing an Adapter
defmodule Drone.Adapters.MyDrone do
@behaviour Drone.Adapter
@impl Drone.Adapter
def connect(opts) do
{:ok, %{ip: Keyword.fetch!(opts, :ip), port: Keyword.get(opts, :port, 8889)}}
end
@impl Drone.Adapter
def command(state, %Drone.Command{type: :takeoff}) do
{:ok, :ok, state}
end
@impl Drone.Adapter
def telemetry(state) do
{:ok, %{x: 0, y: 0, z: 30}, state}
end
@impl Drone.Adapter
def disconnect(_state) do
:ok
end
endSee docs/adapter_authoring.md for a complete guide.
Summary
Functions
Returns the adapter module for a given adapter identifier.
Types
@type state() :: term()