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