Class: TEF::FurComs::Base
- Inherits:
-
Object
- Object
- TEF::FurComs::Base
- 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.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
Initialize an empty base class.
-
#on_message(topic_filter = nil) {|data, topic| ... } ⇒ Object
Add a message callback.
-
#send_message(topic, message, priority: 0, chip_id: 0) ⇒ Object
Send a message to the FurComs bus.
Constructor Details
#initialize ⇒ Base
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.
47 48 49 50 51 52 |
# File 'lib/tef/furcoms/base.rb', line 47 def (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).
35 |
# File 'lib/tef/furcoms/base.rb', line 35 def (topic, , priority: 0, chip_id: 0) end |