Removed the blink process to make the code simpler, added randomness to the transmission intervals

This commit is contained in:
adamdunkels 2009-02-06 10:12:52 +00:00
parent be846d8c90
commit 2e55bb5151

View file

@ -28,17 +28,18 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: example-collect.c,v 1.2 2008/02/24 22:15:46 adamdunkels Exp $ * $Id: example-collect.c,v 1.3 2009/02/06 10:12:52 adamdunkels Exp $
*/ */
/** /**
* \file * \file
* A brief description of what this file is. * Example of how the collect primitive works.
* \author * \author
* Adam Dunkels <adam@sics.se> * Adam Dunkels <adam@sics.se>
*/ */
#include "contiki.h" #include "contiki.h"
#include "lib/rand.h"
#include "net/rime.h" #include "net/rime.h"
#include "net/rime/collect.h" #include "net/rime/collect.h"
#include "net/rime/neighbor.h" #include "net/rime/neighbor.h"
@ -51,42 +52,10 @@ static struct collect_conn tc;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(example_collect_process, "Test collect process"); PROCESS(example_collect_process, "Test collect process");
PROCESS(depth_blink_process, "Depth indicator"); AUTOSTART_PROCESSES(&example_collect_process);
AUTOSTART_PROCESSES(&example_collect_process, &depth_blink_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(depth_blink_process, ev, data)
{
static struct etimer et;
static int count;
PROCESS_BEGIN();
while(1) {
etimer_set(&et, CLOCK_SECOND * 1);
PROCESS_WAIT_UNTIL(etimer_expired(&et));
count = collect_depth(&tc);
if(count == COLLECT_MAX_DEPTH) {
leds_on(LEDS_RED);
} else {
leds_off(LEDS_RED);
count /= NEIGHBOR_ETX_SCALE;
while(count > 0) {
leds_on(LEDS_RED);
etimer_set(&et, CLOCK_SECOND / 16);
PROCESS_WAIT_UNTIL(etimer_expired(&et));
leds_off(LEDS_RED);
etimer_set(&et, CLOCK_SECOND / 4);
PROCESS_WAIT_UNTIL(etimer_expired(&et));
--count;
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv(rimeaddr_t *originator, uint8_t seqno, uint8_t hops) recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)
{ {
printf("Sink got message from %d.%d, seqno %d, hops %d: len %d '%s'\n", printf("Sink got message from %d.%d, seqno %d, hops %d: len %d '%s'\n",
originator->u8[0], originator->u8[1], originator->u8[0], originator->u8[1],
@ -107,7 +76,10 @@ PROCESS_THREAD(example_collect_process, ev, data)
while(1) { while(1) {
static struct etimer et; static struct etimer et;
etimer_set(&et, CLOCK_SECOND * 10); /* Send a packet every 16 seconds; first wait 8 seconds, than a
random time between 0 and 8 seconds. */
etimer_set(&et, CLOCK_SECOND * 8 + rand() % (CLOCK_SECOND * 8));
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
if(etimer_expired(&et)) { if(etimer_expired(&et)) {