openbeacon: save seq to file

This commit is contained in:
schneider 2011-07-17 20:32:17 +02:00
parent 812a8f8b13
commit bfbc6c2732
3 changed files with 42 additions and 2 deletions

View File

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

View File

@ -1,5 +1,9 @@
#ifndef _BYTEORDER_H_
#define _BYTEORDER_H_
#include <stdint.h>
void uint32touint8p(uint32_t v, uint8_t *p);
uint32_t uint8ptouint32(uint8_t *p);
#endif

View File

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