Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
schneider 2011-08-09 18:16:11 +02:00
commit d4a0cdb4c2
8 changed files with 334 additions and 85 deletions

View File

@ -10,8 +10,12 @@ VPATH +=
OBJS += main.o
ifeq "$(wildcard table.c)" "table.c"
ifeq "$(APP)" "serial"
OBJS +=
else
OBJS += table.o
endif
endif
LIBS += lcd/liblcd.a
LIBS += basic/libbasic.a

View File

@ -1,11 +1,18 @@
i: initialize
cb / cm / cr: config funk for beacon/mesh/remote
Ck<hex>: set encryptionkey
Ct<hex>: set txmac
Cc<hex>: set channel
Ct<hex>: set rxmac(0)
Cl<hex>: set rxlens
Ce<hex>: sec encrpytion on/off
pb: preset funk for beacon
pm: preset funk for mesh
pM: preset funk for pubMesh
pr: preset funk for rem0te
t<char>: set packet dump type (b/B/m/M/0)
f<char><hex>: set filter stuff
ck<hex>: set encryptionkey
cm<hex>: set rxmac(0)
ct<hex>: set txmac
cc<hex>: set channel
cl<hex>: set rxlen
ce<hex>: sec encrpytion on/off
s <hex>: send packet
s+ <hex>: send packet 10 times
@ -13,4 +20,4 @@ sd <hex>: send packet with debugoutput
r: recv packets
r+<hex>: recv packets for <hex> seconds
r-<hex>: recv <hex> packets (5 seconds max)
r-<hex>: recv <hex> packets

View File

@ -0,0 +1,20 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include <string.h>
/**************************************************************************/
#include "serial.gen"
void main_serial(void) {
GLOBAL(daytrig)=10;
GLOBAL(lcdbacklight)=10;
handleMenu(&mainmenu);
gpioSetValue (RB_LED3, 1);
ISPandReset();
};
void serial(void);

View File

