openbeacon: increment seq counter on boot
This commit is contained in:
parent
f4dee3550c
commit
643e8365aa
|
@ -10,11 +10,22 @@ const uint32_t key[4] = { 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E };
|
||||||
const uint8_t useencryption = 1;
|
const uint8_t useencryption = 1;
|
||||||
const uint8_t mac[5] = {1,2,3,2,1};
|
const uint8_t mac[5] = {1,2,3,2,1};
|
||||||
|
|
||||||
uint32_t oid = 0;
|
volatile uint32_t oid = 0;
|
||||||
uint32_t seq = 0;
|
volatile uint32_t seq = 0;
|
||||||
uint8_t strength = 0;
|
volatile uint8_t strength = 0;
|
||||||
|
|
||||||
void openbeaconSave()
|
void openbeaconShutdown(void)
|
||||||
|
{
|
||||||
|
openbeaconSave(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
void openbeaconSaveBlock(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
openbeaconSave(seq + OPENBEACON_SAVE + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void openbeaconSave(uint32_t s)
|
||||||
{
|
{
|
||||||
FIL file;
|
FIL file;
|
||||||
BYTE buf[4];
|
BYTE buf[4];
|
||||||
|
@ -23,7 +34,7 @@ void openbeaconSave()
|
||||||
if( f_open(&file, "beacon", FA_OPEN_ALWAYS|FA_WRITE) )
|
if( f_open(&file, "beacon", FA_OPEN_ALWAYS|FA_WRITE) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32touint8p(seq, buf);
|
uint32touint8p(s, buf);
|
||||||
|
|
||||||
if( f_write(&file, buf, 4, &readbytes) )
|
if( f_write(&file, buf, 4, &readbytes) )
|
||||||
return;
|
return;
|
||||||
|
@ -37,7 +48,7 @@ void openbeaconRead()
|
||||||
BYTE buf[4];
|
BYTE buf[4];
|
||||||
UINT readbytes;
|
UINT readbytes;
|
||||||
|
|
||||||
if( f_open(&file, "beacon", FA_OPEN_EXISTING|FA_READ) )
|
if( f_open(&file, "beacon.cfg", FA_OPEN_EXISTING|FA_READ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( f_read(&file, buf, 4, &readbytes) )
|
if( f_read(&file, buf, 4, &readbytes) )
|
||||||
|
@ -53,6 +64,7 @@ void openbeaconSetup(uint32_t id)
|
||||||
oid = id;
|
oid = id;
|
||||||
strength = 0;
|
strength = 0;
|
||||||
openbeaconRead();
|
openbeaconRead();
|
||||||
|
openbeaconSaveBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq,
|
uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq,
|
||||||
|
@ -80,11 +92,11 @@ uint8_t openbeaconSend(void)
|
||||||
nrf_set_strength(strength);
|
nrf_set_strength(strength);
|
||||||
nrf_set_tx_mac(sizeof(mac), mac);
|
nrf_set_tx_mac(sizeof(mac), mac);
|
||||||
|
|
||||||
status = openbeaconSendPacket(oid, seq++, 0xFF, strength++);
|
status = openbeaconSendPacket(oid, seq, 0xFF, strength++);
|
||||||
if( strength == 4 )
|
if( strength == 4 )
|
||||||
strength = 0;
|
strength = 0;
|
||||||
if( seq % OPENBEACON_SAVECOUNTER == 0 )
|
if( seq++ & OPENBEACON_SAVE == OPENBEACON_SAVE )
|
||||||
openbeaconSave();
|
openbeaconSaveBlock();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
#include "funk/nrf24l01p.h"
|
#include "funk/nrf24l01p.h"
|
||||||
#include "basic/byteorder.h"
|
#include "basic/byteorder.h"
|
||||||
|
|
||||||
#define OPENBEACON_SAVECOUNTER (1024*8)
|
#define OPENBEACON_SAVE 0xFFFF
|
||||||
void openbeaconSave();
|
|
||||||
|
void openbeaconShutdown(void);
|
||||||
|
void openbeaconSaveBlock(void);
|
||||||
|
void openbeaconSave(uint32_t s);
|
||||||
void openbeaconRead();
|
void openbeaconRead();
|
||||||
void openbeaconSetup(uint32_t id);
|
void openbeaconSetup(uint32_t id);
|
||||||
uint8_t openbeaconSendPacket(uint32_t id, uint32_t ctr,
|
uint8_t openbeaconSendPacket(uint32_t id, uint32_t ctr,
|
||||||
|
|
Loading…
Reference in New Issue