Schnitzel support

This commit is contained in:
Stefan `Sec` Zehl 2011-08-05 10:29:39 +02:00
parent b025dcf409
commit eb9051aa7d
2 changed files with 75 additions and 5 deletions

View File

@ -120,7 +120,19 @@ char *meshmsgs(void){
return msgtypes; return msgtypes;
}; };
static inline uint32_t popcount(uint32_t *buf, uint8_t n){
int cnt=0;
do {
unsigned m = *buf++;
m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
cnt += m;
} while(--n);
return cnt;
}
extern MPKT meshbuffer[MESHBUFSIZE]; extern MPKT meshbuffer[MESHBUFSIZE];
//# MENU messages //# MENU messages
@ -152,6 +164,12 @@ void m_choose(){
case('T'): case('T'):
strcpy(p,"Time"); strcpy(p,"Time");
break; break;
case('Z'):
strcpy(p,"Schnitzel");
break;
case('z'):
strcpy(p,"S-Score");
break;
case('i'): case('i'):
strcpy(p,"Invaders"); strcpy(p,"Invaders");
break; break;
@ -188,6 +206,12 @@ void m_choose(){
case('T'): case('T'):
lcdPrintln("Time"); lcdPrintln("Time");
break; break;
case('Z'):
strcpy(p,"Schnitzel");
break;
case('z'):
strcpy(p,"S-Score");
break;
case('i'): case('i'):
lcdPrintln("Invaders"); lcdPrintln("Invaders");
break; break;
@ -203,7 +227,19 @@ void m_choose(){
lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS));
lcdNl(); lcdNl();
if(tmm[i]=='T'){ if(tmm[i]=='Z'){
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+ 6),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+10),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+14),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+18),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+22),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+26),8));
lcdPrint(IntToStr(popcount(meshbuffer[j].pkt+6,6),3,0));
lcdPrintln(" pts.");
lcdRefresh();
getInputWaitRelease();
continue;
}else if(tmm[i]=='T'){
lcdPrint(IntToStr(tm->tm_mday,2,F_LONG)); lcdPrint(IntToStr(tm->tm_mday,2,F_LONG));
lcdPrint("."); lcdPrint(".");
lcdPrint(IntToStr(tm->tm_mon+1,2,0)); lcdPrint(IntToStr(tm->tm_mon+1,2,0));

View File

@ -55,6 +55,8 @@ MPKT * meshGetMessage(uint8_t type){
void mesh_cleanup(void){ void mesh_cleanup(void){
time_t now=getSeconds(); time_t now=getSeconds();
for(int i=1;i<MESHBUFSIZE;i++){ for(int i=1;i<MESHBUFSIZE;i++){
if(meshbuffer[i].flags&MF_LOCK)
continue;
if(meshbuffer[i].flags&MF_USED){ if(meshbuffer[i].flags&MF_USED){
if (MO_GEN(meshbuffer[i].pkt)<meshgen) if (MO_GEN(meshbuffer[i].pkt)<meshgen)
meshbuffer[i].flags=MF_FREE; meshbuffer[i].flags=MF_FREE;
@ -126,6 +128,20 @@ void mesh_recvqloop_setup(void){
nrf_rcv_pkt_start(); nrf_rcv_pkt_start();
}; };
static inline uint32_t popcount(uint32_t *buf, uint8_t n){
int cnt=0;
do {
unsigned m = *buf++;
m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
cnt += m;
} while(--n);
return cnt;
}
uint8_t mesh_recvqloop_work(void){ uint8_t mesh_recvqloop_work(void){
__attribute__ ((aligned (4))) uint8_t buf[32]; __attribute__ ((aligned (4))) uint8_t buf[32];
int len; int len;
@ -164,9 +180,26 @@ 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));
// Skip locked packet // Schnitzel
if(mpkt->flags&MF_LOCK) if(MO_TYPE(buf)=='Z'){
return 2; mpkt->flags=MF_USED|MF_LOCK;
MO_TIME_set(mpkt->pkt,getSeconds());
MO_GEN_set(mpkt->pkt,0x70);
for(int i=6;i<MESHPKTSIZE;i++)
mpkt->pkt[i]|=buf[i];
int score=popcount(MO_BODY(mpkt->pkt),6);
MPKT* reply=meshGetMessage('z');
if(MO_TIME(reply->pkt)>=score)
return 1;
MO_TIME_set(reply->pkt,score);
strcpy((char*)MO_BODY(reply->pkt),GLOBAL(nickname));
return 1;
};
// only accept newer/better packets // only accept newer/better packets
if(mpkt->flags==MF_USED) if(mpkt->flags==MF_USED)
@ -179,6 +212,7 @@ uint8_t mesh_recvqloop_work(void){
memcpy(mpkt->pkt,buf,MESHPKTSIZE); memcpy(mpkt->pkt,buf,MESHPKTSIZE);
mpkt->flags=MF_USED; mpkt->flags=MF_USED;
return 1; return 1;
}; };