AutoApi.SetCommand (auto_api v13.2.0) View Source
Abstraction for a set
command in AutoApi (id 0x01
)
The struct
contains two fields:
capability
specifies the capability of the command as a Capability modulestate
specifies the properties included in the command, wrapped in a State struct
Capability and State must be of the same capability type, or an error is generated
Link to this section Summary
Functions
Parses a command binary and returns a SetCommand struct
Returns the identifier of the command.
Returns the name of the command.
Creates a new SetCommand structure with the given state
.
Creates a new SetCommand structure with the given capability
and state
.
Returns the properties set in the command state.
Transforms a SetCommand struct into binary format.
Link to this section Types
Specs
t() :: %AutoApi.SetCommand{ capability: AutoApi.Capability.t(), state: AutoApi.State.t(), version: AutoApi.version() }
Link to this section Functions
Specs
Parses a command binary and returns a SetCommand struct
Examples
iex> # Parses a "lock vehicle doors" command
iex> Elixir.AutoApi.SetCommand.from_bin(<<13, 0, 32, 1, 6, 0, 4, 1, 0, 1, 1>>)
%Elixir.AutoApi.SetCommand{capability: AutoApi.DoorsCapability, state: %AutoApi.DoorsState{locks_state: %AutoApi.Property{data: :locked}}, version: 13}
Specs
identifier() :: byte()
Returns the identifier of the command.
Example
iex> Elixir.AutoApi.SetCommand.identifier() 0x01
Specs
name() :: AutoApi.Command.name()
Returns the name of the command.
Example
iex> Elixir.AutoApi.SetCommand.name() :set
Specs
new(AutoApi.State.t()) :: t()
Creates a new SetCommand structure with the given state
.
The capability
module is derived from the given state structure.
Example
iex> state = %AutoApi.TrunkState{lock: %AutoApi.Property{data: :locked}}
iex> Elixir.AutoApi.SetCommand.new(state)
%Elixir.AutoApi.SetCommand{capability: AutoApi.TrunkCapability, state: %AutoApi.TrunkState{lock: %AutoApi.Property{data: :locked}}, version: 13}
Specs
new(AutoApi.Capability.t(), AutoApi.State.t()) :: t()
Creates a new SetCommand structure with the given capability
and state
.
Example
iex> capability = AutoApi.TrunkCapability
iex> state = %AutoApi.TrunkState{lock: %AutoApi.Property{data: :locked}}
iex> Elixir.AutoApi.SetCommand.new(capability, state)
%Elixir.AutoApi.SetCommand{capability: AutoApi.TrunkCapability, state: %AutoApi.TrunkState{lock: %AutoApi.Property{data: :locked}}, version: 13}
Specs
properties(t()) :: [AutoApi.Capability.property()]
Returns the properties set in the command state.
Examples
iex> state = AutoApi.HoodState.base()
iex> command = Elixir.AutoApi.SetCommand.new(state)
iex> Elixir.AutoApi.SetCommand.properties(command)
[]
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 = Elixir.AutoApi.SetCommand.new(state)
iex> Elixir.AutoApi.SetCommand.properties(command)
[:brake_torque_vectorings, :vehicle_moving]
Specs
Transforms a SetCommand struct into binary format.
If the command is somehow invalid, it returns an error.
Examples
iex> # Request to unlock the doors of the vehicle
iex> locks_state = %AutoApi.Property{data: :unlocked}
iex> state = AutoApi.State.put(%AutoApi.DoorsState{}, :locks_state, locks_state)
iex> command = %Elixir.AutoApi.SetCommand{capability: AutoApi.DoorsCapability, state: state}
iex> Elixir.AutoApi.SetCommand.to_bin(command)
<<13, 0, 32, 1, 6, 0, 4, 1, 0, 1, 0>>
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 = %Elixir.AutoApi.SetCommand{capability: capability, state: state}
iex> Elixir.AutoApi.SetCommand.to_bin(command)
<<13, 0, 38, 1, 5, 0, 13, 1, 0, 10, 7, 0, 64, 4, 0, 0, 0, 0, 0, 0>>