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