From 0403e99362b2a88adec5e3454b831e9f1e57bdac Mon Sep 17 00:00:00 2001 From: Thammi Date: Thu, 11 Aug 2011 17:35:17 +0200 Subject: [PATCH 01/22] Adding a very small tron/snake like game --- firmware/l0dable/tron.c | 98 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 firmware/l0dable/tron.c diff --git a/firmware/l0dable/tron.c b/firmware/l0dable/tron.c new file mode 100644 index 0000000..4fb8428 --- /dev/null +++ b/firmware/l0dable/tron.c @@ -0,0 +1,98 @@ +#include +#include + +#include "basic/basic.h" +#include "basic/random.h" +#include "lcd/display.h" +#include "usetable.h" + +void randomizeCoin(int* x, int* y); + +void ram() { + int key; + + int d = 0; + int x = RESX / 2; + int y = RESY / 2; + + int p = 0; + int q, r; + + randomizeCoin(&q, &r); + + lcdClear(); + + while (1) { + // display + lcdSetPixel(q, r, p % 3); + lcdSetPixel(x, y, 1); + lcdDisplay(); + + // wait + + delayms(20); + + // input + + key=getInputRaw(); + + switch(key) { + case BTN_RIGHT: + d = 3; + break; + case BTN_LEFT: + d = 2; + break; + case BTN_UP: + d = 0; + break; + case BTN_DOWN: + d = 1; + break; + case BTN_ENTER: + return; + } + + // step + + if(d > 1) { + x = (RESX + x + (d & 1) * 2 - 1) % RESX; + } else { + y = (RESY + y + d * 2 - 1) % RESY; + } + + p += 1; + + // collision + + if(x == q && y == r) { + p += 99; + randomizeCoin(&q, &r); + } else if(lcdGetPixel(x, y)) { + lcdClear(); + lcdPrintln("You lost!"); + lcdNl(); + lcdPrintInt(p); + lcdPrintln(" points"); + lcdDisplay(); + + while(getInputRaw() != BTN_ENTER); + + return; + } + } + return; +} + +void randomizeCoin(int* x, int* y) { + // WARNING: if you are really got at this the game freezes :D + for(;;) { + *x = getRandom() % RESX; + *y = getRandom() % RESY; + + if(!lcdGetPixel(*x, *y)) { + return; + } + } +} + From efbb72a31de80080a4e61805ff218279c8f387c0 Mon Sep 17 00:00:00 2001 From: Thammi Date: Thu, 11 Aug 2011 17:42:30 +0200 Subject: [PATCH 02/22] Adding author and license information to tron --- firmware/l0dable/tron.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/l0dable/tron.c b/firmware/l0dable/tron.c index 4fb8428..52a6978 100644 --- a/firmware/l0dable/tron.c +++ b/firmware/l0dable/tron.c @@ -1,3 +1,7 @@ +/* + * Pizzaware by Thammi from Pentaville + */ + #include #include From e3b1ff3a22ea0608f5ecc56dcde47149cf92a381 Mon Sep 17 00:00:00 2001 From: Thammi Date: Fri, 12 Aug 2011 21:41:06 +0200 Subject: [PATCH 03/22] Getting personal when losing tron --- firmware/l0dable/tron.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firmware/l0dable/tron.c b/firmware/l0dable/tron.c index 52a6978..419a1a9 100644 --- a/firmware/l0dable/tron.c +++ b/firmware/l0dable/tron.c @@ -74,7 +74,11 @@ void ram() { randomizeCoin(&q, &r); } else if(lcdGetPixel(x, y)) { lcdClear(); - lcdPrintln("You lost!"); + lcdPrint("You failed,"); + lcdNl(); + lcdPrint(nickname); + lcdPrint("!"); + lcdNl(); lcdNl(); lcdPrintInt(p); lcdPrintln(" points"); From e0ad56aebc3608f10392e469d4a99c98a3862e82 Mon Sep 17 00:00:00 2001 From: Thammi Date: Fri, 12 Aug 2011 21:42:13 +0200 Subject: [PATCH 04/22] Removing pizzaware licence to use bsd --- firmware/l0dable/tron.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/l0dable/tron.c b/firmware/l0dable/tron.c index 419a1a9..78d6364 100644 --- a/firmware/l0dable/tron.c +++ b/firmware/l0dable/tron.c @@ -1,5 +1,5 @@ /* - * Pizzaware by Thammi from Pentaville + * coded by Thammi from Pentaville */ #include From 7f15ac9a4cc4ad747e8eb29e6b823d3927fe4c9b Mon Sep 17 00:00:00 2001 From: Thammi Date: Fri, 12 Aug 2011 23:08:45 +0200 Subject: [PATCH 05/22] Fixing village name --- firmware/l0dable/tron.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/l0dable/tron.c b/firmware/l0dable/tron.c index 78d6364..c238fd5 100644 --- a/firmware/l0dable/tron.c +++ b/firmware/l0dable/tron.c @@ -1,5 +1,5 @@ /* - * coded by Thammi from Pentaville + * coded by Thammi from Pentagon Village */ #include From 33fe346942176a0e988818980d04d1a8f746f894 Mon Sep 17 00:00:00 2001 From: Stefan Tomanek Date: Sat, 13 Aug 2011 14:14:12 +0200 Subject: [PATCH 06/22] add w0rpcore nickname l0dable This l0dable by Benedikt Roth and Stefan Tomanek serves as your main viewscreen, displaying your nickname the way you want it, and lets the stars zoom by. You can accelerate your vessel by pushing the joystick upwards or bring it to a halt by pressing it down - leaving your ship drifting in the endless space. Attach two LEDs to the modulbus connectors (SS2->GND, SS5->GND), so your r0ket can light up its nacelles when breaking the warp barrier. --- firmware/l0dable/nick_w0rpcore.c | 157 +++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 firmware/l0dable/nick_w0rpcore.c diff --git a/firmware/l0dable/nick_w0rpcore.c b/firmware/l0dable/nick_w0rpcore.c new file mode 100644 index 0000000..ca4df31 --- /dev/null +++ b/firmware/l0dable/nick_w0rpcore.c @@ -0,0 +1,157 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "usetable.h" + +#define NUM_STARS 100 +#define SPEED_MAX 10 +#define SPEED_DEFAULT 4 +#define SPEED_STOP 0 +#define SPEED_WARP 6 + +// Two RGB LEDs on the Modulbus +#define LEDA_R RB_SPI_SS0 +#define LEDA_G RB_SPI_SS1 +#define LEDA_B RB_SPI_SS2 + +#define LEDB_R RB_SPI_SS3 +#define LEDB_G RB_SPI_SS4 +#define LEDB_B RB_SPI_SS5 + +typedef struct { + short x, y, z; +} s_star; + +typedef struct { + short speed; +} s_ship; + +static s_ship ship = {SPEED_DEFAULT}; + +static s_star stars[NUM_STARS]; + +void init_star(s_star *star, int z); +void set_warp_lights(uint8_t enabled); +void drift_ship(void); + +void ram(void) +{ + short centerx = RESX >> 1; + short centery = RESY >> 1; + short i; + uint8_t key = 0; + + for (i = 0; i < NUM_STARS; i++) { + init_star(stars + i, i + 1); + } + + static uint8_t count = 0; + while(1) { + count++; + count%=256; + key = getInputRaw(); + if (key == BTN_ENTER) { + break; + } else if ( count%4 == 0 ) { + if (key == BTN_UP && ship.speed < SPEED_MAX) { + ship.speed++; + } else if (key == BTN_DOWN && ship.speed > SPEED_STOP) { + ship.speed--; + } else if (key ==BTN_NONE) { + /* converge towards default speed */ + if (ship.speed < SPEED_DEFAULT) { + ship.speed++; + } else if (ship.speed > SPEED_DEFAULT) { + ship.speed--; + } + } + } + + if (ship.speed > SPEED_WARP) { + set_warp_lights(1); + } else { + set_warp_lights(0); + } + + if (ship.speed == 0 && count%6==0) drift_ship(); + + int dx=0; + int dy=0; + setExtFont(GLOBAL(nickfont)); + dx=DoString(0,0,GLOBAL(nickname)); + dx=(RESX-dx)/2; + if(dx<0) dx=0; + dy=(RESY-getFontHeight())/2; + + lcdClear(); + DoString(dx,dy,GLOBAL(nickname)); + + for (i = 0; i < NUM_STARS; i++) { + stars[i].z -= ship.speed; + + if (ship.speed > 0 && stars[i].z <= 0) + init_star(stars + i, i + 1); + + short tempx = ((stars[i].x * 30) / stars[i].z) + centerx; + short tempy = ((stars[i].y * 30) / stars[i].z) + centery; + + if (tempx < 0 || tempx > RESX - 1 || tempy < 0 || tempy > RESY - 1) { + if (ship.speed > 0) { /* if we are flying, generate new stars in front */ + init_star(stars + i, i + 1); + } else { /* if we are drifting, simply move those stars to the other end */ + stars[i].x = (((tempx%RESX)-centerx)*stars[i].z)/30; + stars[i].y = (((tempy%RESY)-centery)*stars[i].z)/30; + } + continue; + } + + lcdSetPixel(tempx, tempy, 1); + if (stars[i].z < 50) { + lcdSetPixel(tempx + 1, tempy, 1); + } + if (stars[i].z < 20) { + lcdSetPixel(tempx, tempy + 1, 1); + lcdSetPixel(tempx + 1, tempy + 1, 1); + } + } + + lcdRefresh(); + + delayms_queue_plus(50,0); + } + set_warp_lights(0); +} + +void set_warp_lights(uint8_t enabled) { + gpioSetValue(LEDA_R, 0); + gpioSetValue(LEDA_G, 0); + gpioSetValue(LEDA_B, enabled); + + gpioSetValue(LEDB_R, 0); + gpioSetValue(LEDB_G, 0); + gpioSetValue(LEDB_B, enabled); +} + +void drift_ship(void) { + uint8_t d_x = 1; + uint8_t d_y = 1; + for (uint8_t i = 0; i < NUM_STARS; i++) { + stars[i].x += d_x; + stars[i].y += d_y; + } +} + +void init_star(s_star *star, int z) +{ + star->x = (getRandom() % RESX) - (RESX >> 1); + star->y = (getRandom() % RESY) - (RESY >> 1); + star->z = z; + + return; +} + From 14107d9b1ddfcfbd739e151e8c5de26d9e657c61 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 5 Jan 2012 12:53:28 +0100 Subject: [PATCH 07/22] mesh/dbg.pl: fix dequoting. Add "c"orrupt packet --- tools/mesh/dbg.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/mesh/dbg.pl b/tools/mesh/dbg.pl index 65a64bf..fd90e1e 100755 --- a/tools/mesh/dbg.pl +++ b/tools/mesh/dbg.pl @@ -43,12 +43,12 @@ if($cmd =~ /^r/){ my $rr=""; if (@fh = $sel->can_read(100)) { sysread($fh[0],$rr,1024); - $rr=~s/\\\\/\\/g; $read.=$rr; } }; while ($read =~ s/\\1(.*?)\\0//){ my $str=$1; + $str=~s/\\\\/\\/g; my $cs=substr($str,0,length($str)-2); my $crc=unpack("n",substr($str,length($str)-2,2)); my $crc2= crcccitt($cs),"\n"; @@ -167,6 +167,21 @@ if($cmd =~ /^r/){ $par.=chr(shift); #gen $par.=pack("N",scalar(time)+1*60*60+ 600); + $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 "c"){ + $par.="\x1"; + $par.=chr(shift); #gen + $par.=pack("N",scalar(time)+1*60*60+ 600); + $par.= pack("C",shift||0); $par.= pack("C",0); $par.= pack("C",0); From 020d141995d7b3662e006e866ffe494ffc27204e Mon Sep 17 00:00:00 2001 From: schneider Date: Thu, 5 Jan 2012 16:31:58 +0100 Subject: [PATCH 08/22] added jeopardy game announcing l0dable --- firmware/l0dable/jeopardy.c | 148 ++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 firmware/l0dable/jeopardy.c diff --git a/firmware/l0dable/jeopardy.c b/firmware/l0dable/jeopardy.c new file mode 100644 index 0000000..c3b31d1 --- /dev/null +++ b/firmware/l0dable/jeopardy.c @@ -0,0 +1,148 @@ +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "funk/nrf24l01p.h" +#include +#include "basic/random.h" +#include "basic/config.h" +#include "usetable.h" + + +//channel and mac used to transmit game announcements +#define ANNOUNCE_CHANNEL 87 +#define ANNOUNCE_MAC "REM0T" + +struct NRF_CFG config; + +struct packet{ + uint8_t len; + uint8_t protocol; + uint8_t command; + uint32_t id; + uint32_t ctr; + + //union with 19 bytes data + union content{ + struct button{ + uint8_t button; + uint8_t reserved[18]; + }__attribute__((packed)) button; + struct text{ + uint8_t x; + uint8_t y; + uint8_t flags; + uint8_t text[16]; + }__attribute__((packed)) text; + struct nick{ + uint8_t flags; + uint8_t nick[18]; + }__attribute__((packed)) nick; + struct nickrequest{ + uint8_t reserved[19]; + }__attribute__((packed)) nickrequest; + struct ack{ + uint8_t flags; + uint8_t reserved[18]; + }__attribute__((packed)) ack; + struct announce{ + uint8_t gameMac[5]; + uint8_t gameChannel; + //uint8_t playerMac[5]; playerMac = gameMac+1; + uint16_t gameId; + uint8_t gameFlags; + uint8_t interval; + uint8_t jitter; + uint8_t gameTitle[8]; + }__attribute__((packed)) announce; + struct join{ + uint16_t gameId; + uint8_t reserved[17]; + }__attribute__((packed)) join; + }c; + uint16_t crc; +}__attribute__((packed)); + +#define FLAGS_MASS_GAME 1 +#define FLAGS_SHORT_PACKET 2 +#define FLAGS_LONG_RECV 4 + +#define FLAGS_ACK_JOINOK 1 +#define MASS_ID 1 + +#define FLAGS_CLS 1 + +/**************************************************************************/ +/* l0dable for playing games which are announced by other r0kets with the l0dabel r_game */ +/* Values of buf[3]: + * B: packet sent by player, contain information which button is pressed + * T: packet sent by game, contain text for display + * N: packet sent by game, requesting nick + * n: packet sent player, containing nick + * A: packet sent by game, announcing game + * J: packet sent by player, requesting to join game + * a: ack, packet with $ctr was received + */ + +void setLeft(); +void setRight(); +struct packet a; + +void ram(void) +{ + int priv = GLOBAL(privacy); + + GLOBAL(privacy) = 3; + config.nrmacs=1; + config.maclen[0] = 32; + config.channel = ANNOUNCE_CHANNEL; + memcpy(config.mac0, ANNOUNCE_MAC, 5); + memcpy(config.txmac, ANNOUNCE_MAC, 5); + nrf_config_set(&config); + + nrf_set_strength(3); + int rnd; + + volatile uint16_t i; + while( 1 ){ + delayms(100); + i = getRandom()&0xfff; while(i--); + setJeopardy(); + nrf_snd_pkt_crc(sizeof(a),(uint8_t*)&a); + } + GLOBAL(privacy) = priv; +}; + + +void setJeopardy() +{ + a.len = 32; + a.protocol = 'G'; + a.command = 'A'; + a.id = 0; + a.ctr = 1; + a.c.announce.gameMac[0] = 'B'; + a.c.announce.gameMac[1] = 'P'; + a.c.announce.gameMac[2] = 'O'; + a.c.announce.gameMac[3] = 'N'; + a.c.announce.gameMac[4] = 'G'; + + a.c.announce.gameChannel = 91; + a.c.announce.gameId = 23; + a.c.announce.gameFlags = 3; + + a.c.announce.interval = 10; + a.c.announce.jitter = 10; + + a.c.announce.gameTitle[0] = 'J'; + a.c.announce.gameTitle[1] = 'e'; + a.c.announce.gameTitle[2] = 'o'; + a.c.announce.gameTitle[3] = 'p'; + a.c.announce.gameTitle[4] = 'r'; + a.c.announce.gameTitle[5] = 'd'; + a.c.announce.gameTitle[6] = 'y'; + a.c.announce.gameTitle[7] = 0; +} + From 7ec64c04ad4fb6df54664b89e7940c10d5d95757 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 9 Jan 2012 01:44:58 +0100 Subject: [PATCH 09/22] Improve my little rf debugging tool a bit. Needs more docs, though --- tools/mesh/dbg.pl | 234 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 176 insertions(+), 58 deletions(-) diff --git a/tools/mesh/dbg.pl b/tools/mesh/dbg.pl index fd90e1e..667591b 100755 --- a/tools/mesh/dbg.pl +++ b/tools/mesh/dbg.pl @@ -5,7 +5,8 @@ use strict; use IO::Select; -use Digest::CRC qw(crc16 crcccitt); +use Digest::CRC qw(crcccitt); +use POSIX qw(strftime); $|=1; @@ -13,19 +14,88 @@ my @fh; my $read; sub sprint{ - my @str=split(//,shift); - for (@str){ + return join("",map { if (ord($_)>30 && ord($_)<127){ - print $_; + $_; }else{ - print "[x",unpack("H*",$_),"]"; - }; - }; + "[x".unpack("H*",$_)."]"; + } + }split(//,shift)); }; -my $ser=shift || "/dev/ttyS3"; +my %beacon; +sub readbeacon{ + return if( ! -f "BEACON" ); + open(B,"<","BEACON") || die "open: $!"; + while(){ + /(\w+)\s+(.*)/ && do { + $beacon{$1}=$2; + }; + }; + close(B); +}; +sub resolvebeacon{ + my $b=shift; + if(!$beacon{$b}){ + return $b; + }else{ + return "$b ($beacon{$b})"; + }; +}; +sub addbeacon{ + my($b,$n)=@_; + if(!$beacon{$b}){ + $beacon{$b}=$n; + }; +}; +sub writebeacon{ + open(B,">","BEACON") || die "write: $!"; + for(sort keys %beacon){ + print B "$_ $beacon{$_}\n"; + }; + close(B); +}; -open(SER, "+<",$ser) || die "open: $!"; +my $ser=""; + +do {$ser=$_ if ( -e $_ ) } for qw(/dev/ttyS3 /dev/ttyACM0); + +if ($ARGV[0] eq "-h"){ + print STDERR "Mini-Help:\n"; + print STDERR "-s \n"; + print STDERR "\n"; + print STDERR "r receive (number) pakets\n"; + print STDERR " - r x : hexdump packets\n"; + print STDERR " - r m : parse as mesh packet\n"; + print STDERR " - r m : and show only \n"; + print STDERR "\n"; + print STDERR "s send packet (number) times\n"; + print STDERR " - s : send raw hexdump\n"; + print STDERR " - S ... : see source \n"; + print STDERR "\n"; + print STDERR "p config per preset\n"; + print STDERR "- pM - preset mesh\n"; + print STDERR "- pB - preset openbeacon\n"; + print STDERR "\n"; + print STDERR "etc...\n"; + exit(1); +}; +if ($ARGV[0] eq "-s"){ + shift; + $ser=shift; +}; + +my $writend=0; +if ($ARGV[0] eq "-w"){ + shift; + $writend=1; +}; + +END{ + writebeacon if($writend); +}; + +open(SER, "+<",$ser) || die "open serial: $!"; my $sel = IO::Select->new; @@ -34,48 +104,89 @@ $sel->add(\*SER); my $cmd=shift; if($cmd =~ /^r/){ + + readbeacon(); $cmd=~s/r//; - $cmd+=1; + $cmd=100 if $cmd+0==0; my $fmt=shift; + my $arg=shift || undef; my $read=""; - while($cmd-->0){ - while($read !~ /\\1.*\\0/){ - my $rr=""; - if (@fh = $sel->can_read(100)) { - sysread($fh[0],$rr,1024); - $read.=$rr; - } - }; - while ($read =~ s/\\1(.*?)\\0//){ - my $str=$1; - $str=~s/\\\\/\\/g; - my $cs=substr($str,0,length($str)-2); - my $crc=unpack("n",substr($str,length($str)-2,2)); - my $crc2= crcccitt($cs),"\n"; - if($fmt eq "m"){ - my $i=substr($str,0,1); - print "M [",substr($str,0,1),"] "; - print "g=",unpack("C",substr($str,1,1))," "; - if($i eq "T"){ - print "t=",unpack("N",substr($str,2,4))," "; - print "(",scalar gmtime unpack("N",substr($str,2,4)),") "; - print "beacon=",unpack("H*",substr($str,26,4))," "; - }elsif($i eq "B"){ - print "t=",unpack("N",substr($str,2,4))," "; - print "ID=",unpack("c",substr($str,6,1))," "; - print "HOP=",unpack("n",substr($str,11,4))," "; - }; -# print "\n"; + + while($cmd>0){ + if(length($read)>2 && $read !~ /^\\1/){ + $read=~s/^(.[^\\]*)//s; + print "Unparseable stuff: <",sprint($1),">\n"; +# print "Rest was: ",sprint($read),"!\n"; + }; + if ($read !~ s/^\\1(.*?)\\0//s){ + my $rr=""; + sysread(SER,$rr,1024); + $read.=$rr; + }else{ + my $str=$1; + $str=~s/\\\\/\\/g; # dequote + my $pkt_crc= unpack("n",substr($str,length($str)-2,2)); + my $calc_crc= crcccitt(substr($str,0,length($str)-2)); + + if($fmt eq "m"){ + my $i=substr($str,0,1); + next if(defined $arg && $arg ne $i); + print "M [$i] "; + print "g=",unpack("C",substr($str,1,1))," "; + if($i eq "T"){ + print "t="; +# print unpack("N",substr($str,2,4))," "; + print strftime("%Y-%m-%d %H:%M:%S",gmtime unpack("N",substr($str,2,4))); + printf " (%+3d) ",unpack("N",substr($str,2,4))-(time+3600); + print "beacon=",resolvebeacon(unpack("H*",substr($str,26,4)))," "; + }elsif($i eq "i"){ + print "score=",unpack("N",substr($str,2,4))," "; + print "nick=",unpack("Z*",substr($str,6,length($str)-8))," "; + }elsif($i eq "B"){ + print "t=",unpack("N",substr($str,2,4))," "; + print "ID=",unpack("c",substr($str,6,1))," "; + print "HOP=",unpack("n",substr($str,11,4))," "; + }else{ + print ""; + }; +# print "\n"; + }elsif($fmt eq "b"){ + my $i=substr($str,1,1); + if($i eq "\x17"){ + print "BEACON "; + print "ln=",unpack("C",substr($str,0,1))," "; + print "bt=",unpack("H*",substr($str,2,1))," "; + print "str=",unpack("H*",substr($str,3,1))," "; + printf "idx=%08d ",unpack("N",substr($str,4,4)); + print "beacon=",resolvebeacon(unpack("H*",substr($str,8,4)))," "; + if(unpack("H*",substr($str,12,2)) ne "ffff"){ + print "unused=",unpack("H*",substr($str,12,2))," "; + }; + }elsif($i eq "\x23"){ + print "NICK "; + print "beacon=",resolvebeacon(unpack("H*",substr($str,2,4)))," "; + print "nick=",unpack("Z*",substr($str,6,length($str)-2))," "; + addbeacon(unpack("H*",substr($str,2,4)),unpack("Z*",substr($str,6,length($str)-2))); + }else{ + # + print ""; + }; }elsif($fmt eq "x"){ print "<",unpack("H*",$str),">"; - }else{ - print "Read: <"; sprint $str; print ">\n"; - }; - print "CRCFAIL" if ($crc ne $crc2); - print "\n"; - }; - }; - print "rest: <"; sprint $read; print ">\n"; + }else{ + print "<", sprint($str), ">\n"; + }; + print "CRCFAIL" if ($pkt_crc ne $calc_crc); + print "\n"; + $cmd--; + next; + }; + if($read !~ /^\\1/){ + }; + }; + if(length($read)>0){ + print "rest: <", sprint($read), ">\n"; + }; exit; }elsif ($cmd eq "pM"){ syswrite(SER, '\3ORBIT\0'); @@ -89,28 +200,28 @@ if($cmd =~ /^r/){ syswrite(SER, '\6'.pack("H*","10").'\0'); }elsif ($cmd eq "mt"){ my $par=pack("H*",shift); - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\n"; syswrite(SER, '\3'.$par.'\0'); }elsif ($cmd eq "mta"){ my $par=shift; - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\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"; + print "Write: <", sprint($par),">\n"; syswrite(SER, '\4'.$par.'\0'); }elsif ($cmd eq "mra"){ my $par=shift; - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\n"; syswrite(SER, '\4'.$par.'\0'); }elsif ($cmd eq "ch"){ my $par=pack("H*",shift); - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\n"; syswrite(SER, '\5'.$par.'\0'); }elsif ($cmd eq "len"){ my $par=pack("H*",shift); - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\n"; syswrite(SER, '\6'.$par.'\0'); }elsif ($cmd =~ /^S/){ $cmd=~s/S//; @@ -192,13 +303,20 @@ if($cmd =~ /^r/){ $par.=pack("N",0); $par.=pack("N",0); $par.=pack("N",0); + }elsif($scmd eq "i"){ + $par.="i"; + $par.=chr(shift); #gen + $par.=pack("N",shift||42); + + $par.=shift; + $par.="\0"x(30-length($par)); }else{ die; }; $par.=pack("n",crcccitt($par)); # $par.="00"; - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par),">\n"; while($cmd-->0){ syswrite(SER, '\1'.$par.'\0'); print "len: ",length($par),"\n" if($cmd==0); @@ -213,7 +331,7 @@ if($cmd =~ /^r/){ }; if($cmd==0){ - print "Send: <"; sprint $read; print ">\n"; + print "Send: <". sprint($read) , ">\n"; }; }; }elsif ($cmd =~ /^s/){ @@ -221,7 +339,7 @@ if($cmd =~ /^r/){ $cmd+=1; my $par=pack("H*",shift); $par.=pack("n",crcccitt($par)); - print "Write: <"; sprint $par; print ">\n"; + print "Write: <", sprint($par), ">\n"; while($cmd-->0){ syswrite(SER, '\1'.$par.'\0'); print "len: ",length($par),"\n"; @@ -235,14 +353,14 @@ if($cmd =~ /^r/){ } }; - print "Send: <"; sprint $read; print ">\n"; + print "Send: <", sprint($read) , ">\n"; }; }else{ -die; + die "Option not understood\n"; }; if (@fh = $sel->can_read(10)) { sysread($fh[0],$read,1024); } -print "PostRead: <"; sprint $read; print ">\n"; +print "PostRead: <", sprint($read), ">\n"; From f38fb4c1489c2806532f0faf75141e20f12e27cb Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 15 Jan 2012 14:04:26 +0100 Subject: [PATCH 10/22] Remove duplicate sydefs.h confusion. --- firmware/core/sysdefs.h | 12 ++---------- firmware/sysdefs.h | 15 +++------------ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/firmware/core/sysdefs.h b/firmware/core/sysdefs.h index bf79c8e..018c147 100644 --- a/firmware/core/sysdefs.h +++ b/firmware/core/sysdefs.h @@ -39,20 +39,12 @@ #ifndef _SYSDEFS_H_ #define _SYSDEFS_H_ +#include "../sysdefs.h" + #include #include #include -// Stay compatible with ugly "windows" style -#define BOOL bool -#define TRUE true -#define FALSE false - -typedef volatile uint8_t REG8; -typedef volatile uint16_t REG16; -typedef volatile uint32_t REG32; -typedef unsigned char byte_t; - #define pREG8 (REG8 *) #define pREG16 (REG16 *) #define pREG32 (REG32 *) diff --git a/firmware/sysdefs.h b/firmware/sysdefs.h index 10ebfb4..d17cb54 100644 --- a/firmware/sysdefs.h +++ b/firmware/sysdefs.h @@ -36,10 +36,10 @@ */ /**************************************************************************/ -#ifndef _SYSDEFS_H_ -#define _SYSDEFS_H_ +#ifndef _GLOBAL_SYSDEFS_H_ +#define _GLOBAL_SYSDEFS_H_ -#include +#include #include #include @@ -53,18 +53,9 @@ typedef volatile uint16_t REG16; typedef volatile uint32_t REG32; typedef unsigned char byte_t; -#define pREG8 (REG8 *) -#define pREG16 (REG16 *) -#define pREG32 (REG32 *) - -#ifndef NULL -#define NULL ((void *) 0) -#endif - // Save some space #ifndef SIMULATOR #define memcpy memmove #endif #endif - From 71c9a6dc647cfe5c2b69343f866fb20383954b9a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 15 Jan 2012 14:04:57 +0100 Subject: [PATCH 11/22] Make basic/ecc also use our global include --- firmware/basic/ecc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/basic/ecc.h b/firmware/basic/ecc.h index 05b1d3b..a99c173 100644 --- a/firmware/basic/ecc.h +++ b/firmware/basic/ecc.h @@ -1,5 +1,6 @@ #ifndef _ECC_H_ #define _ECC_H_H +#include #include /******************************************************************************/ From 29c7dfdf6488eb2e7ef5289f49ea9667439e6132 Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 16 Jan 2012 15:50:48 +0100 Subject: [PATCH 12/22] improved accuracy of battery voltage measurement Slowing down the ADC 10x while reading the voltage gives better results due to the very high impedance of the voltage devider. Readings are now about 100mV higher than before. --- firmware/basic/voltage.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/firmware/basic/voltage.c b/firmware/basic/voltage.c index a60bdd2..4996077 100644 --- a/firmware/basic/voltage.c +++ b/firmware/basic/voltage.c @@ -3,21 +3,31 @@ #include "basic/basic.h" #include "funk/nrf24l01p.h" -static uint32_t results=5000; +static uint32_t voltage=5000; static uint8_t chrg=1; void VoltageCheck(void){ chrg=gpioGetValue(RB_PWR_CHRG); + //slow down the adc for our high impedance volatage devider + ADC_AD0CR = ((CFG_CPU_CCLK / SCB_SYSAHBCLKDIV) / 100000 - 1 ) << 8; + voltage = adcRead(1); + //speed it up again + ADC_AD0CR = ((CFG_CPU_CCLK / SCB_SYSAHBCLKDIV) / 1000000 - 1 ) << 8; - results = adcRead(1); - results *= 10560; - results /= 1024; - results += 50; - if( results < 3500 ){ + voltage *= 10560; + voltage /= 1024; + + //add the drop over the voltage switch + voltage += 50; + + //battery is assumed empty if the volatge falls bellow 3.5V + if( voltage < 3500 ){ nrf_off(); gpioSetValue (RB_PWR_GOOD, 0); - gpioSetValue (RB_LCD_BL, 0); + gpioSetValue (RB_LCD_BL, 0); + + //put the chip into deep power down SCB_SCR |= SCB_SCR_SLEEPDEEP; PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; __asm volatile ("WFI"); @@ -25,7 +35,7 @@ void VoltageCheck(void){ }; uint32_t GetVoltage(void){ - return results; + return voltage; }; uint8_t GetChrgStat(void){ From eee6ae55f0744a65392ae5b2eaa9503e8e7e13d0 Mon Sep 17 00:00:00 2001 From: schneider Date: Wed, 18 Jan 2012 20:59:12 +0100 Subject: [PATCH 13/22] openbeacon: set rf strength to 3 after sending --- firmware/funk/openbeacon.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/firmware/funk/openbeacon.c b/firmware/funk/openbeacon.c index 3ee67bc..ec048dd 100644 --- a/firmware/funk/openbeacon.c +++ b/firmware/funk/openbeacon.c @@ -72,6 +72,17 @@ static void openbeaconRead() void openbeaconSetup(void) { + uint8_t c = 0; + uint8_t channels[] = {12,17,22,27,32,37,42,47,52,57,62,67,72}; + //nrf_startCW(); + while(0){ + delayms(20); + nrf_set_channel(channels[c++]); + if( c == sizeof(channels) ){ + c = 0; + } + } + oid = GetUUID32(); strength = 0; #if SAVE_OPENBEACON @@ -137,8 +148,6 @@ static void openbeaconSendPacket(uint32_t id, uint32_t seq, void openbeaconSend(void) { - //uint8_t status; - nrf_config_get(&oldconfig); nrf_set_channel(OPENBEACON_CHANNEL); @@ -153,6 +162,6 @@ void openbeaconSend(void) openbeaconSaveBlock(); #endif nrf_config_set(&oldconfig); - //return status; + nrf_set_strength(3); } From d82dde9ecf0d9b088c366fc52c0e6d12ac58afe5 Mon Sep 17 00:00:00 2001 From: schneider Date: Thu, 19 Jan 2012 01:32:05 +0100 Subject: [PATCH 14/22] added authors to w0rpcore --- firmware/l0dable/nick_w0rpcore.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/firmware/l0dable/nick_w0rpcore.c b/firmware/l0dable/nick_w0rpcore.c index ca4df31..57a5526 100644 --- a/firmware/l0dable/nick_w0rpcore.c +++ b/firmware/l0dable/nick_w0rpcore.c @@ -1,3 +1,15 @@ +/* + * This l0dable by Benedikt Roth and Stefan Tomanek serves as your main + * viewscreen, displaying your nickname the way you want it, and lets the + * stars zoom by. You can accelerate your vessel by pushing the joystick + * upwards or bring it to a halt by pressing it down - leaving your ship + * drifting in the endless space. Attach two LEDs to the modulbus + * connectors (SS2->GND, SS5->GND), so your r0ket can light up its nacelles + * when breaking the warp barrier. + * + * commit 33fe346942176a0e988818980d04d1a8f746f894 1 parent 0eaf74fa87 + * wertarbyte authored August 13, 2011 + */ #include #include "basic/basic.h" From d9b7a2c6bd523fe1a93e075ca7d5ddc379af8fe8 Mon Sep 17 00:00:00 2001 From: schneider Date: Thu, 19 Jan 2012 23:01:00 +0100 Subject: [PATCH 15/22] added some filtering for the voltage reading --- firmware/basic/voltage.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/firmware/basic/voltage.c b/firmware/basic/voltage.c index 4996077..ff37ab6 100644 --- a/firmware/basic/voltage.c +++ b/firmware/basic/voltage.c @@ -3,26 +3,31 @@ #include "basic/basic.h" #include "funk/nrf24l01p.h" -static uint32_t voltage=5000; +#define VOLTAGE_SAMPLES 8 +static uint32_t voltage=5000*VOLTAGE_SAMPLES; static uint8_t chrg=1; void VoltageCheck(void){ - + uint32_t v; chrg=gpioGetValue(RB_PWR_CHRG); - //slow down the adc for our high impedance volatage devider + //slow down the adc for our high impedance voltage devider ADC_AD0CR = ((CFG_CPU_CCLK / SCB_SYSAHBCLKDIV) / 100000 - 1 ) << 8; - voltage = adcRead(1); + v = adcRead(1); //speed it up again ADC_AD0CR = ((CFG_CPU_CCLK / SCB_SYSAHBCLKDIV) / 1000000 - 1 ) << 8; - voltage *= 10560; - voltage /= 1024; + v *= 10560; + v /= 1024; //add the drop over the voltage switch - voltage += 50; + v += 50; + + voltage -= voltage/VOLTAGE_SAMPLES; + voltage += v; //battery is assumed empty if the volatge falls bellow 3.5V - if( voltage < 3500 ){ + if( voltage < (3500*VOLTAGE_SAMPLES) ){ + //if( voltage < 3500 ){ nrf_off(); gpioSetValue (RB_PWR_GOOD, 0); gpioSetValue (RB_LCD_BL, 0); @@ -35,7 +40,8 @@ void VoltageCheck(void){ }; uint32_t GetVoltage(void){ - return voltage; + return voltage/8; + //return voltage; }; uint8_t GetChrgStat(void){ From f823ef250462f40356e973c131d4f10b1323a43a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 24 Jan 2012 00:18:36 +0100 Subject: [PATCH 16/22] Add "fake memcpy" lib so broken gcc can compile this --- firmware/l0dable/Makefile | 11 +++++++++-- firmware/l0dable/help/memcpy.c | 10 ++++++++++ firmware/l0dable/mktable.pl | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 firmware/l0dable/help/memcpy.c diff --git a/firmware/l0dable/Makefile b/firmware/l0dable/Makefile index 873523b..ddf10f1 100644 --- a/firmware/l0dable/Makefile +++ b/firmware/l0dable/Makefile @@ -43,8 +43,8 @@ $(LDFILE): %.o : %.c $(CC) $(CFLAGS) -o $@ $< -%.elf: %.o $(FIRMWARE) $(LDFILE) - $(LD) $(LDFLAGS) -T $(LDFILE) -o $@ $< +%.elf: %.o $(FIRMWARE) $(LDFILE) libmemcpy.a + $(LD) $(LDFLAGS) -T $(LDFILE) -o $@ $< -L. -lmemcpy $(SIZE) $@ %.bin: %.elf @@ -85,6 +85,13 @@ $(OBJS): usetable.h usetable.h: ./mktable.pl +help/memcpy.o: help/memcpy.c + +libmemcpy.a: help/memcpy.o + $(AR) rcs $@ $< + $(RANLIB) $(RANLIBFLAGS) $@ + + .SUFFIXES: .PHONY: $(LDFILE) diff --git a/firmware/l0dable/help/memcpy.c b/firmware/l0dable/help/memcpy.c new file mode 100644 index 0000000..42e900d --- /dev/null +++ b/firmware/l0dable/help/memcpy.c @@ -0,0 +1,10 @@ +#include +#include "../usetable.h" + +#undef memcpy + +void * memcpy(void *dst, const void *src, size_t len){ + return + (*(void * (*)(void *, const void *, size_t ))(*(TheTable+_memcpy_nr))) + (dst, src, len); +}; diff --git a/firmware/l0dable/mktable.pl b/firmware/l0dable/mktable.pl index cceebe7..f55b9ee 100755 --- a/firmware/l0dable/mktable.pl +++ b/firmware/l0dable/mktable.pl @@ -5,6 +5,7 @@ use strict; my $DIR="l0dable"; +my $memcpy; if( -d "../$DIR"){ chdir(".."); @@ -105,10 +106,16 @@ for my $idx (0..$#symb){ print C "$_,"; }; print I "#define $_ ($types{$_}(TheTable[$idx]))"; + if($_ eq "memcpy" || $_ eq "memmove"){ + $memcpy=$idx + }; }; print C "};"; +if (defined($memcpy)){ + print I "#define _memcpy_nr $memcpy"; +}; close(I); close(H); close(C); From 3f75d3d02550035d69035d8b97178e8a8a2e416b Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 24 Jan 2012 01:52:50 +0100 Subject: [PATCH 17/22] Cleanup: C files don't need an executable bit. --- firmware/core/libc/stdio.c | 0 firmware/core/libc/string.c | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 firmware/core/libc/stdio.c mode change 100755 => 100644 firmware/core/libc/string.c diff --git a/firmware/core/libc/stdio.c b/firmware/core/libc/stdio.c old mode 100755 new mode 100644 diff --git a/firmware/core/libc/string.c b/firmware/core/libc/string.c old mode 100755 new mode 100644 From f8e1227cff24563b4e9ace44d173796752346b8c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 25 Jan 2012 20:21:29 +0100 Subject: [PATCH 18/22] move date to right, so i can read it better --- firmware/l0dable/dbgmesh.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/l0dable/dbgmesh.c b/firmware/l0dable/dbgmesh.c index c97d9a8..83a6c2f 100644 --- a/firmware/l0dable/dbgmesh.c +++ b/firmware/l0dable/dbgmesh.c @@ -95,6 +95,7 @@ void m_time(void){ lcdPrint(":"); lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); lcdNl(); + lcdPrint(" "); lcdPrint(IntToStr(tm->tm_mday,2,F_LONG)); lcdPrint("."); lcdPrint(IntToStr(tm->tm_mon+1,2,0)); From f5df1d1cccb0c05256dbe116cbda43d6db76c1dc Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 25 Jan 2012 20:22:04 +0100 Subject: [PATCH 19/22] move mesh break date to the future, again --- firmware/funk/mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index e75603e..3a15b43 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -46,7 +46,7 @@ int mesh_sanity(uint8_t * pkt){ if(MO_TYPE(pkt)=='T' && MO_TIME(pkt)<86400) return MP_OK; if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){ - if(MO_TIME(pkt)>1326409200) + if(MO_TIME(pkt)>1336159200) return MP_SEND; if(MO_TIME(pkt)<1324602000) return MP_SEND; From 9ea8561363d7157723b12e2d6f0d74648a0748e5 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 25 Jan 2012 20:23:04 +0100 Subject: [PATCH 20/22] increase release no --- firmware/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/main.c b/firmware/main.c index 3a66d2e..e94a188 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -77,5 +77,5 @@ int main(void) { } int getrelease(void){ - return 0x00000108; + return 0x00000109; }; From 8fa03754248b2c87870f69ff809efd8d490f0d2b Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 26 Jan 2012 20:07:21 +0100 Subject: [PATCH 21/22] enhance smartflash makefile a bit --- tools/smartflash/Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/smartflash/Makefile b/tools/smartflash/Makefile index b9770df..df57f6f 100644 --- a/tools/smartflash/Makefile +++ b/tools/smartflash/Makefile @@ -1,5 +1,11 @@ -setup: +dwim: build setup + +all: dwim run + +build: cd ../../firmware && make clean && make && make l0dables + +setup: cp ../../firmware/firmware.bin . -mkdir files cp ../../firmware/l0dable/*c0d files @@ -14,8 +20,9 @@ setup: @echo @echo Now run ./smartflash +run: + ./smartflash + clean: rm -f firmware.bin generate-keys rm -rf files - - From f6dc1f793d518eb793f21072000545152a0c722b Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 26 Jan 2012 20:08:06 +0100 Subject: [PATCH 22/22] Change timelimits for mesh into something more sensible for real users :) --- firmware/funk/mesh.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 3a15b43..baf8ee7 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -46,12 +46,12 @@ int mesh_sanity(uint8_t * pkt){ if(MO_TYPE(pkt)=='T' && MO_TIME(pkt)<86400) return MP_OK; if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){ - if(MO_TIME(pkt)>1336159200) + if(MO_TIME(pkt)>1370340000) /* 4.Jun 2013 */ return MP_SEND; - if(MO_TIME(pkt)<1324602000) + if(MO_TIME(pkt)<1325376000) /* 1.1.2012 */ return MP_SEND; }else if(MO_TYPE(pkt)>='a' && MO_TYPE(pkt)<='z'){ - if(MO_TIME(pkt)>16777216) + if(MO_TIME(pkt)>16777216) /* 3-byte only */ return MP_SEND; if(MO_TIME(pkt)<0) return MP_SEND;