AutoApi.Command behaviour (auto_api v13.2.0) View Source
Command behavior for handling AutoApi commands
Link to this section Summary
Functions
Parses a binary command and returns a struct with the command data.
Returns the identifier of the command
Returns the name of the command
Returns the properties set in the command.
Parses a command and returns it in binary format.
Link to this section Types
Specs
name() :: :get | :get_availability | :set
Specs
t() :: AutoApi.GetAvailabilityCommand.t() | AutoApi.GetCommand.t() | AutoApi.SetCommand.t()
Link to this section Functions
Specs
Parses a binary command and returns a struct with the command data.
The struct type determines the command action, and further data is contained in the struct fields themselves.
Possible result types are:
- AutoApi.GetAvailabilityCommand
- AutoApi.GetCommand
- AutoApi.SetCommand
See the documentation for each module to understand what their fields stand for.
Examples
iex> Elixir.AutoApi.Command.from_bin(<<0x0D, 0x00, 0x33, 0x02, 0x01, 0x04>>)
%AutoApi.GetAvailabilityCommand{capability: AutoApi.DiagnosticsCapability, properties: [:mileage, :engine_rpm]}
iex> Elixir.AutoApi.Command.from_bin(<<0x0D, 0x00, 0x33, 0x00, 0x01, 0x04>>)
%AutoApi.GetCommand{capability: AutoApi.DiagnosticsCapability, properties: [:mileage, :engine_rpm]}
iex> # Parses a "lock vehicle doors" command
iex> Elixir.AutoApi.Command.from_bin(<<13, 0, 32, 1, 6, 0, 4, 1, 0, 1, 1>>)
%AutoApi.SetCommand{capability: AutoApi.DoorsCapability, state: %AutoApi.DoorsState{locks_state: %AutoApi.Property{data: :locked}}}
Specs
identifier(t()) :: identifier()
Returns the identifier of the command
Example
iex> command = AutoApi.GetAvailabilityCommand.new(AutoApi.DiagnosticsCapability, []) iex> AutoApi.Command.identifier(command) 0x02
Specs
Returns the name of the command
Example
iex> command = AutoApi.GetAvailabilityCommand.new(AutoApi.DiagnosticsCapability, []) iex> AutoApi.Command.name(command) :get_availability
Specs
properties(t()) :: [AutoApi.Capability.property()]
Returns the properties set in the command.
For Get and GetAvailability commands, it returns the list of properties in the command, or all the state properties if the list is empty.
For SetCommands, it returns the list of properties with anything set in them
Examples
iex> command = AutoApi.GetAvailabilityCommand.new(AutoApi.HoodCapability, [])
iex> Elixir.AutoApi.Command.properties(command)
[:position, :lock, :lock_safety, :nonce, :vehicle_signature, :timestamp, :vin, :brand]
iex> command = AutoApi.GetCommand.new(AutoApi.HoodCapability, [])
iex> Elixir.AutoApi.Command.properties(command)
[:position, :lock, :lock_safety, :nonce, :vehicle_signature, :timestamp, :vin, :brand]
iex> state = AutoApi.RaceState.base()
...> |> AutoApi.State.put(:vehicle_moving, data: :sport, timestamp: ~U[2021-03-12 10:54:14Z])
...> |> AutoApi.State.put(:brake_torque_vectorings, data: %{axle: :front, state: :active})
iex> command = AutoApi.SetCommand.new(state)
iex> Elixir.AutoApi.Command.properties(command)
[:brake_torque_vectorings, :vehicle_moving]
Specs
Parses a command and returns it in binary format.
This is a convenience function that only delegates to the to_bin/1
function of the command module.
Examples
iex> # Request all properties for race state iex> command = %AutoApi.GetAvailabilityCommand{capability: AutoApi.RaceCapability, properties: []} iex> Elixir.AutoApi.Command.to_bin(command) <<13, 0, 87, 2>>
iex> # Request the door locks state iex> command = %AutoApi.GetCommand{capability: AutoApi.DoorsCapability, properties: [:locks_state]} iex> Elixir.AutoApi.Command.to_bin(command) <<13, 0, 32, 0, 6>>
iex> # Request to honk the horn for 2.5 seconds iex> capability = AutoApi.HonkHornFlashLightsCapability iex> honk_time = %{value: 2.5, unit: :seconds} iex> state = AutoApi.State.put(capability.state().base(), :honk_time, data: honk_time) iex> command = %AutoApi.SetCommand{capability: capability, state: state} iex> Elixir.AutoApi.Command.to_bin(command) <<13, 0, 38, 1, 5, 0, 13, 1, 0, 10, 7, 0, 64, 4, 0, 0, 0, 0, 0, 0>>
Link to this section Callbacks
Specs
Specs
identifier() :: byte()
Specs
name() :: name()
Specs
properties(t()) :: [AutoApi.Capability.property()]