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

This commit is contained in:
schneider 2011-12-27 10:30:57 +01:00
commit 6bdab57058
14 changed files with 478 additions and 12 deletions

View File

@ -19,9 +19,9 @@ MPKT meshbuffer[MESHBUFSIZE];
struct NRF_CFG oldconfig; struct NRF_CFG oldconfig;
static int meshgen_gt(char gen){ static int mesh_gt(char curgen, char newgen){
unsigned char dif=meshgen-gen; unsigned char dif=curgen-newgen;
if(meshgen==0) if(curgen==0)
return 1; return 1;
return (dif>128); return (dif>128);
}; };
@ -53,6 +53,7 @@ int mesh_sanity(uint8_t * pkt){
}; };
if(MO_TYPE(pkt)!='A' && if(MO_TYPE(pkt)!='A' &&
MO_TYPE(pkt)!='a' && MO_TYPE(pkt)!='a' &&
MO_TYPE(pkt)!='B' &&
MO_TYPE(pkt)!='E' && MO_TYPE(pkt)!='E' &&
MO_TYPE(pkt)!='F' && MO_TYPE(pkt)!='F' &&
MO_TYPE(pkt)!='G' && MO_TYPE(pkt)!='G' &&
@ -213,7 +214,7 @@ uint8_t mesh_recvqloop_work(void){
// New mesh generation? // New mesh generation?
if(MO_TYPE(buf)=='T'){ if(MO_TYPE(buf)=='T'){
if(meshgen_gt(MO_GEN(buf))){ if(mesh_gt(meshgen,MO_GEN(buf))){
meshgen=MO_GEN(buf); meshgen=MO_GEN(buf);
_timet=0; _timet=0;
meshincctr=0; meshincctr=0;
@ -241,6 +242,15 @@ uint8_t mesh_recvqloop_work(void){
// Store packet in a same/free slot // Store packet in a same/free slot
MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); MPKT* mpkt=meshGetMessage(MO_TYPE(buf));
// Propagation test
if(MO_TYPE(buf)=='B'){
if(! mesh_gt(MO_BODY(mpkt->pkt)[0],MO_BODY(buf)[0]) )
return 0;
(*(
(uint32_t*)(MO_BODY(buf)+6)
))++;
MO_TIME_set(mpkt->pkt,0);
};
#if 0 #if 0
// Schnitzel // Schnitzel
if(MO_TYPE(buf)=='Z'){ if(MO_TYPE(buf)=='Z'){

View File

@ -136,4 +136,5 @@ o_fill
o_set_shader o_set_shader
o_identity o_identity
o_transform o_transform
getrelease
#Add stuff here #Add stuff here

View File

@ -26,17 +26,19 @@ void getsp(void);
void uptime(void); void uptime(void);
void uuid(void); void uuid(void);
void lcdrtest(void); void lcdrtest(void);
void release(void);
static const struct MENU submenu_debug={ "debug", { static const struct MENU submenu_debug={ "debug", {
{ "ChkBattery", &ChkBattery}, { "ChkBattery", &ChkBattery},
{ "ChkLight", &ChkLight}, { "ChkLight", &ChkLight},
{ "MeshInfo", &m_time}, { "MeshInfo", &m_time},
{ "ChkFunk", &ChkFunk}, { "ChkFunk", &ChkFunk},
{ "Qstatus", &Qstatus}, // { "Qstatus", &Qstatus},
// { "ShowSP", &getsp}, // { "ShowSP", &getsp},
{ "lcdrtest", &lcdrtest}, { "LcdRead", &lcdrtest},
{ "Uptime", &uptime}, { "Uptime", &uptime},
{ "Uuid", &uuid}, { "Uuid", &uuid},
{ "Release", &release},
{NULL,NULL} {NULL,NULL}
}}; }};
@ -126,7 +128,7 @@ void uuid(void) {
lcdPrintln(IntToStrX(iap_return.Result[2],8)); lcdPrintln(IntToStrX(iap_return.Result[2],8));
lcdPrintln(IntToStrX(iap_return.Result[3],8)); lcdPrintln(IntToStrX(iap_return.Result[3],8));
lcdNl(); lcdNl();
lcdPrintln("Beacon ID:"); lcdPrintln("Bacon ID:");
lcdPrintln(IntToStrX(GetUUID32(),8)); lcdPrintln(IntToStrX(GetUUID32(),8));
lcdRefresh(); lcdRefresh();
while(!getInputRaw())work_queue(); while(!getInputRaw())work_queue();
@ -331,3 +333,11 @@ void lcdrtest(void){
lcdRefresh(); lcdRefresh();
while(!getInputRaw())delayms(10); while(!getInputRaw())delayms(10);
}; };
void release(){
lcdPrintln("r0ket");
lcdPrintln("Release: ");
lcdPrintln(IntToStrX(getrelease(),8));
lcdRefresh();
while(!getInputRaw())work_queue();
};

View File

@ -28,7 +28,7 @@ void ram(void) {
char buf[20]; char buf[20];
int line; int line;
char startline=0; int startline=0;
char *message=NULL; char *message=NULL;
char filvers; char filvers;
char favers[5]; char favers[5];
@ -61,7 +61,7 @@ void ram(void) {
lcdClear(); lcdClear();
DoString(0,0,"Fahrplan "); DoString(0,0,"Fahrplan ");
DoString(60,0,favers); DoString(60,0,favers);
DoString(0,16,"SW Rel. V0.002"); DoString(0,16,"SW Rel. V0.004");
if(filvers!=2) { if(filvers!=2) {
DoString(0,24,"Incompatible "); DoString(0,24,"Incompatible ");
DoString(0,32,"Binary. Get "); DoString(0,32,"Binary. Get ");
@ -76,11 +76,11 @@ void ram(void) {
} }
DoString(0,24,"On C3 get new "); DoString(0,24,"On C3 get new ");
DoString(0,32,"version from "); DoString(0,32,"version from ");
DoString(0,40,"r0ket.de for "); DoString(0,40,"r0ket.de ");
DoString(0,48,"better UI "); DoString(0,48," ");
/* DoInt(0,24,filvers); */ /* DoInt(0,24,filvers); */
lcdDisplay(); lcdDisplay();
delayms(1000); delayms(100);
DoString(0,56," PRESS BUTTON "); DoString(0,56," PRESS BUTTON ");
lcdDisplay(); lcdDisplay();
getInputWait(); getInputWait();

Binary file not shown.

Binary file not shown.

View File

@ -2,3 +2,4 @@ size_t strlen(const char *s);
char strcpy(char * restrict dst, const char * restrict src); char strcpy(char * restrict dst, const char * restrict src);
void memcpy(void *dst, const void *src, size_t len); void memcpy(void *dst, const void *src, size_t len);
void memset(void *s, int c, size_t n); void memset(void *s, int c, size_t n);
int getrelease();

View File

@ -75,3 +75,7 @@ int main(void) {
wrapper(); // see module/ subdirectory wrapper(); // see module/ subdirectory
} }
int getrelease(void){
return 0x00000104;
};

187
tools/mesh/dbg.pl Executable file
View File

@ -0,0 +1,187 @@
#!/usr/bin/perl
#
# vim:set ts=4 sw=4:
use strict;
use IO::Select;
use Digest::CRC qw(crc16 crcccitt);
$|=1;
my @fh;
my $read;
sub sprint{
my @str=split(//,shift);
for (@str){
if (ord($_)>30 && ord($_)<127){
print $_;
}else{
print "[x",unpack("H*",$_),"]";
};
};
};
my $ser=shift || "/dev/ttyS3";
open(SER, "+<",$ser) || die "open: $!";
my $sel = IO::Select->new;
$sel->add(\*SER);
my $cmd=shift;
if($cmd =~ /^r/){
$cmd=~s/r//;
$cmd+=1;
my $fmt=shift;
while($cmd-->0){
my $read="";
while($read !~ /\\1.*\\0/){
my $rr="";
if (@fh = $sel->can_read(100)) {
sysread($fh[0],$rr,1024);
$read.=$rr;
}
};
print "Read: <"; sprint $read; print ">\n";
$read =~ s/^\\1//;
if($fmt eq "m"){
print "M [",substr($read,0,1),"] ";
print "g=",unpack("C",substr($read,1,1))," ";
print "t=",unpack("N",substr($read,2,4))," ";
print "beacon=",unpack("H*",substr($read,26,4))," ";
print "\n";
};
my $cs=substr($read,0,30);
my $crc=substr($read,30,2);
print unpack("n",$crc),"<>";
print crcccitt($cs),"\n";
};
}elsif ($cmd eq "mt"){
my $par=pack("H*",shift);
print "Write: <"; sprint $par; print ">\n";
syswrite(SER, '\3'.$par.'\0');
}elsif ($cmd eq "mta"){
my $par=shift;
print "Write: <"; sprint $par; print ">\n";
print "len: ",length($par),"\n";
syswrite(SER, '\3'.$par.'\0');
}elsif ($cmd eq "mr"){
my $par=pack("H*",shift);
print "Write: <"; sprint $par; print ">\n";
syswrite(SER, '\4'.$par.'\0');
}elsif ($cmd eq "mra"){
my $par=shift;
print "Write: <"; sprint $par; print ">\n";
syswrite(SER, '\4'.$par.'\0');
}elsif ($cmd eq "ch"){
my $par=pack("H*",shift);
print "Write: <"; sprint $par; print ">\n";
syswrite(SER, '\5'.$par.'\0');
}elsif ($cmd eq "len"){
my $par=pack("H*",shift);
print "Write: <"; sprint $par; print ">\n";
syswrite(SER, '\6'.$par.'\0');
}elsif ($cmd =~ /^S/){
$cmd=~s/S//;
$cmd+=1;
my $par="";
my $scmd=shift||"t";
if($scmd eq "t"){
$par.="T";
$par.=chr(shift); #gen
$par.=pack("N",scalar(time)+1*60*60);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
}elsif($scmd eq "a"){
$par.="A";
$par.=chr(shift); #gen
$par.=pack("N",scalar(time)+1*60*60+ 300);
$par.= pack("C",shift||0);
$par.= pack("C",0);
$par.= pack("C",0);
$par.= pack("C",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
}elsif($scmd eq "b"){
$par.="B";
$par.=chr(shift); #gen
$par.=pack("N",scalar(time)+1*60*60+ 300);
$par.= pack("C",shift||0);
$par.= pack("C",0);
$par.= pack("C",0);
$par.= pack("C",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
$par.=pack("N",0);
}else{
die;
};
$par.=pack("n",crcccitt($par));
print "Write: <"; sprint $par; print ">\n";
while($cmd-->0){
syswrite(SER, '\1'.$par.'\0');
print "len: ",length($par),"\n" if($cmd==0);
my $read="";
while($read !~ /\\2.*\\0/){
my $rr="";
if (@fh = $sel->can_read(100)) {
sysread($fh[0],$rr,1024);
$read.=$rr;
}
};
if($cmd==0){
print "Send: <"; sprint $read; print ">\n";
};
};
}elsif ($cmd =~ /^s/){
$cmd=~s/s//;
$cmd+=1;
my $par=pack("H*",shift);
$par.=pack("n",crcccitt($par));
print "Write: <"; sprint $par; print ">\n";
while($cmd-->0){
syswrite(SER, '\1'.$par.'\0');
print "len: ",length($par),"\n";
my $read="";
while($read !~ /\\2.*\\0/){
my $rr="";
if (@fh = $sel->can_read(100)) {
sysread($fh[0],$rr,1024);
$read.=$rr;
}
};
print "Send: <"; sprint $read; print ">\n";
};
}else{
die;
};
if (@fh = $sel->can_read(10)) {
sysread($fh[0],$read,1024);
}
print "PostRead: <"; sprint $read; print ">\n";

21
tools/smartflash/Makefile Normal file
View File

@ -0,0 +1,21 @@
setup:
cd ../../firmware && make clean && make && make l0dables
cp ../../firmware/firmware.bin .
-mkdir files 1files
cp ../../firmware/l0dable/*c0d 1files
cp ../../firmware/l0dable/*nik files
cp ../../firmware/l0dable/*int files
cp ../../firmware/l0dable/files/* files
cp ../font/binary/*f0n files
cp ../image/lcd/*lcd files
cp ../image/lcd/i42.lcd files/nick.lcd
cd ../crypto && make clean && make generate-keys
cp ../crypto/generate-keys .
@echo
@echo Now run ./smartflash
clean:
rm firmware.bin generate-keys
rm -rf files 1files

23
tools/smartflash/README Normal file
View File

@ -0,0 +1,23 @@
smarflash recognizes r0kets in firmware flash or mass storage flash mode and flashes them to factory defaults with a new generated random crypto key.
Runs only under linux (sorry, but requires /sys/... stuff)
You NEED to disable your automounter and run it as root.
Disabling automounter on ubuntu 10.4:
run gconf-editor
apps > nautilus > preferences
media_automount = OFF
media_automount_open = OFF
media_autorun_never = ON
run "make setup" to generate/gathe the necessary files
then run "./smarflash" and flash away.
TODO ideas:
- keep cryptokey if already there.
- ability to format if not? Or somehow force formatting?
- fix broken FS: save config/keys // reformat // copy back

3
tools/smartflash/flash Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
dd if=firmware.bin seek=4 of=/dev/$1 2>/dev/null
echo "FLASH done: $1"

53
tools/smartflash/mass Executable file
View File

@ -0,0 +1,53 @@
#!/bin/sh
dev=$1
dir=/tmp/r0ket
set -e
if [ ! -d $dir ] ; then
mkdir $dir
fi
if [ ! -d $dir/$dev ] ; then
mkdir $dir/$dev
fi
umount /dev/$dev 2>/dev/null || true
./generate-keys
mount /dev/$dev -t vfat $dir/$dev
cp files/* $dir/$dev
cp \
1files/invaders.c0d \
1files/mandel.c0d \
1files/r_player.c0d \
1files/jump.c0d \
1files/bricks.c0d \
1files/rockets.c0d \
1files/fahrplan.c0d \
1files/r0type.c0d \
1files/beaconid.c0d \
1files/people.c0d \
1files/starfld.c0d \
1files/static.c0d \
1files/sendcard.c0d \
1files/recvcard.c0d \
1files/showcard.c0d \
1files/pongo.c0d \
1files/minichat.c0d \
1files/blink.c0d \
1files/pwgen.c0d \
1files/showlcd.c0d \
1files/tedliz.c0d \
1files/leiwand.c0d \
1files/scope.c0d \
1files/Geigerct.c0d \
1files/voltage.c0d \
files/debug.int \
files/* \
$dir/$dev
#sync
#ls -l $dir/$dev
umount /dev/$dev
echo "MASS done: $dev $dir"

153
tools/smartflash/smartflash Executable file
View File

@ -0,0 +1,153 @@
#!/usr/bin/perl
use strict;
$|=1;
my $DEV="/sys/bus/usb/devices";
sub getline{
my($path)=@_;
open(my $f,"<",$DEV."/".$path) || do {
# print "failed opening $path: $!\n";
return "";
};
my $l=<$f>;
close($f);
chomp($l);
return $l;
};
my %found;
my %done;
sub gosub {
my ($dev,$grep)=@_;
my $dh;
my $dir;
opendir($dh, $DEV."/".$dev) || do {
# print "Failure for $dev?\n";
return "";
};
($dir)=grep {/$grep/} grep {/^[^.]/} readdir($dh);
if($dir eq ""){
return "";
};
close $dh;
$dev.="/".$dir;
return $dev;
};
sub getdev{
my ($dev)=@_;
my $dh;
my $dir;
$dev=gosub($dev,":1");
$dev=gosub($dev,"^host");
$dev=gosub($dev,"^target");
$dev=~/target(.*)/;
$dev=gosub($dev,$1);
$dev=gosub($dev,"^block");
$dev=gosub($dev,".");
$dev=~m!/([^/]*)$!;
my $r=$1;
if($r!~/^sd/){
# print "Strange device? $dev -> $r\n";
return "";
};
return $r;
};
my %pids;
use POSIX ":sys_wait_h";
my $kid;
$SIG{CHLD}=sub {
do {
$kid = waitpid(-1, WNOHANG);
delete $pids{$kid};
}while $kid>0;
};
sub dwim{
my($dev)=@_;
# print ("checking $dev\n");
my $pr=getline($dev."/idProduct");
return -1 if($pr eq "");
my $ve=getline($dev."/idVendor");
my $mf=getline($dev."/manufacturer");
# print "$pr:$ve\n";
if("$ve:$pr" eq "16c0:08ac") {
return 1 if $done{$dev}==1;
my $sdev=getdev($dev);
if ($sdev eq ""){
print "$dev not ready.\n";
return 1;
};
print "Mass storage $dev -> $sdev\n";
my $pid = fork();
if (not defined $pid) {
die "fork failed\n";
} elsif ($pid == 0) {
system("./mass $sdev");
exit(0);
} else {
# print "IM THE PARENT $pid\n";
$pids{$pid}=1;
# print join(",",%pids),"\n";
# print scalar keys %pids;
# print "\n";
}
$done{$dev}=1;
return 1;
};
if("$ve:$pr" eq "04cc:0003") {
return 1 if $done{$dev}==2;
my $sdev=getdev($dev);
if ($sdev eq ""){
print "$dev not ready.\n";
return 1;
};
print "flash $dev -> $sdev\n";
system("./flash $sdev");
$done{$dev}=2;
return 1;
};
return -1;
};
my %disable;
while(1){
opendir(my $dh, $DEV);
my @paths=readdir($dh);
close $dh;
# print "f: ",join(",",@files),"\n";
device:
for my $path (@paths){
next if ($disable{$path});
next if $path =~ /^usb/;
next if $path =~ /:/;
# print "p $path\n";
$found{$path}=1;
my $res=dwim($path);
if($res==-1){
print "Disabling: $path\n";
$disable{$path}=1;
};
};
for my $a (keys %done){
if (!$found{$a}){
delete $done{$a};
print "$a vanished\n";
};
};
%found=();
# print "\n";
sleep(1);
print scalar(keys %pids),"\r";
};