Sky motelist support for MacOS X

This commit is contained in:
Laurent Deru 2012-04-03 14:59:36 +02:00 committed by Niclas Finne
parent a4813d815f
commit cc863e7bd4
2 changed files with 128 additions and 31 deletions

View File

@ -58,27 +58,49 @@ ifeq ($(HOST_OS),Windows)
CMOTES = $(shell $(MOTELIST) | grep COM | \
cut -f 4 -d \ | \
perl -ne 'print $$1 . " " if(/COM(\d+)/);')
endif
# If we are not running under Windows, we assume Linux
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-linux
TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)
ifeq ($(TMOTE_BSL), 1)
PATH := $(PATH):$(CONTIKI)/tools/sky
BSL = $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)
NUMPAR = 1
else
BSL = $(CONTIKI)/tools/sky/msp430-bsl-linux --telosb
BSL_FILETYPE = -I
else
ifeq ($(HOST_OS),Darwin)
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-macos
TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)
ifeq ($(TMOTE_BSL), 1)
PATH := $(PATH):$(CONTIKI)/tools/sky
BSL = $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)
NUMPAR = 1
else
BSL = $(CONTIKI)/tools/sky/msp430-bsl-linux --telosb
BSL_FILETYPE = -I
endif
MOTES = $(shell $(MOTELIST) 2>&- | grep usbserial | \
cut -f 4 -d \ | \
perl -ne 'print $$1 . " " if(m-(/dev/[\w+\.\-]+)-);')
CMOTES=$(MOTES)
endif
MOTES = $(shell $(MOTELIST) 2>&- | grep USB | \
cut -f 4 -d \ | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
CMOTES=$(MOTES)
else
# Else we assume Linux
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-linux
TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)
ifeq ($(TMOTE_BSL), 1)
PATH := $(PATH):$(CONTIKI)/tools/sky
BSL = $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)
NUMPAR = 1
else
BSL = $(CONTIKI)/tools/sky/msp430-bsl-linux --telosb
BSL_FILETYPE = -I
endif
MOTES = $(shell $(MOTELIST) 2>&- | grep USB | \
cut -f 4 -d \ | \
perl -ne 'print $$1 . " " if(m-(/dev/[\w+\.\-]+)-);')
CMOTES=$(MOTES)
endif
endif
endif
motelist: sky-motelist
@ -91,7 +113,7 @@ sky-motes:
ifdef MOTE
%.upload: %.ihex
cp $< $(IHEXFILE)
$(MAKE) sky-u.$(subst /,-,$(word $(MOTE), $(MOTES)))
$(MAKE) sky-u.$(subst /,_,$(word $(MOTE), $(MOTES)))
else # MOTE
%.upload: %.ihex
cp $< $(IHEXFILE)
@ -103,7 +125,7 @@ ifdef FILE
@echo Uploading $(FILE)
cp $(FILE) $(IHEXFILE)
ifdef MOTE
$(MAKE) sky-u.$(subst /,-,$(word $(MOTE), $(MOTES)))
$(MAKE) sky-u.$(subst /,_,$(word $(MOTE), $(MOTES)))
else # MOTE
$(MAKE) sky-reset sky-upload
endif # MOTE
@ -114,25 +136,25 @@ endif
sky-upload: sky-reset
$(MAKE) -j $(NUMPAR) sky-upload-sequence
sky-upload-sequence: $(foreach PORT, $(MOTES), sky-u.$(subst /,-,$(PORT)))
sky-upload-sequence: $(foreach PORT, $(MOTES), sky-u.$(subst /,_,$(PORT)))
@echo Done
sky-reset:
$(MAKE) -k -j $(NUMPAR) sky-reset-sequence
sky-reset-sequence: $(foreach PORT, $(MOTES), sky-r.$(subst /,-,$(PORT)))
sky-reset-sequence: $(foreach PORT, $(MOTES), sky-r.$(subst /,_,$(PORT)))
@echo Done
sky-u.%:
@echo +++++ Erasing $(subst -,/,$*); \
$(BSL) -c $(subst -,/,$*) -e && sleep 2 ; \
echo +++++ Programming $(subst -,/,$*) ; \
$(BSL) -c $(subst -,/,$*) $(BSL_FILETYPE) -p $(IHEXFILE) && sleep 2 ; \
echo +++++ Resetting $(subst -,/,$*) ; \
$(BSL) -c $(subst -,/,$*) -r
@echo +++++ Erasing $(subst _,/,$*); \
$(BSL) -c $(subst _,/,$*) -e && sleep 2 ; \
echo +++++ Programming $(subst _,/,$*) ; \
$(BSL) -c $(subst _,/,$*) $(BSL_FILETYPE) -p $(IHEXFILE) && sleep 2 ; \
echo +++++ Resetting $(subst _,/,$*) ; \
$(BSL) -c $(subst _,/,$*) -r
sky-r.%:
$(BSL) -c $(subst -,/,$*) -r
$(BSL) -c $(subst _,/,$*) -r
sizeplot:
msp430-size $(OBJECTDIR)/*.o | $(CONTIKI)/tools/sky/check-size > size-data

75
tools/sky/motelist-macos Executable file
View 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.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 );
}
}
}