View Source Cantastic.Emitter (Cantastic v1.0.1)
Cantastic.Emitter is a GenServer used to emit CAN frames at the frequency defined in your YAML configuration file.
There is one Emitter process started per emitted frame on a CAN network.
Here is an example on how to configure a simple emitter and start emitting frames immediately:
:ok = Emitter.configure(:network_name, "my_frame", %{
parameters_builder_function: :default,
initial_data: %{
"gear" => "drive"
},
enable: true
})
Summary
Functions
Returns a specification to start this module under a supervisor.
Configure the emitter, it has to be called before enable/2.
Disable the emitter(s), the frame is/are then not emitted on the bus anymore.
Enable the emitter(s), the frame(s) is/are then emitted on the bus at the predefined frequency.
Forward a frame to another CAN network
Send the frame once.
configure/2 has to be called before the emitter can start emitting on the bus.
Update the emitter's data.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Configure the emitter, it has to be called before enable/2.
You must provide a parameters_builder_function that will be used by the emitter to compute the actual Cantastic.Signal value(s).
The function will receive the Emitter's data as a parameter and should return {:ok, parameters, data}, where parameters is a map containing a value for each signal of the emitter's frame.
If all you need is to send the current values stored in data, you can simply pass :default as parameters_builder_function, which is equivalent to fn (data) -> {:ok, data, data}.
You can start to emit immediately by setting the enable key to true.
The initial_data key allows you to provide the initial values.
Returns: :ok
Examples
iex> Cantastic.Emitter.configure(:network_name, %{
parameters_builder_function: fn (data) ->
{
:ok,
%{"counter" => data["counter"], "gear" => data["gear"]},
%{data | "counter" => data["counter"] + 1}
}
end,
initial_data: %{"counter" => 0, "gear" => "drive"}
})
:ok
iex> Cantastic.Emitter.configure(:network_name, %{
parameters_builder_function: :default,
initial_data: %{"gear" => "drive"},
enable: true
})
:ok
Disable the emitter(s), the frame is/are then not emitted on the bus anymore.
Returns: :ok
Examples
iex> Cantastic.Emitter.disable(:drive_can, "engine_status")
:ok
iex> Cantastic.Emitter.disable(:drive_can, ["engine_status", "throttle"])
:ok
Enable the emitter(s), the frame(s) is/are then emitted on the bus at the predefined frequency.
Returns: :ok
Examples
iex> Cantastic.Emitter.enable(:drive_can, "engine_status")
:ok
iex> Cantastic.Emitter.enable(:drive_can, ["engine_status", "throttle"])
:ok
Forward a frame to another CAN network
Returns: :ok
Examples
iex> Cantastic.Emitter.forward(:my_network, frame)
:ok
Send the frame once.
configure/2 has to be called before the emitter can start emitting on the bus.
Returns :ok.
Example
iex> Cantastic.Emitter.send_frame(:network_name, "my_frame")
:ok
Update the emitter's data.
It allows you to modify the signal's values to sent on the bus. Your function receives the data map and must return the updated version.
Returns: :ok
Examples
iex> Cantastic.Emitter.update(:network_name, "my_frame", fn(data) ->
%{data | gear: "parking"}
end)
:ok