@ -23,7 +23,7 @@
#define BEACON_CHANNEL 81
#define BEACON_MAC "\x1\x2\x3\x2\1"
#include "SECRETS"
#include "SECRETS.release"
char funkencrypt=0;
@ -47,9 +47,15 @@ struct NRF_CFG config = {
.maclen ="\x10",
};
int process(char * input);
char type=0;
char filter=0;
uint8_t filterdata[10];
char outc[2]= {0,0};
static int process(char * input);
#define INPUTLEN 99
//# MENU serial
void dwim(void){
char input[INPUTLEN+1];
int inputptr=0;
@ -58,6 +64,8 @@ void dwim(void){
usbCDCInit();
delayms(500);
getInputWaitRelease();
nrf_init();
gpioSetValue (RB_LED1, 0);
puts("D start\r\n");
while(!getInputRaw()){
@ -97,13 +105,13 @@ void dwim(void){
};
inputptr+=l;
};
gpioSetValue (RB_LED1, 0);
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 * hextobyte(char * input, int *len){
static uint8_t buf[BUFLEN];
int p=0;
@ -123,7 +131,16 @@ uint8_t * hextobyte(char * input, int *len){
return buf;
};
int process(char * input){
static uint32_t gethexval(char * input){
int len;
uint8_t *hex=hextobyte(input,&len);
uint32_t v=hex[0];
while(--len>0)
v=v*256+(*++hex);
return v;
};
static int process(char * input){
if(input == NULL || input[0]==0)
return -1;
@ -135,7 +152,8 @@ int process(char * input){
if(input[0]=='i'){
nrf_init();
nrf_config_set(&config);
}else if(input[0]=='c'){
}else if(input[0]=='p'){
type=input[1];
if(input[1]=='m'){
config.channel=MESH_CHANNEL;
memcpy(config.txmac,MESH_MAC,5);
@ -145,6 +163,18 @@ int process(char * input){
nrf_config_set(&config);
memcpy(thekey,meshkey,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='M'){
config.channel=83;
memcpy(config.txmac,MESH_MAC,5);
memcpy(config.mac0,MESH_MAC,5);
config.maclen[0]=0x20;
config.nrmacs=1;
nrf_config_set(&config);
static const uint32_t const pubmesh[4] = {
0x00000042, 0x000005ec, 0x00000023, 0x00000005
};
memcpy(thekey,pubmesh,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='r'){
config.channel=REMOTE_CHANNEL;
memcpy(config.txmac,REMOTE_MAC,5);
@ -163,6 +193,43 @@ int process(char * input){
nrf_config_set(&config);
memcpy(thekey,openbeaconkey,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='B'){
config.channel=BEACON_CHANNEL;
memcpy(config.txmac,BEACON_MAC,5);
memcpy(config.mac0,BEACON_MAC,5);
config.maclen[0]=0x10;
config.nrmacs=1;
nrf_config_set(&config);
static const uint32_t pubbeaconkey[4] = {
0xB4595344, 0xD3E119B6, 0xA814D0EC, 0xEFF5A24E
};
memcpy(thekey,pubbeaconkey,sizeof(thekey));
funkencrypt=1;
};
}else if(input[0]=='t'){
type=input[1];
}else if(input[0]=='c'){
int len;
uint8_t *hex=hextobyte(&input[2],&len);
if(input[1]=='k'){
thekey[0]=uint8ptouint32(hex);
thekey[1]=uint8ptouint32(hex+4);
thekey[2]=uint8ptouint32(hex+8);
thekey[3]=uint8ptouint32(hex+12);
}else if(input[1]=='m'){
memcpy(config.mac0,hex,5);
nrf_config_set(&config);
}else if(input[1]=='t'){
memcpy(config.txmac,hex,5);
nrf_config_set(&config);
}else if(input[1]=='c'){
config.channel=hex[0];
nrf_config_set(&config);
}else if(input[1]=='l'){
config.maclen[0]=hex[0];
nrf_config_set(&config);
}else if(input[1]=='e'){
funkencrypt= hex[0];
}else if(input[1]=='?'){
nrf_config_get(&config);
puts_plus("Ch: ");puts_plus(IntToStrX( config.channel,2 )); puts_plus("\r\n");
@ -203,41 +270,6 @@ int process(char * input){
puts_plus(IntToStrX( funkencrypt,2 ));
puts_plus("\r\n");
};
}else if(input[0]=='C'){
int len;
uint8_t *hex=hextobyte(&input[2],&len);
if(input[1]=='k'){
thekey[0]=uint8ptouint32(hex);
thekey[1]=uint8ptouint32(hex+4);
thekey[2]=uint8ptouint32(hex+8);
thekey[3]=uint8ptouint32(hex+12);
}else if(input[1]=='m'){
config.mac0[0]=uint8ptouint32(hex);
config.mac0[1]=uint8ptouint32(hex+4);
config.mac0[2]=uint8ptouint32(hex+8);
config.mac0[3]=uint8ptouint32(hex+12);
config.mac0[4]=uint8ptouint32(hex+16);
nrf_config_set(&config);
}else if(input[1]=='t'){
config.txmac[0]=uint8ptouint32(hex);
config.txmac[1]=uint8ptouint32(hex+4);
config.txmac[2]=uint8ptouint32(hex+8);
config.txmac[3]=uint8ptouint32(hex+12);
config.txmac[4]=uint8ptouint32(hex+16);
nrf_config_set(&config);
}else if(input[1]=='c'){
config.channel=*hex;
nrf_config_set(&config);
}else if(input[1]=='l'){
config.maclen[0]=uint8ptouint32(hex);
config.maclen[1]=uint8ptouint32(hex+4);
config.maclen[2]=uint8ptouint32(hex+8);
config.maclen[3]=uint8ptouint32(hex+12);
config.maclen[4]=uint8ptouint32(hex+16);
nrf_config_set(&config);
}else if(input[1]=='e'){
funkencrypt= uint8ptouint32(hex);
};
}else if (input[0]=='s'){
__attribute__ ((aligned (4))) uint8_t buf[32];
int status=0;
@ -262,14 +294,18 @@ int process(char * input){
memcpy(buf,hex,len);
status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL);
if(debug){
puts_plus("P ");
puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] ");
if(debug){
for(int i=0;i<len;i++){
puts_plus(IntToStrX( buf[i],2 ));
puts_plus(" ");
};
};
puts_plus("S ");
puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] ");
puts_plus("state=");
puts_plus(IntToStrX( status,2 ));
puts("\r\n");
while(--ctr>0){
@ -277,46 +313,60 @@ int process(char * input){
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("\r\n");
}else if (input[0]=='f'){
int len;
filter=input[1];
uint8_t *hex=hextobyte(input+2,&len);
if(len>9)
len=9;
memcpy(filterdata,hex,len);
puts_plus("F ");
if(filter){
puts_plus("[");
outc[0]=filter;
puts_plus(outc);
puts_plus("]");
for(int i=0;i<len;i++){
puts_plus(IntToStrX(filterdata[i],2 ));
};
}else{
puts_plus("off");
};
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;
int t=5;
if(input[1]=='+'){
if(input[2]!=0){
uint8_t *hex=hextobyte(&input[2],&len);
t=getTimer()+hex[0]*1000/SYSTICKSPEED;
t=gethexval(&input[2]);
};
pctr=-1;
}
if(input[1]=='-'){
uint8_t *hex=hextobyte(&input[2],&len);
pctr=hex[0];
pctr=gethexval(&input[2]);
t=-1;
}
puts_plus("D receive ...\r\n");
puts_plus("D rcv: ");
puts_plus(IntToStr(pctr,8,0));
puts_plus("pkts, ");
puts_plus(IntToStr(t,8,0));
puts_plus("secs ");
if(filter){
puts_plus("FILTER=");
outc[0]=filter;
puts_plus(outc);
};
puts_plus(" ...\r\n");
if(t>0)
t=getTimer()+t*1000/SYSTICKSPEED;
nrf_rcv_pkt_start();
do{
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,funkencrypt?thekey:NULL);
@ -325,17 +375,76 @@ int process(char * input){
delayms(10);
continue;
};
puts_plus("R ");
puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] ");
if (!filter){
if(len==-3){
puts_plus("[!crc] ");
len=16;
len=32;
};
};
if(type=='m' || type=='M'){
if(filter && filter!=buf[0])
continue;
puts_plus("R ");
puts_plus(IntToStrX( buf[0],2 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[1],2 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+2),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+6),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+10),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+14),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+18),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+22),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+26),8 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[30],2 ));
puts_plus(IntToStrX( buf[31],2 ));
puts_plus(" ");
}else if(type=='B'){
if(filter)
if(uint8ptouint32(buf+8)!=uint8ptouint32(filterdata))
continue;
puts_plus("RF ");
puts_plus(IntToStrX( buf[2],2 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+8),8 ));
}else if(type=='b'){
if(filter)
if(uint8ptouint32(buf+8)!=uint8ptouint32(filterdata))
continue;
puts_plus("R ");
puts_plus(IntToStrX( buf[0],2 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[1],2 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[2],2 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[3],2 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+4),8 ));
puts_plus(" ");
puts_plus(IntToStrX( uint8ptouint32(buf+8),8 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[12],2 ));
puts_plus(IntToStrX( buf[13],2 ));
puts_plus(" ");
puts_plus(IntToStrX( buf[14],2 ));
puts_plus(IntToStrX( buf[15],2 ));
}else{
puts_plus("R ");
puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] ");
for(int i=0;i<len;i++){
puts_plus(IntToStrX( buf[i],2 ));
puts_plus(" ");
};
if(pctr<0){
};
if(1){
int l=0;
CDC_OutBufAvailChar (&l);
if(l>0){
@ -344,9 +453,9 @@ int process(char * input){
};
};
puts("\r\n");
if(pctr--==0)
if(--pctr==0)
break;
}while(t>getTimer());
}while((t>0)?(t>getTimer()):1);
nrf_rcv_pkt_end();
}else{

View File

@ -0,0 +1,49 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include <string.h>
#include "core/cpu/cpu.h"
#include "core/uart/uart.h"
/**************************************************************************/
#define BUF 5
void main_uart(void) {
uint8_t uartBuffer[BUF] = { 'T', 'e', 's', 't', '\n' };
uint8_t o[2]={0,0};
gpioSetDir(RB_LED0, gpioDirection_Output);
gpioSetValue (RB_LED0, 1);
lcdPrintln("Hi");
lcdRefresh();
uartInit(9600);
lcdPrintln("Inited.");
lcdRefresh();
uartSend((uint8_t *)uartBuffer, BUF);
lcdPrintln("sent.");
lcdRefresh();
uartRxBufferWrite('x');
// Get a reference to the UART control block
// uart_pcb_t *pcb = uartGetPCB();
gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0));
// Read any text available in the queue
while (uartRxBufferDataPending())
{
gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0));
// Read the first available character
uint8_t c = uartRxBufferRead();
o[0]=c;
lcdPrint(o);
lcdRefresh();
uartSend(&c, 1);
}
};

