Ejemplo n.º 1
0
uint8_t selectGame()
{  
    int len, i, selected;
    struct packet p;
    int a = 0;
    config.channel = ANNOUNCE_CHANNEL;
    memcpy(config.mac0, ANNOUNCE_MAC, 5);
    nrf_config_set(&config);

    gamecount = 0;
    for(i=0;i<60;i++){
        len= nrf_rcv_pkt_time(30, sizeof(p), (uint8_t*)&p);
        if (len==sizeof(p)){
            if( a ) a = 0; else a = 1;
            gpioSetValue (RB_LED2, a);
            processPacket(&p);
        }
    }
    selected = 0;
    while(1){
        showGames(selected);
        int key=getInputWait();
        getInputWaitRelease();
        switch(key){
            case BTN_DOWN:
                if( selected < gamecount-1 ){
                    selected++;
                }
                break;
            case BTN_UP:
                if( selected > 0 ){
                    selected--;
                }
                break;
            case BTN_LEFT:
                return 0;
            case BTN_ENTER:
            case BTN_RIGHT:
                if( gamecount == 0 )
                    return 0;
                gameId = games[selected].gameId;
                memcpy(config.txmac, games[selected].gameMac, 5);
                memcpy(config.mac0, games[selected].gameMac, 5);
                config.mac0[4]++;
                config.channel = games[selected].gameChannel;
                interval = games[selected].interval;
                jitter = games[selected].jitter;
                flags = games[selected].gameFlags;
                nrf_config_set(&config);
                if( games[selected].gameFlags & FLAGS_MASS_GAME )
                    return 1;
                else
                    return joinGame();
        }
    }
}
Ejemplo n.º 2
0
void ram(void) {
    struct NRF_CFG config;
    uint8_t buf[16];
    
    // Space to save signal strength and username.
    uint8_t count = 0;
    char usernames[8][16];
    uint8_t strength[8];

    config.nrmacs=1;
    config.maclen[0] = 16;
    config.channel = 81;
    memcpy(config.mac0, "\x01\x02\x03\x02\x01", 5);
    nrf_config_set(&config);
    lcdClear();
    lcdPrintln("Track it:");
    lcdPrintln("---------");
    lcdRefresh();
    do{
        if( nrf_rcv_pkt_time(64,sizeof(buf),buf) == 16 ){
            buf[14] = 0;
            // TODO: allow last package parameter 0x25
            if( buf[1] == 0x23 || buf[1] == 0x24){
                if(0==insertUser(usernames, strength, (char *)buf+6, buf[3],
                  count)) {
                  if(count<8) ++count;
                  printNames(usernames, strength, count);
                }
            }
        }
    }while ((getInputRaw())==BTN_NONE);
}
Ejemplo n.º 3
0
void configNrf(){
    struct NRF_CFG config;
	config.nrmacs = 1;
	config.maclen[0] = 32;
	config.channel = CHANNEL;
    memcpy(config.mac0, ANNOUNCEMENT_MAC, 5);
    memcpy(config.txmac, ANNOUNCEMENT_MAC, 5);
	nrf_config_set(&config);
    nrf_set_strength(3);
}
Ejemplo n.º 4
0
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);
    nrf_config_set(&config);

    id = getRandom();
    ctr = 1;
 
    while( selectGame() ){
        playGame();
    }
    GLOBAL(privacy) = priv;
};
Ejemplo n.º 5
0
void mesh_sendloop(void){
    int ctr=0;
    __attribute__ ((aligned (4))) uint8_t buf[32];
    int status;
    uint32_t rnd=0xffffffff;

    if(meshnice)
        rnd=getRandom();

    nrf_config_get(&oldconfig);
    nrf_set_channel(MESH_CHANNEL);
    nrf_set_tx_mac(strlen(MESH_MAC),(uint8_t*)MESH_MAC);

    // Update [T]ime packet
    MO_TIME_set(meshbuffer[0].pkt,getSeconds());
    MO_GEN_set(meshbuffer[0].pkt,meshgen);
    if(GLOBAL(privacy)==0)
        uint32touint8p(GetUUID32(),MO_BODY(meshbuffer[0].pkt));
    else
        uint32touint8p(0,MO_BODY(meshbuffer[0].pkt));

    MO_BODY(meshbuffer[0].pkt)[4]=meshnice;

    for (int i=0;i<MESHBUFSIZE;i++){
        if(!meshbuffer[i].flags&MF_USED)
            continue;
        if(meshbuffer[i].flags&MF_LOCK)
            continue;
        if(meshnice&0xf){
            if((rnd++)%0xf < (meshnice&0x0f)){
                meshincctr++;
                continue;
            };
        };
        ctr++;
        memcpy(buf,meshbuffer[i].pkt,MESHPKTSIZE);
        status=nrf_snd_pkt_crc_encr(MESHPKTSIZE,buf,meshkey);
        //Check status? But what would we do...
    };

    nrf_config_set(&oldconfig);
};
Ejemplo n.º 6
0
Archivo: funk.c Proyecto: Bediko/r0ket
void f_cfg_set(void){
    struct NRF_CFG config = {
        .channel= 13,
        .txmac= "R0KET",
        .nrmacs=1,
        .mac0=  "R0KET",
        .maclen ="\x10",
    };

    nrf_config_set(&config);
};

