Class: Lignite::Connection
- Inherits:
-
Object
- Object
- Lignite::Connection
show all
- Extended by:
- Logger
- Includes:
- Bytes, Logger
- Defined in:
- lib/lignite/connection.rb,
lib/lignite/connection/tap.rb,
lib/lignite/connection/usb.rb,
lib/lignite/connection/replay.rb,
lib/lignite/connection/bluetooth.rb
Overview
Defined Under Namespace
Classes: Bluetooth, Replay, ReplayError, Tap, Usb
Subclasses must implement
collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
default_logger, logger
Methods included from Bytes
#bin_to_hex, #f32, #hex_to_bin, #u16, #u32, #u8, #unpack_f32, #unpack_u16, #unpack_u32, #unpack_u8
Constructor Details
Returns a new instance of Connection.
31
32
33
|
# File 'lib/lignite/connection.rb', line 31
def initialize
@buf = ""
end
|
Class Method Details
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/lignite/connection.rb', line 11
def self.create
@c ||= Replay.new(ENV["LIGNITE_REPLAY"]) if ENV["LIGNITE_REPLAY"]
@c ||= begin
logger.debug "Connection: trying USB"
Usb.new
rescue NoUsbDevice
logger.debug "Connection: trying BT"
Bluetooth.new
end
@c = Tap.new(@c, ENV["LIGNITE_TAP"]) if ENV["LIGNITE_TAP"]
logger.debug "Connection: #{@c.inspect}"
@c
end
|
.reset ⇒ Object
27
28
29
|
# File 'lib/lignite/connection.rb', line 27
def self.reset
@c = nil
end
|
Instance Method Details
#close ⇒ Object
45
46
47
|
# File 'lib/lignite/connection.rb', line 45
def close
Connection.reset
end
|
#read(maxlen) ⇒ Object
|
# File 'lib/lignite/connection.rb', line 37
|
Returns a complete message.
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/lignite/connection.rb', line 58
def receive
size = nil
loop do
lenbuf = bufread(2)
size = unpack_u16(lenbuf)
break unless size.zero?
@buf = ""
end
res = bufread(size)
res
end
|
#send(payload) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/lignite/connection.rb', line 50
def send(payload)
packet = u16(payload.bytesize) + payload
logger.debug "-> #{packet.inspect}"
write(packet)
end
|
#write(data) ⇒ Object
|
# File 'lib/lignite/connection.rb', line 40
|