Bugfixes, updates
This commit is contained in:
parent
a9e8e9f4fe
commit
940da856de
27 changed files with 557 additions and 288 deletions
|
@ -36,7 +36,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: abc.c,v 1.12 2007/03/31 18:31:27 adamdunkels Exp $
|
||||
* $Id: abc.c,v 1.13 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@
|
|||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "net/rime.h"
|
||||
|
||||
struct abc_hdr {
|
||||
|
@ -89,8 +89,7 @@ abc_send(struct abc_conn *c)
|
|||
PRINTF("%d: abc: abc_send on channel %d\n", rimeaddr_node_addr.u16, c->channel);
|
||||
|
||||
hdr->channel = c->channel;
|
||||
rimebuf_compact();
|
||||
rime_driver_send();
|
||||
rime_output();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: abc.h,v 1.11 2007/03/31 18:31:27 adamdunkels Exp $
|
||||
* $Id: abc.h,v 1.12 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
|
@ -58,7 +58,6 @@
|
|||
#ifndef __ABC_H__
|
||||
#define __ABC_H__
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "net/rime/rimebuf.h"
|
||||
|
||||
struct abc_conn;
|
||||
|
@ -72,9 +71,17 @@ struct abc_callbacks {
|
|||
void (* recv)(struct abc_conn *ptr);
|
||||
};
|
||||
|
||||
#ifdef CHAMELEON
|
||||
#include "net/chameleon/chameleon.h"
|
||||
#endif /* CHAMELEON */
|
||||
|
||||
struct abc_conn {
|
||||
#ifdef CHAMELEON
|
||||
struct chameleon_channel channel;
|
||||
#else /* CHAMELEON */
|
||||
struct abc_conn *next;
|
||||
u16_t channel;
|
||||
#endif /* CHAMELEON */
|
||||
const struct abc_callbacks *u;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: ibc.c,v 1.9 2007/03/29 23:18:22 adamdunkels Exp $
|
||||
* $Id: ibc.c,v 1.10 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -43,8 +43,7 @@
|
|||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "net/rime/ibc.h"
|
||||
#include "net/rime.h"
|
||||
#include "contiki-net.h"
|
||||
#include <string.h>
|
||||
|
||||
struct ibc_hdr {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: mesh.c,v 1.7 2007/03/29 23:18:48 adamdunkels Exp $
|
||||
* $Id: mesh.c,v 1.8 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -84,7 +84,8 @@ found_route(struct route_discovery_conn *rdc, rimeaddr_t *dest)
|
|||
struct mesh_conn *c = (struct mesh_conn *)
|
||||
((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn));
|
||||
|
||||
if(rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
||||
if(c->queued_data != NULL &&
|
||||
rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
||||
queuebuf_to_rimebuf(c->queued_data);
|
||||
queuebuf_free(c->queued_data);
|
||||
c->queued_data = NULL;
|
||||
|
@ -100,6 +101,7 @@ route_timed_out(struct route_discovery_conn *rdc)
|
|||
|
||||
if(c->queued_data != NULL) {
|
||||
queuebuf_free(c->queued_data);
|
||||
c->queued_data = NULL;
|
||||
}
|
||||
|
||||
if(c->cb->timedout) {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: nf.c,v 1.11 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: nf.c,v 1.12 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -51,16 +51,12 @@
|
|||
#define HOPS_MAX 16
|
||||
|
||||
struct nf_hdr {
|
||||
u8_t hops;
|
||||
u8_t originator_seqno;
|
||||
u16_t originator_seqno;
|
||||
rimeaddr_t originator;
|
||||
u16_t hops;
|
||||
};
|
||||
|
||||
static u8_t seqno;
|
||||
|
||||
static void send(void *ptr);
|
||||
|
||||
#define DEBUG 0
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
|
@ -68,60 +64,23 @@ static void send(void *ptr);
|
|||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_timer(struct nf_conn *c)
|
||||
{
|
||||
ctimer_set(&c->t, c->queue_time, send, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
send(void *ptr)
|
||||
{
|
||||
struct nf_conn *c = ptr;
|
||||
|
||||
if(c->packets_received > 0) {
|
||||
c->packets_received = 0;
|
||||
set_timer(c);
|
||||
} else {
|
||||
/* DEBUGF(3, "nf: send()\n");*/
|
||||
queuebuf_to_rimebuf(c->buf);
|
||||
queuebuf_free(c->buf);
|
||||
c->buf = NULL;
|
||||
PRINTF("%d.%d: nf send to uibc\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
uibc_send(&c->c, c->queue_time);
|
||||
if(c->u->sent != NULL) {
|
||||
c->u->sent(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
queue_for_send(struct nf_conn *c)
|
||||
send(struct nf_conn *c)
|
||||
{
|
||||
if(c->buf == NULL) {
|
||||
c->buf = queuebuf_new_from_rimebuf();
|
||||
}
|
||||
if(c->buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
c->packets_received = 0;
|
||||
set_timer(c);
|
||||
return 1;
|
||||
PRINTF("%d.%d: nf send to ipolite\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
return ipolite_send(&c->c, c->queue_time, 4);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
recv_from_uibc(struct uibc_conn *uibc, rimeaddr_t *from)
|
||||
recv_from_ipolite(struct ipolite_conn *ipolite, rimeaddr_t *from)
|
||||
{
|
||||
register struct nf_conn *c = (struct nf_conn *)uibc;
|
||||
struct nf_conn *c = (struct nf_conn *)ipolite;
|
||||
struct nf_hdr *hdr = rimebuf_dataptr();
|
||||
u8_t hops;
|
||||
struct queuebuf *queuebuf;
|
||||
|
||||
c->packets_received++;
|
||||
|
||||
hops = hdr->hops;
|
||||
|
||||
/* Remember packet if we need to forward it. */
|
||||
|
@ -151,7 +110,7 @@ recv_from_uibc(struct uibc_conn *uibc, rimeaddr_t *from)
|
|||
c->last_originator_seqno,
|
||||
hops);
|
||||
hdr->hops++;
|
||||
queue_for_send(c);
|
||||
send(c);
|
||||
rimeaddr_copy(&c->last_originator, &hdr->originator);
|
||||
c->last_originator_seqno = hdr->originator_seqno;
|
||||
}
|
||||
|
@ -164,13 +123,31 @@ recv_from_uibc(struct uibc_conn *uibc, rimeaddr_t *from)
|
|||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct uibc_callbacks nf = {recv_from_uibc, NULL, NULL};
|
||||
static void
|
||||
sent(struct ipolite_conn *ipolite)
|
||||
{
|
||||
struct nf_conn *c = (struct nf_conn *)ipolite;
|
||||
if(c->u->sent != NULL) {
|
||||
c->u->sent(c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
dropped(struct ipolite_conn *ipolite)
|
||||
{
|
||||
struct nf_conn *c = (struct nf_conn *)ipolite;
|
||||
if(c->u->dropped != NULL) {
|
||||
c->u->dropped(c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct ipolite_callbacks nf = {recv_from_ipolite, sent, dropped};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
nf_open(struct nf_conn *c, clock_time_t queue_time,
|
||||
u16_t channel, const struct nf_callbacks *u)
|
||||
{
|
||||
uibc_open(&c->c, channel, &nf);
|
||||
ipolite_open(&c->c, channel, &nf);
|
||||
c->u = u;
|
||||
c->queue_time = queue_time;
|
||||
}
|
||||
|
@ -178,24 +155,22 @@ nf_open(struct nf_conn *c, clock_time_t queue_time,
|
|||
void
|
||||
nf_close(struct nf_conn *c)
|
||||
{
|
||||
uibc_close(&c->c);
|
||||
ipolite_close(&c->c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
nf_send(struct nf_conn *c)
|
||||
nf_send(struct nf_conn *c, u8_t seqno)
|
||||
{
|
||||
if(c->buf != NULL) {
|
||||
queuebuf_free(c->buf);
|
||||
c->buf = NULL;
|
||||
}
|
||||
|
||||
if(rimebuf_hdralloc(sizeof(struct nf_hdr))) {
|
||||
struct nf_hdr *hdr = rimebuf_hdrptr();
|
||||
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
||||
rimeaddr_copy(&c->last_originator, &hdr->originator);
|
||||
c->last_originator_seqno = hdr->originator_seqno = ++seqno;
|
||||
c->last_originator_seqno = hdr->originator_seqno = seqno;
|
||||
hdr->hops = 0;
|
||||
return queue_for_send(c);
|
||||
PRINTF("%d.%d: nf sending '%s'\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
(char *)rimebuf_dataptr());
|
||||
return send(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -203,7 +178,7 @@ nf_send(struct nf_conn *c)
|
|||
void
|
||||
nf_cancel(struct nf_conn *c)
|
||||
{
|
||||
ctimer_stop(&c->t);
|
||||
ipolite_cancel(&c->c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: nf.h,v 1.9 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: nf.h,v 1.10 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@
|
|||
|
||||
#include "net/rime/ctimer.h"
|
||||
#include "net/rime/queuebuf.h"
|
||||
#include "net/rime/uibc.h"
|
||||
#include "net/rime/ipolite.h"
|
||||
|
||||
struct nf_conn;
|
||||
|
||||
|
@ -69,24 +69,22 @@ struct nf_callbacks {
|
|||
int (* recv)(struct nf_conn *c, rimeaddr_t *from,
|
||||
rimeaddr_t *originator, u8_t seqno, u8_t hops);
|
||||
void (* sent)(struct nf_conn *c);
|
||||
void (* dropped)(struct nf_conn *c);
|
||||
};
|
||||
|
||||
struct nf_conn {
|
||||
struct uibc_conn c;
|
||||
struct ctimer t;
|
||||
struct queuebuf *buf;
|
||||
clock_time_t queue_time;
|
||||
u8_t packets_received;
|
||||
u8_t last_originator_seqno;
|
||||
rimeaddr_t last_originator;
|
||||
struct ipolite_conn c;
|
||||
const struct nf_callbacks *u;
|
||||
clock_time_t queue_time;
|
||||
rimeaddr_t last_originator;
|
||||
u8_t last_originator_seqno;
|
||||
};
|
||||
|
||||
void nf_open(struct nf_conn *c, clock_time_t queue_time,
|
||||
u16_t channel, const struct nf_callbacks *u);
|
||||
void nf_close(struct nf_conn *c);
|
||||
|
||||
int nf_send(struct nf_conn *c);
|
||||
int nf_send(struct nf_conn *c, u8_t seqno);
|
||||
|
||||
#endif /* __SIBC_H__ */
|
||||
/** @} */
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: queuebuf.c,v 1.8 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: queuebuf.c,v 1.9 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -43,14 +43,14 @@
|
|||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "net/rime/queuebuf.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include <string.h> /* for memcpy() */
|
||||
|
||||
#ifdef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_NUM QUEUEBUF_CONF_NUM
|
||||
#else
|
||||
#define QUEUEBUF_NUM 2
|
||||
#define QUEUEBUF_NUM 4
|
||||
#endif
|
||||
|
||||
#ifdef QUEUEBUF_CONF_REF_NUM
|
||||
|
@ -82,12 +82,20 @@ MEMB(refbufmem, struct queuebuf_ref, QUEUEBUF_REF_NUM);
|
|||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#define QUEUEBUF_STATS 1
|
||||
#if QUEUEBUF_STATS
|
||||
u8_t queuebuf_len, queuebuf_ref_len, queuebuf_max_len;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
queuebuf_init(void)
|
||||
{
|
||||
memb_init(&bufmem);
|
||||
memb_init(&refbufmem);
|
||||
#if QUEUEBUF_STATS
|
||||
queuebuf_max_len = QUEUEBUF_NUM;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
struct queuebuf *
|
||||
|
@ -99,6 +107,14 @@ queuebuf_new_from_rimebuf(void)
|
|||
if(rimebuf_is_reference()) {
|
||||
rbuf = memb_alloc(&refbufmem);
|
||||
if(rbuf != NULL) {
|
||||
#if QUEUEBUF_STATS
|
||||
++queuebuf_ref_len;
|
||||
#if NETSIM
|
||||
node_log("%d %d\n",
|
||||
queuebuf_len,
|
||||
queuebuf_ref_len);
|
||||
#endif /* NETSIM */
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
rbuf->len = rimebuf_datalen();
|
||||
rbuf->ref = rimebuf_reference_ptr();
|
||||
rbuf->hdrlen = rimebuf_copyto_hdr(rbuf->hdr);
|
||||
|
@ -109,6 +125,19 @@ queuebuf_new_from_rimebuf(void)
|
|||
} else {
|
||||
buf = memb_alloc(&bufmem);
|
||||
if(buf != NULL) {
|
||||
#if QUEUEBUF_STATS
|
||||
++queuebuf_len;
|
||||
if(queuebuf_len == queuebuf_max_len + 1) {
|
||||
memb_free(&bufmem, buf);
|
||||
queuebuf_len--;
|
||||
return NULL;
|
||||
}
|
||||
#if NETSIM
|
||||
node_log("%d %d\n",
|
||||
queuebuf_len,
|
||||
queuebuf_ref_len);
|
||||
#endif /* NETSIM */
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
buf->len = rimebuf_copyto(buf->data);
|
||||
} else {
|
||||
PRINTF("queuebuf_new_from_rimebuf: could not allocate a queuebuf\n");
|
||||
|
@ -122,8 +151,24 @@ queuebuf_free(struct queuebuf *buf)
|
|||
{
|
||||
if(memb_inmemb(&bufmem, buf)) {
|
||||
memb_free(&bufmem, buf);
|
||||
#if QUEUEBUF_STATS
|
||||
--queuebuf_len;
|
||||
#if NETSIM
|
||||
node_log("%d %d\n",
|
||||
queuebuf_len,
|
||||
queuebuf_ref_len);
|
||||
#endif /* NETSIM */
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
} else if(memb_inmemb(&refbufmem, buf)) {
|
||||
memb_free(&refbufmem, buf);
|
||||
#if QUEUEBUF_STATS
|
||||
--queuebuf_ref_len;
|
||||
#if NETSIM
|
||||
node_log("%d %d\n",
|
||||
queuebuf_len,
|
||||
queuebuf_ref_len);
|
||||
#endif /* NETSIM */
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rime.c,v 1.7 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: rime.c,v 1.8 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -44,6 +44,9 @@
|
|||
*/
|
||||
|
||||
#include "net/rime.h"
|
||||
|
||||
static void (* output)(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rime_init(void)
|
||||
|
@ -52,6 +55,8 @@ rime_init(void)
|
|||
queuebuf_init();
|
||||
route_init();
|
||||
rimebuf_clear();
|
||||
output = NULL;
|
||||
neighbor_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -60,4 +65,19 @@ rime_input(void)
|
|||
abc_input_packet();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rime_set_output(void (*f)(void))
|
||||
{
|
||||
output = f;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rime_output(void)
|
||||
{
|
||||
rimebuf_compact();
|
||||
if(output) {
|
||||
output();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rimebuf.h,v 1.8 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: rimebuf.h,v 1.9 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@
|
|||
#ifndef __RIMEBUF_H__
|
||||
#define __RIMEBUF_H__
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "contiki-conf.h"
|
||||
|
||||
/**
|
||||
* \brief The size of the rimebuf, in bytes
|
||||
|
@ -298,7 +298,6 @@ int rimebuf_hdralloc(int size);
|
|||
*/
|
||||
int rimebuf_hdrreduce(int size);
|
||||
|
||||
|
||||
#endif /* __RIMEBUF_H__ */
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: route-discovery.c,v 1.5 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: route-discovery.c,v 1.6 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -82,10 +82,11 @@ send_rreq(struct route_discovery_conn *c, rimeaddr_t *dest)
|
|||
rimebuf_set_datalen(sizeof(struct route_msg));
|
||||
|
||||
msg->pad = 0;
|
||||
msg->rreq_id = c->rreq_id++;
|
||||
msg->rreq_id = c->rreq_id;
|
||||
rimeaddr_copy(&msg->dest, dest);
|
||||
|
||||
nf_send(&c->rreqconn);
|
||||
nf_send(&c->rreqconn, c->rreq_id);
|
||||
c->rreq_id++;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: ruc.c,v 1.9 2007/03/31 18:33:27 adamdunkels Exp $
|
||||
* $Id: ruc.c,v 1.10 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -74,6 +74,7 @@ sent_by_suc(struct suc_conn *suc)
|
|||
c->transmissions_left--;
|
||||
if(c->transmissions_left == 0) {
|
||||
suc_cancel(&c->c);
|
||||
c->u->timedout(c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: ruc.h,v 1.6 2007/03/31 18:33:27 adamdunkels Exp $
|
||||
* $Id: ruc.h,v 1.7 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,6 +48,7 @@ struct ruc_conn;
|
|||
struct ruc_callbacks {
|
||||
int (* recv)(struct ruc_conn *c, rimeaddr_t *from, u8_t seqno);
|
||||
void (* sent)(struct ruc_conn *c);
|
||||
void (* timedout)(struct ruc_conn *c);
|
||||
};
|
||||
|
||||
struct ruc_conn {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph0.c,v 1.4 2007/04/02 09:51:45 adamdunkels Exp $
|
||||
* $Id: rudolph0.c,v 1.5 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,7 @@
|
|||
|
||||
#define STEADY_TIME CLOCK_SECOND * 2
|
||||
|
||||
#define DEFAULT_SEND_INTERVAL CLOCK_SECOND / 2
|
||||
enum {
|
||||
TYPE_DATA,
|
||||
TYPE_NACK,
|
||||
|
@ -62,7 +63,7 @@ enum {
|
|||
|
||||
#define VERSION_LT(a, b) ((signed char)((a) - (b)) < 0)
|
||||
|
||||
#define DEBUG 0
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
|
@ -98,7 +99,7 @@ send_nack(struct rudolph0_conn *c)
|
|||
hdr->chunk = c->current.h.chunk;
|
||||
|
||||
PRINTF("Sending nack for %d:%d\n", hdr->version, hdr->chunk);
|
||||
uabc_send(&c->nackc, c->send_interval / 2);
|
||||
polite_send(&c->nackc, c->send_interval / 2, sizeof(struct rudolph0_hdr));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -158,10 +159,10 @@ recv(struct sabc_conn *sabc)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
recv_nack(struct uabc_conn *uabc)
|
||||
recv_nack(struct polite_conn *polite)
|
||||
{
|
||||
struct rudolph0_conn *c = (struct rudolph0_conn *)
|
||||
((char *)uabc - offsetof(struct rudolph0_conn,
|
||||
((char *)polite - offsetof(struct rudolph0_conn,
|
||||
nackc));
|
||||
struct rudolph0_datapacket *p = rimebuf_dataptr();
|
||||
|
||||
|
@ -178,7 +179,7 @@ recv_nack(struct uabc_conn *uabc)
|
|||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct uabc_callbacks uabc = { recv_nack, NULL, NULL };
|
||||
static const struct polite_callbacks polite = { recv_nack, NULL, NULL };
|
||||
static const struct sabc_callbacks sabc = { recv, sent };
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -186,17 +187,18 @@ rudolph0_open(struct rudolph0_conn *c, u16_t channel,
|
|||
const struct rudolph0_callbacks *cb)
|
||||
{
|
||||
sabc_open(&c->c, channel, &sabc);
|
||||
uabc_open(&c->nackc, channel + 1, &uabc);
|
||||
polite_open(&c->nackc, channel + 1, &polite);
|
||||
c->cb = cb;
|
||||
c->current.h.version = 0;
|
||||
c->state = STATE_RECEIVER;
|
||||
c->send_interval = DEFAULT_SEND_INTERVAL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph0_close(struct rudolph0_conn *c)
|
||||
{
|
||||
sabc_close(&c->c);
|
||||
uabc_close(&c->nackc);
|
||||
polite_close(&c->nackc);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -204,6 +206,7 @@ rudolph0_send(struct rudolph0_conn *c, clock_time_t send_interval)
|
|||
{
|
||||
c->state = STATE_SENDER;
|
||||
c->current.h.version++;
|
||||
c->current.h.version++;
|
||||
c->current.h.chunk = 0;
|
||||
c->current.h.type = TYPE_DATA;
|
||||
read_new_datapacket(c);
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph0.h,v 1.3 2007/04/02 09:51:45 adamdunkels Exp $
|
||||
* $Id: rudolph0.h,v 1.4 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@
|
|||
|
||||
#include "net/rime.h"
|
||||
#include "net/rime/sabc.h"
|
||||
#include "net/rime/uabc.h"
|
||||
#include "net/rime/polite.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
struct rudolph0_conn;
|
||||
|
@ -96,7 +96,7 @@ struct rudolph0_datapacket {
|
|||
|
||||
struct rudolph0_conn {
|
||||
struct sabc_conn c;
|
||||
struct uabc_conn nackc;
|
||||
struct polite_conn nackc;
|
||||
const struct rudolph0_callbacks *cb;
|
||||
clock_time_t send_interval;
|
||||
u8_t state;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph1.c,v 1.8 2007/04/02 19:12:37 adamdunkels Exp $
|
||||
* $Id: rudolph1.c,v 1.9 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -51,8 +51,9 @@
|
|||
#include "cfs/cfs.h"
|
||||
|
||||
#define DEFAULT_SEND_INTERVAL CLOCK_SECOND * 2
|
||||
#define TRICKLE_INTERVAL TRICKLE_SECOND / 2
|
||||
#define TRICKLE_INTERVAL CLOCK_SECOND / 2
|
||||
#define NACK_TIMEOUT CLOCK_SECOND / 4
|
||||
#define REPAIR_TIMEOUT CLOCK_SECOND / 4
|
||||
|
||||
struct rudolph1_hdr {
|
||||
u8_t type;
|
||||
|
@ -121,8 +122,9 @@ write_data(struct rudolph1_conn *c, int chunk, u8_t *data, int datalen)
|
|||
}
|
||||
|
||||
if(datalen < RUDOLPH1_DATASIZE) {
|
||||
PRINTF("%d: get %d bytes, file complete\n",
|
||||
rimeaddr_node_addr.u16, datalen);
|
||||
PRINTF("%d.%d: get %d bytes, file complete\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
datalen);
|
||||
c->cb->write_chunk(c, chunk * RUDOLPH1_DATASIZE,
|
||||
RUDOLPH1_FLAG_LASTCHUNK, data, datalen);
|
||||
} else {
|
||||
|
@ -143,8 +145,10 @@ send_nack(struct rudolph1_conn *c)
|
|||
hdr->version = c->version;
|
||||
hdr->chunk = c->chunk;
|
||||
|
||||
PRINTF("Sending nack for %d:%d\n", hdr->version, hdr->chunk);
|
||||
uabc_send(&c->uabc, CLOCK_SECOND / 4);
|
||||
PRINTF("%d.%d: Sending nack for %d:%d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
hdr->version, hdr->chunk);
|
||||
ipolite_send(&c->ipolite, NACK_TIMEOUT, sizeof(struct rudolph1_hdr));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -164,16 +168,22 @@ handle_data(struct rudolph1_conn *c, struct rudolph1_datapacket *p)
|
|||
}
|
||||
/* }*/
|
||||
} else if(p->h.version == c->version) {
|
||||
PRINTF("%d.%d: got chunk %d (%d) highest heard %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.chunk, c->chunk, c->highest_chunk_heard);
|
||||
|
||||
if(p->h.chunk == c->chunk) {
|
||||
PRINTF("%d.%d: received chunk %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.chunk);
|
||||
write_data(c, p->h.chunk, p->data, p->datalen);
|
||||
c->highest_chunk_heard = c->chunk;
|
||||
if(c->highest_chunk_heard < c->chunk) {
|
||||
c->highest_chunk_heard = c->chunk;
|
||||
}
|
||||
c->chunk++;
|
||||
} else if(p->h.chunk > c->chunk) {
|
||||
PRINTF("%d: received chunk %d > %d, sending NACK\n",
|
||||
rimeaddr_node_addr.u16,
|
||||
PRINTF("%d.%d: received chunk %d > %d, sending NACK\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.chunk, c->chunk);
|
||||
send_nack(c);
|
||||
c->highest_chunk_heard = p->h.chunk;
|
||||
|
@ -184,7 +194,7 @@ handle_data(struct rudolph1_conn *c, struct rudolph1_datapacket *p)
|
|||
/* If we have heard a higher chunk number, we send a NACK so that
|
||||
we get a repair for the next packet. */
|
||||
|
||||
if(c->highest_chunk_heard < p->h.chunk) {
|
||||
if(c->highest_chunk_heard > p->h.chunk) {
|
||||
send_nack(c);
|
||||
}
|
||||
} else { /* p->h.version < c->current.h.version */
|
||||
|
@ -208,16 +218,37 @@ recv_trickle(struct trickle_conn *trickle)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
recv_uabc(struct uabc_conn *uabc)
|
||||
sent_ipolite(struct ipolite_conn *ipolite)
|
||||
{
|
||||
PRINTF("%d.%d: Sent ipolite\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
dropped_ipolite(struct ipolite_conn *ipolite)
|
||||
{
|
||||
PRINTF("%d.%d: dropped ipolite\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
recv_ipolite(struct ipolite_conn *ipolite, rimeaddr_t *from)
|
||||
{
|
||||
struct rudolph1_conn *c = (struct rudolph1_conn *)
|
||||
((char *)uabc - offsetof(struct rudolph1_conn, uabc));
|
||||
((char *)ipolite - offsetof(struct rudolph1_conn, ipolite));
|
||||
struct rudolph1_datapacket *p = rimebuf_dataptr();
|
||||
|
||||
PRINTF("%d.%d: Got ipolite type %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.type);
|
||||
|
||||
c->nacks++;
|
||||
|
||||
if(p->h.type == TYPE_NACK) {
|
||||
PRINTF("Got NACK for %d:%d\n", p->h.version, p->h.chunk);
|
||||
PRINTF("%d.%d: Got NACK for %d:%d (%d:%d)\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.version, p->h.chunk,
|
||||
c->version, c->chunk);
|
||||
if(p->h.version == c->version) {
|
||||
if(p->h.chunk < c->chunk) {
|
||||
/* Format and send a repair packet */
|
||||
|
@ -225,14 +256,17 @@ recv_uabc(struct uabc_conn *uabc)
|
|||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.chunk);
|
||||
format_data(c, p->h.chunk);
|
||||
uabc_send(&c->uabc, c->send_interval / 2);
|
||||
ipolite_send(&c->ipolite, REPAIR_TIMEOUT, sizeof(struct rudolph1_hdr));
|
||||
}
|
||||
} else if(LT(p->h.version, c->version)) {
|
||||
format_data(c, 0);
|
||||
uabc_send(&c->uabc, c->send_interval / 2);
|
||||
ipolite_send(&c->ipolite, c->send_interval / 2, sizeof(struct rudolph1_hdr));
|
||||
}
|
||||
} else if(p->h.type == TYPE_DATA) {
|
||||
/* This is a repair packet from someone else. */
|
||||
PRINTF("%d.%d: got repair for chunk %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
p->h.chunk);
|
||||
handle_data(c, p);
|
||||
}
|
||||
}
|
||||
|
@ -244,26 +278,32 @@ send_next_packet(void *ptr)
|
|||
int len;
|
||||
if(c->nacks == 0) {
|
||||
len = format_data(c, c->chunk);
|
||||
trickle_send(&c->trickle, c->trickle_interval);
|
||||
trickle_send(&c->trickle);
|
||||
if(len == RUDOLPH1_DATASIZE) {
|
||||
ctimer_set(&c->t, c->send_interval, send_next_packet, c);
|
||||
}
|
||||
PRINTF("%d.%d: send_next_packet chunk %d, next %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
c->chunk, c->chunk + 1);
|
||||
|
||||
c->highest_chunk_heard = c->chunk;
|
||||
c->chunk++;
|
||||
|
||||
} else {
|
||||
ctimer_set(&c->t, c->send_interval, send_next_packet, c);
|
||||
}
|
||||
c->nacks = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct uabc_callbacks uabc = { recv_uabc, NULL, NULL };
|
||||
static const struct ipolite_callbacks ipolite = { recv_ipolite, sent_ipolite, dropped_ipolite };
|
||||
static const struct trickle_callbacks trickle = { recv_trickle };
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph1_open(struct rudolph1_conn *c, u16_t channel,
|
||||
const struct rudolph1_callbacks *cb)
|
||||
{
|
||||
trickle_open(&c->trickle, channel, &trickle);
|
||||
uabc_open(&c->uabc, channel + 1, &uabc);
|
||||
trickle_open(&c->trickle, TRICKLE_INTERVAL, channel, &trickle);
|
||||
ipolite_open(&c->ipolite, channel + 1, &ipolite);
|
||||
c->cb = cb;
|
||||
c->version = 0;
|
||||
c->send_interval = DEFAULT_SEND_INTERVAL;
|
||||
|
@ -273,7 +313,7 @@ void
|
|||
rudolph1_close(struct rudolph1_conn *c)
|
||||
{
|
||||
trickle_close(&c->trickle);
|
||||
uabc_close(&c->uabc);
|
||||
ipolite_close(&c->ipolite);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -281,9 +321,9 @@ rudolph1_send(struct rudolph1_conn *c, clock_time_t send_interval)
|
|||
{
|
||||
c->version++;
|
||||
c->chunk = c->highest_chunk_heard = 0;
|
||||
c->trickle_interval = TRICKLE_INTERVAL;
|
||||
/* c->trickle_interval = TRICKLE_INTERVAL;*/
|
||||
format_data(c, 0);
|
||||
trickle_send(&c->trickle, c->trickle_interval);
|
||||
trickle_send(&c->trickle);
|
||||
c->chunk++;
|
||||
c->send_interval = send_interval;
|
||||
ctimer_set(&c->t, send_interval, send_next_packet, c);
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph1.h,v 1.4 2007/04/02 17:53:27 adamdunkels Exp $
|
||||
* $Id: rudolph1.h,v 1.5 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -82,13 +82,13 @@ struct rudolph1_callbacks {
|
|||
|
||||
struct rudolph1_conn {
|
||||
struct trickle_conn trickle;
|
||||
struct uabc_conn uabc;
|
||||
struct ipolite_conn ipolite;
|
||||
const struct rudolph1_callbacks *cb;
|
||||
struct ctimer t;
|
||||
clock_time_t send_interval;
|
||||
u16_t chunk, highest_chunk_heard;
|
||||
u8_t version;
|
||||
u8_t trickle_interval;
|
||||
/* u8_t trickle_interval;*/
|
||||
u8_t nacks;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: tree.c,v 1.10 2007/03/31 18:33:04 adamdunkels Exp $
|
||||
* $Id: tree.c,v 1.11 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ send_adv(struct tree_conn *tc, clock_time_t interval)
|
|||
rimebuf_set_datalen(sizeof(struct adv_msg));
|
||||
hdr = rimebuf_dataptr();
|
||||
hdr->hopcount = tc->hops_from_sink;
|
||||
uibc_send(&tc->uibc_conn, interval);
|
||||
ipolite_send(&tc->ipolite_conn, interval, rimebuf_totlen());
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -111,14 +111,18 @@ update_hopcount(struct tree_conn *tc)
|
|||
if(tc->hops_from_sink != SINK) {
|
||||
n = neighbor_best();
|
||||
if(n == NULL) {
|
||||
/* if(hopcount != HOPCOUNT_MAX) {
|
||||
printf("%d: didn't find a best neighbor, setting hopcount to max\n", node_id);
|
||||
}*/
|
||||
if(tc->hops_from_sink != HOPCOUNT_MAX) {
|
||||
PRINTF("%d.%d: didn't find a best neighbor, setting hopcount to max\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
}
|
||||
tc->hops_from_sink = HOPCOUNT_MAX;
|
||||
} else {
|
||||
if(n->hopcount + 1 != tc->hops_from_sink) {
|
||||
tc->hops_from_sink = n->hopcount + 1;
|
||||
send_adv(tc, MIN_INTERVAL);
|
||||
PRINTF("%d.%d: new hopcount %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
tc->hops_from_sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +142,10 @@ update_hopcount(struct tree_conn *tc)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
||||
adv_packet_received(struct ipolite_conn *c, rimeaddr_t *from)
|
||||
{
|
||||
struct tree_conn *tc = (struct tree_conn *)
|
||||
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
||||
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
||||
struct adv_msg *msg = rimebuf_dataptr();
|
||||
struct neighbor *n;
|
||||
|
||||
|
@ -155,6 +159,10 @@ adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
|||
neighbor_add(from, msg->hopcount, radio_sensor.value(1));
|
||||
} else {
|
||||
neighbor_update(n, msg->hopcount, radio_sensor.value(1));
|
||||
PRINTF("%d.%d: updating neighbor %d.%d, radio sensor %d, hops %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
n->addr.u8[0], n->addr.u8[1],
|
||||
radio_sensor.value(1), msg->hopcount);
|
||||
}
|
||||
|
||||
update_hopcount(tc);
|
||||
|
@ -162,19 +170,28 @@ adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
adv_packet_sent(struct uibc_conn *c)
|
||||
adv_packet_sent(struct ipolite_conn *c)
|
||||
{
|
||||
struct tree_conn *tc = (struct tree_conn *)
|
||||
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
||||
send_adv(tc, MAX_INTERVAL);
|
||||
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
||||
/* send_adv(tc, MAX_INTERVAL);*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
adv_packet_dropped(struct uibc_conn *c)
|
||||
adv_packet_dropped(struct ipolite_conn *c)
|
||||
{
|
||||
struct tree_conn *tc = (struct tree_conn *)
|
||||
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
||||
send_adv(tc, MAX_INTERVAL);
|
||||
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
||||
/* send_adv(tc, MAX_INTERVAL);*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
send_timer(void *ptr)
|
||||
{
|
||||
struct tree_conn *tc = ptr;
|
||||
|
||||
send_adv(tc, MAX_INTERVAL / 2);
|
||||
ctimer_set(&tc->t, MAX_INTERVAL, send_timer, tc);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
|
@ -235,29 +252,37 @@ node_packet_sent(struct ruc_conn *c)
|
|||
tc->forwarding = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct uibc_callbacks uibc_callbacks =
|
||||
static void
|
||||
node_packet_timedout(struct ruc_conn *c)
|
||||
{
|
||||
struct tree_conn *tc = (struct tree_conn *)
|
||||
((char *)c - offsetof(struct tree_conn, ruc_conn));
|
||||
|
||||
tc->forwarding = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct ipolite_callbacks ipolite_callbacks =
|
||||
{adv_packet_received, adv_packet_sent, adv_packet_dropped};
|
||||
static const struct ruc_callbacks ruc_callbacks = {node_packet_received,
|
||||
node_packet_sent};
|
||||
node_packet_sent,
|
||||
node_packet_timedout};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tree_open(struct tree_conn *tc, u16_t channels,
|
||||
const struct tree_callbacks *cb)
|
||||
{
|
||||
uibc_open(&tc->uibc_conn, channels, &uibc_callbacks);
|
||||
ipolite_open(&tc->ipolite_conn, channels, &ipolite_callbacks);
|
||||
ruc_open(&tc->ruc_conn, channels + 1, &ruc_callbacks);
|
||||
tc->hops_from_sink = HOPCOUNT_MAX;
|
||||
/* rimebuf_clear();
|
||||
rimebuf_reference(&tc.hello, sizeof(tc.hello));
|
||||
sibc_send_stubborn(&sibc_conn, CLOCK_SECOND * 8);*/
|
||||
tc->cb = cb;
|
||||
send_adv(tc, MAX_INTERVAL);
|
||||
ctimer_set(&tc->t, MAX_INTERVAL, send_timer, tc);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tree_close(struct tree_conn *tc)
|
||||
{
|
||||
uibc_close(&tc->uibc_conn);
|
||||
ipolite_close(&tc->ipolite_conn);
|
||||
ruc_close(&tc->ruc_conn);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -279,6 +304,10 @@ tree_send(struct tree_conn *tc)
|
|||
struct neighbor *n;
|
||||
struct hdr *hdr;
|
||||
|
||||
if(tc->hops_from_sink == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(rimebuf_hdralloc(sizeof(struct hdr))) {
|
||||
hdr = rimebuf_hdrptr();
|
||||
hdr->originator_seqno = tc->seqno++;
|
||||
|
@ -291,6 +320,8 @@ tree_send(struct tree_conn *tc)
|
|||
ruc_send(&tc->ruc_conn, &n->addr, MAX_RETRANSMISSIONS);
|
||||
} else {
|
||||
/* printf("Didn't find any neighbor\n");*/
|
||||
PRINTF("%d.%d: did not find any neighbor to send to\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: tree.h,v 1.6 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: tree.h,v 1.7 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@
|
|||
#ifndef __TREE_H__
|
||||
#define __TREE_H__
|
||||
|
||||
#include "net/rime/uibc.h"
|
||||
#include "net/rime/ipolite.h"
|
||||
#include "net/rime/ruc.h"
|
||||
|
||||
struct tree_callbacks {
|
||||
|
@ -69,12 +69,13 @@ struct tree_callbacks {
|
|||
};
|
||||
|
||||
struct tree_conn {
|
||||
struct uibc_conn uibc_conn;
|
||||
struct ipolite_conn ipolite_conn;
|
||||
struct ruc_conn ruc_conn;
|
||||
const struct tree_callbacks *cb;
|
||||
struct ctimer t;
|
||||
u8_t forwarding;
|
||||
u8_t hops_from_sink;
|
||||
u8_t seqno;
|
||||
const struct tree_callbacks *cb;
|
||||
};
|
||||
|
||||
void tree_open(struct tree_conn *c, u16_t channels,
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: trickle.c,v 1.4 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: trickle.c,v 1.5 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -45,156 +45,88 @@
|
|||
|
||||
#include "net/rime/trickle.h"
|
||||
|
||||
struct trickle_hdr {
|
||||
u8_t seqno;
|
||||
u8_t interval;
|
||||
};
|
||||
|
||||
#define K 1
|
||||
|
||||
#define INTERVAL_MIN 1
|
||||
#define INTERVAL_MAX 4
|
||||
|
||||
#define SEQNO_LT(a, b) ((signed char)((a) - (b)) < 0)
|
||||
|
||||
static int trickle_pt(struct trickle_conn *c);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
send(struct trickle_conn *c)
|
||||
send(void *ptr)
|
||||
{
|
||||
struct trickle_hdr *hdr;
|
||||
struct trickle_conn *c = ptr;
|
||||
|
||||
if(c->q != NULL) {
|
||||
queuebuf_to_rimebuf(c->q);
|
||||
rimebuf_hdralloc(sizeof(struct trickle_hdr));
|
||||
hdr = rimebuf_hdrptr();
|
||||
hdr->seqno = c->seqno;
|
||||
hdr->interval = c->interval;
|
||||
abc_send(&c->c);
|
||||
nf_send(&c->c, c->seqno);
|
||||
ctimer_set(&c->t, c->interval << c->interval_scaling,
|
||||
send, c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_intervaltimer(struct trickle_conn *c)
|
||||
static int
|
||||
recv(struct nf_conn *nf, rimeaddr_t *from,
|
||||
rimeaddr_t *originator, u8_t seqno, u8_t hops)
|
||||
{
|
||||
ctimer_set(&c->intervaltimer,
|
||||
CLOCK_SECOND * (c->interval << c->interval_scaling) /
|
||||
TRICKLE_SECOND,
|
||||
(void (*)(void *))trickle_pt, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_listentimer(struct trickle_conn *c)
|
||||
{
|
||||
ctimer_set(&c->timer,
|
||||
CLOCK_SECOND * (c->interval << c->interval_scaling) /
|
||||
(2 * TRICKLE_SECOND),
|
||||
(void (*)(void *))trickle_pt, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_transmittimer(struct trickle_conn *c)
|
||||
{
|
||||
clock_time_t tval;
|
||||
struct trickle_conn *c = (struct trickle_conn *)nf;
|
||||
|
||||
tval = CLOCK_SECOND * (c->interval << c->interval_scaling) /
|
||||
(2 * TRICKLE_SECOND);
|
||||
|
||||
ctimer_set(&c->timer, random_rand() & tval,
|
||||
(void (*)(void *))trickle_pt, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
reset_interval(struct trickle_conn *c)
|
||||
{
|
||||
PT_INIT(&c->pt);
|
||||
trickle_pt(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
recv(struct abc_conn *abc)
|
||||
{
|
||||
struct trickle_conn *c = (struct trickle_conn *)abc;
|
||||
struct trickle_hdr *hdr = rimebuf_dataptr();
|
||||
|
||||
rimebuf_hdrreduce(sizeof(struct trickle_hdr));
|
||||
|
||||
if(hdr->seqno == c->seqno) {
|
||||
c->count++;
|
||||
c->cb->recv(c);
|
||||
} else if(SEQNO_LT(hdr->seqno, c->seqno)) {
|
||||
if(seqno == c->seqno) {
|
||||
/* c->cb->recv(c);*/
|
||||
} else if(SEQNO_LT(seqno, c->seqno)) {
|
||||
c->interval_scaling = 0;
|
||||
send(c);
|
||||
} else { /* hdr->seqno > c->seqno */
|
||||
c->interval = hdr->interval;
|
||||
c->seqno = hdr->seqno;
|
||||
c->seqno = seqno;
|
||||
/* Store the incoming data in the queuebuf */
|
||||
if(c->q != NULL) {
|
||||
queuebuf_free(c->q);
|
||||
}
|
||||
c->q = queuebuf_new_from_rimebuf();
|
||||
reset_interval(c);
|
||||
|
||||
c->interval_scaling = 0;
|
||||
send(c);
|
||||
c->cb->recv(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
trickle_pt(struct trickle_conn *c)
|
||||
static void
|
||||
sent_or_dropped(struct nf_conn *nf)
|
||||
{
|
||||
PT_BEGIN(&c->pt);
|
||||
struct trickle_conn *c = (struct trickle_conn *)nf;
|
||||
|
||||
c->interval_scaling = INTERVAL_MIN;
|
||||
|
||||
while(1) {
|
||||
c->count = 0;
|
||||
set_intervaltimer(c);
|
||||
set_listentimer(c);
|
||||
PT_YIELD(&c->pt); /* Wait for listen timer to expire. */
|
||||
set_transmittimer(c);
|
||||
PT_YIELD(&c->pt); /* Wait for transmit timer to expire. */
|
||||
if(c->count < K) {
|
||||
send(c);
|
||||
}
|
||||
PT_YIELD(&c->pt); /* Wait for interval timer to expire. */
|
||||
c->interval_scaling++;
|
||||
if(c->interval_scaling > INTERVAL_MAX) {
|
||||
c->interval_scaling = INTERVAL_MAX;
|
||||
}
|
||||
c->interval_scaling++;
|
||||
if(c->interval_scaling > INTERVAL_MAX) {
|
||||
c->interval_scaling = INTERVAL_MAX;
|
||||
}
|
||||
PT_END(&c->pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct abc_callbacks abc = {recv};
|
||||
static const struct nf_callbacks nf = {recv,
|
||||
sent_or_dropped,
|
||||
sent_or_dropped};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
trickle_open(struct trickle_conn *c, u16_t channel,
|
||||
const struct trickle_callbacks *cb)
|
||||
trickle_open(struct trickle_conn *c, clock_time_t interval,
|
||||
u16_t channel, const struct trickle_callbacks *cb)
|
||||
{
|
||||
abc_open(&c->c, channel, &abc);
|
||||
nf_open(&c->c, interval, channel, &nf);
|
||||
c->cb = cb;
|
||||
c->q = NULL;
|
||||
c->count = 0;
|
||||
c->interval = interval;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
trickle_close(struct trickle_conn *c)
|
||||
{
|
||||
abc_close(&c->c);
|
||||
ctimer_stop(&c->intervaltimer);
|
||||
ctimer_stop(&c->timer);
|
||||
nf_close(&c->c);
|
||||
ctimer_stop(&c->t);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
trickle_send(struct trickle_conn *c, u8_t interval)
|
||||
trickle_send(struct trickle_conn *c)
|
||||
{
|
||||
if(c->q != NULL) {
|
||||
queuebuf_free(c->q);
|
||||
}
|
||||
c->q = queuebuf_new_from_rimebuf();
|
||||
c->seqno++;
|
||||
c->interval = interval;
|
||||
reset_interval(c);
|
||||
send(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: trickle.h,v 1.3 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: trickle.h,v 1.4 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -59,6 +59,7 @@
|
|||
#define __TRICKLE_H__
|
||||
|
||||
#include "net/rime.h"
|
||||
#include "net/rime/nf.h"
|
||||
|
||||
struct trickle_conn;
|
||||
|
||||
|
@ -67,24 +68,20 @@ struct trickle_callbacks {
|
|||
};
|
||||
|
||||
struct trickle_conn {
|
||||
struct abc_conn c;
|
||||
struct nf_conn c;
|
||||
const struct trickle_callbacks *cb;
|
||||
struct ctimer t;
|
||||
struct queuebuf *q;
|
||||
struct ctimer intervaltimer;
|
||||
struct ctimer timer;
|
||||
struct pt pt;
|
||||
u8_t interval;
|
||||
clock_time_t interval;
|
||||
u8_t seqno;
|
||||
u8_t count;
|
||||
u8_t interval_scaling;
|
||||
};
|
||||
|
||||
void trickle_open(struct trickle_conn *c, u16_t channel,
|
||||
const struct trickle_callbacks *cb);
|
||||
void trickle_open(struct trickle_conn *c, clock_time_t interval,
|
||||
u16_t channel, const struct trickle_callbacks *cb);
|
||||
void trickle_close(struct trickle_conn *c);
|
||||
|
||||
#define TRICKLE_SECOND 8
|
||||
void trickle_send(struct trickle_conn *c, u8_t interval);
|
||||
void trickle_send(struct trickle_conn *c);
|
||||
|
||||
#endif /* __TRICKLE_H__ */
|
||||
/** @} */
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: uabc.c,v 1.5 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: uabc.c,v 1.6 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -105,6 +105,7 @@ uabc_close(struct uabc_conn *c)
|
|||
ctimer_stop(&c->t);
|
||||
if(c->q != NULL) {
|
||||
queuebuf_free(c->q);
|
||||
c->q = NULL;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -123,4 +124,14 @@ uabc_send(struct uabc_conn *c, clock_time_t interval)
|
|||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uabc_cancel(struct uabc_conn *c)
|
||||
{
|
||||
ctimer_stop(&c->t);
|
||||
if(c->q != NULL) {
|
||||
queuebuf_free(c->q);
|
||||
c->q = NULL;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: uabc.h,v 1.2 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: uabc.h,v 1.3 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -80,6 +80,7 @@ void uabc_open(struct uabc_conn *c, u16_t channel,
|
|||
const struct uabc_callbacks *cb);
|
||||
void uabc_close(struct uabc_conn *c);
|
||||
int uabc_send(struct uabc_conn *c, clock_time_t interval);
|
||||
void uabc_cancel(struct uabc_conn *c);
|
||||
|
||||
#endif /* __UABC_H__ */
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/**
|
||||
* \addtogroup rimeuc
|
||||
* @{
|
||||
|
@ -33,7 +34,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: uc.c,v 1.9 2007/03/31 18:31:29 adamdunkels Exp $
|
||||
* $Id: uc.c,v 1.10 2007/05/15 08:09:21 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,6 +48,10 @@
|
|||
#include "net/rime/uc.h"
|
||||
#include <string.h>
|
||||
|
||||
/* XXX This is a hack: MAC protocols may use this address as the
|
||||
receiver address of packets. */
|
||||
rimeaddr_t uc_receiver;
|
||||
|
||||
struct uc_hdr {
|
||||
rimeaddr_t receiver;
|
||||
};
|
||||
|
@ -94,9 +99,13 @@ uc_send(struct uc_conn *c, rimeaddr_t *receiver)
|
|||
{
|
||||
PRINTF("%d: uc_send to %d\n", rimeaddr_node_addr.u16, receiver->u16);
|
||||
if(rimebuf_hdralloc(sizeof(struct uc_hdr))) {
|
||||
int ret;
|
||||
struct uc_hdr *hdr = rimebuf_hdrptr();
|
||||
rimeaddr_copy(&hdr->receiver, receiver);
|
||||
return ibc_send(&c->c);
|
||||
rimeaddr_copy(&uc_receiver, receiver);
|
||||
ret = ibc_send(&c->c);
|
||||
rimeaddr_copy(&uc_receiver, &rimeaddr_null);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ ifndef TARGET
|
|||
TARGET=netsim
|
||||
endif
|
||||
all: test-abc test-meshroute test-treeroute test-trickle test-uabc \
|
||||
test-rudolph0 test-rudolph1
|
||||
test-rudolph0 test-rudolph1 test-rudolph2 test-rucb
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: test-rudolph1.c,v 1.6 2007/04/02 18:06:35 adamdunkels Exp $
|
||||
* $Id: test-rudolph1.c,v 1.7 2007/05/15 08:10:32 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,9 @@
|
|||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "cfs/cfs-ram.h"
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -80,14 +82,14 @@ write_chunk(struct rudolph1_conn *c, int offset, int flag,
|
|||
int ret;
|
||||
cfs_seek(fd, offset);
|
||||
ret = cfs_write(fd, data, datalen);
|
||||
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
|
||||
}
|
||||
|
||||
cfs_close(fd);
|
||||
|
||||
if(flag == RUDOLPH1_FLAG_LASTCHUNK) {
|
||||
int i;
|
||||
/* printf("+++ rudolph1 entire file received at %lu\n", clock_time());*/
|
||||
printf("+++ rudolph1 entire file received at %d, %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
leds_off(LEDS_RED);
|
||||
leds_on(LEDS_YELLOW);
|
||||
|
||||
|
@ -96,7 +98,9 @@ write_chunk(struct rudolph1_conn *c, int offset, int flag,
|
|||
unsigned char buf;
|
||||
cfs_read(fd, &buf, 1);
|
||||
if(buf != (unsigned char)i) {
|
||||
printf("error: diff at %d, %d != %d\n", i, i, buf);
|
||||
printf("%d.%d: error: diff at %d, %d != %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
i, i, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +120,9 @@ read_chunk(struct rudolph1_conn *c, int offset, char *to, int maxsize)
|
|||
|
||||
cfs_seek(fd, offset);
|
||||
ret = cfs_read(fd, to, maxsize);
|
||||
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
|
||||
/* printf("%d.%d: read_chunk %d bytes at %d, %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
ret, offset, (unsigned char)to[0]);*/
|
||||
cfs_close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
@ -124,11 +130,24 @@ const static struct rudolph1_callbacks rudolph1_call = {write_chunk,
|
|||
read_chunk};
|
||||
static struct rudolph1_conn rudolph1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "node-id.h"
|
||||
static void
|
||||
log_queuelen(struct rtimer *t, void *ptr)
|
||||
{
|
||||
#if NETSIM
|
||||
extern u8_t queuebuf_len, queuebuf_ref_len;
|
||||
node_log("%d %d\n",
|
||||
queuebuf_len,
|
||||
queuebuf_ref_len);
|
||||
rtimer_set(t, RTIMER_TIME(t) + RTIMER_ARCH_SECOND, 1,
|
||||
log_queuelen, ptr);
|
||||
#endif /* NETSIM */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
PROCESS_THREAD(test_rudolph1_process, ev, data)
|
||||
{
|
||||
static int fd;
|
||||
static struct rtimer t;
|
||||
PROCESS_EXITHANDLER(rudolph1_close(&rudolph1);)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
|
@ -138,6 +157,9 @@ PROCESS_THREAD(test_rudolph1_process, ev, data)
|
|||
rudolph1_open(&rudolph1, 128, &rudolph1_call);
|
||||
button_sensor.activate();
|
||||
|
||||
rtimer_set(&t, RTIMER_NOW() + RTIMER_ARCH_SECOND, 1,
|
||||
log_queuelen, NULL);
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
if(rimeaddr_node_addr.u8[0] == 1 &&
|
||||
|
|
175
examples/rime/test-rudolph2.c
Normal file
175
examples/rime/test-rudolph2.c
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: test-rudolph2.c,v 1.1 2007/05/15 08:10:32 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Testing the rudolph2 code in Rime
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime/rudolph2.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define FILESIZE 2000
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_rudolph2_process, "Rudolph2 test");
|
||||
AUTOSTART_PROCESSES(&test_rudolph2_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_chunk(struct rudolph2_conn *c, int offset, int flag,
|
||||
char *data, int datalen)
|
||||
{
|
||||
int fd;
|
||||
#if NETSIM
|
||||
{
|
||||
char buf[100];
|
||||
sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE);
|
||||
ether_set_text(buf);
|
||||
}
|
||||
#endif /* NETSIM */
|
||||
|
||||
if(flag == RUDOLPH2_FLAG_NEWFILE) {
|
||||
/*printf("+++ rudolph2 new file incoming at %lu\n", clock_time());*/
|
||||
leds_on(LEDS_RED);
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE);
|
||||
} else {
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
|
||||
}
|
||||
|
||||
if(datalen > 0) {
|
||||
int ret;
|
||||
cfs_seek(fd, offset);
|
||||
ret = cfs_write(fd, data, datalen);
|
||||
}
|
||||
|
||||
cfs_close(fd);
|
||||
|
||||
if(flag == RUDOLPH2_FLAG_LASTCHUNK) {
|
||||
int i;
|
||||
printf("+++ rudolph2 entire file received at %d, %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
leds_off(LEDS_RED);
|
||||
leds_on(LEDS_YELLOW);
|
||||
|
||||
fd = cfs_open("hej", CFS_READ);
|
||||
for(i = 0; i < FILESIZE; ++i) {
|
||||
unsigned char buf;
|
||||
cfs_read(fd, &buf, 1);
|
||||
if(buf != (unsigned char)i) {
|
||||
printf("%d.%d: error: diff at %d, %d != %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
i, i, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if NETSIM
|
||||
ether_send_done();
|
||||
#endif
|
||||
cfs_close(fd);
|
||||
}
|
||||
}
|
||||
static int
|
||||
read_chunk(struct rudolph2_conn *c, int offset, char *to, int maxsize)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
fd = cfs_open("hej", CFS_READ);
|
||||
|
||||
cfs_seek(fd, offset);
|
||||
ret = cfs_read(fd, to, maxsize);
|
||||
/* printf("%d.%d: read_chunk %d bytes at %d, %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
ret, offset, (unsigned char)to[0]);*/
|
||||
cfs_close(fd);
|
||||
return ret;
|
||||
}
|
||||
const static struct rudolph2_callbacks rudolph2_call = {write_chunk,
|
||||
read_chunk};
|
||||
static struct rudolph2_conn rudolph2;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "node-id.h"
|
||||
|
||||
PROCESS_THREAD(test_rudolph2_process, ev, data)
|
||||
{
|
||||
static int fd;
|
||||
PROCESS_EXITHANDLER(rudolph2_close(&rudolph2);)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
|
||||
rudolph2_open(&rudolph2, 128, &rudolph2_call);
|
||||
button_sensor.activate();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
if(rimeaddr_node_addr.u8[0] == 1 &&
|
||||
rimeaddr_node_addr.u8[1] == 1) {
|
||||
{
|
||||
int i;
|
||||
|
||||
fd = cfs_open("hej", CFS_WRITE);
|
||||
for(i = 0; i < FILESIZE; i++) {
|
||||
unsigned char buf = i;
|
||||
cfs_write(fd, &buf, 1);
|
||||
}
|
||||
cfs_close(fd);
|
||||
}
|
||||
rudolph2_send(&rudolph2, CLOCK_SECOND * 2);
|
||||
#if NETSIM
|
||||
ether_send_done();
|
||||
#endif /* NETSIM */
|
||||
|
||||
}
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
||||
data == &button_sensor);
|
||||
rudolph2_stop(&rudolph2);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: test-trickle.c,v 1.4 2007/03/31 18:43:45 adamdunkels Exp $
|
||||
* $Id: test-trickle.c,v 1.5 2007/05/15 08:10:32 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,7 @@ PROCESS_THREAD(test_trickle_process, ev, data)
|
|||
PROCESS_EXITHANDLER(trickle_close(&trickle);)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
trickle_open(&trickle, 128, &trickle_call);
|
||||
trickle_open(&trickle, CLOCK_SECOND, 128, &trickle_call);
|
||||
button_sensor.activate();
|
||||
|
||||
while(1) {
|
||||
|
@ -73,7 +73,7 @@ PROCESS_THREAD(test_trickle_process, ev, data)
|
|||
data == &button_sensor);
|
||||
|
||||
rimebuf_copyfrom("Hello, world", 13);
|
||||
trickle_send(&trickle, TRICKLE_SECOND / 4);
|
||||
trickle_send(&trickle);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
|
|
Loading…
Reference in a new issue