From b0b30b86a57e28cfdcd5f2fdda5f2720f2b8b4f8 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 01:53:48 +0100 Subject: [PATCH 1/7] Fix mesh. Actually check CRCs again. Increment release no. --- firmware/funk/mesh.c | 4 +++- firmware/funk/mesh.h | 2 +- firmware/funk/nrf24l01p.c | 3 +-- firmware/main.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index f0ef254..aa56457 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -198,7 +198,7 @@ static inline uint32_t popcount(uint32_t *buf, uint8_t n){ uint8_t mesh_recvqloop_work(void){ __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; + unsigned int len; len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,NULL); @@ -249,6 +249,8 @@ uint8_t mesh_recvqloop_work(void){ (*( (uint32_t*)(MO_BODY(buf)+6) ))++; + if(GLOBAL(privacy)==0) + uint32touint8p(GetUUID32(),MO_BODY(buf)+20); MO_TIME_set(mpkt->pkt,0); }; #if 0 diff --git a/firmware/funk/mesh.h b/firmware/funk/mesh.h index 318dd2a..535c661 100644 --- a/firmware/funk/mesh.h +++ b/firmware/funk/mesh.h @@ -9,7 +9,7 @@ #define M_RECVTIM 100 #define MESH_CHANNEL 83 -#define MESH_MAC "MESHB" +#define MESH_MAC "BMESH" #define MO_TYPE(x) (x[0]) #define MO_TYPE_set(x,y) (x[0]=y) diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index b07f195..27ee840 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -151,8 +151,7 @@ int nrf_rcv_pkt_poll_dec(int maxsize, uint8_t * pkt, uint32_t const key[4]){ if(len <=0) return len; - if(key==NULL) - return len; +// if(key==NULL) return len; cmpcrc=crc16(pkt,len-2); if(key!=NULL) diff --git a/firmware/main.c b/firmware/main.c index 538f541..f193350 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -77,5 +77,5 @@ int main(void) { } int getrelease(void){ - return 0x00000104; + return 0x00000105; }; From 642a71303dba477d7d1da8e832e176c0c3f3290c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 02:05:35 +0100 Subject: [PATCH 2/7] New loadable to show release --- firmware/l0dable/release.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 firmware/l0dable/release.c diff --git a/firmware/l0dable/release.c b/firmware/l0dable/release.c new file mode 100644 index 0000000..32c1b65 --- /dev/null +++ b/firmware/l0dable/release.c @@ -0,0 +1,21 @@ +#include +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/render.h" +#include "lcd/print.h" + +#include "usetable.h" + +/**************************************************************************/ + +void ram(void) { + lcdClear(); + lcdPrintln("r0ket"); + lcdPrintln("Release: "); + lcdPrintln(IntToStrX(getrelease(),8)); + lcdRefresh(); + while(!getInputRaw())work_queue(); +}; From 3d9da1ec9e45e8bd16e8b784c048ddf89e109e65 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 11:56:16 +0100 Subject: [PATCH 3/7] bpong-client improved incl. player ctr --- tools/game/bong/bong.html | 10 ++++++++++ tools/game/bong/bong.js | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/game/bong/bong.html b/tools/game/bong/bong.html index bb00663..39f122b 100644 --- a/tools/game/bong/bong.html +++ b/tools/game/bong/bong.html @@ -28,6 +28,14 @@ div } div.score +{ + color: #33FF33; + background-color: transparent; + width: 640px; + font-size: 20px; + font-family: courier new; +} +div.player { color: #33FF33; background-color: transparent; @@ -46,5 +54,7 @@ div.score
s_data...
debug
+
0
+
0
diff --git a/tools/game/bong/bong.js b/tools/game/bong/bong.js index d172cc0..bfe79ea 100644 --- a/tools/game/bong/bong.js +++ b/tools/game/bong/bong.js @@ -1,5 +1,5 @@ // Initialisation -var socket = "ws://83.133.179.198:8888/data"; +var socket = "ws://127.0.0.1:8888/data"; var field= { w: 320, h: 240 }; var paddle = { w: 2, h: 30 }; var ball = { w: 5, h: 5, s: 5 }; @@ -12,6 +12,9 @@ function pong() { this.score = {}; this.score.left = {}; this.score.right = {}; + this.cnt = {}; + this.cnt.left = {}; + this.cnt.right = {}; this.field = {}; this.game = { run: 0 }; @@ -40,6 +43,12 @@ function pong() { setupavatar(this.right); setupavatar(this.field); + this.cnt.left.avatar=$('div#player_left'); + this.cnt.right.avatar=$('div#player_right'); + + $('div#player_left').css({top: 2*this.field.size.h-30}); + $('div#player_right').css({top: 2*this.field.size.h-30}); + this.field.avatar.focus(); this.score.left.pts=0; @@ -209,10 +218,15 @@ pong.prototype.socketstart = function(uri){ var result=JSON.parse(data); if (result.right){ this.setright(result.right); - } else if (result.left){ + } ; + if (result.left){ this.setleft(result.left); - }else { - // unknown json input + }; + if (result.cntl){ + this.cnt.left.avatar.html(result.cntl); + }; + if (result.cntr){ + this.cnt.right.avatar.html(result.cntr); }; }else{ // unknown non-json input From 66ae4deb2a45a2049134ec0513d74ae97e6bc8c2 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 16:59:24 +0100 Subject: [PATCH 4/7] fix json parsing. Also: global variables solve problems :-) --- tools/game/bong/bong.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/game/bong/bong.js b/tools/game/bong/bong.js index bfe79ea..4d58046 100644 --- a/tools/game/bong/bong.js +++ b/tools/game/bong/bong.js @@ -216,17 +216,17 @@ pong.prototype.socketstart = function(uri){ $('#socket').html(data); if(data.slice(0,1)=="{"){ var result=JSON.parse(data); - if (result.right){ - this.setright(result.right); + if ("right" in result){ + game.setright(result.right); } ; - if (result.left){ - this.setleft(result.left); + if ("left" in result){ + game.setleft(result.left); }; - if (result.cntl){ - this.cnt.left.avatar.html(result.cntl); + if ("cntl" in result){ + game.cnt.left.avatar.html(result.cntl); }; - if (result.cntr){ - this.cnt.right.avatar.html(result.cntr); + if ("cntr" in result){ + game.cnt.right.avatar.html(result.cntr); }; }else{ // unknown non-json input From 85247db7d2adbe1d3fe8558a9e3ce8ff5bcebd6f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 17:26:59 +0100 Subject: [PATCH 5/7] Add bong-integrator for openbeacon reader support. Sorry, it's hacky. --- tools/game/bong/integrator-reader.py | 77 ++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/tools/game/bong/integrator-reader.py b/tools/game/bong/integrator-reader.py index 8d42fb7..890b488 100644 --- a/tools/game/bong/integrator-reader.py +++ b/tools/game/bong/integrator-reader.py @@ -9,35 +9,80 @@ import os.path import logging import threading import socket +import time from tornado.options import define, options define("port", default=8888, help="run on the given port", type=int) pong=None -pos=0.5 +left=0.0 +right=0.0 +cntr=0 +cntl=0 +info={} def sendpos(): + global right, left + global cntr, cntl + global info + sstr="{ \"right\": %s, \"cntr\": %s , \"cntl\": %s, \"left\": %s }"%(right,cntr,cntl,left) if pong: - pong.write_message("{ \"right\": "+str(pos)+" }") - threading.Timer(.5,sendpos).start() + pong.write_message(sstr) +# print sstr + threading.Timer(.1,sendpos).start() + for (id,(b,t,r)) in info.items(): + if(t+51: - pos=1 - def workPacket(data, addr): - print "new packet:", list(data), addr + global right, left + global cntr, cntl + global reid + global r0id + global button + global info +# print "new packet:", list(data), addr + reid=ord(data[4])*256 + ord(data[5]) + r0id=ord(data[19])*256*256*256 + ord(data[20])*256*256+ord(data[21])*256+ord(data[22]) + button=ord(data[27]) + rl=1 + if reid == 1123: + rl=2 + info[r0id]=(button,time.time(),rl) + print "added rl=%s r0=%s bu=%s"%(rl,r0id,button) def readerThread(): sock = socket.socket( socket.AF_INET, # Internet From 3a20ddf824a1c50c26139e27741ae79c1bbf9072 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 17:28:23 +0100 Subject: [PATCH 6/7] subtle fixes --- tools/smartflash/Makefile | 1 + tools/smartflash/mass | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/smartflash/Makefile b/tools/smartflash/Makefile index 79b8c25..b27adbe 100644 --- a/tools/smartflash/Makefile +++ b/tools/smartflash/Makefile @@ -6,6 +6,7 @@ setup: cp ../../firmware/l0dable/*nik files cp ../../firmware/l0dable/*int files cp ../../firmware/l0dable/files/* files + mv files/debug.int 1files/debug.int cp ../font/binary/*f0n files cp ../image/lcd/*lcd files cp ../image/lcd/i42.lcd files/nick.lcd diff --git a/tools/smartflash/mass b/tools/smartflash/mass index cf7a3cd..d5d6cc8 100755 --- a/tools/smartflash/mass +++ b/tools/smartflash/mass @@ -17,7 +17,6 @@ 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 \ @@ -29,6 +28,7 @@ cp \ 1files/r0type.c0d \ 1files/beaconid.c0d \ 1files/people.c0d \ + 1files/release.c0d \ 1files/starfld.c0d \ 1files/static.c0d \ 1files/sendcard.c0d \ @@ -44,7 +44,7 @@ cp \ 1files/scope.c0d \ 1files/Geigerct.c0d \ 1files/voltage.c0d \ - files/debug.int \ + 1files/debug.int \ files/* \ $dir/$dev #sync From ea19c3618badca98bd8ee8d9ca295f4f5d13d42d Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 27 Dec 2011 17:29:55 +0100 Subject: [PATCH 7/7] little improvements --- tools/mesh/dbg.pl | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/mesh/dbg.pl b/tools/mesh/dbg.pl index 399349b..bf9ba01 100755 --- a/tools/mesh/dbg.pl +++ b/tools/mesh/dbg.pl @@ -37,8 +37,8 @@ if($cmd =~ /^r/){ $cmd=~s/r//; $cmd+=1; my $fmt=shift; + my $read=""; while($cmd-->0){ - my $read=""; while($read !~ /\\1.*\\0/){ my $rr=""; if (@fh = $sel->can_read(100)) { @@ -46,20 +46,34 @@ if($cmd =~ /^r/){ $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))," "; + while ($read =~ s/\\1(.*?)\\0//){ + my $str=$1; + my $cs=substr($str,0,30); + my $crc=unpack("n",substr($str,30,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"; + }else{ + print "Read: <"; sprint $str; print ">\n"; + }; + print "CRCFAIL" if ($crc ne $crc2); print "\n"; }; - my $cs=substr($read,0,30); - my $crc=substr($read,30,2); - print unpack("n",$crc),"<>"; - print crcccitt($cs),"\n"; }; + print "rest: <"; sprint $read; print ">\n"; + exit; }elsif ($cmd eq "mt"){ my $par=pack("H*",shift); print "Write: <"; sprint $par; print ">\n"; @@ -120,7 +134,7 @@ if($cmd =~ /^r/){ }elsif($scmd eq "b"){ $par.="B"; $par.=chr(shift); #gen - $par.=pack("N",scalar(time)+1*60*60+ 300); + $par.=pack("N",scalar(time)+1*60*60+ 600); $par.= pack("C",shift||0); $par.= pack("C",0); @@ -137,6 +151,7 @@ if($cmd =~ /^r/){ }; $par.=pack("n",crcccitt($par)); +# $par.="00"; print "Write: <"; sprint $par; print ">\n"; while($cmd-->0){ syswrite(SER, '\1'.$par.'\0');