make TYPE=serial a proper air debugging tool

This commit is contained in:
Stefan `Sec` Zehl 2011-07-29 22:30:36 +02:00
parent 62a8270609
commit d621d9b117
5 changed files with 235 additions and 486 deletions

View File

@ -1,38 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include "lcd/display.h"
#include "filesystem/ff.h"
#include <string.h>
/**************************************************************************/
void readcfg(void) {
readConfig();
};
void savecfg(void){
saveConfig();
};
void applycfg(void){
applyConfig();
};
void show(void){
lcdClear();
lcdPrint("time:"); lcdPrintInt(globalconfig.time); lcdNl();
lcdPrint("btrig:"); lcdPrintInt(globalconfig.backlighttrigger); lcdNl();
lcdPrint("bval:"); lcdPrintInt(globalconfig.backlightvalue); lcdNl();
lcdPrint("lcd:"); lcdPrintInt(globalconfig.lcdstate); lcdNl();
lcdPrint("priv:"); lcdPrintInt(globalconfig.privacy); lcdNl();
lcdRefresh();
};
void lcdmirror(void){
lcdToggleFlag(LCD_MIRRORX);
};

View File

@ -1,274 +0,0 @@
#include <sysinit.h>
#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 <string.h>
#define REMOTE_CHANNEL 91
#define REMOTE_MAC "REM0T"
#if CFG_USBMSC
#error "MSC is defined"
#endif
#if !CFG_USBCDC
#error "CDC is not defined"
#endif
/**************************************************************************/
uint32_t const remotekey[4] = {
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
void r_init(void){
nrf_init();
struct NRF_CFG config = {
.channel= REMOTE_CHANNEL,
.txmac= REMOTE_MAC,
.nrmacs=1,
.mac0= REMOTE_MAC,
.maclen ="\x10",
};
nrf_config_set(&config);
};
void s_init(void){
usbCDCInit();
nrf_init();
struct NRF_CFG config = {
.channel= REMOTE_CHANNEL,
.txmac= REMOTE_MAC,
.nrmacs=1,
.mac0= REMOTE_MAC,
.maclen ="\x10",
};
nrf_config_set(&config);
};
void process(uint8_t * input){
__attribute__ ((aligned (4))) uint8_t buf[32];
puts("process: ");
puts(input);
puts("\r\n");
if(input[0]=='M'){
buf[0]=0x10; // Length: 16 bytes
buf[1]='M'; // Proto
buf[2]=0x01;
buf[3]=0x01; // Unused
uint32touint8p(0,buf+4);
uint32touint8p(0x41424344,buf+8);
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
nrf_snd_pkt_crc_encr(16,buf,remotekey);
nrf_rcv_pkt_start();
};
};
#define INPUTLEN 99
void r_recv(void){
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
uint8_t input[INPUTLEN+1];
int inputptr=0;
nrf_rcv_pkt_start();
puts("D start");
getInputWaitRelease();
while(!getInputRaw()){
delayms(100);
// Input
int l=INPUTLEN-inputptr;
CDC_OutBufAvailChar (&l);
if(l>0){
CDC_RdOutBuf (input+inputptr, &l);
input[inputptr+l+1]=0;
for(int i=0;i<l;i++){
if(input[inputptr+i] =='\r'){
input[inputptr+i]=0;
process(input);
if(i<l)
memmove(input,input+inputptr+i+1,l-i);
inputptr=-i-1;
break;
};
};
};
inputptr+=l;
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,remotekey);
// Receive
if(len<=0){
delayms(10);
continue;
};
if(buf[1]=='C'){ // Cursor
puts("C ");
puts(IntToStrX( buf[2],2 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+4), 8 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+8), 8 ));
}else{
puts("U ");
// puts("[");puts(IntToStrX(len,2));puts("] ");
puts(IntToStrX( *(int*)(buf+ 0),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 1),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 2),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 3),2 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+4),8 ));
puts(".");
puts(IntToStrX( uint8ptouint32(buf+8),8 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+10),4 ));
};
puts("\r\n");
};
nrf_rcv_pkt_end();
puts("D exit");
}
void r_s1(void){
static int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
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,remotekey);
lcdClear();
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
};
void r_s2(void){
static int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int status;
buf[0]=0x10; // Length: 16 bytes
buf[1]='C'; // 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,remotekey);
buf[0]=0x10; // Length: 16 bytes
buf[1]='I'; // 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,remotekey);
lcdClear();
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
};
void r_send(void){
int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
int status;
while(1){
buf[0]=0x10; // Length: 16 bytes
buf[1]='C'; // Proto
buf[2]=getInputRaw();
buf[3]=0x00; // Unused
ctr++;
*(int*)(buf+4)=ctr;
/*
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
*/
buf[8]=0x0; // Object id
buf[9]=0x0;
buf[10]=0x05;
buf[11]=0xec;
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
lcdClear();
lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl();
if(buf[2]==BTN_ENTER)
break;
status=nrf_snd_pkt_crc_encr(16,buf,remotekey);
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
len=nrf_rcv_pkt_time_encr(100,sizeof(buf),buf,remotekey);
if(len>0){
lcdPrint("Got!");
lcdDisplay();
break;
};
delayms(10);
};
};

