add back zolertia tool folder
This commit is contained in:
parent
f35a7a2f36
commit
8b8798ada9
62
tools/zolertia/license-bsl.txt
Normal file
62
tools/zolertia/license-bsl.txt
Normal file
@ -0,0 +1,62 @@
|
||||
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.
|
295
tools/zolertia/motelist-zolertia
Executable file
295
tools/zolertia/motelist-zolertia
Executable file
@ -0,0 +1,295 @@
|
||||
#!/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;
|
||||
}
|
||||
|
75
tools/zolertia/motelist-zolertia-macos
Executable file
75
tools/zolertia/motelist-zolertia-macos
Executable file
@ -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.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 );
|
||||
}
|
||||
}
|
||||
}
|
1929
tools/zolertia/z1-bsl
Executable file
1929
tools/zolertia/z1-bsl
Executable file
File diff suppressed because it is too large
Load Diff
1941
tools/zolertia/z1-bsl-nopic
Executable file
1941
tools/zolertia/z1-bsl-nopic
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user