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

This commit is contained in:
schneider 2011-12-27 17:34:36 +01:00
commit d88250fc5a
11 changed files with 150 additions and 43 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,21 @@
#include <sysinit.h>
#include <string.h>
#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();
};

View File

@ -77,5 +77,5 @@ int main(void) {
}
int getrelease(void){
return 0x00000104;
return 0x00000105;
};

View File

@ -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
</input>
<div style="font-size:14;color:black;background-color:white;" id="socket">s_data...</div>
<div style="font-size:14;color:black;background-color:white;" id="debug">debug</div>
<div class="player" style="text-align:left" id="player_left">0</div>
<div class="player" style="text-align:right" id="player_right">0</div>
</body>
</html>

View File

@ -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;
@ -207,12 +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);
} else if (result.left){
this.setleft(result.left);
}else {
// unknown json input
if ("right" in result){
game.setright(result.right);
} ;
if ("left" in result){
game.setleft(result.left);
};
if ("cntl" in result){
game.cnt.left.avatar.html(result.cntl);
};
if ("cntr" in result){
game.cnt.right.avatar.html(result.cntr);
};
}else{
// unknown non-json input

View File

@ -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+5<time.time()):
# print "time=%s"%(time.time())
del info[id]
sumr=0.0
suml=0.0
cntr=0.0
cntl=0.0
for (id,(b,t,r)) in info.items():
if r==1:
cntr+=1
else:
cntl+=1
if b&1==1:
if r==1:
sumr-=1
else:
suml-=1
if b&2==2:
if r==1:
sumr+=1
else:
suml+=1
# print "summing: suml=%s cntl=%s sumr=%s cntr=%s"%(suml,cntl,sumr,cntr)
if cntr==0:
right=0
else:
right=sumr/cntr
if cntl==0:
left=0
else:
left=suml/cntl
# print "right=%s left=%s"%(right,left)
sendpos()
def receivedPacket(packet):
global pos
if isinstance(packet,r0ketrem0te.packets.Button):
if packet.button == 2:
pos+=.01
if packet.button == 1:
pos-=.01
if pos <0:
pos=0
if pos >1:
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

View File

@ -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');

View File

@ -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

View File

@ -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