예제 #1
0
파일: mesh.c 프로젝트: falkorichter/r0ket
uint8_t mesh_recvqloop_work(void){
    __attribute__ ((aligned (4))) uint8_t buf[32];
    int len;

        len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,meshkey);

        // Receive
        if(len<=0){
            return 0;
        };

        if(MO_GEN(buf)>meshgen){
            if(meshgen)
                meshgen++;
            else
                meshgen=MO_GEN(buf);
            _timet=0;
            meshincctr=0;
            meshnice=0;
        };

        if(MO_TYPE(buf)=='T'){
            time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED));
            if (toff>_timet){ // Do not live in the past.
                _timet = toff;
                meshincctr++;
            };
            if(MO_BODY(buf)[4] > meshnice)
                meshnice=MO_BODY(buf)[4];
            return 1;
        };

        // Safety: Truncate ascii packets by 0-ing the CRC
        buf[MESHPKTSIZE-2]=0;

        // Store packet in a same/free slot
        MPKT* mpkt=meshGetMessage(MO_TYPE(buf));

        // Skip locked packet
        if(mpkt->flags&MF_LOCK)
            return 2;

        // only accept newer/better packets
        if(mpkt->flags==MF_USED)
            if(MO_TIME(buf)<=MO_TIME(mpkt->pkt))
                return 2;

        if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') ||
                (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C'))
                    meshmsg=1;

        memcpy(mpkt->pkt,buf,MESHPKTSIZE);
        mpkt->flags=MF_USED;
        return 1;
};
예제 #2
0
파일: jump.c 프로젝트: Bediko/r0ket
static uint32_t highscore_get(char nick[]){
    MPKT * mpkt= meshGetMessage('j');

    strcpy(nick,(char*)MO_BODY(mpkt->pkt));

	return MO_TIME(mpkt->pkt);
}
예제 #3
0
파일: spam.c 프로젝트: astro/lun1k
static int mesh_sanity(uint8_t * pkt){
    if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){
        if(MO_TIME(pkt)>1313803870)
            return 1;
        if(MO_TIME(pkt)<1312075898)
            return 1;
    }else if(MO_TYPE(pkt)>='a' && MO_TYPE(pkt)<='z'){
        if(MO_TIME(pkt)>16777216)
            return 1;
        if(MO_TIME(pkt)<0)
            return 1;
    };
    if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
        return 1;
    return 0;
};
예제 #4
0
파일: mesh.c 프로젝트: falkorichter/r0ket
void mesh_cleanup(void){
    time_t now=getSeconds();
    for(int i=1;i<MESHBUFSIZE;i++){
        if(meshbuffer[i].flags&MF_USED){
            if (MO_GEN(meshbuffer[i].pkt)<meshgen)
                meshbuffer[i].flags=MF_FREE;
            if (MO_TYPE(meshbuffer[i].pkt)>='a' &&
                    MO_TYPE(meshbuffer[i].pkt)<='z'){
                ;
            }else{
                if (MO_TIME(meshbuffer[i].pkt)<now)
                    meshbuffer[i].flags=MF_FREE;
                if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY)
                    meshbuffer[i].flags=MF_FREE;
            };
        };
    };
};
예제 #5
0
static bool highscore_set(uint32_t score, char nick[]) {
    MPKT * mpkt= meshGetMessage('i');
    if(MO_TIME(mpkt->pkt)>score)
        return false;

    MO_TIME_set(mpkt->pkt,score);
    strcpy((char*)MO_BODY(mpkt->pkt),nick);
	return true;
}
예제 #6
0
static uint32_t highscore_get(char nick[]){
#if 0
    MPKT * mpkt= meshGetMessage('s');
    char * packet_nick = (char*)MO_BODY(mpkt->pkt);
    // the packet crc end is already zeroed
    if(MAXNICK<MESHPKTSIZE-2-6-1)
        packet_nick[MAXNICK-1] = 0;
    strcpy(nick, packet_nick);
    return MO_TIME(mpkt->pkt);
#endif
    return 0;
}
예제 #7
0
static void getGeigerMeshVal()
{
	MPKT * mpkt= meshGetMessage('g');
	//char buf[32];
	if (MO_TIME(mpkt->pkt)!=0) {
		lcdPrint("Mesh:");
		lcdPrintln((char*)MO_BODY(mpkt->pkt));
		//lcdPrintln("cpm");
	} else {
		mpkt->flags=MF_FREE;
	}
}
예제 #8
0
파일: jump.c 프로젝트: Bediko/r0ket
static bool highscore_set(uint32_t score, char nick[]) {
    MPKT * mpkt= meshGetMessage('j');
    if(MO_TIME(mpkt->pkt)>score)
        return false;

    MO_TIME_set(mpkt->pkt,score);
    strcpy((char*)MO_BODY(mpkt->pkt),nick);
    if(GLOBAL(privacy)==0){
        uint32touint8p(GetUUID32(),mpkt->pkt+26);
        mpkt->pkt[25]=0;
    };
	return true;
}
예제 #9
0
파일: snake.c 프로젝트: cokesme/f1rmware
static uint32_t highscore_get()
{
    uint32_t score = 0;
    readFile("snake.5cr", &score, sizeof(score));

    // old r0ket code to send highscore to the world
#if 0
    MPKT * mpkt= meshGetMessage('s');
    char * packet_nick = (char*)MO_BODY(mpkt->pkt);
    // the packet crc end is already zeroed
    if(MAXNICK<MESHPKTSIZE-2-6-1)
        packet_nick[MAXNICK-1] = 0;
    strcpy(nick, packet_nick);
    return MO_TIME(mpkt->pkt);
#endif

    return score;
}
예제 #10
0
파일: snake.c 프로젝트: cokesme/f1rmware
static bool highscore_set(uint32_t score)
{
    writeFile("snake.5cr", &score , sizeof(uint32_t));

    // old r0ket code to get highscore from the world
#if 0
    MPKT * mpkt= meshGetMessage('s');
    if(MO_TIME(mpkt->pkt)>score)
        return false;

    MO_TIME_set(mpkt->pkt,score);
    strcpy((char*)MO_BODY(mpkt->pkt),nick);
    if(GLOBAL(privacy)==0) {
        uint32touint8p(GetUUID32(),mpkt->pkt+26);
        mpkt->pkt[25]=0;
    };
#endif
    return true;
}