From: Roland Hieber Date: Tue, 1 Nov 2011 16:40:33 +0000 (+0100) Subject: remote control pwnage X-Git-Url: https://git.rohieb.name/wsn-p.git/commitdiff_plain/5009bb21cc2816403ed01365499d88eea7335a24 remote control pwnage --- diff --git a/exercise_remotecontrol/rime/Makefile b/exercise_remotecontrol/rime/Makefile index c568329..f853b6c 100644 --- a/exercise_remotecontrol/rime/Makefile +++ b/exercise_remotecontrol/rime/Makefile @@ -1,5 +1,5 @@ include ../../Makefile.properties -CONTIKI_PROJECT=led_remote_control_rime +CONTIKI_PROJECT=led_remote_control pwnage all: $(CONTIKI_PROJECT) diff --git a/exercise_remotecontrol/rime/led_remote_control.c b/exercise_remotecontrol/rime/led_remote_control.c new file mode 100644 index 0000000..b3b9899 --- /dev/null +++ b/exercise_remotecontrol/rime/led_remote_control.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + +PROCESS(led_remote_control_rime, "binary LED counter via button over Rime"); +AUTOSTART_PROCESSES(&led_remote_control_rime); + +void recv(struct broadcast_conn *ptr, const rimeaddr_t * sender) { + char * val = (char *) packetbuf_dataptr(); + printf("node %d: recv from %d: %d\n", rimeaddr_node_addr, *sender, *val); + // FIXME + if(*val % 2) { + leds_toggle(LEDS_GREEN); + } + leds_toggle(LEDS_YELLOW); + printf("toggled LEDs\n"); +} + +static struct broadcast_conn bc; +static const struct broadcast_callbacks bccb = { recv }; + +PROCESS_THREAD(led_remote_control_rime, ev, data) { + PROCESS_EXITHANDLER(broadcast_close(&bc)); + + PROCESS_BEGIN(); + + leds_init(); + leds_off(LEDS_ALL); + + SENSORS_ACTIVATE(button_sensor); + + broadcast_open(&bc, 129, &bccb); + + static struct etimer timer; + static char i; + for(i = 0; 1; i++) { + PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); + + // debounce for 250 ms + etimer_set(&timer, CLOCK_SECOND * 0.25); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + + packetbuf_copyfrom(&i, sizeof(i)); + broadcast_send(&bc); + printf("node %d: broadcast sent: %d\n", rimeaddr_node_addr, i); + } + + PROCESS_END(); +} diff --git a/exercise_remotecontrol/rime/led_remote_control_rime.c b/exercise_remotecontrol/rime/led_remote_control_rime.c deleted file mode 100644 index b3b9899..0000000 --- a/exercise_remotecontrol/rime/led_remote_control_rime.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include -#include - -PROCESS(led_remote_control_rime, "binary LED counter via button over Rime"); -AUTOSTART_PROCESSES(&led_remote_control_rime); - -void recv(struct broadcast_conn *ptr, const rimeaddr_t * sender) { - char * val = (char *) packetbuf_dataptr(); - printf("node %d: recv from %d: %d\n", rimeaddr_node_addr, *sender, *val); - // FIXME - if(*val % 2) { - leds_toggle(LEDS_GREEN); - } - leds_toggle(LEDS_YELLOW); - printf("toggled LEDs\n"); -} - -static struct broadcast_conn bc; -static const struct broadcast_callbacks bccb = { recv }; - -PROCESS_THREAD(led_remote_control_rime, ev, data) { - PROCESS_EXITHANDLER(broadcast_close(&bc)); - - PROCESS_BEGIN(); - - leds_init(); - leds_off(LEDS_ALL); - - SENSORS_ACTIVATE(button_sensor); - - broadcast_open(&bc, 129, &bccb); - - static struct etimer timer; - static char i; - for(i = 0; 1; i++) { - PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); - - // debounce for 250 ms - etimer_set(&timer, CLOCK_SECOND * 0.25); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); - - packetbuf_copyfrom(&i, sizeof(i)); - broadcast_send(&bc); - printf("node %d: broadcast sent: %d\n", rimeaddr_node_addr, i); - } - - PROCESS_END(); -} diff --git a/exercise_remotecontrol/rime/pwnage.c b/exercise_remotecontrol/rime/pwnage.c new file mode 100644 index 0000000..c46777a --- /dev/null +++ b/exercise_remotecontrol/rime/pwnage.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +PROCESS(pwnage, "total pwnage!"); +AUTOSTART_PROCESSES(&pwnage); + +void recv(struct broadcast_conn *ptr, const rimeaddr_t * sender) { + char * val = (char *) packetbuf_dataptr(); + printf("node %d: recv from %d: %s\n", rimeaddr_node_addr, *sender, val); +} + +static struct broadcast_conn bc; +static const struct broadcast_callbacks bccb = { recv }; + +PROCESS_THREAD(pwnage, ev, data) { + PROCESS_EXITHANDLER(broadcast_close(&bc)); + + PROCESS_BEGIN(); + + leds_init(); + leds_off(LEDS_ALL); + + SENSORS_ACTIVATE(button_sensor); + + broadcast_open(&bc, 129, &bccb); + + static struct etimer timer; + static char i; + for(i = 0; 1; i++) { + PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); + + // debounce for 250 ms + etimer_set(&timer, CLOCK_SECOND * 0.25); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + + char foo[] = "Spam, Spam, Wonderful Spam!"; + packetbuf_copyfrom(foo, sizeof(foo)); + broadcast_send(&bc); + printf("node %d: broadcast sent\n", rimeaddr_node_addr, i); + } + + PROCESS_END(); +}