void f_enctog(void){
    enctoggle=1-enctoggle;
    if(enctoggle)
        lcdPrintln("Encrypt ON!");
    else
        lcdPrintln("encrypt off!");

};
Ejemplo n.º 7
0
Archivo: funk.c Proyecto: Bediko/r0ket
void f_init(void){
    nrf_init();

    struct NRF_CFG config = {
        .channel= BEACON_CHANNEL,
        .txmac= BEACON_MAC,
        .nrmacs=1,
        .mac0=  BEACON_MAC,
        .maclen ="\x10",
    };

    nrf_config_set(&config);
    lcdPrintln("Done.");
};

void f_status(void){
    int dx=0;
    int dy=8;
    uint8_t buf[4];

    buf[0]=C_R_REGISTER | R_CONFIG;
    buf[1]=0;
    buf[2]=0;
    buf[3]=0;
    dx=DoString(0,dy,"S:"); 
    dx=DoCharX(dx,dy,buf[0]);
    dx=DoCharX(dx,dy,buf[1]);
    dx=DoCharX(dx,dy,buf[2]);
    dx=DoCharX(dx,dy,buf[3]);
    dy+=8;
    nrf_cmd_rw_long(buf,2);
    dx=DoString(0,dy,"R:");
    dx=DoCharX(dx,dy,buf[0]);
    dx=DoCharX(dx,dy,buf[1]);
    dx=DoCharX(dx,dy,buf[2]);
    dx=DoCharX(dx,dy,buf[3]);
    dy+=8;

    int status=nrf_cmd_status(C_NOP);
    dx=DoString(0,dy,"St:"); DoCharX(dx,dy,status);dy+=8;
};
Ejemplo n.º 8
0
Archivo: people.c Proyecto: C3MA/r0ket
void ram(void) {
    struct NRF_CFG config;
    uint8_t buf[16];

    config.nrmacs=1;
    config.maclen[0] = 16;
    config.channel = 81;
    memcpy(config.mac0, "\x01\x02\x03\x02\x01", 5);
    nrf_config_set(&config);
    lcdClear();
    lcdPrintln("People nearby:");
    //lcdPrint("nearby:");
    lcdRefresh();
    do{
        if( nrf_rcv_pkt_time(64,sizeof(buf),buf) == 16 ){
            buf[14] = 0;
            if( buf[1] == 0x23 || buf[1] == 0x24){
                lcdPrintln((char*)(buf+6));
                //lcdPrintln("foo");
            }
            lcdRefresh();
        }
    }while ((getInputRaw())==BTN_NONE);
}
Ejemplo n.º 9
0
void mesh_recvqloop_end(void){
    nrf_rcv_pkt_end();
    nrf_config_set(&oldconfig);
}
Ejemplo n.º 10
0
void main_bridge(void)
{
    GLOBAL(daytrig)=10;
    GLOBAL(lcdbacklight)=10;
    GLOBAL(privacy) = 3;
    char input[64];
    char led1=0;
    char led2=0;

    usbCDCInit();
    delayms(500);
    nrf_init();
    nrf_config_set(&config);
    
    nrf_rcv_pkt_start(R_CONFIG_EN_CRC);
    while(1){
        int l, i, status;
        CDC_OutBufAvailChar (&l);
        if(l>0){
            gpioSetValue (RB_LED0, led1);led1=1-led1;
            CDC_RdOutBuf (input, &l);
            for(i=0; i<l; i++){
                uint8_t cmd = serialmsg_put(input[i]);
                if( cmd != SERIAL_NONE ){
                    switch( cmd ){
                        case '1':
                            // can we loose packets here?
                            nrf_rcv_pkt_end();
                            status=snd_pkt_no_crc(serialmsg_len, serialmsg_message);
                            //status=nrf_snd_pkt_crc(serialmsg_len, serialmsg_message);
                            nrf_rcv_pkt_start(R_CONFIG_EN_CRC);
                        break;
                        case '3':
                            memcpy(config.txmac, serialmsg_message, 5);
                            nrf_write_long(C_W_REGISTER|R_TX_ADDR,5,config.txmac);
                        break;
                        case '4':
                            memcpy(config.mac0, serialmsg_message, 5);
                            nrf_write_long(C_W_REGISTER|R_RX_ADDR_P0,5,config.mac0);
                            nrf_write_reg(R_EN_RXADDR,1);
                        break;
                        case '5':
                            config.channel=serialmsg_message[0];
                            nrf_set_channel(config.channel);
                            nrf_cmd(C_FLUSH_RX);
                        break;
                        case '6':
                            config.maclen[0]=serialmsg_message[0];
                            nrf_write_reg(R_RX_PW_P0,config.maclen[0]);
                        break;
                        case '7':
                            puts("\\7");
                            char s[sizeof(uint32_t)+1];
                            *((uint32_t*)s) =GetUUID32();
                            s[sizeof(uint32_t)]=0;
                            puts(s);
                            puts("\\0");
                        break;
                        case '8': /* set mac width */
                            nrf_write_reg(R_SETUP_AW,serialmsg_message[0]);
                        break;
                        case '9': // Dis/Enable CRC
                            nrf_write_reg(R_CONFIG, R_CONFIG_PRIM_RX|R_CONFIG_PWR_UP|
                                    ((serialmsg_message[0]&1)?R_CONFIG_EN_CRC :0)|
                                    ((serialmsg_message[0]&2)?R_CONFIG_CRCO :0)
                                    
                                    );
                            /* maybe add enhanced shockburst stuff here */
                            nrf_cmd(C_FLUSH_RX);
                            nrf_write_reg(R_STATUS,0);
                        break;

                    };
                    puts("\\2\\0");
                }
            }
        }
        int len;
        uint8_t buf[32];
        len=nrf_rcv_pkt_poll(sizeof(buf),buf);
        if( len > 0 ){
            gpioSetValue (RB_LED2, led2);led2=1-led2;
            puts("\\1");
            dump_encoded(len, buf);
            puts("\\0");
        }
    }
}
Ejemplo n.º 11
0
Archivo: msn.c Proyecto: nupfel/r0ket
/*Message Receiver*/
void waitMsg()
{
    uint8_t key;
    unsigned char buf[32];
    char sender_nick[10];
    int n,i;
    int index=0;
    int rcv =0;
    int try=0;
    do
    {
        key = getInput();
        if(1)
        {
            nrf_config_set(&config);
            n = nrf_rcv_pkt_time(100,32,buf);
            getInputWaitTimeout(100);
            if(n == 32)
            {
                index=buf[0];
                for(i=0; i<10; i++)
                    sender_nick[i]=buf[i+1];
                lcdClear();
                lcdPrintln("");
                lcdPrintln("CCC MSN 0.1b");
                lcdPrintln("---------------");
                lcdPrintln(msgs[index]);
                lcdPrintln("");
                lcdPrintln("Received");
                lcdPrintln("");
                lcdPrintln("_______________");
                lcdPrintln(sender_nick);
                lcdRefresh();
                blink();
                rcv=1;
                try=0;
            } else if(rcv)
            {
                lcdClear();
                lcdPrintln("");
                lcdPrintln("CCC MSN 0.1b");
                lcdPrintln("-----------------");
                lcdPrintln("Waiting...");
                lcdPrint("Try ");
                lcdPrintln(IntToStr(try,5,0));
                lcdPrintln("");
                lcdPrintln(msgs[index]);
                lcdPrintln("_______________");
                lcdPrintln(sender_nick);
                lcdRefresh();
            }
            try++;
        }
        if(!rcv)
        {
            lcdClear();
            lcdPrintln("");
            lcdPrintln("CCC MSN 0.1b");
            lcdPrintln("-----------------");
            lcdPrintln("Waiting...");
            lcdPrintln("");
            lcdPrint("Try ");
            lcdPrintln(IntToStr(try,5,0));
            lcdPrintln("");
            lcdPrintln("_______________");
            lcdPrintln("W8 Users Auto");
            lcdRefresh();
        }
Ejemplo n.º 12
0
void main_bridge(void)
{
    GLOBAL(daytrig)=10;
    GLOBAL(lcdbacklight)=10;
    GLOBAL(privacy) = 3;
    char input[64];
    char led1=0;
    char led2=0;

    usbCDCInit();
    delayms(500);
    nrf_init();
    nrf_config_set(&config);
    
    nrf_rcv_pkt_start();
    while(1){
        int l, i, status;
        CDC_OutBufAvailChar (&l);
        if(l>0){
            gpioSetValue (RB_LED0, led1);led1=1-led1;
            CDC_RdOutBuf (input, &l);
            for(i=0; i<l; i++){
                uint8_t cmd = serialmsg_put(input[i]);
                if( cmd != SERIAL_NONE ){
                    switch( cmd ){
                        case '1':
                            // can we loose packets here?
                            nrf_rcv_pkt_end();
                            status=snd_pkt_no_crc(serialmsg_len, serialmsg_message);
                            //status=nrf_snd_pkt_crc(serialmsg_len, serialmsg_message);
                            nrf_rcv_pkt_start();
                        break;
                        case '3':
                            memcpy(config.txmac, serialmsg_message, 5);
                            nrf_config_set(&config);
                        break;
                        case '4':
                            memcpy(config.mac0, serialmsg_message, 5);
                            nrf_config_set(&config);
                        break;
                        case '5':
                            config.channel=serialmsg_message[0];
                            nrf_config_set(&config);
                        break;
                        case '6':
                            config.maclen[0]=serialmsg_message[0];
                            nrf_config_set(&config);
                        break;
                        case '7':
                            puts("\\7");
                            char s[sizeof(uint32_t)+1];
                            *((uint32_t*)s) =GetUUID32();
                            s[sizeof(uint32_t)]=0;
                            puts(s);
                            puts("\\0");
                        break;
                    };
                    puts("\\2\\0");
                }
            }
        }
        int len;
        uint8_t buf[32];
        len=nrf_rcv_pkt_poll(sizeof(buf),buf);
        if( len > 0 ){
            gpioSetValue (RB_LED2, led2);led2=1-led2;
            puts("\\1");
            dump_encoded(len, buf);
            puts("\\0");
        }
    }
}