nes-proj/examples/rime/test-polite.c

51 lines
1.2 KiB
C
Raw Normal View History

2007-05-22 21:04:00 +00:00
#include "net/rime/polite.h"
#include "contiki.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
2007-05-22 21:04:00 +00:00
PROCESS(test_polite_process, "");
AUTOSTART_PROCESSES(&test_polite_process);
/*---------------------------------------------------------------------------*/
static void
2007-05-22 21:04:00 +00:00
recv(struct polite_conn *c)
{
printf("recv '%s'\n", (char *)rimebuf_dataptr());
}
static void
2007-05-22 21:04:00 +00:00
sent(struct polite_conn *c)
{
printf("sent\n");
}
static void
2007-05-22 21:04:00 +00:00
dropped(struct polite_conn *c)
{
printf("dropped\n");
}
2007-05-22 21:04:00 +00:00
static const struct polite_callbacks callbacks = { recv, sent, dropped };
/*---------------------------------------------------------------------------*/
2007-05-22 21:04:00 +00:00
PROCESS_THREAD(test_polite_process, ev, data)
{
2007-05-22 21:04:00 +00:00
static struct polite_conn c;
2007-05-22 21:04:00 +00:00
PROCESS_EXITHANDLER(polite_close(&c));
PROCESS_BEGIN();
2007-05-22 21:04:00 +00:00
polite_open(&c, 128, &callbacks);
while(1) {
static struct etimer et;
etimer_set(&et, CLOCK_SECOND * 4);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
rimebuf_copyfrom("Hej", 4);
2007-05-22 21:04:00 +00:00
polite_send(&c, CLOCK_SECOND * 4, 4);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/