Module: Xap
- Defined in:
- lib/xap.rb,
lib/xap/parser.rb,
lib/xap/schema.rb,
lib/xap/xap_dev.rb,
lib/xap/xap_msg.rb,
lib/xap/xap_address.rb,
lib/xap/xap_handler.rb,
lib/xap/schema/xap_bsc.rb,
lib/xap/parser/parse_xap.rb,
lib/xap/schema/xap_bsc_device.rb
Overview
An XapDevice model of an xAP Basic Status and Control device. ©2012 Mike Bourgeous
Defined Under Namespace
Modules: Parser, Schema Classes: XapAddress, XapDevice, XapHandler, XapHeartbeat, XapMessage, XapUnsupportedMessage
Constant Summary collapse
- XAP_PORT =
3639- BCAST_ADDR =
'255.255.255.255'- @@connection =
nil
Class Method Summary collapse
-
.add_device(device) ⇒ Object
Adds the given XapDevice to the current xAP socket server.
-
.add_receiver(src_addr, callback) ⇒ Object
Adds a message receiver to the current xAP socket server.
-
.log(msg) ⇒ Object
TODO: Use Logger.
-
.random_uid ⇒ Object
Generates a random xAP UID of the form ‘FF(01..FE)(01..FE)00’.
-
.remove_device(device) ⇒ Object
Removes the given XapDevice from the current xAP socket server.
-
.remove_receiver(src_addr, callback) ⇒ Object
Removes a message receiver from the current xAP socket server.
-
.start_xap ⇒ Object
Opens a UDP socket for sending and receiving xAP messages.
-
.stop_xap ⇒ Object
Closes the xAP server UDP socket, if one exists.
-
.xap_running? ⇒ Boolean
Returns true if the xAP handler is connected to its UDP socket, false otherwise.
Class Method Details
.add_device(device) ⇒ Object
Adds the given XapDevice to the current xAP socket server.
175 176 177 178 |
# File 'lib/xap/xap_handler.rb', line 175 def self.add_device device raise 'The xAP server is not running. Call start_xap first.' unless @@connection XapHandler.instance.add_device device end |
.add_receiver(src_addr, callback) ⇒ Object
Adds a message receiver to the current xAP socket server.
187 188 189 190 |
# File 'lib/xap/xap_handler.rb', line 187 def self.add_receiver src_addr, callback raise 'The xAP server is not running. Call start_xap first.' unless @@connection XapHandler.instance.add_receiver src_addr, callback end |
.log(msg) ⇒ Object
TODO: Use Logger
18 19 20 |
# File 'lib/xap.rb', line 18 def self.log msg puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S.%6N %z')} - xAP - #{msg}" end |
.random_uid ⇒ Object
Generates a random xAP UID of the form ‘FF(01..FE)(01..FE)00’.
10 11 12 13 14 |
# File 'lib/xap.rb', line 10 def self.random_uid a = Random.rand(253) + 1 b = Random.rand(253) + 1 sprintf "FF%02X%02X00", a, b end |
.remove_device(device) ⇒ Object
Removes the given XapDevice from the current xAP socket server.
181 182 183 184 |
# File 'lib/xap/xap_handler.rb', line 181 def self.remove_device device raise 'The xAP server is not running. Call start_xap first.' unless @@connection XapHandler.instance.remove_device device end |
.remove_receiver(src_addr, callback) ⇒ Object
Removes a message receiver from the current xAP socket server.
193 194 195 196 |
# File 'lib/xap/xap_handler.rb', line 193 def self.remove_receiver src_addr, callback raise 'The xAP server is not running. Call start_xap first.' unless @@connection XapHandler.instance.remove_receiver src_addr, callback end |
.start_xap ⇒ Object
Opens a UDP socket for sending and receiving xAP messages. The EventMachine event loop must be running.
154 155 156 157 158 159 160 |
# File 'lib/xap/xap_handler.rb', line 154 def self.start_xap # EventMachine doesn't seem to support using '::' for IP address @@connection ||= EM.open_datagram_socket '0.0.0.0', XAP_PORT, XapHandler, "xAP Server" unless @@connection @@connection # TODO: xAP hub support end |
.stop_xap ⇒ Object
Closes the xAP server UDP socket, if one exists.
163 164 165 166 |
# File 'lib/xap/xap_handler.rb', line 163 def self.stop_xap @@connection.close_connection_after_writing if @@connection @@connection = nil end |
.xap_running? ⇒ Boolean
Returns true if the xAP handler is connected to its UDP socket, false otherwise.
170 171 172 |
# File 'lib/xap/xap_handler.rb', line 170 def self.xap_running? !!XapHandler.instance end |