c46777ab8b7924607cf32037cb51e6eb41c30cf9
[wsn-p.git] / exercise_remotecontrol / rime / pwnage.c
1 #include <contiki.h>
2 #include <leds.h>
3 #include <stdio.h>
4 #include <button-sensor.h>
5 #include <net/rime.h>
6
7 PROCESS(pwnage, "total pwnage!");
8 AUTOSTART_PROCESSES(&pwnage);
9
10 void recv(struct broadcast_conn *ptr, const rimeaddr_t * sender) {
11 char * val = (char *) packetbuf_dataptr();
12 printf("node %d: recv from %d: %s\n", rimeaddr_node_addr, *sender, val);
13 }
14
15 static struct broadcast_conn bc;
16 static const struct broadcast_callbacks bccb = { recv };
17
18 PROCESS_THREAD(pwnage, ev, data) {
19 PROCESS_EXITHANDLER(broadcast_close(&bc));
20
21 PROCESS_BEGIN();
22
23 leds_init();
24 leds_off(LEDS_ALL);
25
26 SENSORS_ACTIVATE(button_sensor);
27
28 broadcast_open(&bc, 129, &bccb);
29
30 static struct etimer timer;
31 static char i;
32 for(i = 0; 1; i++) {
33 PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
34
35 // debounce for 250 ms
36 etimer_set(&timer, CLOCK_SECOND * 0.25);
37 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
38
39 char foo[] = "Spam, Spam, Wonderful Spam!";
40 packetbuf_copyfrom(foo, sizeof(foo));
41 broadcast_send(&bc);
42 printf("node %d: broadcast sent\n", rimeaddr_node_addr, i);
43 }
44
45 PROCESS_END();
46 }
This page took 0.040469 seconds and 3 git commands to generate.