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

Link to this type reader_options() View Source
reader_options() ::
  {:active, boolean()} |
  {:listener, pid()} |
  {:name, binary()}

Link to this section Functions

Link to this function configure(pid, opts) View Source
configure(GenServer.server(), reader_options()) ::
  :ok |
  {:error, term()}

Configure reader process.

The folowing options are available:

  • :active - (true or false) specifies whether data is received as messages or by calling read/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 receive Reader 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.

Link to this function handle_info(msg, state) View Source
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 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)
[]
Link to this function start_link(opts \\ []) View Source
start_link([term()]) :: {:ok, pid()} | {:error, term()}
Link to this function write(pid, msg) View Source
write(GenServer.server(), binary()) :: :ok | {:error, term()}

Send data to Module for processing