View File

@ -1,12 +1,12 @@
#include <sysinit.h>
#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"
@ -16,12 +16,23 @@
#include <string.h>
#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"
uint32_t const testkey[4] = {
uint32_t const beaconkey[4] = {
0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E
};
uint32_t remotekey[4] = {
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
uint32_t meshkey[4] = {
0x0, 0x0, 0x0, 0x0
};
#if CFG_USBMSC
#error "MSC is defined"
@ -33,107 +44,231 @@ uint32_t const testkey[4] = {
/**************************************************************************/
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;
void ser_enable(void) {
usbCDCInit();
};
delayms(500);
getInputWaitRelease();
puts("D start\r\n");
void ser_disable(void) {
usbCDCOff();
};
while(!getInputRaw()){
delayms(10);
#define myLEN 10
void ser_read(){
uint8_t buf[myLEN+1];
int l=myLEN;
lcdPrint("Bytes:");
// Input
int l=INPUTLEN-inputptr;
CDC_OutBufAvailChar (&l);
lcdPrintInt(l);
lcdNl();
lcdPrint("read:");
CDC_RdOutBuf (buf, &l);
lcdPrintInt(l);
lcdNl();
if(l>0){
CDC_RdOutBuf (input+inputptr, &l);
input[inputptr+l]=0;
puts(&input[inputptr]);
for(int i=0;i<l;i++){
if(input[inputptr+i] =='\r'){
input[inputptr+i]=0;
process(input);
if(i<l)
memmove(input,input+inputptr+i+1,l-i);
inputptr=-i-1;
break;
};
};
};
inputptr+=l;
};
buf[l]=0;
lcdPrintln(buf);
};
puts("D exit\r\n");
}
void ser_say(){
puts("hello world\r\n");
};
int process(char * input){
if(input == NULL || input[0]==0)
return;
void f_init(){
puts("\r\n");
puts("D [");
puts(input);
puts("]\r\n");
if(input[0]=='i'){
nrf_init();
struct NRF_CFG config = {
.channel= BEACON_CHANNEL,
.txmac= BEACON_MAC,
.nrmacs=1,
.mac0= BEACON_MAC,
.maclen ="\x10",
};
nrf_config_set(&config);
};
void f_beacon(void){
struct NRF_CFG config = {
.channel= BEACON_CHANNEL,
.txmac= BEACON_MAC,
.nrmacs=1,
.mac0= BEACON_MAC,
.maclen ="\x10",
};
}else if(input[0]=='c'){
if(input[1]=='m'){
config.channel=MESH_CHANNEL;
memcpy(config.txmac,MESH_MAC,5);
memcpy(config.mac0,MESH_MAC,5);
config.maclen[0]=0x20;
config.nrmacs=1;
nrf_config_set(&config);
};
memcpy(thekey,meshkey,sizeof(thekey));
}else if(input[1]=='r'){
config.channel=REMOTE_CHANNEL;
memcpy(config.txmac,REMOTE_MAC,5);
memcpy(config.mac0,REMOTE_MAC,5);
config.maclen[0]=0x10;
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,remotekey,sizeof(thekey));
}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);
memcpy(thekey,beaconkey,sizeof(thekey));
}else if(input[1]=='?'){
nrf_config_get(&config);
puts("Ch: ");puts(IntToStrX( config.channel,2 )); puts("\r\n");
int enctoggle=0;
puts("TxMac: ");
for(int i=0;i<5;i++)
puts(IntToStrX( config.txmac[i],2 ));
puts("\r\n");
void f_enctog(){
enctoggle=1-enctoggle;
lcdClear();
lcdPrint("Encryption:");
if(enctoggle)
lcdPrintln("ON");
else
lcdPrintln("Off");
};
puts("Len : ");
for(int i=0;i<5;i++)
puts(IntToStrX( config.maclen[i],2 ));
puts("\r\n");
void f_recser(void){
puts("0mac : ");
for(int i=0;i<5;i++)
puts(IntToStrX( config.mac0[i],2 ));
puts("\r\n");
puts("1mac : ");
for(int i=0;i<5;i++)
puts(IntToStrX( config.mac1[i],2 ));
puts("\r\n");
puts("2345 : ");
for(int i=0;i<4;i++)
puts(IntToStrX( config.mac2345[i],2 ));
puts("\r\n");
puts("key : ");
for(int i=0;i<4;i++){
puts(IntToStrX( thekey[i],8 ));
puts(" ");
};
puts("\r\n");
}else if(input[1]=='k'){
thekey[0]=0;
thekey[1]=0;
thekey[2]=0;
thekey[3]=0;
};
}else if (input[0]=='s'){
__attribute__ ((aligned (4))) uint8_t buf[32];
int status=0;
if (input[1]==' '){
int p=2;
int bp=0;
char c;
// puts("\r\n");
while(bp<32){
if(input[p]==0 || input[p+1]==0)
break;
if(input[p]==' '){
p++;
continue;
};
c=((input[p]>'9')?input[p]-'a'+10:input[p]-'0')*16+
((input[p+1]>'9')?input[p+1]-'a'+10:input[p+1]-'0');
// puts(IntToStrX( c,2 ));
// puts(".");
buf[bp]=c;
bp++;p+=2;
};
// puts("\r\n");
if(bp<10) bp=10;
bp+=2;
puts("S Len:");
puts(IntToStrX( bp,2 ));
puts("\r\n");
status=nrf_snd_pkt_crc_encr(bp,buf,thekey);
puts("P ");
puts("[");puts(IntToStrX(bp,2));puts("] ");
for(int i=0;i<bp;i++){
puts(IntToStrX( buf[i],2 ));
puts(" ");
};
puts("\r\n");
}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,thekey);
}else{
};
puts("S state=");
puts(IntToStrX( status,2 ));
puts("\r\n");
}else if (input[0]=='r'){
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
int pctr=5;
int t=getTimer()+5000/SYSTICKSPEED;
getInputWaitRelease();
if(input[1]=='0')
pctr=-1;
puts("D receive ...\r\n");
nrf_rcv_pkt_start();
do{
len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL);
if(len==0){
puts("(Timeout)\r\n");
};
puts("pkt: ");
puts("[");puts(IntToStrX(len,2));puts("] ");
puts(IntToStrX( *(int*)(buf+ 0),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 1),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 2),2 ));
puts(" ");
puts(IntToStrX( *(int*)(buf+ 3),2 ));
puts(".");
puts(IntToStrX( *(int*)(buf+ 4),8 ));
puts(".");
puts(IntToStrX( *(int*)(buf+ 8),8 ));
puts(".");
puts(IntToStrX( *(int*)(buf+ 12),4 ));
puts(" [");
len=crc16(buf,14);
puts(IntToStrX(len,4)); puts("]\r\n");
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,thekey);
// Receive
if(len==0||len==-1||len==-2){ //No pkt, Pkt2large, NoPktError
delayms(10);
}while ((getInputRaw())==BTN_NONE);
continue;
};
puts("R ");
puts("[");puts(IntToStrX(len,2));puts("] ");
for(int i=0;i<len;i++){
puts(IntToStrX( buf[i],2 ));
puts(" ");
};
if(len==-3)
puts(" [!crc]");
puts("\r\n");
delayms(1);
if(pctr--==0)
break;
}while(t>getTimer());
nrf_rcv_pkt_end();
}else{
puts("D no action\r\n");
};
puts("D done.\r\n");
return 0;
};

