Class: TEF::FurComs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tef/furcoms/base.rb

Overview

Base class for a FurComs bus.

This base class represents a single, bidirectional connection point to a FurComs bus. It provides function prototypes for sending and receiving messages that shall be overloaded by actual implementations.

See Also:

Author:

  • The System (Neira)

Direct Known Subclasses

MQTT, Serial

Instance Method Summary collapse

Constructor Details

#initializeBase

Initialize an empty base class.

Note that this class cannot be used for communication!



23
24
25
# File 'lib/tef/furcoms/base.rb', line 23

def initialize()
	@message_procs = [];
end

Instance Method Details

#on_message(topic_filter = nil) {|data, topic| ... } ⇒ Object

Add a message callback.

Calling this function with a block will add a callback to received messages. Any new message that is received will be passed to the callback.

Parameters:

  • topic_filter (String, RegExp) (defaults to: nil)

    Optional topic filter to use, either a String (for exact match) or Regexp

Yield Parameters:

  • data (String)

    Raw data received from the FurComs bus. ASCII-8 encoded, may contain any binary character.

  • topic (String)

    Topic string that this message was received on.



47
48
49
50
51
52
# File 'lib/tef/furcoms/base.rb', line 47

def on_message(topic_filter = nil, &block)
	o_msg = { topic: topic_filter, block: block };
	@message_procs << o_msg;

	o_msg
end

#send_message(topic, message, priority: 0, chip_id: 0) ⇒ Object

Send a message to the FurComs bus.

This will send a message onto topic, using the given priority and chip_id (defaulting both to 0).

Parameters:

  • topic (String)

    Topic to send the message onto

  • message (String)

    Binary string of data to send, expected to be ASCII-8 encoded, can contain any character (including null)



35
# File 'lib/tef/furcoms/base.rb', line 35

def send_message(topic, message, priority: 0, chip_id: 0) end