#include #include "basic/basic.h" #include "basic/byteorder.h" #include "lcd/lcd.h" #include "lcd/print.h" #include "funk/nrf24l01p.h" #include "usbcdc/usb.h" #include "usbcdc/usbcore.h" #include "usbcdc/usbhw.h" #include "usbcdc/cdcuser.h" #include "usbcdc/cdc_buf.h" #include "usbcdc/util.h" #include #define REMOTE_CHANNEL 91 #define REMOTE_MAC "REM0T" #define MESH_CHANNEL 85 #define MESH_MAC "MESHB" #define BEACON_CHANNEL 81 #define BEACON_MAC "\x1\x2\x3\x2\1" #include "SECRETS" char funkencrypt=0; #if CFG_USBMSC #error "MSC is defined" #endif #if !CFG_USBCDC #error "CDC is not defined" #endif /**************************************************************************/ uint32_t thekey[4] = { 0x0, 0x0, 0x0, 0x0 }; struct NRF_CFG config = { .channel= BEACON_CHANNEL, .txmac= BEACON_MAC, .nrmacs=1, .mac0= BEACON_MAC, .maclen ="\x10", }; int process(char * input); #define INPUTLEN 99 void dwim(void){ char input[INPUTLEN+1]; int inputptr=0; char dirty=0; usbCDCInit(); delayms(500); getInputWaitRelease(); puts("D start\r\n"); while(!getInputRaw()){ // Input int l=INPUTLEN-inputptr; CDC_OutBufAvailChar (&l); if(l>0){ dirty=10; if(l>1) dirty=50; CDC_RdOutBuf (input+inputptr, &l); if(input[inputptr]==8){ inputptr=0; puts("\r\n"); continue; }; input[inputptr+l]=0; puts_plus(&input[inputptr]); for(int i=0;i0) dirty--; if(dirty==1) puts(""); }; inputptr+=l; }; puts("D exit\r\n"); } #define BUFLEN 32 #define NYB(x) ((x>'9')?(x|0x20)-'a'+10:x-'0') uint8_t * hextobyte(char * input, int *len){ static uint8_t buf[BUFLEN]; int p=0; int bp=0; char c; while(bp0){ delayms(23); memcpy(buf,hex,len); status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL); }; }else if (input[1]=='t'){ static int ctr=1; int status; buf[0]=0x10; // Length: 16 bytes buf[1]='1'; // Proto buf[2]=0x00; buf[3]=0x00; // Unused uint32touint8p(ctr++,buf+4); uint32touint8p(0x5ec,buf+8); buf[12]=0xff; // salt (0xffff always?) buf[13]=0xff; status=nrf_snd_pkt_crc_encr(16,buf,funkencrypt?thekey:NULL); }else{ }; puts_plus("S state="); puts_plus(IntToStrX( status,2 )); puts_plus("\r\n"); }else if (input[0]=='r'){ __attribute__ ((aligned (4))) uint8_t buf[32]; int len; int pctr=5; int t=getTimer()+5000/SYSTICKSPEED; if(input[1]=='+'){ if(input[2]!=0){ uint8_t *hex=hextobyte(&input[2],&len); t=getTimer()+hex[0]*1000/SYSTICKSPEED; }; pctr=-1; } if(input[1]=='-'){ uint8_t *hex=hextobyte(&input[2],&len); pctr=hex[0]; } puts_plus("D receive ...\r\n"); nrf_rcv_pkt_start(); do{ len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,funkencrypt?thekey:NULL); // Receive if(len==0||len==-1||len==-2){ //No pkt, Pkt2large, NoPktError delayms(10); continue; }; puts_plus("R "); puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] "); if(len==-3){ puts_plus("[!crc] "); len=16; }; for(int i=0;i0){ puts_plus("\r\nD Abort.\r\n"); break; }; }; puts("\r\n"); if(pctr--==0) break; }while(t>getTimer()); nrf_rcv_pkt_end(); }else{ puts_plus("D no action\r\n"); }; puts("D done.\r\n"); return 0; };