Added exithandlers so that the examples can be run as loadable (and unloadble) modules

This commit is contained in:
adamdunkels 2007-03-25 12:10:29 +00:00
parent 4fa44208eb
commit c3457e82a4
9 changed files with 76 additions and 14 deletions

View file

@ -1,5 +1,4 @@
CONTIKI = ../..
APPS = rudolph
all: test-abc test-meshroute test-treeroute test-trickle test-uabc \
test-rudolph0 test-rudolph1

View file

@ -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();
}
/*---------------------------------------------------------------------------*/

View file

@ -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);

View file

@ -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();
{

View file

@ -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();
{

View file

@ -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 <stdio.h>
static struct tree_conn tc;
/*---------------------------------------------------------------------------*/

View file

@ -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");*/

View file

@ -1,6 +1,9 @@
#include "net/rime/uabc.h"
#include "contiki.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
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);
}

48
examples/rime/test-uibc.c Normal file
View file

@ -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();
}
/*---------------------------------------------------------------------------*/