funk: use openbeacon code

This commit is contained in:
schneider 2011-07-18 01:16:44 +02:00
parent 54e29bc10b
commit 0eb87072ff
4 changed files with 24 additions and 42 deletions

View File

@ -10,6 +10,8 @@
#include <string.h>
#include "funk/rftransfer.h"
#include "funk/openbeacon.h"
/**************************************************************************/
#define BEACON_CHANNEL 81
@ -151,34 +153,9 @@ void f_enctog(void){
};
void f_send(void){
static char ctr=1;
uint8_t buf[32];
int status;
buf[0]=0x10; // Length: 16 bytes
buf[1]=0x17; // Proto - fixed at 0x17?
buf[2]=0xff; // Flags (0xff)
buf[3]=0xff; // Send intensity
/*
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
*/
*(int*)(buf+4)=ctr++;
buf[8]=0x0; // Object id
buf[9]=0x0;
buf[10]=0x05;
buf[11]=0xec;
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,enctoggle?testkey:NULL);
uint8_t status;
status = openbeaconSend();
lcdPrint("Status:");
lcdPrintCharHex(status);
lcdNl();
@ -247,10 +224,10 @@ static menuentry menu[] = {
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_funk(void) {
backlightInit();
font=&Font_7x8;
openbeaconSetup(0x5ec);
while (1) {
lcdFill(0); // clear display buffer
lcdDisplay(0);
@ -262,6 +239,7 @@ void main_funk(void) {
void tick_funk(void){
static int foo=0;
static int toggle=0;
if(foo++>50){
toggle=1-toggle;
foo=0;

View File

@ -2,7 +2,7 @@
#define _NRF24L01P_H 1
#include <stdint.h>
#define MAX_PKT (32-2) // 2 bytes are our CRC
#define MAX_PKT (32) // space for crc is supplied by the caller
// SPI commands
#define C_R_REGISTER 0x00

View File

@ -6,11 +6,11 @@
#include "filesystem/ff.h"
const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
const uint8_t enctoggle = 0;
const uint8_t useencryption = 0;
const uint8_t mac[5] = {1,2,3,2,1};
uint32_t oid = 0;
uint32_t ctr = 0;
uint32_t seq = 0;
uint8_t strength = 0;
void openbeaconSave()
@ -22,7 +22,7 @@ void openbeaconSave()
if( f_open(&file, "beacon", FA_OPEN_ALWAYS|FA_WRITE) )
return;
uint32touint8p(ctr, buf);
uint32touint8p(seq, buf);
if( f_write(&file, buf, 4, &readbytes) )
return;
@ -41,7 +41,9 @@ void openbeaconRead()
if( f_read(&file, buf, 4, &readbytes) )
return;
ctr = uint8ptouint32(buf);
seq = uint8ptouint32(buf);
f_close(&file);
}
@ -52,34 +54,36 @@ void openbeaconSetup(uint32_t id)
openbeaconRead();
}
void openbeaconSendPacket(uint32_t id, uint32_t ctr, uint8_t flags, uint8_t strength)
uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq,
uint8_t flags, uint8_t strength)
{
uint8_t buf[32];
int status;
buf[0]=0x10; // Length: 16 bytes
buf[1]=0x17; // Proto - fixed at 0x17?
buf[2]=flags;
buf[3]=strength*85; // Send intensity
uint32touint8p(ctr, buf+4);
uint32touint8p(seq, buf+4);
uint32touint8p(id, buf+8);
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,enctoggle?key:NULL);
return nrf_snd_pkt_crc_encr(32,buf,useencryption?key:NULL);
}
void openbeaconSend(void)
uint8_t openbeaconSend(void)
{
uint8_t status;
nrf_set_strength(strength);
nrf_set_tx_mac(sizeof(mac), mac);
openbeaconSendPacket(oid, ctr++, 0xFF, strength++);
status = openbeaconSendPacket(oid, seq++, 0xFF, strength++);
if( strength == 4 )
strength = 0;
if( ctr % OPENBEACON_SAVECOUNTER == 0 )
if( seq % OPENBEACON_SAVECOUNTER == 0 )
openbeaconSave();
return status;
}

View File

@ -9,8 +9,8 @@
void openbeaconSave();
void openbeaconRead();
void openbeaconSetup(uint32_t id);
void openbeaconSendPacket(uint32_t id, uint32_t ctr,
uint8_t openbeaconSendPacket(uint32_t id, uint32_t ctr,
uint8_t flags, uint8_t strength);
void openbeaconSend(void);
uint8_t openbeaconSend(void);
#endif