View File

@ -82,3 +82,9 @@
#define CFG_USBCDC_BUFFERSIZE (256)
/* you will need these for the UART */
#if 0
#define CFG_INTERFACE_UART (1)
#define CFG_UART_BAUDRATE (115200)
#define CFG_UART_BUFSIZE (512)
#endif

View File

@ -0,0 +1,50 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/render.h"
#include "lcd/print.h"
#include "usetable.h"
/**************************************************************************/
void ram(void) {
int v,mv;
do{
lcdClear();
lcdPrintln("Battery status:");
mv=GetVoltage();
v=mv/1000;
lcdNl();
if (mv<3550){
lcdPrintln(" Charge NOW!");
}else if (mv<3650){
lcdPrintln(" Charge soon");
}else if (mv<4000){
lcdPrintln(" OK");
}else if(mv<4200){
lcdPrintln(" Good");
}else{
lcdPrintln(" Full");
};
lcdNl();
lcdPrint(" ");
lcdPrint(IntToStr(v,2,0));
lcdPrint(".");
lcdPrint(IntToStr(mv%1000,3,F_ZEROS));
lcdPrintln("V");
lcdNl();
if(gpioGetValue(RB_PWR_CHRG)){
lcdPrintln("(not charging)");
}else{
lcdPrintln("CHARGING");
};
lcdRefresh();
} while ((getInputWaitTimeout(242))==BTN_NONE);
}

View File

@ -1,4 +1,8 @@
drive=/cygdrive/f
if [ ! -z "$1" ] ; then
dirve=/cygdrive/$a
fi
file=$drive/firmware.bin
while : ; do