]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/platforms/msp430/motelist/motelist-macos
Added support for MAC OS in tools compilation
[tinyos-2.x.git] / tools / platforms / msp430 / motelist / motelist-macos
diff --git a/tools/platforms/msp430/motelist/motelist-macos b/tools/platforms/msp430/motelist/motelist-macos
new file mode 100644 (file)
index 0000000..ee5618b
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+use strict;
+
+my $help = <<'EOF';
+usage: motelist [options]
+
+options:
+  -h  display this help
+  -c  compact format, not pretty but easier for parsing
+EOF
+
+my %Opt = (
+  compact => 0,
+  dev_prefix => [ "/dev/tty.usbserial-" ],
+);
+
+while (@ARGV) {
+  last unless $ARGV[0] =~ /^-/;
+  my $opt = shift @ARGV;
+  if( $opt eq "-h" ) { print "$help\n"; exit 0; }
+  elsif( $opt eq "-c" ) { $Opt{compact} = 1; }
+  else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; }
+}
+
+print_motelist( scan_dev() );
+
+#
+#  Scan /dev for tty.usbserial-*
+#
+sub  scan_dev {
+  my @devs;
+  foreach (`ls /dev/tty.usbserial-* 2>&1`) {
+    my($dev, $serial) = /(\/dev\/tty.usbserial-(\S+))/;
+    if ($serial ne "*:") {
+      my $d;
+      $d->{"InfoSerial"} = $serial;
+      $d->{"SerialDevName"} = $dev;
+      push(@devs, $d);
+    }
+  }
+  return @devs;
+}
+
+
+#
+#  Print motelist
+#
+sub print_motelist {
+  my @devs = @_;
+
+  #  If none were found, quit
+  if( @devs == 0 ) {
+    print "No devices found.\n";
+    return;
+  }
+
+  #  Print a header
+  if( !$Opt{compact} ) {
+    print << "EOF" unless $Opt{compact};
+Reference  Device                      Description
+---------- --------------------------- ---------------------------------------
+EOF
+  }
+
+  #  Print the usb information
+  for my $dev (@devs) {
+    my $desc = "(none)";
+    my @output = ( $dev->{"InfoSerial"}, $dev->{"SerialDevName"}, $desc );
+    if( $Opt{compact} ) {
+      print join(",",@output) . "\n";
+    } else {
+      printf( "%-10s %-27s %s\n", @output );
+    }
+  }
+}