- Application Description
- Code Example
#include <stdio.h>
#include "board.h"
#include "hif.h"
#include "radio.h"
#include "xmpl.h"
#define XMPL_FRAME_SIZE (40)
uint8_t rxbuf[XMPL_FRAME_SIZE + 2];
uint8_t buf[sizeof(buffer_t) + XMPL_FRAME_SIZE];
buffer_t *pbuf;
int main(void)
{
uint8_t frame_header[] = {0x01, 0x80, 0, 0x11,0x22,0x33,0x44};
LED_INIT();
#if HIF_TYPE != HIF_NONE
hif_init(HIF_DEFAULT_BAUDRATE);
#endif
radio_init(rxbuf,sizeof(rxbuf));
sei();
radio_set_param(RP_CHANNEL(CHANNEL));
radio_set_state(STATE_RX);
pbuf = buffer_init(buf, sizeof(buf), 0);
while(1)
{
if (BUFFER_IS_LOCKED(pbuf) == true)
{
uint8_t c, i, seq;
for(i=0; i<sizeof(frame_header);i++)
{
c = buffer_get_char(pbuf);
if ( (i != 2) && (c != frame_header[i]))
{
break;
}
if(i==2)
{
seq = c;
}
}
if (i==7)
{
LED_TOGGLE(0);
#if HIF_TYPE != HIF_NONE
hif_put_blk (BUFFER_PDATA(pbuf), BUFFER_SIZE(pbuf));
#endif
}
else
{
LED_TOGGLE(1);
}
BUFFER_RESET(pbuf,0);
BUFFER_SET_UNLOCK(pbuf);
}
WAIT_MS(500);
}
}
uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed, uint8_t crc)
{
if ( BUFFER_IS_LOCKED(pbuf) == false && crc == 0)
{
buffer_append_block(pbuf, frm, len-2);
BUFFER_SET_LOCK(pbuf);
}
return frm;
}