Added a new type for all addresses in Rime: rimeaddr_t. This is an abstract type that currently is defined as a 16-bit quantity but that most likely will be redefined in the future

This commit is contained in:
adamdunkels 2007-03-15 19:43:07 +00:00
parent 2b119b054e
commit ab0d556353
19 changed files with 216 additions and 92 deletions

View file

@ -1,3 +1,3 @@
CONTIKI_SOURCEFILES += rimebuf.c queuebuf.c ctimer.c neighbor.c rime.c \ CONTIKI_SOURCEFILES += rimebuf.c queuebuf.c rimeaddr.c ctimer.c neighbor.c rime.c \
ibc.c uc.c suc.c ruc.c sibc.c sabc.c abc.c \ ibc.c uc.c suc.c ruc.c sibc.c sabc.c abc.c \
nf.c # ccsabc.c abc-udp.c nf.c # ccsabc.c abc-udp.c

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ibc.c,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: ibc.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -43,18 +43,22 @@
#include <string.h> #include <string.h>
struct ibc_hdr { struct ibc_hdr {
node_id_t sender_id; rimeaddr_t sender;
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_abc(struct abc_conn *bc) recv_from_abc(struct abc_conn *bc)
{ {
rimeaddr_t sender;
struct ibc_conn *c = (struct ibc_conn *)bc; struct ibc_conn *c = (struct ibc_conn *)bc;
struct ibc_hdr *hdr = rimebuf_dataptr(); struct ibc_hdr *hdr = rimebuf_dataptr();
rimeaddr_copy(&sender, &hdr->sender);
rimebuf_hdrreduce(sizeof(struct ibc_hdr)); rimebuf_hdrreduce(sizeof(struct ibc_hdr));
DEBUGF(1, "%d: ibc: recv_from_bc\n", node_id); DEBUGF(1, "%d: ibc: recv_from_bc\n", node_id);
c->u->recv(c, hdr->sender_id); c->u->recv(c, &sender);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static const struct abc_callbacks ibc = {recv_from_abc}; static const struct abc_callbacks ibc = {recv_from_abc};
@ -73,7 +77,7 @@ ibc_send(struct ibc_conn *c)
DEBUGF(1, "%d: ibc_send\n", node_id); DEBUGF(1, "%d: ibc_send\n", node_id);
if(rimebuf_hdrextend(sizeof(struct ibc_hdr))) { if(rimebuf_hdrextend(sizeof(struct ibc_hdr))) {
struct ibc_hdr *hdr = rimebuf_hdrptr(); struct ibc_hdr *hdr = rimebuf_hdrptr();
hdr->sender_id = node_id; rimeaddr_copy(&hdr->sender, &rimeaddr_node_addr);
return abc_send(&c->c); return abc_send(&c->c);
} }
return 0; return 0;

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ibc.h,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: ibc.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -42,12 +42,12 @@
#define __IBC_H__ #define __IBC_H__
#include "net/rime/abc.h" #include "net/rime/abc.h"
#include "net/rime/node-id-t.h" #include "net/rime/rimeaddr.h"
struct ibc_conn; struct ibc_conn;
struct ibc_callbacks { struct ibc_callbacks {
void (* recv)(struct ibc_conn *ptr, node_id_t sender); void (* recv)(struct ibc_conn *ptr, rimeaddr_t *sender);
}; };
struct ibc_conn { struct ibc_conn {

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor.c,v 1.2 2007/03/15 09:56:15 adamdunkels Exp $ * $Id: neighbor.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -42,7 +42,6 @@
#include "contiki.h" #include "contiki.h"
#include "net/rime/neighbor.h" #include "net/rime/neighbor.h"
#include "node-id.h"
#define MAX_NEIGHBORS 5 #define MAX_NEIGHBORS 5
@ -56,13 +55,13 @@ neighbor_periodic(int max_time)
int i; int i;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(neighbors[i].nodeid != 0 && if(!rimeaddr_cmp(&neighbors[i].addr, &rimeaddr_null) &&
neighbors[i].time < max_time) { neighbors[i].time < max_time) {
neighbors[i].time++; neighbors[i].time++;
if(neighbors[i].time == max_time) { if(neighbors[i].time == max_time) {
neighbors[i].hopcount = HOPCOUNT_MAX; neighbors[i].hopcount = HOPCOUNT_MAX;
/* printf("%d: removing old neighbor %d\n", node_id, neighbors[i].nodeid);*/ /* printf("%d: removing old neighbor %d\n", node_id, neighbors[i].nodeid);*/
neighbors[i].nodeid = 0; rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null);
} }
} }
} }
@ -74,17 +73,17 @@ neighbor_init(void)
int i; int i;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
neighbors[i].nodeid = 0; rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
struct neighbor * struct neighbor *
neighbor_find(node_id_t nodeid) neighbor_find(rimeaddr_t *addr)
{ {
int i; int i;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(neighbors[i].nodeid == nodeid) { if(rimeaddr_cmp(&neighbors[i].addr, addr)) {
return &neighbors[i]; return &neighbors[i];
} }
} }
@ -102,7 +101,7 @@ neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
neighbor_add(node_id_t nodeid, u8_t nhopcount, u16_t nsignal) neighbor_add(rimeaddr_t *addr, u8_t nhopcount, u16_t nsignal)
{ {
int i, n; int i, n;
u8_t hopcount; u8_t hopcount;
@ -115,12 +114,12 @@ neighbor_add(node_id_t nodeid, u8_t nhopcount, u16_t nsignal)
n = 0; n = 0;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(neighbors[i].nodeid == 0 || if(rimeaddr_cmp(&neighbors[i].addr, &rimeaddr_null) ||
neighbors[i].nodeid == nodeid) { rimeaddr_cmp(&neighbors[i].addr, addr)) {
n = i; n = i;
break; break;
} }
if(neighbors[i].nodeid != 0) { if(!rimeaddr_cmp(&neighbors[i].addr, &rimeaddr_null)) {
if(neighbors[i].hopcount > hopcount) { if(neighbors[i].hopcount > hopcount) {
hopcount = neighbors[i].hopcount; hopcount = neighbors[i].hopcount;
signal = neighbors[i].signal; signal = neighbors[i].signal;
@ -142,20 +141,20 @@ neighbor_add(node_id_t nodeid, u8_t nhopcount, u16_t nsignal)
node_id, neighbors[n].nodeid, hopcount, signal, n);*/ node_id, neighbors[n].nodeid, hopcount, signal, n);*/
neighbors[n].time = 0; neighbors[n].time = 0;
neighbors[n].nodeid = nodeid; rimeaddr_copy(&neighbors[i].addr, addr);
neighbors[n].hopcount = nhopcount; neighbors[n].hopcount = nhopcount;
neighbors[n].signal = nsignal; neighbors[n].signal = nsignal;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
neighbor_remove(node_id_t nodeid) neighbor_remove(rimeaddr_t *addr)
{ {
int i; int i;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(neighbors[i].nodeid == nodeid) { if(rimeaddr_cmp(&neighbors[i].addr, addr)) {
printf("%d: removing %d @ %d\n", node_id, nodeid, i); printf("%d: removing %d @ %d\n", rimeaddr_node_addr.u16, addr->u16, i);
neighbors[i].nodeid = 0; rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null);
neighbors[i].hopcount = HOPCOUNT_MAX; neighbors[i].hopcount = HOPCOUNT_MAX;
return; return;
} }
@ -179,7 +178,7 @@ neighbor_best(void)
/* Find the lowest hopcount. */ /* Find the lowest hopcount. */
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
/* printf("%d:%d ", neighbors[i].nodeid, neighbors[i].hopcount);*/ /* printf("%d:%d ", neighbors[i].nodeid, neighbors[i].hopcount);*/
if(neighbors[i].nodeid != 0 && if(!rimeaddr_cmp(&neighbors[i].addr, &rimeaddr_null) &&
hopcount > neighbors[i].hopcount) { hopcount > neighbors[i].hopcount) {
hopcount = neighbors[i].hopcount; hopcount = neighbors[i].hopcount;
lowest = i; lowest = i;
@ -194,7 +193,7 @@ neighbor_best(void)
signal = 0; signal = 0;
best = lowest; best = lowest;
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(neighbors[i].nodeid != 0 && if(!rimeaddr_cmp(&neighbors[i].addr, &rimeaddr_null) &&
hopcount == neighbors[i].hopcount && hopcount == neighbors[i].hopcount &&
neighbors[i].signal > signal) { neighbors[i].signal > signal) {
signal = neighbors[i].signal; signal = neighbors[i].signal;

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $ * $Id: neighbor.h,v 1.2 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -41,27 +41,25 @@
#ifndef __NEIGHBOR_H__ #ifndef __NEIGHBOR_H__
#define __NEIGHBOR_H__ #define __NEIGHBOR_H__
#include "net/rime/node-id-t.h" #include "net/rime/rimeaddr.h"
struct neighbor { struct neighbor {
u16_t signal; u16_t signal;
u16_t time; u16_t time;
node_id_t nodeid; rimeaddr_t addr;
u8_t hopcount; u8_t hopcount;
}; };
void neighbor_init(void); void neighbor_init(void);
void neighbor_periodic(int max_time); void neighbor_periodic(int max_time);
void neighbor_add(node_id_t nodeid, u8_t hopcount, u16_t signal); void neighbor_add(rimeaddr_t *addr, u8_t hopcount, u16_t signal);
void neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal); void neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal);
void neighbor_remove(node_id_t nodeid); void neighbor_remove(rimeaddr_t *addr);
struct neighbor *neighbor_find(node_id_t nodeid); struct neighbor *neighbor_find(rimeaddr_t *addr);
struct neighbor *neighbor_best(void); struct neighbor *neighbor_best(void);
#define NEIGHBOR_NODEID(n) ((n)->nodeid)
#endif /* __NEIGHBOR_H__ */ #endif /* __NEIGHBOR_H__ */

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: nf.c,v 1.3 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: nf.c,v 1.4 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -50,7 +50,7 @@
struct nf_hdr { struct nf_hdr {
u8_t hops; u8_t hops;
u8_t originator_seqno; u8_t originator_seqno;
node_id_t originator_id; rimeaddr_t originator;
}; };
static u8_t seqno; static u8_t seqno;
@ -99,7 +99,7 @@ queue_for_send(struct nf_conn *c)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id) recv_from_ibc(struct ibc_conn *ibc, rimeaddr_t *from)
{ {
register struct nf_conn *c = (struct nf_conn *)ibc; register struct nf_conn *c = (struct nf_conn *)ibc;
struct nf_hdr *hdr = rimebuf_dataptr(); struct nf_hdr *hdr = rimebuf_dataptr();
@ -115,10 +115,10 @@ recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id)
rimebuf_hdrreduce(sizeof(struct nf_hdr)); rimebuf_hdrreduce(sizeof(struct nf_hdr));
if(c->u->recv != NULL) { if(c->u->recv != NULL) {
if(!(hdr->originator_id == c->last_originator_id && if(!(rimeaddr_cmp(&hdr->originator, &c->last_originator) &&
hdr->originator_seqno <= c->last_originator_seqno)) { hdr->originator_seqno <= c->last_originator_seqno)) {
if(c->u->recv(c, from_id, hdr->originator_id, hdr->originator_seqno, if(c->u->recv(c, from, &hdr->originator, hdr->originator_seqno,
hops)) { hops)) {
if(queuebuf != NULL) { if(queuebuf != NULL) {
@ -135,7 +135,7 @@ recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id)
hops);*/ hops);*/
hdr->hops++; hdr->hops++;
queue_for_send(c); queue_for_send(c);
c->last_originator_id = hdr->originator_id; rimeaddr_copy(&c->last_originator, &hdr->originator);
c->last_originator_seqno = hdr->originator_seqno; c->last_originator_seqno = hdr->originator_seqno;
} }
} }
@ -167,8 +167,8 @@ nf_send(struct nf_conn *c)
if(rimebuf_hdrextend(sizeof(struct nf_hdr))) { if(rimebuf_hdrextend(sizeof(struct nf_hdr))) {
struct nf_hdr *hdr = rimebuf_hdrptr(); struct nf_hdr *hdr = rimebuf_hdrptr();
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
c->last_originator_id = hdr->originator_id = node_id; 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; hdr->hops = 0;
return queue_for_send(c); return queue_for_send(c);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: nf.h,v 1.3 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: nf.h,v 1.4 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -48,8 +48,8 @@
struct nf_conn; struct nf_conn;
struct nf_callbacks { struct nf_callbacks {
int (* recv)(struct nf_conn *c, node_id_t from, int (* recv)(struct nf_conn *c, rimeaddr_t *from,
node_id_t originator, u8_t seqno, u8_t hops); rimeaddr_t *originator, u8_t seqno, u8_t hops);
void (* sent)(struct nf_conn *c); void (* sent)(struct nf_conn *c);
}; };
@ -59,7 +59,7 @@ struct nf_conn {
struct queuebuf *buf; struct queuebuf *buf;
u8_t packets_received; u8_t packets_received;
u8_t last_originator_seqno; u8_t last_originator_seqno;
node_id_t last_originator_id; rimeaddr_t last_originator;
const struct nf_callbacks *u; const struct nf_callbacks *u;
}; };

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rime-debug.h,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: rime-debug.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -41,7 +41,7 @@
#ifndef __RIME_DEBUG_H__ #ifndef __RIME_DEBUG_H__
#define __RIME_DEBUG_H__ #define __RIME_DEBUG_H__
#define DEBUG_LEVEL 1 #define DEBUG_LEVEL 0
#if DEBUG_LEVEL > 0 #if DEBUG_LEVEL > 0
#include <stdio.h> #include <stdio.h>

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rime.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $ * $Id: rime.c,v 1.2 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -39,6 +39,7 @@
*/ */
#include "net/rime.h" #include "net/rime.h"
#include "node-id.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
rime_init(void) rime_init(void)
@ -46,5 +47,13 @@ rime_init(void)
ctimer_init(); ctimer_init();
queuebuf_init(); queuebuf_init();
rimebuf_clear(); rimebuf_clear();
rimeaddr_node_addr.u16 = node_id;
}
/*---------------------------------------------------------------------------*/
void
rime_input_packet(void)
{
abc_input_packet();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

58
core/net/rime/rimeaddr.c Normal file
View file

@ -0,0 +1,58 @@
/*
* 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: rimeaddr.c,v 1.1 2007/03/15 19:43:07 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "rimeaddr.h"
rimeaddr_t rimeaddr_node_addr;
const rimeaddr_t rimeaddr_null = {.u16 = 0};
/*---------------------------------------------------------------------------*/
void
rimeaddr_copy(rimeaddr_t *dest, const rimeaddr_t *src)
{
dest->u16 = src->u16;
}
/*---------------------------------------------------------------------------*/
int
rimeaddr_cmp(const rimeaddr_t *addr1, const rimeaddr_t *addr2)
{
return addr1->u16 == addr2->u16;
}
/*---------------------------------------------------------------------------*/

56
core/net/rime/rimeaddr.h Normal file
View file

@ -0,0 +1,56 @@
/*
* 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: rimeaddr.h,v 1.1 2007/03/15 19:43:07 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __RIMEADDR_H__
#define __RIMEADDR_H__
typedef union {
unsigned char u8[2];
unsigned short u16;
} rimeaddr_t;
void rimeaddr_copy(rimeaddr_t *dest, const rimeaddr_t *from);
int rimeaddr_cmp(const rimeaddr_t *addr1, const rimeaddr_t *addr2);
extern rimeaddr_t rimeaddr_node_addr;
extern const rimeaddr_t rimeaddr_null;
#endif /* __RIMEADDR_H__ */

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ruc.c,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: ruc.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -66,7 +66,7 @@ sent_by_suc(struct suc_conn *suc)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_suc(struct suc_conn *suc, node_id_t from_id) recv_from_suc(struct suc_conn *suc, rimeaddr_t *from)
{ {
struct ruc_conn *c = (struct ruc_conn *)suc; struct ruc_conn *c = (struct ruc_conn *)suc;
struct ruc_hdr *hdr = rimebuf_dataptr(); struct ruc_hdr *hdr = rimebuf_dataptr();
@ -92,18 +92,18 @@ recv_from_suc(struct suc_conn *suc, node_id_t from_id)
rimebuf_hdrreduce(sizeof(struct ruc_hdr)); rimebuf_hdrreduce(sizeof(struct ruc_hdr));
if(c->u->recv != NULL) { if(c->u->recv != NULL) {
send_ack = c->u->recv(c, from_id, packet_seqno); send_ack = c->u->recv(c, from, packet_seqno);
} }
if(send_ack) { if(send_ack) {
DEBUGF(4, "%d: ruc: Sending ACK to %d for %d\n", node_id, from_id, DEBUGF(4, "%d: ruc: Sending ACK to %d for %d\n", node_id, from,
packet_seqno); packet_seqno);
rimebuf_clear(); rimebuf_clear();
rimebuf_hdrextend(sizeof(struct ruc_hdr)); rimebuf_hdrextend(sizeof(struct ruc_hdr));
hdr = rimebuf_hdrptr(); hdr = rimebuf_hdrptr();
hdr->type = TYPE_ACK; hdr->type = TYPE_ACK;
hdr->seqno = packet_seqno; hdr->seqno = packet_seqno;
suc_send_uc(&c->c, from_id); suc_send_uc(&c->c, from);
} else { } else {
DEBUGF(4, "%d: Not sending ACK\n", node_id); DEBUGF(4, "%d: Not sending ACK\n", node_id);
} }
@ -121,13 +121,13 @@ ruc_setup(struct ruc_conn *c, u16_t channel,
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
ruc_send(struct ruc_conn *c, node_id_t receiver_id) ruc_send(struct ruc_conn *c, rimeaddr_t *receiver)
{ {
if(rimebuf_hdrextend(sizeof(struct ruc_hdr))) { if(rimebuf_hdrextend(sizeof(struct ruc_hdr))) {
struct ruc_hdr *hdr = rimebuf_hdrptr(); struct ruc_hdr *hdr = rimebuf_hdrptr();
hdr->type = TYPE_DATA; hdr->type = TYPE_DATA;
hdr->seqno = seqno; hdr->seqno = seqno;
return suc_send_stubborn(&c->c, receiver_id); return suc_send_stubborn(&c->c, receiver);
} }
return 0; return 0;
} }

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ruc.h,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: ruc.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -46,7 +46,7 @@
struct ruc_conn; struct ruc_conn;
struct ruc_callbacks { struct ruc_callbacks {
int (* recv)(struct ruc_conn *c, node_id_t from, u8_t seqno); int (* recv)(struct ruc_conn *c, rimeaddr_t *from, u8_t seqno);
void (* sent)(struct ruc_conn *c); void (* sent)(struct ruc_conn *c);
}; };
@ -59,6 +59,6 @@ struct ruc_conn {
void ruc_setup(struct ruc_conn *c, u16_t channel, void ruc_setup(struct ruc_conn *c, u16_t channel,
const struct ruc_callbacks *u); const struct ruc_callbacks *u);
int ruc_send(struct ruc_conn *c, node_id_t receiver_id); int ruc_send(struct ruc_conn *c, rimeaddr_t *receiver);
#endif /* __RRUC_H__ */ #endif /* __RRUC_H__ */

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: sibc.c,v 1.2 2007/03/15 10:01:04 adamdunkels Exp $ * $Id: sibc.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -44,12 +44,12 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id) recv_from_ibc(struct ibc_conn *ibc, rimeaddr_t *from)
{ {
register struct sibc_conn *c = (struct sibc_conn *)ibc; register struct sibc_conn *c = (struct sibc_conn *)ibc;
/* DEBUGF(3, "sibc: recv_from_ibc from %d\n", from_id);*/ /* DEBUGF(3, "sibc: recv_from_ibc from %d\n", from_id);*/
if(c->u->recv != NULL) { if(c->u->recv != NULL) {
c->u->recv(c, from_id); c->u->recv(c, from);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: sibc.h,v 1.2 2007/03/15 10:01:05 adamdunkels Exp $ * $Id: sibc.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -48,7 +48,7 @@
struct sibc_conn; struct sibc_conn;
struct sibc_callbacks { struct sibc_callbacks {
void (* recv)(struct sibc_conn *c, node_id_t from); void (* recv)(struct sibc_conn *c, rimeaddr_t *from);
void (* sent)(struct sibc_conn *c); void (* sent)(struct sibc_conn *c);
}; };

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: suc.c,v 1.2 2007/03/15 10:01:05 adamdunkels Exp $ * $Id: suc.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -44,12 +44,12 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_uc(struct uc_conn *uc, node_id_t from_id) recv_from_uc(struct uc_conn *uc, rimeaddr_t *from)
{ {
register struct suc_conn *c = (struct suc_conn *)uc; register struct suc_conn *c = (struct suc_conn *)uc;
DEBUGF(3, "%d: suc: recv_from_uc from %d %p\n", node_id, from_id, c); DEBUGF(3, "%d: suc: recv_from_uc from %d %p\n", node_id, from_id, c);
if(c->u->recv != NULL) { if(c->u->recv != NULL) {
c->u->recv(c, from_id); c->u->recv(c, from);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -68,9 +68,9 @@ send(void *ptr)
{ {
struct suc_conn *c = ptr; struct suc_conn *c = ptr;
DEBUGF(3, "%d: suc: resend to %d\n", node_id, c->receiver_id); DEBUGF(3, "%d: suc: resend to %d\n", node_id, c->receiver);
queuebuf_to_rimebuf(c->buf); queuebuf_to_rimebuf(c->buf);
uc_send(&c->c, c->receiver_id); uc_send(&c->c, &c->receiver);
suc_set_timer(c, CLOCK_SECOND); suc_set_timer(c, CLOCK_SECOND);
if(c->u->sent != NULL) { if(c->u->sent != NULL) {
c->u->sent(c); c->u->sent(c);
@ -84,7 +84,7 @@ suc_set_timer(struct suc_conn *c, clock_time_t t)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id) suc_send_stubborn(struct suc_conn *c, rimeaddr_t *receiver)
{ {
if(c->buf != NULL) { if(c->buf != NULL) {
queuebuf_free(c->buf); queuebuf_free(c->buf);
@ -93,11 +93,11 @@ suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id)
if(c->buf == NULL) { if(c->buf == NULL) {
return 0; return 0;
} }
c->receiver_id = receiver_id; rimeaddr_copy(&c->receiver, receiver);
ctimer_set(&c->t, CLOCK_SECOND, send, c); ctimer_set(&c->t, CLOCK_SECOND, send, c);
DEBUGF(3, "%d: suc_send_stubborn to %d\n", node_id, c->receiver_id); DEBUGF(3, "%d: suc_send_stubborn to %d\n", node_id, c->receiver);
uc_send(&c->c, c->receiver_id); uc_send(&c->c, &c->receiver);
if(c->u->sent != NULL) { if(c->u->sent != NULL) {
c->u->sent(c); c->u->sent(c);
} }
@ -107,9 +107,9 @@ suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
suc_send_uc(struct suc_conn *c, node_id_t receiver_id) suc_send_uc(struct suc_conn *c, rimeaddr_t *receiver)
{ {
return uc_send(&c->c, receiver_id); return uc_send(&c->c, receiver);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: suc.h,v 1.2 2007/03/15 10:01:05 adamdunkels Exp $ * $Id: suc.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -48,7 +48,7 @@
struct suc_conn; struct suc_conn;
struct suc_callbacks { struct suc_callbacks {
void (* recv)(struct suc_conn *c, node_id_t from); void (* recv)(struct suc_conn *c, rimeaddr_t *from);
void (* sent)(struct suc_conn *c); void (* sent)(struct suc_conn *c);
}; };
@ -57,16 +57,16 @@ struct suc_conn {
struct ctimer t; struct ctimer t;
struct queuebuf *buf; struct queuebuf *buf;
const struct suc_callbacks *u; const struct suc_callbacks *u;
node_id_t receiver_id; rimeaddr_t receiver;
}; };
void suc_setup(struct suc_conn *c, u16_t channel, void suc_setup(struct suc_conn *c, u16_t channel,
const struct suc_callbacks *u); const struct suc_callbacks *u);
int suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id); int suc_send_stubborn(struct suc_conn *c, rimeaddr_t *receiver);
void suc_cancel(struct suc_conn *c); void suc_cancel(struct suc_conn *c);
int suc_send_uc(struct suc_conn *c, node_id_t receiver_id); int suc_send_uc(struct suc_conn *c, rimeaddr_t *receiver);
void suc_set_timer(struct suc_conn *c, clock_time_t t); void suc_set_timer(struct suc_conn *c, clock_time_t t);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: uc.c,v 1.2 2007/03/15 10:01:05 adamdunkels Exp $ * $Id: uc.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -43,20 +43,20 @@
#include <string.h> #include <string.h>
struct uc_hdr { struct uc_hdr {
node_id_t receiver_id; rimeaddr_t receiver;
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id) recv_from_ibc(struct ibc_conn *ibc, rimeaddr_t *from)
{ {
struct uc_conn *c = (struct uc_conn *)ibc; struct uc_conn *c = (struct uc_conn *)ibc;
struct uc_hdr *hdr = rimebuf_dataptr(); struct uc_hdr *hdr = rimebuf_dataptr();
DEBUGF(2, "%d: uc: recv_from_ibc, receiver id %d %p hdr %p\n", DEBUGF(2, "%d: uc: recv_from_ibc, receiver %d %p hdr %p\n",
node_id, hdr->receiver_id, c, hdr); node_id, hdr->receiver, c, hdr);
if(hdr->receiver_id == node_id) { if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_node_addr)) {
rimebuf_hdrreduce(sizeof(struct uc_hdr)); rimebuf_hdrreduce(sizeof(struct uc_hdr));
c->u->recv(c, from_id); c->u->recv(c, from);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -71,12 +71,12 @@ uc_setup(struct uc_conn *c, u16_t channel,
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
uc_send(struct uc_conn *c, node_id_t receiver_id) uc_send(struct uc_conn *c, rimeaddr_t *receiver)
{ {
DEBUGF(2, "%d: uc_send to %d\n", node_id, receiver_id); DEBUGF(2, "%d: uc_send to %d\n", node_id, receiver_id);
if(rimebuf_hdrextend(sizeof(struct uc_hdr))) { if(rimebuf_hdrextend(sizeof(struct uc_hdr))) {
struct uc_hdr *hdr = rimebuf_hdrptr(); struct uc_hdr *hdr = rimebuf_hdrptr();
hdr->receiver_id = receiver_id; rimeaddr_copy(&hdr->receiver, receiver);
return ibc_send(&c->c); return ibc_send(&c->c);
} }
return 0; return 0;

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: uc.h,v 1.2 2007/03/15 10:01:05 adamdunkels Exp $ * $Id: uc.h,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $
*/ */
/** /**
@ -46,7 +46,7 @@
struct uc_conn; struct uc_conn;
struct uc_callbacks { struct uc_callbacks {
void (* recv)(struct uc_conn *c, node_id_t from_id); void (* recv)(struct uc_conn *c, rimeaddr_t *from);
}; };
struct uc_conn { struct uc_conn {
@ -56,6 +56,6 @@ struct uc_conn {
void uc_setup(struct uc_conn *c, u16_t channel, void uc_setup(struct uc_conn *c, u16_t channel,
const struct uc_callbacks *u); const struct uc_callbacks *u);
int uc_send(struct uc_conn *c, node_id_t receiver_id); int uc_send(struct uc_conn *c, rimeaddr_t *receiver);
#endif /* __UC_H__ */ #endif /* __UC_H__ */