Allow the network to settle before sending first packet. Packet transmissions are now periodic, and randomized within each period.
This commit is contained in:
parent
81d23a3a36
commit
820d6eb334
1 changed files with 16 additions and 6 deletions
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: example-collect.c,v 1.15 2010/11/07 10:32:13 adamdunkels Exp $
|
* $Id: example-collect.c,v 1.16 2011/01/10 15:11:44 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,6 +69,9 @@ static const struct collect_callbacks callbacks = { recv };
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS_THREAD(example_collect_process, ev, data)
|
PROCESS_THREAD(example_collect_process, ev, data)
|
||||||
{
|
{
|
||||||
|
static struct etimer periodic;
|
||||||
|
static struct etimer et;
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);
|
collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);
|
||||||
|
@ -79,23 +82,30 @@ PROCESS_THREAD(example_collect_process, ev, data)
|
||||||
collect_set_sink(&tc, 1);
|
collect_set_sink(&tc, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allow some time for the network to settle. */
|
||||||
|
etimer_set(&et, 120 * CLOCK_SECOND);
|
||||||
|
PROCESS_WAIT_UNTIL(etimer_expired(&et));
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
static struct etimer et;
|
|
||||||
|
|
||||||
/* Send a packet every 16 seconds; first wait 8 seconds, than a
|
/* Send a packet every 30 seconds. */
|
||||||
random time between 0 and 8 seconds. */
|
if(etimer_expired(&periodic)) {
|
||||||
|
etimer_set(&periodic, CLOCK_SECOND * 30);
|
||||||
|
etimer_set(&et, random_rand() % (CLOCK_SECOND * 30));
|
||||||
|
}
|
||||||
|
|
||||||
etimer_set(&et, CLOCK_SECOND * 16 + random_rand() % (CLOCK_SECOND * 16));
|
|
||||||
PROCESS_WAIT_EVENT();
|
PROCESS_WAIT_EVENT();
|
||||||
|
|
||||||
|
|
||||||
if(etimer_expired(&et)) {
|
if(etimer_expired(&et)) {
|
||||||
static rimeaddr_t oldparent;
|
static rimeaddr_t oldparent;
|
||||||
const rimeaddr_t *parent;
|
const rimeaddr_t *parent;
|
||||||
|
|
||||||
printf("Sending\n");
|
printf("Sending\n");
|
||||||
packetbuf_clear();
|
packetbuf_clear();
|
||||||
packetbuf_set_datalen(sprintf(packetbuf_dataptr(),
|
packetbuf_set_datalen(sprintf(packetbuf_dataptr(),
|
||||||
"%s", "Hello") + 1);
|
"%s", "Hello") + 1);
|
||||||
collect_send(&tc, 10);
|
collect_send(&tc, 15);
|
||||||
|
|
||||||
parent = collect_parent(&tc);
|
parent = collect_parent(&tc);
|
||||||
if(!rimeaddr_cmp(parent, &oldparent)) {
|
if(!rimeaddr_cmp(parent, &oldparent)) {
|
||||||
|
|
Loading…
Reference in a new issue