From e2039ec2f4313f8adf8a6d8f7346080bfd05f41e Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 17 Jul 2011 20:01:29 +0200 Subject: [PATCH 1/5] added byteorder utils --- firmware/basic/Makefile | 1 + firmware/basic/byteorder.c | 9 +++++++++ firmware/basic/byteorder.h | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 firmware/basic/byteorder.c create mode 100644 firmware/basic/byteorder.h diff --git a/firmware/basic/Makefile b/firmware/basic/Makefile index c7fe8c1..7bbd1bb 100644 --- a/firmware/basic/Makefile +++ b/firmware/basic/Makefile @@ -14,6 +14,7 @@ OBJS += crc.o OBJS += menu.o OBJS += xxtea.o OBJS += ecc.o +OBJS += byteorder.o LIBNAME=basic diff --git a/firmware/basic/byteorder.c b/firmware/basic/byteorder.c new file mode 100644 index 0000000..9099c56 --- /dev/null +++ b/firmware/basic/byteorder.c @@ -0,0 +1,9 @@ +#include + +void uint32touint8p(uint32_t v, uint8_t *p) +{ + *p++ = (v>>24)&0xFF; + *p++ = (v>>16)&0xFF; + *p++ = (v>> 8)&0xFF; + *p++ = (v>> 0)&0xFF; +} diff --git a/firmware/basic/byteorder.h b/firmware/basic/byteorder.h new file mode 100644 index 0000000..ba1073e --- /dev/null +++ b/firmware/basic/byteorder.h @@ -0,0 +1,5 @@ +#ifndef _BYTEORDER_H_ +#define _BYTEORDER_H_ +void uint32touint8p(uint32_t v, uint8_t *p); + +#endif From bfbc6c2732c310c0f0827c5a16116c406495f13e Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 17 Jul 2011 20:32:17 +0200 Subject: [PATCH 2/5] openbeacon: save seq to file --- firmware/basic/byteorder.c | 10 ++++++++++ firmware/basic/byteorder.h | 4 ++++ firmware/funk/openbeacon.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/firmware/basic/byteorder.c b/firmware/basic/byteorder.c index 9099c56..4239e60 100644 --- a/firmware/basic/byteorder.c +++ b/firmware/basic/byteorder.c @@ -7,3 +7,13 @@ void uint32touint8p(uint32_t v, uint8_t *p) *p++ = (v>> 8)&0xFF; *p++ = (v>> 0)&0xFF; } + +uint32_t uint8ptouint32(uint8_t *p) +{ + uint32_t v; + v |= *p++; v<<=8; + v |= *p++; v<<=8; + v |= *p++; v<<=8; + v |= *p; + return v; +} diff --git a/firmware/basic/byteorder.h b/firmware/basic/byteorder.h index ba1073e..5b2ed4d 100644 --- a/firmware/basic/byteorder.h +++ b/firmware/basic/byteorder.h @@ -1,5 +1,9 @@ #ifndef _BYTEORDER_H_ #define _BYTEORDER_H_ + +#include + void uint32touint8p(uint32_t v, uint8_t *p); +uint32_t uint8ptouint32(uint8_t *p); #endif diff --git a/firmware/funk/openbeacon.c b/firmware/funk/openbeacon.c index 0a90644..77fe87c 100644 --- a/firmware/funk/openbeacon.c +++ b/firmware/funk/openbeacon.c @@ -3,19 +3,44 @@ #include "funk/nrf24l01p.h" #include "basic/byteorder.h" #include "sysdefs.h" +#include "filesystem/ff.h" const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; const uint8_t enctoggle = 0; + uint32_t oid = 0; uint32_t ctr = 0; uint8_t strength = 0; void openbeaconSave() { + FIL file; /* File object */ + BYTE buf[4]; + UINT readbytes; + + if( f_open(&file, "beacon", FA_OPEN_ALWAYS|FA_WRITE) ) + return; + + uint32touint8p(ctr, buf); + + if( f_write(&file, buf, 4, &readbytes) ) + return; + + f_close(&file); } void openbeaconRead() { + FIL file; /* File object */ + BYTE buf[4]; + UINT readbytes; + + if( f_open(&file, "beacon", FA_OPEN_EXISTING|FA_READ) ) + return; + + if( f_read(&file, buf, 4, &readbytes) ) + return; + ctr = uint8ptouint32(buf); } @@ -48,12 +73,13 @@ void openbeaconSendPacket(uint32_t id, uint32_t ctr, uint8_t flags, uint8_t stre void openbeaconSend(void) { //uint8_t tmp = nrfgetstrength(); - //nrfsetstrength(strength); + uint8_t tmp = 3; + nrf_set_strength(strength); openbeaconSendPacket(oid, ctr++, 0xFF, strength++); if( strength == 4 ) strength = 0; if( ctr % OPENBEACON_SAVECOUNTER == 0 ) openbeaconSave(); //maybe this produces timing problems? - //nrfsetstrength(tmp); + nrf_set_strength(tmp); } From c9ca6d1be6f2fd3be7a9ab06dfad7fda91fa537c Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 17 Jul 2011 20:34:59 +0200 Subject: [PATCH 3/5] removed broken xxtea byte level routines --- firmware/basic/xxtea.c | 80 ------------------------------------------ firmware/basic/xxtea.h | 6 ---- 2 files changed, 86 deletions(-) diff --git a/firmware/basic/xxtea.c b/firmware/basic/xxtea.c index 306c72b..d126793 100644 --- a/firmware/basic/xxtea.c +++ b/firmware/basic/xxtea.c @@ -14,86 +14,6 @@ #define MX (((z>>5^y<<2) + (y>>3^z<<4)) ^ ((sum^y) + (k[(p&3)^e] ^ z))) #include "xxtea.h" -uint32_t charp2uint32(uint8_t *data, uint8_t bytes) -{ - uint32_t r = 0; - if( bytes ){ - r |= *data++; - } - if( bytes > 1){ - r<<=8; - r |= *data++; - } - if( bytes > 2){ - r<<=8; - r |= *data++; - } - if( bytes > 3){ - r<<=8; - r |= *data++; - } - return r; -} - -void charp2uint32p(uint8_t* data, uint8_t n, uint32_t *v) -{ - int i,j=0; - int fullwords = n/4; - for(i=0; i>24; - if( bytes > 1) - buf[1] = (data>>16)&0xFF; - if( bytes > 2) - buf[2] = (data>>8)&0xFF; - if( bytes > 3) - buf[3] = (data>>0)&0xFF; -} - -void uint32p2charp(uint8_t* data, uint8_t n, uint32_t *v) -{ - int i; - int fullwords = n/4; - - for(i=0; i 8 ) - return; - charp2uint32p(data, n, v); - xxtea_encode_words(v, words, k); - uint32p2charp(data, n, v); -} - -void xxtea_decode(uint8_t *data, int n, uint32_t const k[4]) -{ - uint32_t v[8]; //maximum 32 bytes - int words = (n+3)/4; - if( words > 8 ) - return; - charp2uint32p(data, n, v); - xxtea_decode_words(v, words, k); - uint32p2charp(data, n, v); -} - void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]) { if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return; diff --git a/firmware/basic/xxtea.h b/firmware/basic/xxtea.h index 1718308..e8b99c9 100644 --- a/firmware/basic/xxtea.h +++ b/firmware/basic/xxtea.h @@ -1,12 +1,6 @@ #ifndef _XXTEA_H_ #define _XXTEA_H_ -uint32_t charp2uint32(uint8_t *data, uint8_t bytes); -void charp2uint32p(uint8_t* data, uint8_t n, uint32_t *v); -void uint322charp(uint32_t data, uint8_t *buf, uint8_t bytes); -void uint32p2charp(uint8_t* data, uint8_t n, uint32_t *v); -void xxtea_encode(uint8_t *data, int n, uint32_t const k[4]); -void xxtea_decode(uint8_t *v, int n, uint32_t const k[4]); void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]); void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]); From cf9a19de17a1b3399b8b2b3e1691a1e8d5ad15a5 Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 17 Jul 2011 21:01:09 +0200 Subject: [PATCH 4/5] openbeacon: set mac --- firmware/funk/openbeacon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/funk/openbeacon.c b/firmware/funk/openbeacon.c index 77fe87c..309b0e8 100644 --- a/firmware/funk/openbeacon.c +++ b/firmware/funk/openbeacon.c @@ -7,6 +7,7 @@ const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; const uint8_t enctoggle = 0; +const uint8_t mac[5] = {1,2,3,2,1}; uint32_t oid = 0; uint32_t ctr = 0; @@ -14,7 +15,7 @@ uint8_t strength = 0; void openbeaconSave() { - FIL file; /* File object */ + FIL file; BYTE buf[4]; UINT readbytes; @@ -31,7 +32,7 @@ void openbeaconSave() void openbeaconRead() { - FIL file; /* File object */ + FIL file; BYTE buf[4]; UINT readbytes; @@ -72,14 +73,13 @@ void openbeaconSendPacket(uint32_t id, uint32_t ctr, uint8_t flags, uint8_t stre void openbeaconSend(void) { - //uint8_t tmp = nrfgetstrength(); - uint8_t tmp = 3; nrf_set_strength(strength); + nrf_set_tx_mac(sizeof(mac), mac); + openbeaconSendPacket(oid, ctr++, 0xFF, strength++); if( strength == 4 ) strength = 0; if( ctr % OPENBEACON_SAVECOUNTER == 0 ) openbeaconSave(); - //maybe this produces timing problems? - nrf_set_strength(tmp); } + From 84d09d8fb956d311a14800e73c644945df0b2ccc Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 17 Jul 2011 21:02:37 +0200 Subject: [PATCH 5/5] default: we only have one file open --- firmware/applications/default.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 6aa970d..4da267b 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -11,7 +11,7 @@ FATFS FatFs[_VOLUMES]; /* File system object for logical drive */ #define CONFIGLEN 2 int lcdInitConfig(){ - FIL file[2]; /* File objects */ + FIL file; /* File objects */ BYTE buf[CONFIGLEN]; UINT readbytes; int res; @@ -24,13 +24,13 @@ int lcdInitConfig(){ return 1; }; - res=f_open(&file[0], "r0ket.cfg", FA_OPEN_EXISTING|FA_READ); + res=f_open(&file, "r0ket.cfg", FA_OPEN_EXISTING|FA_READ); lcdPrint("open:"); lcdPrintln(f_get_rc_string(res)); if(res){ lcdPrintln("new r0ket.cfg..."); - res=f_open(&file[0], "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE); + res=f_open(&file, "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE); lcdPrint("create:"); lcdPrintln(f_get_rc_string(res)); if(res){ @@ -39,7 +39,7 @@ int lcdInitConfig(){ buf[0]='0'; buf[1]='0'; - res = f_write(&file[0], buf, 2, &readbytes); + res = f_write(&file, buf, 2, &readbytes); lcdPrint("write:"); lcdPrintln(f_get_rc_string(res)); if(res){ @@ -50,7 +50,7 @@ int lcdInitConfig(){ lcdPrintInt(readbytes); lcdPrintln("b"); - res=f_close(&file[0]); + res=f_close(&file); lcdPrint("close:"); lcdPrintln(f_get_rc_string(res)); if(res){ @@ -62,7 +62,7 @@ int lcdInitConfig(){ for(int i=0;i