Class: Dino::TxRx::Base
- Inherits:
-
Object
- Object
- Dino::TxRx::Base
- Includes:
- Observable
- Defined in:
- lib/dino/tx_rx/base.rb
Instance Method Summary collapse
- #close_read ⇒ Object
- #flush_read ⇒ Object
- #gets ⇒ Object
- #handshake ⇒ Object
- #read ⇒ Object
- #write(message) ⇒ Object
Instance Method Details
#close_read ⇒ Object
21 22 23 24 25 |
# File 'lib/dino/tx_rx/base.rb', line 21 def close_read return nil if @thread.nil? Thread.kill(@thread) @thread = nil end |
#flush_read ⇒ Object
55 56 57 |
# File 'lib/dino/tx_rx/base.rb', line 55 def flush_read gets until gets == nil end |
#gets ⇒ Object
59 60 61 |
# File 'lib/dino/tx_rx/base.rb', line 59 def gets IO.select([io], nil, nil, 0.005) && io.gets end |
#handshake ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dino/tx_rx/base.rb', line 36 def handshake flush_read 100.times do begin write("!9000000.") Timeout::timeout(0.1) do line = gets.to_s if line.match /ACK:/ flush_read return line.chop.split(/:/)[1].to_i end end rescue nil end end raise BoardNotFound end |
#read ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dino/tx_rx/base.rb', line 9 def read @thread ||= Thread.new do loop do line = gets if line && line.match(/\A\d+:/) pin, = line.chop.split(/:/) pin && && changed && notify_observers(pin, ) end end end end |
#write(message) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/dino/tx_rx/base.rb', line 27 def write() loop do if IO.select(nil, [io], nil) io.syswrite() break end end end |