From c3457e82a411664e4559f2759ef6d4891629f5cb Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sun, 25 Mar 2007 12:10:29 +0000 Subject: [PATCH] Added exithandlers so that the examples can be run as loadable (and unloadble) modules --- examples/rime/Makefile | 1 - examples/rime/test-abc.c | 7 +++-- examples/rime/test-meshroute.c | 3 ++- examples/rime/test-rudolph0.c | 8 +++--- examples/rime/test-rudolph1.c | 6 ++--- examples/rime/test-treeroute.c | 4 ++- examples/rime/test-trickle.c | 3 ++- examples/rime/test-uabc.c | 10 +++++-- examples/rime/test-uibc.c | 48 ++++++++++++++++++++++++++++++++++ 9 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 examples/rime/test-uibc.c diff --git a/examples/rime/Makefile b/examples/rime/Makefile index 9475b6525..61f418011 100644 --- a/examples/rime/Makefile +++ b/examples/rime/Makefile @@ -1,5 +1,4 @@ CONTIKI = ../.. -APPS = rudolph all: test-abc test-meshroute test-treeroute test-trickle test-uabc \ test-rudolph0 test-rudolph1 diff --git a/examples/rime/test-abc.c b/examples/rime/test-abc.c index 10e88b58a..1704c99e2 100644 --- a/examples/rime/test-abc.c +++ b/examples/rime/test-abc.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-abc.c,v 1.2 2007/03/22 23:58:37 adamdunkels Exp $ + * $Id: test-abc.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -53,13 +53,15 @@ AUTOSTART_PROCESSES(&test_abc_process); static void abc_recv(struct abc_conn *c) { - /* log_message("abc message received", rimebuf_dataptr());*/ + printf("abc message received '%s'\n", (char *)rimebuf_dataptr()); } const static struct abc_callbacks abc_call = {abc_recv}; static struct abc_conn abc; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_abc_process, ev, data) { + PROCESS_EXITHANDLER(abc_close(&abc);) + PROCESS_BEGIN(); abc_open(&abc, 128, &abc_call); @@ -75,6 +77,7 @@ PROCESS_THREAD(test_abc_process, ev, data) abc_send(&abc); } + PROCESS_END(); } /*---------------------------------------------------------------------------*/ diff --git a/examples/rime/test-meshroute.c b/examples/rime/test-meshroute.c index 807416f00..0a5e8bd5a 100644 --- a/examples/rime/test-meshroute.c +++ b/examples/rime/test-meshroute.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-meshroute.c,v 1.2 2007/03/22 19:03:56 adamdunkels Exp $ + * $Id: test-meshroute.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -77,6 +77,7 @@ const static struct mesh_callbacks callbacks = {recv, sent, timedout}; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_mesh_process, ev, data) { + PROCESS_EXITHANDLER(mesh_close(&mesh);) PROCESS_BEGIN(); mesh_open(&mesh, 128, &callbacks); diff --git a/examples/rime/test-rudolph0.c b/examples/rime/test-rudolph0.c index 2081cc998..3617e112b 100644 --- a/examples/rime/test-rudolph0.c +++ b/examples/rime/test-rudolph0.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-rudolph0.c,v 1.2 2007/03/22 23:58:57 adamdunkels Exp $ + * $Id: test-rudolph0.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -39,7 +39,7 @@ */ #include "contiki.h" -#include "rudolph0.h" +#include "net/rime/rudolph0.h" #include "dev/button-sensor.h" @@ -111,9 +111,11 @@ static struct rudolph0_conn rudolph0; PROCESS_THREAD(test_rudolph0_process, ev, data) { static int fd; + + PROCESS_EXITHANDLER(rudolph0_close(&rudolph0);) + PROCESS_BEGIN(); - process_start(&cfs_ram_process, NULL); PROCESS_PAUSE(); { diff --git a/examples/rime/test-rudolph1.c b/examples/rime/test-rudolph1.c index ef1de81f3..681767e13 100644 --- a/examples/rime/test-rudolph1.c +++ b/examples/rime/test-rudolph1.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-rudolph1.c,v 1.2 2007/03/22 23:58:57 adamdunkels Exp $ + * $Id: test-rudolph1.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -39,7 +39,7 @@ */ #include "contiki.h" -#include "rudolph1.h" +#include "net/rime/rudolph1.h" #include "dev/button-sensor.h" @@ -111,9 +111,9 @@ static struct rudolph1_conn rudolph1; PROCESS_THREAD(test_rudolph1_process, ev, data) { static int fd; + PROCESS_EXITHANDLER(rudolph1_close(&rudolph1);) PROCESS_BEGIN(); - process_start(&cfs_ram_process, NULL); PROCESS_PAUSE(); { diff --git a/examples/rime/test-treeroute.c b/examples/rime/test-treeroute.c index 1dbccb35f..c658bf6d2 100644 --- a/examples/rime/test-treeroute.c +++ b/examples/rime/test-treeroute.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-treeroute.c,v 1.2 2007/03/22 19:03:56 adamdunkels Exp $ + * $Id: test-treeroute.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -45,6 +45,8 @@ #include "dev/pir-sensor.h" #include "dev/button-sensor.h" +#include + static struct tree_conn tc; /*---------------------------------------------------------------------------*/ diff --git a/examples/rime/test-trickle.c b/examples/rime/test-trickle.c index a18aac377..09e119de4 100644 --- a/examples/rime/test-trickle.c +++ b/examples/rime/test-trickle.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-trickle.c,v 1.2 2007/03/21 23:25:16 adamdunkels Exp $ + * $Id: test-trickle.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $ */ /** @@ -61,6 +61,7 @@ static struct trickle_conn trickle; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_trickle_process, ev, data) { + PROCESS_EXITHANDLER(trickle_close(&trickle);) PROCESS_BEGIN(); /* log_message("Trickle", "running");*/ diff --git a/examples/rime/test-uabc.c b/examples/rime/test-uabc.c index 62249140a..a77c0d8df 100644 --- a/examples/rime/test-uabc.c +++ b/examples/rime/test-uabc.c @@ -1,6 +1,9 @@ #include "net/rime/uabc.h" #include "contiki.h" + +#include + /*---------------------------------------------------------------------------*/ PROCESS(test_uabc_process, ""); AUTOSTART_PROCESSES(&test_uabc_process); @@ -8,7 +11,7 @@ AUTOSTART_PROCESSES(&test_uabc_process); static void recv(struct uabc_conn *c) { - printf("recv\n"); + printf("recv '%s'\n", (char *)rimebuf_dataptr()); } static void sent(struct uabc_conn *c) @@ -25,6 +28,9 @@ static const struct uabc_callbacks callbacks = { recv, sent, dropped }; PROCESS_THREAD(test_uabc_process, ev, data) { static struct uabc_conn c; + + PROCESS_EXITHANDLER(uabc_close(&c)); + PROCESS_BEGIN(); uabc_open(&c, 128, &callbacks); @@ -34,7 +40,7 @@ PROCESS_THREAD(test_uabc_process, ev, data) etimer_set(&et, CLOCK_SECOND * 4); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); rimebuf_copyfrom("Hej", 4); - uabc_send(&c, CLOCK_SECOND); + uabc_send(&c, CLOCK_SECOND * 4); } diff --git a/examples/rime/test-uibc.c b/examples/rime/test-uibc.c new file mode 100644 index 000000000..d21e14012 --- /dev/null +++ b/examples/rime/test-uibc.c @@ -0,0 +1,48 @@ + +#include "net/rime/uibc.h" +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +PROCESS(test_uibc_process, ""); +AUTOSTART_PROCESSES(&test_uibc_process); +/*---------------------------------------------------------------------------*/ +static void +recv(struct uibc_conn *c, rimeaddr_t *from) +{ + printf("recv '%s' from %d.%d\n", rimebuf_dataptr(), + from->u8[0], from->u8[1]); +} +static void +sent(struct uibc_conn *c) +{ + printf("sent\n"); +} +static void +dropped(struct uibc_conn *c) +{ + printf("dropped\n"); +} +static const struct uibc_callbacks callbacks = { recv, sent, dropped }; +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(test_uibc_process, ev, data) +{ + static struct uibc_conn c; + + PROCESS_EXITHANDLER(uibc_close(&c)); + + PROCESS_BEGIN(); + + uibc_open(&c, 128, &callbacks); + + while(1) { + static struct etimer et; + etimer_set(&et, CLOCK_SECOND * 4); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + rimebuf_copyfrom("Hej", 4); + uibc_send(&c, CLOCK_SECOND * 4); + + + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/