Class: Artoo::Commands::Connect

Inherits:
Artoo::Commands show all
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 #{options[:radio]} bind /dev/rfcomm#{options[:comm]} #{address} 1")
    run("sudo ln -s /dev/rfcomm#{options[:comm]} /dev/#{name}")
  when :macosx
    say "OSX binds devices on its own volition."
  else
    say "OS not yet supported..."
  end
end

#scanObject



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 options[:type]
    when 'bluetooth'
      run("hcitool scan")
    when 'serial'
      run("ls /dev/tty*")
    when 'usb'
      run("lsusb")            
    else
      say "ERROR: scan type '#{options[: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 + options[: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#{options[:baudrate]},echo=0 TCP-LISTEN:#{port},fork")
      break unless $? == 1
      attempts -= 1
    end

  when :macosx
    while(attempts > 0) do
      run("socat -d -d -b#{options[: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