Merge pull request #699 from g-oikonomou/contrib/tools/zolertia-motelist
Change platform zoul to use the new motelist
This commit is contained in:
commit
7f0c5b0b36
@ -3,6 +3,9 @@
|
||||
# Future extensions to the build system that are of a similar nature (for
|
||||
# embedded devices only), can be achieved by extending this Makefile here.
|
||||
|
||||
###
|
||||
### Targets using the tools/serial-io
|
||||
###
|
||||
RLWRAPGOALS = login serialdump serialview
|
||||
|
||||
.PHONY: $(RLWRAPGOALS)
|
||||
@ -31,3 +34,14 @@ serialview: $(SERIAL_DUMP_BIN)
|
||||
|
||||
login: $(SERIAL_DUMP_BIN)
|
||||
$(SERIALDUMP) -b$(BAUDRATE) $(PORT)
|
||||
|
||||
###
|
||||
### Targets using tools/motelist
|
||||
###
|
||||
CONTIKI_NG_MOTELIST_DIR = $(TOOLS_DIR)/motelist
|
||||
CONTIKI_NG_MOTELIST = python $(CONTIKI_NG_MOTELIST_DIR)/motelist.py
|
||||
|
||||
.PHONY: motelist-all
|
||||
|
||||
motelist-all:
|
||||
$(CONTIKI_NG_MOTELIST)
|
||||
|
29
Makefile.help
Normal file
29
Makefile.help
Normal file
@ -0,0 +1,29 @@
|
||||
usage:
|
||||
@echo "Usage:"
|
||||
@echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [PORT=(PORT)] [target]"
|
||||
@echo ""
|
||||
@echo "Typical usage:"
|
||||
@echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]"
|
||||
@echo ""
|
||||
@echo " Will build Contiki-NG firmware(s) from the current example dir"
|
||||
@echo " for platform TARGET, board BOARD."
|
||||
@echo ""
|
||||
@echo "Miscellaneous targets:"
|
||||
@echo " targets Prints list of supported platforms"
|
||||
@echo " boards Prints a list of supported boards for TARGET"
|
||||
@echo " savetarget Saves TARGET and BOARD for future invocations of make"
|
||||
@echo " savedefines Saves DEFINES for future invocations of make"
|
||||
@echo " clean Removes all compiled files for TARGET"
|
||||
@echo " distclean Removes all compiled files for all TARGETs"
|
||||
@echo " viewconf Prints Contiki-NG build configuration for TARGET"
|
||||
@echo " %.flashprof Shows a Flash/ROM profile of a given firmware (e.g. hello-world.flashprof)"
|
||||
@echo " %.ramprof Shows a RAM profile of a given firmware (e.g. hello-world.ramprof)"
|
||||
@echo " %.o Produces an object file from a given source file (e.g. hello-world.o)"
|
||||
@echo " %.e Produces the pre-processed version of a given source file (e.g. hello-world.e)"
|
||||
@echo " %.s Produces an assembly file from a given source file (e.g. hello-world.s)"
|
||||
@echo " login View the serial output of the device connected to PORT"
|
||||
@echo " serialview Same as login, but prepend serial output with a unix timestamp"
|
||||
@echo " serialdump same as serialview, but also save the output to a file"
|
||||
@echo " motelist-all Prints a list of connected devices"
|
||||
|
||||
help: usage
|
@ -395,34 +395,7 @@ endif
|
||||
%.flashprof: %.$(TARGET)
|
||||
$(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4
|
||||
|
||||
usage:
|
||||
@echo "Usage:"
|
||||
@echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [PORT=(PORT)] [target]"
|
||||
@echo ""
|
||||
@echo "Typical usage:"
|
||||
@echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]"
|
||||
@echo ""
|
||||
@echo " Will build Contiki-NG firmware(s) from the current example dir"
|
||||
@echo " for platform TARGET, board BOARD."
|
||||
@echo ""
|
||||
@echo "Miscellaneous targets:"
|
||||
@echo " targets Prints list of supported platforms"
|
||||
@echo " boards Prints a list of supported boards for TARGET"
|
||||
@echo " savetarget Saves TARGET and BOARD for future invocations of make"
|
||||
@echo " savedefines Saves DEFINES for future invocations of make"
|
||||
@echo " clean Removes all compiled files for TARGET"
|
||||
@echo " distclean Removes all compiled files for all TARGETs"
|
||||
@echo " viewconf Prints Contiki-NG build configuration for TARGET"
|
||||
@echo " %.flashprof Shows a Flash/ROM profile of a given firmware (e.g. hello-world.flashprof)"
|
||||
@echo " %.ramprof Shows a RAM profile of a given firmware (e.g. hello-world.ramprof)"
|
||||
@echo " %.o Produces an object file from a given source file (e.g. hello-world.o)"
|
||||
@echo " %.e Produces the pre-processed version of a given source file (e.g. hello-world.e)"
|
||||
@echo " %.s Produces an assembly file from a given source file (e.g. hello-world.s)"
|
||||
@echo " login View the serial output of the device connected to PORT"
|
||||
@echo " serialview Same as login, but prepend serial output with a unix timestamp"
|
||||
@echo " serialdump same as serialview, but also save the output to a file"
|
||||
|
||||
help: usage
|
||||
include $(CONTIKI)/Makefile.help
|
||||
|
||||
targets:
|
||||
@ls $(CONTIKI)/arch/platform $(TARGETDIRS)
|
||||
|
@ -46,23 +46,8 @@ MODULES += arch/dev/cc1200 arch/dev/rgb-led os/storage/cfs
|
||||
|
||||
BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py
|
||||
|
||||
### Use the specific Zoul subplatform to query for connected devices
|
||||
ifdef MOTELIST_ZOLERTIA
|
||||
MOTELIST_FLAGS += -b $(MOTELIST_ZOLERTIA)
|
||||
endif
|
||||
|
||||
### Detect if a mote is connected over serial port
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
USBDEVPREFIX=
|
||||
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos
|
||||
MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,)
|
||||
else
|
||||
### If we are not running under Mac, we assume Linux
|
||||
USBDEVPREFIX=
|
||||
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia
|
||||
MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \
|
||||
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
|
||||
endif
|
||||
MOTES := $(shell python $(TOOLS_DIR)/motelist/motelist.py --omit-header \
|
||||
| grep $(MOTELIST_ZOLERTIA) | cut -f1 -d " ")
|
||||
|
||||
### If PORT is defined, override to keep backward compatibility
|
||||
ifdef PORT
|
||||
@ -81,7 +66,8 @@ endif
|
||||
|
||||
### Variable that expands into a pattern rule to upload to a given MOTE.
|
||||
### Requires $(MOTE) to be defined
|
||||
### $$$$ Double escapes $s that need to be passed to the shell - once for when make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make.
|
||||
### $$$$ Double escapes $s that need to be passed to the shell - once for when
|
||||
### make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make.
|
||||
define UPLOAD_RULE
|
||||
%.$(MOTE): %.bin %.elf
|
||||
@echo "Flashing $(MOTE)"
|
||||
@ -94,10 +80,8 @@ endef
|
||||
### Create an upload rule for every MOTE connected
|
||||
$(foreach MOTE,$(MOTES),$(eval $(UPLOAD_RULE)))
|
||||
|
||||
motelist:
|
||||
$(MOTELIST)
|
||||
zoul-motelist:
|
||||
$(MOTELIST) $(MOTELIST_FLAGS)
|
||||
.PHONY: zoul-motes
|
||||
|
||||
zoul-motes:
|
||||
@echo $(MOTES)
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
MOTELIST_ZOLERTIA = firefly
|
||||
MOTELIST_ZOLERTIA := Firefly
|
||||
BOARD_SOURCEFILES += board.c
|
||||
|
@ -1,2 +1,2 @@
|
||||
MOTELIST_ZOLERTIA = firefly
|
||||
MOTELIST_ZOLERTIA := Firefly
|
||||
BOARD_SOURCEFILES += board.c
|
||||
|
@ -1,4 +1,4 @@
|
||||
MOTELIST_ZOLERTIA = orion
|
||||
MOTELIST_ZOLERTIA := Orion
|
||||
MODULES += arch/dev/enc28j60
|
||||
CC2538_ENC28J60_ARCH ?= gpio
|
||||
ifeq ($(WITH_IP64),1)
|
||||
|
@ -1,4 +1,4 @@
|
||||
MOTELIST_ZOLERTIA = remote
|
||||
MOTELIST_ZOLERTIA := RE-Mote
|
||||
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c
|
||||
|
||||
MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc
|
||||
|
@ -1,4 +1,4 @@
|
||||
MOTELIST_ZOLERTIA = remote
|
||||
MOTELIST_ZOLERTIA := RE-Mote
|
||||
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c
|
||||
|
||||
MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc
|
||||
|
@ -1,62 +0,0 @@
|
||||
Copyright (c) 2001-2003 Chris Liechti <cliechti@gmx.net>
|
||||
|
||||
All Rights Reserved.
|
||||
|
||||
This is the Python license. In short, you can use this product in
|
||||
commercial and non-commercial applications, modify it, redistribute it.
|
||||
A notification to the author when you use and/or modify it is welcome.
|
||||
|
||||
TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||
============================================
|
||||
|
||||
LICENSE AGREEMENT
|
||||
-----------------
|
||||
|
||||
1. This LICENSE AGREEMENT is between the copyright holder of this
|
||||
product, and the Individual or Organization ("Licensee") accessing
|
||||
and otherwise using this product in source or binary form and its
|
||||
associated documentation.
|
||||
|
||||
2. Subject to the terms and conditions of this License Agreement,
|
||||
the copyright holder hereby grants Licensee a nonexclusive,
|
||||
royalty-free, world-wide license to reproduce, analyze, test,
|
||||
perform and/or display publicly, prepare derivative works, distribute,
|
||||
and otherwise use this product alone or in any derivative version,
|
||||
provided, however, that copyright holders License Agreement and
|
||||
copyright holders notice of copyright are retained in this product
|
||||
alone or in any derivative version prepared by Licensee.
|
||||
|
||||
3. In the event Licensee prepares a derivative work that is based on
|
||||
or incorporates this product or any part thereof, and wants to make
|
||||
the derivative work available to others as provided herein, then
|
||||
Licensee hereby agrees to include in any such work a brief summary of
|
||||
the changes made to this product.
|
||||
|
||||
4. The copyright holder is making this product available to Licensee
|
||||
on an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS
|
||||
OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT
|
||||
LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY
|
||||
REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR
|
||||
ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS PRODUCT WILL
|
||||
NOT INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
|
||||
5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY
|
||||
OTHER USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR
|
||||
CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING,
|
||||
DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY
|
||||
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
THEREOF.
|
||||
|
||||
6. This License Agreement will automatically terminate upon a
|
||||
material breach of its terms and conditions.
|
||||
|
||||
7. Nothing in this License Agreement shall be deemed to create any
|
||||
relationship of agency, partnership, or joint venture between the
|
||||
copyright holder and Licensee. This License Agreement does not grant
|
||||
permission to use trademarks or trade names from the copyright holder
|
||||
in a trademark sense to endorse or promote products or services of
|
||||
Licensee, or any third party.
|
||||
|
||||
8. By copying, installing or otherwise using this product, Licensee
|
||||
agrees to be bound by the terms and conditions of this License
|
||||
Agreement.
|
@ -1,295 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
# $Id: motelist-z1,v 1.1 2010/08/24 15:48:20 joxe Exp $
|
||||
# @author Cory Sharp <cory@moteiv.com>
|
||||
# @author Joe Polastre
|
||||
|
||||
my $help = <<'EOF';
|
||||
usage: motelist [options]
|
||||
|
||||
$Revision: 1.1 $
|
||||
|
||||
options:
|
||||
-h display this help
|
||||
-c compact format, not pretty but easier for parsing
|
||||
-f specify the usb-serial file (for smote.cs)
|
||||
-k kernel version: 2.4, 2.6, auto (default)
|
||||
-m method to scan usb: procfs, sysfs, auto (default)
|
||||
-dev_prefix force the device prefix for the serial device
|
||||
-usb display extra usb information
|
||||
-b specify which Zolertia board to list (z1, remote, etc)
|
||||
EOF
|
||||
|
||||
my %Opt = (
|
||||
compact => 0,
|
||||
usb => 0,
|
||||
board => "",
|
||||
method => "auto",
|
||||
kernel => "auto",
|
||||
dev_prefix => [ "/dev/usb/tts/", "/dev/ttyUSB", "/dev/tts/USB" ],
|
||||
usbserial => "sudo cat /proc/tty/driver/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; }
|
||||
elsif( $opt eq "-f" ) { $Opt{usbserial} = shift @ARGV; }
|
||||
elsif( $opt eq "-k" ) { $Opt{kernel} = shift @ARGV; }
|
||||
elsif( $opt eq "-m" ) { $Opt{method} = shift @ARGV; }
|
||||
elsif( $opt eq "-dev_prefix" ) { $Opt{dev_prefix} = shift @ARGV; }
|
||||
elsif( $opt eq "-usb" ) { $Opt{usb} = 1; }
|
||||
elsif( $opt eq "-b" ) { $Opt{board} = shift @ARGV; }
|
||||
else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; }
|
||||
}
|
||||
|
||||
if( $Opt{kernel} eq "auto" ) {
|
||||
$Opt{kernel} = "unknown";
|
||||
$Opt{kernel} = $1 if snarf("/proc/version") =~ /\bLinux version (\d+\.\d+)/;
|
||||
}
|
||||
|
||||
if( $Opt{method} eq "auto" ) {
|
||||
$Opt{method} = ($Opt{kernel} eq "2.4") ? "procfs" : "sysfs";
|
||||
}
|
||||
|
||||
if( $Opt{board} eq "z1" ) {
|
||||
$Opt{board} = "Zolertia Z1";
|
||||
} elsif( $Opt{board} eq "remote" ) {
|
||||
$Opt{board} = "Zolertia RE-Mote platform";
|
||||
} elsif( $Opt{board} eq "firefly" ) {
|
||||
$Opt{board} = "Zolertia Firefly platform";
|
||||
} elsif( $Opt{board} eq "orion" ) {
|
||||
$Opt{board} = "Zolertia Orion Ethernet router";
|
||||
}
|
||||
|
||||
my @devs = $Opt{method} eq "procfs" ? scan_procfs() : scan_sysfs();
|
||||
print_motelist( sort { cmp_usbdev($a,$b) } @devs );
|
||||
|
||||
|
||||
#
|
||||
# SysFS
|
||||
#
|
||||
sub scan_sysfs {
|
||||
|
||||
my $tmp = '($_->{UsbVendor}||"") eq "10c4" && ($_->{UsbProduct}||"") eq "ea60"';
|
||||
|
||||
if($Opt{board}) {
|
||||
$tmp = '($_->{ProductString}||"") eq $Opt{board} && ' . $tmp
|
||||
}
|
||||
|
||||
# Scan /sys/bus/usb/drivers/usb for CP210x devices
|
||||
my @cpdevs =
|
||||
grep { eval "$tmp" }
|
||||
map { {
|
||||
SysPath => $_,
|
||||
UsbVendor => snarf("$_/idVendor",1),
|
||||
UsbProduct => snarf("$_/idProduct",1),
|
||||
ProductString => snarf("$_/product",1),
|
||||
} }
|
||||
glob("/sys/bus/usb/drivers/usb/*");
|
||||
|
||||
# Gather information about each CP210x device
|
||||
for my $f (@cpdevs) {
|
||||
my $syspath = $f->{SysPath};
|
||||
$f->{InfoSerial} = snarf("$syspath/serial",1);
|
||||
$f->{InfoManufacturer} = snarf("$syspath/manufacturer",1);
|
||||
$f->{InfoProduct} = snarf("$syspath/product",1);
|
||||
$f->{UsbDevNum} = snarf("$syspath/devnum",1);
|
||||
|
||||
my $devstr = readlink($syspath);
|
||||
if( $devstr =~ m{([^/]+)/usb(\d+)/.*-([^/]+)$} ) {
|
||||
$f->{UsbPath} = "usb-$1-$3";
|
||||
$f->{UsbBusNum} = $2;
|
||||
}
|
||||
($f->{SysDev} = $syspath) =~ s{^.*/}{};
|
||||
|
||||
my $port = "$syspath/$f->{SysDev}:1.0";
|
||||
($f->{DriverName} = readlink("$port/driver")) =~ s{^.*/}{} if -l "$port/driver";
|
||||
($f->{SerialDevName} = (glob("$port/tty*"),undef)[0]) =~ s{^.*/}{};
|
||||
$f->{SerialDevNum} = $1 if $f->{SerialDevName} =~ /(\d+)/;
|
||||
$f->{SerialDevName} = getSerialDevName( $f->{SerialDevNum} ) || " (none)";
|
||||
}
|
||||
return @cpdevs;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Scan Procfs
|
||||
#
|
||||
sub scan_procfs {
|
||||
|
||||
my $text_devs = snarf("< /proc/bus/usb/devices");
|
||||
my $text_serial = snarf($Opt{usbserial});
|
||||
|
||||
my @usbdevs = map { {parse_usb_devices_text($_)} }
|
||||
grep { !/^\s*$/ } split /\n+(?=T:)/, $text_devs;
|
||||
my %usbtree = build_usb_tree( @usbdevs );
|
||||
my %usbserialtree = build_usbserial_tree( $text_serial );
|
||||
for my $tts ( values %usbserialtree ) {
|
||||
$usbtree{usbkey($tts->{path})}{usbserial} = $tts if defined $tts->{path};
|
||||
}
|
||||
|
||||
my @cpdevs = map { {
|
||||
UsbVendor => $_->{Vendor},
|
||||
UsbProduct => $_->{ProdID},
|
||||
InfoManufacturer => $_->{Manufacturer},
|
||||
InfoProduct => $_->{Product},
|
||||
InfoSerial => $_->{SerialNumber},
|
||||
UsbBusNum => $_->{nbus},
|
||||
UsbDevNum => $_->{ndev},
|
||||
UsbPath => (($Opt{kernel} eq "2.4") ? $_->{usbserial}{path} : $_->{usbpath}),
|
||||
DriverName => $_->{driver},
|
||||
SerialDevNum => $_->{usbserial}{tts},
|
||||
SerialDevName => getSerialDevName($_->{usbserial}{tts}) || " (none)",
|
||||
} }
|
||||
grep { ($_->{Vendor}||"") eq "0403" && ($_->{ProdID}||"") eq "6001" }
|
||||
values %usbtree;
|
||||
|
||||
return @cpdevs;
|
||||
}
|
||||
|
||||
sub build_usb_tree {
|
||||
my @devs = @_;
|
||||
my %tree = ();
|
||||
for my $dev (sort { $a->{Lev} <=> $b->{Lev} } @devs) {
|
||||
my ($bus,$lev,$prnt) = ( $dev->{Bus}+0, $dev->{Lev}+0, $dev->{Prnt}+0 );
|
||||
my $devnum = $dev->{"Dev#"}+0;
|
||||
$dev->{nbus} = $bus;
|
||||
$dev->{ndev} = $devnum;
|
||||
$tree{"bus$bus"} = {} unless exists $tree{"bus$bus"};
|
||||
$tree{"bus$bus"}{"dev$devnum"} = $dev;
|
||||
if( $lev == 0 ) {
|
||||
$dev->{usbpath} = "usb-$dev->{SerialNumber}";
|
||||
} else {
|
||||
my $sep = ($lev==1) ? "-" : ".";
|
||||
$dev->{parent} = $tree{"bus$bus"}{"dev$prnt"};
|
||||
$dev->{usbpath} = $dev->{parent}{usbpath} . $sep . ($dev->{Port}+1);
|
||||
}
|
||||
$tree{usbkey($dev->{usbpath})} = $dev;
|
||||
}
|
||||
return %tree;
|
||||
}
|
||||
|
||||
sub parse_usb_devices_text {
|
||||
my $text = shift;
|
||||
$text =~ s/^\S+\s*//gm;
|
||||
return ($text =~ m/([^\s=]+)=\s*(.*?\S)\s*(?=[^\s=]+=|$)/mg);
|
||||
}
|
||||
|
||||
sub build_usbserial_tree {
|
||||
my $text = shift;
|
||||
my %tree = ();
|
||||
while( $text =~ /^([^:]+):(.*)/mg ) {
|
||||
my ($tts,$params) = ($1,$2);
|
||||
$tree{$tts} = { tts => $tts };
|
||||
while ($params =~ m/\s+([^:]+):(?:"([^"]*)"|(\S+))/g) {
|
||||
$tree{$tts}{$1} = $2||$3;
|
||||
}
|
||||
}
|
||||
return %tree;
|
||||
}
|
||||
|
||||
sub usbkey {
|
||||
if( $Opt{kernel} eq "2.4" ) {
|
||||
(my $key = $_[0]) =~ s/^.*-//;
|
||||
return $key;
|
||||
}
|
||||
return $_[0];
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# getSerialDevName
|
||||
#
|
||||
# For each device, force to use dev_prefix if it's not an array. Otherwise,
|
||||
# assume it's a list of candidate prefixes. Check them and commit to the
|
||||
# first one that actually exists.
|
||||
#
|
||||
sub getSerialDevName {
|
||||
my $devnum = shift;
|
||||
my $devname = undef;
|
||||
if( defined $devnum ) {
|
||||
if( ref($Opt{dev_prefix}) eq "ARRAY" ) {
|
||||
$devname = $devnum;
|
||||
for my $prefix (@{$Opt{dev_prefix}}) {
|
||||
my $file = $prefix . $devnum;
|
||||
if( -e $file ) { $devname = $file; last; }
|
||||
}
|
||||
} else {
|
||||
$devname = $Opt{dev_prefix} . $devnum;
|
||||
}
|
||||
}
|
||||
return $devname;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# 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} ) {
|
||||
if( $Opt{usb} ) {
|
||||
print << "EOF" unless $Opt{compact};
|
||||
--- --- ------------------------ -------------- ---------------- -------------------------------------
|
||||
Bus Dev USB Path Reference Device Description
|
||||
--- --- ------------------------ -------------- ---------------- -------------------------------------
|
||||
EOF
|
||||
} else {
|
||||
print << "EOF" unless $Opt{compact};
|
||||
-------------- ---------------- ---------------------------------------------
|
||||
Reference Device Description
|
||||
-------------- ---------------- ---------------------------------------------
|
||||
EOF
|
||||
}
|
||||
}
|
||||
|
||||
# Print the usb information
|
||||
for my $dev (sort { cmp_usbdev($a,$b) } @devs) {
|
||||
my $desc = join( " ", $dev->{InfoManufacturer}||"", $dev->{InfoProduct}||"" ) || " (none)";
|
||||
my @output = ( $dev->{InfoSerial}||" (none)", $dev->{SerialDevName}, $desc );
|
||||
@output = ( $dev->{UsbBusNum}, $dev->{UsbDevNum}, $dev->{UsbPath}, @output ) if $Opt{usb};
|
||||
if( $Opt{compact} ) {
|
||||
print join(",",@output) . "\n";
|
||||
} else {
|
||||
printf( ($Opt{usb}?"%3d %3d %-24s ":"")."%-14s %-16s %s\n", @output );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Cmp Usbdev's
|
||||
#
|
||||
sub cmp_usbdev {
|
||||
my ($a,$b) = @_;
|
||||
if( defined $a->{SerialDevNum} ) {
|
||||
if( defined $b->{SerialDevNum} ) {
|
||||
return $a->{SerialDevNum} <=> $b->{SerialDevNum};
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 1 if defined $b->{SerialDevNum};
|
||||
return ($a->{InfoSerial}||"") cmp ($b->{InfoSerial}||"");
|
||||
}
|
||||
|
||||
#
|
||||
# Read a file in
|
||||
#
|
||||
sub snarf {
|
||||
open my $fh, $_[0] or return undef;
|
||||
my $text = do{local $/;<$fh>};
|
||||
close $fh;
|
||||
$text =~ s/\s+$// if $_[1];
|
||||
return $text;
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
#!/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.SLAB" ],
|
||||
);
|
||||
|
||||
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.SLAB*
|
||||
#
|
||||
sub scan_dev {
|
||||
my @devs;
|
||||
foreach (`ls /dev/tty.SLAB* 2>&1`) {
|
||||
my($dev, $serial) = /(\/dev\/tty.SLAB(\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 );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user