auto_api v0.1.0 AutoApi.DiagnosticsCommand View Source

Handles Diagnostics commands and apply binary commands on %AutoApi.DiagnosticsState{}

Link to this section Summary

Functions

Parses the binary command and makes changes or returns the state

Converts VehicleLocation state to capability’s state in binary

Converts command to binary format

Link to this section Functions

Link to this function execute(state, arg) View Source
execute(AutoApi.DiagnosticsState.t(), binary()) :: {:state | :state_changed, AutoApi.DiagnosticsState.t()}

Parses the binary command and makes changes or returns the state

iex> AutoApi.DiagnosticsCommand.execute(%AutoApi.DiagnosticsState{}, <<0x00>>)
  {:state, %AutoApi.DiagnosticsState{}}

  iex> command = <<0x01>> <> <<0x01, 2::integer-16, 100::integer-16>> <> <<0x03, 2::integer-16, 50::integer-16>>
  iex> AutoApi.DiagnosticsCommand.execute(%AutoApi.DiagnosticsState{}, command)
  {:state_changed, %AutoApi.DiagnosticsState{mileage: 100, speed: 50}}

Converts VehicleLocation state to capability’s state in binary

iex> AutoApi.DiagnosticsCommand.state(%AutoApi.DiagnosticsState{engine_oil_temperature: 20,engine_rpm: 70, fuel_level: 99, mileage: 2000, speed: 100, washer_fluid_level: :low, tire: []})
  <<1, 12, 0, 4, 0, 0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 11, 0, 4, 0, 0, 0, 0, 7, 0, 4, 0,       0, 0, 0, 13, 0, 2, 0, 0, 14, 0, 2, 0, 0, 2, 0, 2, 0, 20, 4, 0, 2, 0, 70, 6, 0,       2, 0, 0, 5, 0, 1, 99, 1, 0, 2, 7, 208, 3, 0, 2, 0, 100, 9, 0, 1, 0>>

  iex> AutoApi.DiagnosticsCommand.state(%AutoApi.DiagnosticsState{engine_oil_temperature: 20,engine_rpm: 70, fuel_level: 99, mileage: 2000, speed: 100,washer_fluid_level: :low, tire: [%{tire_position: :front_left, tire_pressure: 1.0}]})
  <<1, 12, 0, 4, 0, 0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 11, 0, 4, 0, 0, 0, 0, 7, 0, 4, 0,       0, 0, 0, 13, 0, 2, 0, 0, 14, 0, 2, 0, 0, 2, 0, 2, 0, 20, 4, 0, 2, 0, 70, 6, 0,       2, 0, 0, 5, 0, 1, 99, 1, 0, 2, 7, 208, 3, 0, 2, 0, 100, 10, 0, 13, 0, 63, 128,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 1, 0>>

Converts command to binary format

iex> AutoApi.DiagnosticsCommand.to_bin(:get_diagnostics_state, [])
<<0x00>>