-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.c
59 lines (47 loc) · 1.79 KB
/
receiver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "contiki.h"
#include "net/rime/rime.h"
#include "random.h"
#include "dev/leds.h"
#include <stdio.h>
#include "sys/etimer.h"
#include "sys/rtimer.h"
#include "net/netstack.h"
int count = 0;
/*---------------------------------------------------------------------------*/
PROCESS(broadcast_process, "Receiver");
AUTOSTART_PROCESSES(&broadcast_process);
/*---------------------------------------------------------------------------*/
static void
broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
//count is incremented when rtimer fires. When a packet is received, print count value and reset it to 1
printf("*** Received '%s' slots counted between consecutive receptions = %u\n",(char *)packetbuf_dataptr(), count);
count = 1; //reset the count value to zero
}
static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
static struct broadcast_conn broadcast;
/*---------------------------------------------------------------------------*/
static void trigger(struct rtimer *t , void *ptr)
{
count++;
rtimer_set(t,RTIMER_TIME(t) + RTIMER_ARCH_SECOND/100,1,trigger,ptr); //reset the rtimer
}
PROCESS_THREAD(broadcast_process, ev, data)
{
PROCESS_EXITHANDLER(broadcast_close(&broadcast);)
PROCESS_BEGIN();
count = 0;
static struct rtimer rt;
static struct etimer et;
leds_on(LEDS_GREEN); //green LED indicates that the mote is a receiver
NETSTACK_MAC.off(1);
broadcast_open(&broadcast, 129, &broadcast_call);
rtimer_set(&rt,RTIMER_NOW() + RTIMER_ARCH_SECOND/100,1,trigger,NULL); //set the rtimer to fire every RTIMER_ARCH_SECOND/100 seconds
while(1)
{
etimer_set(&et,CLOCK_SECOND/100);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/