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; }
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; }
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); };
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"); } } }
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"); } } }