View File

@ -9,7 +9,6 @@
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include "funk/nrf24l01p.h"
#include "usb/usbmsc.h"
#include <string.h>
@ -29,55 +28,8 @@ void show_ticks(void) {
};
void adc_light(void) {
int dx=0;
int dy=8;
dx=DoString(0,dy,"Light:");
DoString(0,dy+16,"Night:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,globalconfig.backlighttrigger);
lcdDisplay();
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay();
ISPandReset();
}
void lcd_mirror(void) {
lcdToggleFlag(LCD_MIRRORX);
};
void lcd_invert(void) {
lcdToggleFlag(LCD_INVERTED);
};
void adc_check(void) {
int dx=0;
int dy=8;
// Print Voltage
dx=DoString(0,dy,"Voltage:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetVoltage());
lcdDisplay();
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
void msc_menu(void){
DoString(0,8,"MSC Enabled.");
lcdDisplay();
usbMSCInit();
getInputWaitRelease();
getInputWait();
DoString(0,16,"MSC Disabled.");
usbMSCOff();
};

View File

@ -1,26 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include <string.h>
#include "funk/rftransfer.h"
#include "funk/openbeacon.h"
#include "core/iap/iap.h"
/**************************************************************************/
void f_uuid(void) {
IAP_return_t iap_return;
iap_return = iapReadSerialNumber();
lcdPrintIntHex(iap_return.Result[0]); lcdNl();
lcdPrintIntHex(iap_return.Result[1]); lcdNl();
lcdPrintIntHex(iap_return.Result[2]); lcdNl();
lcdPrintIntHex(iap_return.Result[3]); lcdNl();
}