Class: Artoo::Commands::Connect
- Inherits:
-
Artoo::Commands
- Object
- Artoo::Commands
- Artoo::Commands::Connect
- Defined in:
- lib/artoo/commands/connect.rb
Instance Method Summary collapse
Instance Method Details
#bind(address, name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/artoo/commands/connect.rb', line 34 def bind(address, name) case os when :linux run("sudo rfcomm -i #{[:radio]} bind /dev/rfcomm#{[:comm]} #{address} 1") run("sudo ln -s /dev/rfcomm#{[:comm]} /dev/#{name}") when :macosx say "OSX binds devices on its own volition." else say "OS not yet supported..." end end |
#scan ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/artoo/commands/connect.rb', line 11 def scan case os when :linux case [:type] when 'bluetooth' run("hcitool scan") when 'serial' run("ls /dev/tty*") when 'usb' run("lsusb") else say "ERROR: scan type '#{[:type]}' not supported!" end when :macosx run("ls /dev/tty*") else say "OS not yet supported..." end end |
#serial(name, port) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/artoo/commands/connect.rb', line 49 def serial(name, port) attempts = 1 + [:retries].to_i case os when :linux run("sudo chmod a+rw /dev/#{name}") while(attempts > 0) do run("socat -d -d FILE:/dev/#{name},nonblock,raw,b#{[:baudrate]},echo=0 TCP-LISTEN:#{port},fork") break unless $? == 1 attempts -= 1 end when :macosx while(attempts > 0) do run("socat -d -d -b#{[:baudrate]} FILE:/dev/#{name},nonblock,raw,echo=0 TCP-LISTEN:#{port},fork") break unless $? == 1 attempts -= 1 end else say "OS not yet supported..." end end |