- Application Description
The application fills a piece of text as chunks in a linear buffer and sends it. The example illustrates
- the initialization of a linear buffer (see grpIoUtilBuffer),
- the appending of characters as payload,
- the prepending of a frame header prior the payload,
- the extraction of data pointer and data size from the buffer.
- reset of the buffer.
- Code Example
#include <stdio.h>
#include "board.h"
#include "hif.h"
#include "radio.h"
#include "xmpl.h"
int main(void)
{
#define XMPL_FRAME_SIZE (40)
uint8_t txbuf[sizeof(buffer_t) + XMPL_FRAME_SIZE + 2];
uint8_t frame_header[] = {0x01, 0x80, 0, 0x11,0x22,0x33,0x44};
buffer_t *pbuf;
char limmerick[] = "A wonderful bird is the pelican,\n\r"
"His bill will hold more than his belican,\n\r"
"He can take in his beak\n\r"
"Enough food for a week\n\r"
"But I'm damned if I see how the helican!\n\r\n\r";
char *plim;
LED_INIT();
radio_init(NULL, 0);
sei();
radio_set_param(RP_CHANNEL(CHANNEL));
radio_set_state(STATE_TX);
pbuf = buffer_init(txbuf, sizeof(txbuf)-2, sizeof(frame_header));
plim = limmerick;
while(1)
{
do
{
if (buffer_append_char(pbuf, *plim) == EOF)
{
break;
}
plim++;
}
while (*plim != 0 && *plim != '\n');
buffer_prepend_block(pbuf, frame_header, sizeof(frame_header));
radio_set_state(STATE_TX);
radio_send_frame(BUFFER_SIZE(pbuf)+ 2, BUFFER_PDATA(pbuf), 0);
LED_TOGGLE(0);
WAIT_MS(500);
BUFFER_RESET(pbuf,sizeof(frame_header));
frame_header[2]++;
if (*plim == 0) plim = limmerick;
}
}