Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
schneider 2012-05-01 10:48:17 +08:00
commit 132b11a47a
19 changed files with 352 additions and 71 deletions

View File

@ -14,5 +14,6 @@ h->r:\5<CHANNEL>\0
r->h: \2\0 r->h: \2\0
h->r:\6<MACLEN>\0 h->r:\6<MACLEN>\0
r->h: \2\0 r->h: \2\0
h->r:\7\0
r->h: \7<UUID>\0

View File

@ -99,6 +99,14 @@ void main_bridge(void)
config.maclen[0]=serialmsg_message[0]; config.maclen[0]=serialmsg_message[0];
nrf_config_set(&config); nrf_config_set(&config);
break; break;
case '7':
puts("\\7");
char s[sizeof(uint32_t)+1];
*((uint32_t*)s) =GetUUID32();
s[sizeof(uint32_t)]=0;
puts(s);
puts("\\0");
break;
}; };
puts("\\2\\0"); puts("\\2\\0");
} }

View File

@ -8,7 +8,7 @@
uint32_t uuid32=0; uint32_t uuid32=0;
uint16_t uuid16=0; uint16_t uuid16=0;
uint32_t __GetUUID32(void){ static uint32_t __GetUUID32(void){
IAP_return_t iap_return; IAP_return_t iap_return;
iap_return = iapReadSerialNumber(); iap_return = iapReadSerialNumber();
if (iap_return.ReturnCode == 0){ if (iap_return.ReturnCode == 0){
@ -24,28 +24,22 @@ uint32_t __GetUUID32(void){
}; };
// What OpenBeacon used. Do we want this? // What OpenBeacon used. Do we want this?
uint16_t __GetUUID16(void){ static uint16_t __GetUUID16(void){
IAP_return_t iap_return; IAP_return_t iap_return;
iap_return = iapReadSerialNumber(); iap_return = iapReadSerialNumber();
return crc16 ((uint8_t *) iap_return.Result, sizeof (iap_return.Result)); return crc16 ((uint8_t *) iap_return.Result, sizeof (iap_return.Result));
}; };
uint32_t initUUID(void){ void initUUID(void){
uuid32=__GetUUID32(); uuid32=__GetUUID32();
uuid16=__GetUUID16(); uuid16=__GetUUID16();
}; };
uint32_t GetUUID32(void){ uint32_t GetUUID32(void){
if(uuid32==0){
initUUID();
};
return uuid32; return uuid32;
}; };
uint16_t GetUUID16(void){ uint16_t GetUUID16(void){
if(uuid32==0){
initUUID();
};
return uuid16; return uuid16;
}; };

View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
uint32_t GetUUID32(void); uint32_t GetUUID32(void);
void initUUID(void);
#endif #endif

View File

@ -103,11 +103,18 @@ int readFile(char * filename, char * data, int len){
}; };
int readTextFile(char * filename, char * data, int len){ int readTextFile(char * filename, char * data, int len){
UINT readbytes; int readbytes;
if(len<1) return -1;
readbytes=readFile(filename,data,len-1); readbytes=readFile(filename,data,len-1);
if(len>=0) if(readbytes<0){
data[0]=0;
return readbytes;
};
data[readbytes]=0; data[readbytes]=0;
while(readbytes>0 && data[readbytes-1]<0x20){
data[--readbytes]=0;
};
return readbytes; return readbytes;
}; };

Binary file not shown.

Binary file not shown.

View File

@ -384,7 +384,7 @@ int DoChar(int sx, int sy, int c){
}; };
#define UTF8 #define UTF8
// decode 2 and 4-byte utf-8 strings. // decode 2 and 3-byte utf-8 strings.
#define UT2(a) ( ((a[0]&31)<<6) + (a[1]&63) ) #define UT2(a) ( ((a[0]&31)<<6) + (a[1]&63) )
#define UT3(a) ( ((a[0]&15)<<12) + ((a[1]&63)<<6) + (a[2]&63) ) #define UT3(a) ( ((a[0]&15)<<12) + ((a[1]&63)<<6) + (a[2]&63) )

View File

@ -50,6 +50,7 @@ void main(void) {
// initialise basic badge functions // initialise basic badge functions
rbInit(); rbInit();
initUUID(); // Cache UUID values.
lcdInit(); // display lcdInit(); // display
@ -80,5 +81,5 @@ void main(void) {
} }
int getrelease(void){ int getrelease(void){
return 0x0000010d; return 0x0000010e;
}; };

1
tools/mesh/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
BEACON

190
tools/mesh/beacon-udp.pl Executable file
View File

@ -0,0 +1,190 @@
#!/usr/bin/perl
#
# vim:set ts=4 sw=4:
use strict;
use warnings;
use POSIX qw(strftime);
#use Time::HiRes qw(time);
use Digest::CRC qw(crcccitt);
use FindBin;
use lib "$FindBin::Bin/lib";
use r0ket;
$|=1;
use Getopt::Long;
my $server = "127.0.0.1";
my $port = 2342;
my $id = 1234;
my $verbose = 0;
my $fast = 0;
my $channel = 81;
my $mac = "0102030201";
my $ser = undef;
my $help = 0;
my $intvl = 2;
my $lintvl = 60;
GetOptions (
"server=s" => \$server,
"port=n" => \$port,
"id=n" => \$id,
"dev=s" => \$ser,
"fast" => \$fast,
"verbose" => \$verbose,
"channel=n" => \$channel,
"mac=s" => \$mac,
"help" => \$help,
);
if($help){
die "Currently no help. Please check the source\n";
};
$ser=r0ket::r0ket_init($ser);
# Default openbeacon settings.
r0ket::set_txmac(pack("H*",$mac)); # Not really needed.
r0ket::set_rxmac(pack("H*",$mac));
r0ket::set_channel($channel);
r0ket::set_rxlen(16);
$r0ket::quiet=1; # Hackety-hack :)
my %bdata;
use Socket;
use Sys::Hostname;
my($iaddr,$proto,$paddr);
$iaddr = gethostbyname(hostname());
$iaddr = pack('C4', 0,0,0,0);
$proto = getprotobyname('udp');
$paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
bind(SOCKET, $paddr) || die "bind: $!";
my $hisiaddr = inet_aton($server) || die "unknown server name";
my $hispaddr = sockaddr_in($port, $hisiaddr);
###send(SOCKET, 0, 0, $hispaddr);
my $xterm=0;
my $screen=1;
my $crcerr=0;
my $errors=0;
my $ctr=0;
my($lcrcerr,$lctr,$lerrors)=(0,0,0);
if($verbose){
my($dev)=$ser;
if(!defined $dev){
$dev="<undef>";
}else{
$dev=~s!/dev/!!;
};
print "OpenBeacon Reader $id sending [$dev] to [$server:$port]\n";
if($xterm){
print "\e]2;",
"$id\[$dev] -> $server:$port @ ",
strftime("%Y-%m-%d %H:%M:%S ",localtime),
"\a";
}elsif($screen){
print "\ek",
"$id\[$dev]",
"\e\\";
};
print "\n";
};
sub interrupt {
if($xterm){
print "\e]2;", "<exit>", "\a";
}elsif($screen){
print "\ek", `hostname`, "\e\\";
};
exit;
}
if($verbose){
$SIG{INT} = \&interrupt;
};
my $lasttime=time;
my $llasttime=time;
my $pkt;
my $donl=0;
my($typenick,$typebeacon,$typeunknown)=(0,0,0);
my($ltypenick,$ltypebeacon,$ltypeunknown)=(0,0,0);
while(1){
$pkt=r0ket::get_packet();
if($verbose){
if(time-$lasttime >= $intvl){
print "\r";
if(time-$llasttime >= $lintvl){
$donl=1;
$llasttime=time;
};
$lasttime=time;
print strftime("%Y-%m-%d %H:%M:%S ",localtime);
printf "[%ds] cnt=%3d [b=%3d, n=%3d, ?=%3d] errs=%3d crcerr=%3d ",
$intvl,
($ctr-$lctr),
($typebeacon-$ltypebeacon),
($typenick-$ltypenick),
($typeunknown-$ltypeunknown),
($errors-$lerrors),
($crcerr-$lcrcerr);
($lctr,$lerrors,$lcrcerr)= ($ctr,$errors,$crcerr);
($ltypenick,$ltypebeacon,$ltypeunknown)= ($typenick,$typebeacon,$typeunknown);
if($donl){
$donl=0;
print "\n";
};
};
};
next if($pkt eq "ack"); # in-band signalling.
if(length($pkt) != 16){ # Sanity check
$errors++;
next;
};
$ctr++;
my $idoff=0;
if(substr($pkt,12,1) eq "\xee"){
$idoff=1000;
};
my $hdr= pack("CCnnNN",
1, # proto (BEACONLOG_SIGHTING)
0, # interface (we only have one antenna per "reader")
$id+$idoff, # readerid
length($pkt)+16, # size
$ctr, # sequence
time # timestamp
);
my $crc=pack("n",0xffff ^ crcccitt($hdr.$pkt));
send(SOCKET, $crc.$hdr.$pkt,0,$hispaddr);
next if($fast);
my $p=r0ket::nice_beacon($pkt);
if($p->{crc} ne "ok"){
$crcerr++;
next;
};
if($p->{type} eq "beacon"){
$typebeacon++;
}elsif($p->{type} eq "nick"){
$typenick++;
}else{
$typeunknown++;
};
if($idoff){
$typeunknown++;
};
};
r0ket::rest();

View File

@ -7,12 +7,18 @@ use Curses;
use POSIX qw(strftime); use POSIX qw(strftime);
use Time::HiRes qw(time); use Time::HiRes qw(time);
use lib '.'; use FindBin;
use lib "$FindBin::Bin/lib";
use r0ket; use r0ket;
$|=1; $|=1;
r0ket::r0ket_init(); my $ser;
if($ARGV[0] eq "-d"){
shift;
$ser=shift;
};
r0ket::r0ket_init($ser);
# Default openbeacon settings. # Default openbeacon settings.
r0ket::set_txmac(pack("H*","0102030201")); r0ket::set_txmac(pack("H*","0102030201"));

View File

@ -13,12 +13,20 @@ use Time::HiRes;
our $verbose=0; our $verbose=0;
our $bridge; # Open device our $bridge; # Open device
our $quiet=0;
our $timediff=60*60*2;
my $rxlen=0; # Filter for get_pkt()
### Utility ### Utility
sub sprint{ sub sprint{
return join("",map { return join("",map {
if (ord($_)>30 && ord($_)<127){ if (ord($_)>30 && ord($_)<127){
if(ord($_)==92){
"\\\\";
}else{
$_; $_;
};
}else{ }else{
# "[x".unpack("H*",$_)."]"; # "[x".unpack("H*",$_)."]";
"\\".unpack("C",$_); "\\".unpack("C",$_);
@ -91,8 +99,9 @@ sub writebeacon{
### Packet mgmt ### Packet mgmt
our $buffer; our $buffer;
our $firstpkt=2; our $firstpkt=1;
sub get_packet{ sub get_data{
my $filter=shift||0;
sub _get_bytes{ sub _get_bytes{
my $rr; my $rr;
sysread($bridge,$rr,1024); sysread($bridge,$rr,1024);
@ -100,35 +109,57 @@ sub get_packet{
select(undef,undef,undef,0.05); select(undef,undef,undef,0.05);
}; };
$buffer.=$rr; $buffer.=$rr;
# print "recv: ",unpack("H*",$rr),"\n";
}; };
my $cnt=0; my $cnt=0;
while(++$cnt<100){ while(1){
if(length($buffer)<2){ if(length($buffer)<2){
_get_bytes(); _get_bytes();
}elsif($buffer !~ /^\\[12]/){ }elsif($buffer !~ /^\\[1-9]/){
$buffer=~s/^(.[^\\]*)//s; if($buffer =~ /[^\\]\\[1-9]/){
$buffer =~ s/^(.*?[^\\])(\\[1-9])/\2/s;
}else{
$buffer = s/(.*)//s;
};
if($firstpkt){ if($firstpkt){
$firstpkt--; $firstpkt--;
}else{ }else{
print STDERR "Unparseable stuff: <",sprint($1),">\n"; print STDERR "Unparseable stuff: <",sprint($1),">\n" if(!$quiet);
}; };
}elsif ($buffer =~ s/^\\2\\0//s){ }elsif ($buffer =~ s/^\\(\d)(.*?)\\0//s){
return 'ack'; # In-band signalling. Evil %) my ($type,$str)=($1,$2);
}elsif ($buffer =~ s/^\\1(.*?)\\0//s){
my $str=$1;
$str=~s/\\\\/\\/g; # dequote $str=~s/\\\\/\\/g; # dequote
# print STDERR "ret:pkt[$type]=",(sprint $str),"\n";
if($filter==0){
return ($type,$str);
}elsif($filter==$type){
return $str; return $str;
};
}else{ }else{
_get_bytes(); _get_bytes();
}; };
if(++$cnt%100 == 0){
if(!$quiet){
print STDERR "No packets for 5 seconds?\n";
};
};
};
};
sub get_packet{
my $pkt;
while(1){
$pkt=get_data(1);
if($rxlen==0 || length($pkt)==$rxlen){
return $pkt;
};
}; };
die "No packets for 5seconds?\n";
}; };
sub rest{ sub rest{
if(length($buffer)>0){ if(length($buffer)>0){
print "rest: <", sprint($buffer), ">\n"; print "rest: <", sprint($buffer), ">\n" if(!$quiet);
}; };
}; };
@ -149,7 +180,7 @@ sub nice_mesh{
$out->{string}.=sprintf " t=%s (%+4d) rel=%s beacon=%s", $out->{string}.=sprintf " t=%s (%+4d) rel=%s beacon=%s",
strftime("%Y-%m-%d %H:%M:%S",gmtime $out->{time}), strftime("%Y-%m-%d %H:%M:%S",gmtime $out->{time}),
$out->{time}-(Time::HiRes::time+3600), $out->{time}-(Time::HiRes::time+$timediff),
$out->{release}, $out->{release},
resolvebeacon($out->{beacon}); resolvebeacon($out->{beacon});
}elsif($type eq "i"){ }elsif($type eq "i"){
@ -255,7 +286,7 @@ sub nice_beacon{
$out->{idx}, $out->{idx},
$out->{beacon}; $out->{beacon};
if(unpack("H*",substr($pkt,12,2)) ne "ffff"){ if(unpack("H*",substr($pkt,12,2)) ne "ffff"){
print "unused=",unpack("H*",substr($pkt,12,2))," "; print "unused=",unpack("H*",substr($pkt,12,2))," " if (!$quiet);
}; };
}elsif($type eq "\x23"){ }elsif($type eq "\x23"){
$out->{type}= "nick"; $out->{type}= "nick";
@ -265,6 +296,7 @@ sub nice_beacon{
$out->{string}=sprintf "NICK beacon=%s nick=%s", $out->{string}=sprintf "NICK beacon=%s nick=%s",
$out->{beacon}, $out->{beacon},
$out->{nick}; $out->{nick};
addbeacon($out->{beacon},$out->{nick});
}else{ }else{
$out->{string}="<?:".unpack("H*",$pkt).">"; $out->{string}="<?:".unpack("H*",$pkt).">";
}; };
@ -283,11 +315,7 @@ sub nice_beacon{
}; };
sub r0ket_init{ sub r0ket_init{
my $ser; my $ser=shift;
if ($ARGV[0] eq "-s"){
shift;
$ser=shift;
};
if(!defined $ser){ if(!defined $ser){
if (defined $ENV{R0KETBRIDGE} && -e $ENV{R0KETBRIDGE}){ if (defined $ENV{R0KETBRIDGE} && -e $ENV{R0KETBRIDGE}){
$ser=$ENV{R0KETBRIDGE} $ser=$ENV{R0KETBRIDGE}
@ -300,6 +328,7 @@ sub r0ket_init{
if($verbose){ if($verbose){
print "using: $ser\n"; print "using: $ser\n";
}; };
return $ser;
}; };
sub send_raw { sub send_raw {
@ -329,15 +358,16 @@ sub set_channel {
send_pkt_num(pack("C",shift),5); send_pkt_num(pack("C",shift),5);
}; };
sub set_rxlen { sub set_rxlen {
$rxlen=$_[0];
send_pkt_num(pack("C",shift),6); send_pkt_num(pack("C",shift),6);
}; };
sub wait_ok { sub wait_ok {
my $pkt; my ($type,$pkt);
$pkt=get_packet(); ($type,$pkt)=get_data();
while($pkt ne "ack"){ while($type ne "2"){
print "pkt=",(sprint $pkt),"\n"; print "pkt[$type]=[",length($pkt),"]",(sprint $pkt),"\n";
$pkt=get_packet(); ($type,$pkt)=get_data();
}; };
print "ok!\n"; print "ok!\n";
return 1; return 1;

View File

@ -6,12 +6,18 @@ use strict;
use Curses; use Curses;
use POSIX qw(strftime); use POSIX qw(strftime);
use lib '.'; use FindBin;
use lib "$FindBin::Bin/lib";
use r0ket; use r0ket;
$|=1; $|=1;
r0ket::r0ket_init(); my $ser;
if($ARGV[0] eq "-d"){
shift;
$ser=shift;
};
r0ket::r0ket_init($ser);
# Default mesh settings. # Default mesh settings.
r0ket::set_txmac("ORBIT"); r0ket::set_txmac("ORBIT");
@ -55,7 +61,7 @@ while(1){
$p->{generation}, $p->{generation},
$p->{release}, $p->{release},
strftime("%Y-%m-%d %H:%M:%S",gmtime $p->{time}), strftime("%Y-%m-%d %H:%M:%S",gmtime $p->{time}),
$p->{time}-(time+3600), $p->{time}-(time+$r0ket::timediff),
r0ket::getbeacon($p->{beacon}) r0ket::getbeacon($p->{beacon})
); );
$win->refresh; $win->refresh;

View File

@ -9,22 +9,31 @@ use Digest::CRC qw(crcccitt);
use POSIX qw(strftime); use POSIX qw(strftime);
use FindBin; use FindBin;
use lib "$FindBin::Bin"; use lib "$FindBin::Bin/lib";
use r0ket; use r0ket;
$|=1; $|=1;
r0ket::r0ket_init(); ### Commandline options
use Getopt::Long;
my $ser = undef;
my $help = 0;
my $writend = 0;
GetOptions (
"dev=s" => \$ser,
"help" => \$help,
"write" => \$writend,
);
my @fh; $help=1 if($ARGV[0] =~ /^[h?]/);
my $read;
if ($ARGV[0] =~ /^-?-?h/){ if ($help){
print STDERR "Mini-Help:\n"; print STDERR "Mini-Help:\n";
print STDERR "-s <devicename> (or \$R0KETBRIDGE)\n"; print STDERR "-d <devicename> (or \$R0KETBRIDGE)\n";
print STDERR "-w write beacon2nick file\n"; print STDERR "-w write beacon2nick file\n";
print STDERR "\n"; print STDERR "\n";
print STDERR "recv<num>: receive (number) pakets\n"; print STDERR "recv<num>: receive (number) pakets\n";
print STDERR " - r : try to autodetect packet format\n";
print STDERR " - r hex : hexdump packets\n"; print STDERR " - r hex : hexdump packets\n";
print STDERR " - r ascii : asciidump packets\n"; print STDERR " - r ascii : asciidump packets\n";
print STDERR " - r beacon : parse as openbeacon\n"; print STDERR " - r beacon : parse as openbeacon\n";
@ -47,22 +56,23 @@ if ($ARGV[0] =~ /^-?-?h/){
print STDERR "- c tx - set txmac\n"; print STDERR "- c tx - set txmac\n";
print STDERR "- c len - set rxlength\n"; print STDERR "- c len - set rxlength\n";
print STDERR "- c ch - set channel\n"; print STDERR "- c ch - set channel\n";
print STDERR "- c <opt>hex - set any option via hex string\n"; print STDERR "- c <opt>hex - set any of the previous option via hex string\n";
print STDERR "- c id - read beacon id\n";
print STDERR "\n"; print STDERR "\n";
print STDERR "etc...\n"; print STDERR "etc...\n";
exit(1); exit(1);
}; };
my $writend=0;
if ($ARGV[0] eq "-w"){
shift;
$writend=1;
};
END{ END{
r0ket::writebeacon if($writend); r0ket::writebeacon if($writend);
}; };
r0ket::r0ket_init($ser);
$r0ket::verbose=1;
my @fh;
my $read;
my $cmd=shift; my $cmd=shift;
if($cmd =~ /^r/){ if($cmd =~ /^r/){
@ -158,6 +168,10 @@ if($cmd =~ /^r/){
r0ket::set_channel(shift); r0ket::set_channel(shift);
}elsif ($set =~ /^len/){ }elsif ($set =~ /^len/){
r0ket::set_rxlen(shift); r0ket::set_rxlen(shift);
}elsif ($set =~ /^id/){
r0ket::send_pkt_num("",7);
my $id=r0ket::get_data(7);
print "r0ket id: ",r0ket::hprint($id),"\n";
}else{ }else{
die "Unknown config argument $set\n"; die "Unknown config argument $set\n";
}; };
@ -181,7 +195,7 @@ if($cmd =~ /^r/){
if($scmd eq "t"){ if($scmd eq "t"){
$pkt.="T"; $pkt.="T";
$pkt.=chr(shift); #gen $pkt.=chr(shift); #gen
$pkt.=pack("N",scalar(time)+1*60*60); $pkt.=pack("N",scalar(time)+$r0ket::timediff);
$pkt.=pack("N",0); $pkt.=pack("N",0);
$pkt.=pack("N",0); $pkt.=pack("N",0);
@ -192,7 +206,7 @@ if($cmd =~ /^r/){
}elsif($scmd eq "a"){ }elsif($scmd eq "a"){
$pkt.="A"; $pkt.="A";
$pkt.=chr(shift); #gen $pkt.=chr(shift); #gen
$pkt.=pack("N",scalar(time)+1*60*60+ 300); $pkt.=pack("N",scalar(time)+$r0ket::timediff+ 300);
$pkt.= pack("C",shift||0); $pkt.= pack("C",shift||0);
$pkt.= pack("C",0); $pkt.= pack("C",0);
@ -207,7 +221,7 @@ if($cmd =~ /^r/){
}elsif($scmd eq "b"){ }elsif($scmd eq "b"){
$pkt.="B"; $pkt.="B";
$pkt.=chr(shift); #gen $pkt.=chr(shift); #gen
$pkt.=pack("N",scalar(time)+1*60*60+ 600); $pkt.=pack("N",scalar(time)+$r0ket::timediff+ 600);
$pkt.= pack("C",shift||0); $pkt.= pack("C",shift||0);
$pkt.= pack("C",0); $pkt.= pack("C",0);
@ -222,7 +236,7 @@ if($cmd =~ /^r/){
}elsif($scmd eq "c"){ }elsif($scmd eq "c"){
$pkt.="\x1"; $pkt.="\x1";
$pkt.=chr(shift); #gen $pkt.=chr(shift); #gen
$pkt.=pack("N",scalar(time)+1*60*60+ 600); $pkt.=pack("N",scalar(time)+$r0ket::timediff+ 600);
$pkt.= pack("C",shift||0); $pkt.= pack("C",shift||0);
$pkt.= pack("C",0); $pkt.= pack("C",0);

View File

@ -1,2 +1,3 @@
firmware.bin firmware.bin
bridge.bin
files files

View File

@ -27,6 +27,11 @@ setup:
@echo @echo
@echo "Now run ./smartflash (as root)" @echo "Now run ./smartflash (as root)"
bridge:
cd ../../firmware && make APP=bridge TABLE=NO USBSERIAL=YES clean all
cp ../../firmware/bridge.bin .
sudo ./smartflash bridge.bin
run: run:
sudo ./smartflash sudo ./smartflash

View File

@ -1,3 +1,11 @@
#!/bin/sh #!/bin/sh
dd if=firmware.bin seek=4 of=/dev/$1 2>/dev/null bin=frimware.bin
if [ ! -z "$3" ] ; then
bin=$3
fi
dd if=$3 seek=4 of=/dev/$1 2>/dev/null
if [ -z "$3" ] ; then
echo "FLASH done: $1 @ $2" echo "FLASH done: $1 @ $2"
else
echo "=== FLASH of $3 done: $1 @ $2"
fi

View File

@ -5,6 +5,8 @@ $|=1;
my $DEV="/sys/bus/usb/devices"; my $DEV="/sys/bus/usb/devices";
my $arg=$ARGV[0];
sub getline{ sub getline{
my($path)=@_; my($path)=@_;
open(my $f,"<",$DEV."/".$path) || do { open(my $f,"<",$DEV."/".$path) || do {
@ -110,15 +112,21 @@ sub dwim{
return 1; return 1;
}; };
print "flash $dev -> $sdev\n"; print "flash $dev -> $sdev\n";
system("./flash $sdev $dev"); system("./flash $sdev $dev $arg");
$done{$dev}=2; $done{$dev}=2;
return 1; return 1;
};
if("$ve:$pr" eq "239a:1002") {
return 1 if $done{$dev}==3;
my $sdev=getdev($dev);
$done{$dev}=3;
print "BRIDGE r0ket @ $dev, ignoring\n";
return 0;
}; };
print "$ve:$pr [$mf] @ "; print "$ve:$pr [$mf] @ ";
return -1; return -1;
}; };
my %disable;
while(1){ while(1){
opendir(my $dh, $DEV); opendir(my $dh, $DEV);
my @paths=grep {/^[^.]/} readdir($dh); my @paths=grep {/^[^.]/} readdir($dh);
@ -126,15 +134,15 @@ while(1){
# print "f: ",join(",",@files),"\n"; # print "f: ",join(",",@files),"\n";
device: device:
for my $path (@paths){ for my $path (@paths){
next if ($disable{$path});
next if $path =~ /^usb/; next if $path =~ /^usb/;
next if $path =~ /:/; next if $path =~ /:/;
# print "p $path\n"; # print "p $path\n";
$found{$path}=1; $found{$path}=1;
my $res=dwim($path); my $res=0;
$res=dwim($path) unless ($done{$path}==-1);
if($res==-1){ if($res==-1){
print "$path -- ignoring it forever\n"; print "$path -- unknown device, skipping\n";
$disable{$path}=1; $done{$path}=-1;
}; };
}; };
for my $a (keys %done){ for my $a (keys %done){