lib/artoo/commands/connect.rb in artoo-1.5.0 vs lib/artoo/commands/connect.rb in artoo-1.6.0

- old
+ new

@@ -15,16 +15,16 @@ when 'bluetooth' run("hcitool scan") when 'serial' run("ls /dev/tty*") when 'usb' - run("lsusb") + run("lsusb") else say "ERROR: scan type '#{options[:type]}' not supported!" end when :macosx - run("ls /dev/tty*") + run("ls /dev/tty*") else say "OS not yet supported..." end end @@ -46,14 +46,22 @@ desc "serial [NAME] [PORT]", "Connect a serial device to a TCP socket using socat" option :retries, :aliases => "-r", :default => 0, :desc => "Number of times to retry connecting on failure" option :baudrate, :aliases => "-b", :default => 57600, :desc => "Baud rate to use to connect to the serial device" def serial(name, port) attempts = 1 + options[:retries].to_i - + + # check that Socat is installed + system("socat -V &> /dev/null") + unless $?.success? + say "Socat not installed. Cannot bind serial to TCP." + say "Please install with 'artoo install socat' and try again." + return + end + 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