Ibus protocol helper v0.1.0 ExIbus.Reader View Source
This module is responsible for reading and fetching messages from data that it receives. Data could be sent byte by byte or message by message.
Link to this section Summary
Functions
Configure reader process
Handle new part of message or message Message will be places in buffer and sytem will try to get a valid message from it
Read list of available messages in reader. Note that list of messages might be empty if nothing was parsed
Send data to Module for processing
Link to this section Types
reader_options() :: {:active, boolean()} | {:listener, pid()} | {:name, binary()}
Link to this section Functions
configure(GenServer.server(), reader_options()) :: :ok | {:error, term()}
Configure reader process.
The folowing options are available:
:active
- (true
orfalse
) specifies whether data is received as messages or by callingread/2
. See discussion below.:listener
-pid
that will receive messages in active mode.:name
- Reader name. If you need to start several readers you are able to use different names and you will receiveReader
name into message later.
Active mode defaults to true and means that data received on the Ibus Reader is reported in messages. The messages have the following form:
{:ex_ibus, reader_name, data}
or
{:ex_ibus, reader_name, {:error, reason}}
When in active mode, flow control can not be used to push back on the
sender and messages will accumulated in the mailbox should data arrive
fast enough. If this is an issue, set :active
to false and call
read/1
manually when ready for more data.
handle_info({:message, binary()}, ExIbus.Reader.State.t()) :: {:noreply, ExIbus.Reader.State.t()} | {:error, term()}
Handle new part of message or message Message will be places in buffer and sytem will try to get a valid message from it
On success message fetching message will be avaliable into ExIbus.Reader.read()
function
or will be sent to pid in case of :active
mode
iex> {:ok, pid} = ExIbus.Reader.start_link()
iex> send(pid, {:message, <<0x68, 0x04, 0x18, 0x0A, 0x00, 0x7E>>})
iex> ExIbus.Reader.read(pid)
[%ExIbus.Message{src: <<0x68>>, dst: <<0x18>>, msg: <<0x0A, 0x00>>}]
read(GenServer.server()) :: [ExIbus.Message.t()] | {:error, term()}
Read list of available messages in reader. Note that list of messages might be empty if nothing was parsed.
iex> {:ok, pid} = ExIbus.Reader.start_link()
iex> ExIbus.Reader.read(pid)
[]
start_link([term()]) :: {:ok, pid()} | {:error, term()}
write(GenServer.server(), binary()) :: :ok | {:error, term()}
Send data to Module for processing