Fixed type offset bug in rimebuf_addr() and removed unused type for attributes and addresses. Replaced memcpy with loop.

This commit is contained in:
nifi 2008-04-02 14:49:21 +00:00
parent 8d47324d8f
commit f187981cd6
2 changed files with 25 additions and 18 deletions

View File

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rimebuf.c,v 1.13 2008/03/20 09:40:31 adamdunkels Exp $ * $Id: rimebuf.c,v 1.14 2008/04/02 14:49:21 nifi Exp $
*/ */
/** /**
@ -117,12 +117,17 @@ rimebuf_copyfrom(const void *from, uint16_t len)
void void
rimebuf_compact(void) rimebuf_compact(void)
{ {
int i, len;
if(rimebuf_is_reference()) { if(rimebuf_is_reference()) {
memcpy(&rimebuf[RIMEBUF_HDR_SIZE], rimebuf_reference_ptr(), memcpy(&rimebuf[RIMEBUF_HDR_SIZE], rimebuf_reference_ptr(),
rimebuf_datalen()); rimebuf_datalen());
} else { } else if (bufptr > 0) {
memcpy(&rimebuf[RIMEBUF_HDR_SIZE], &rimebuf[bufptr + RIMEBUF_HDR_SIZE], len = rimebuf_datalen() + RIMEBUF_HDR_SIZE;
rimebuf_datalen()); for (i = RIMEBUF_HDR_SIZE; i < len; i++) {
rimebuf[i] = rimebuf[bufptr + i];
}
bufptr = 0; bufptr = 0;
} }
} }
@ -260,10 +265,11 @@ rimebuf_attr_clear(void)
{ {
int i; int i;
for(i = 0; i < RIMEBUF_NUM_ATTRS; ++i) { for(i = 0; i < RIMEBUF_NUM_ATTRS; ++i) {
rimebuf_attrs[i].type = RIMEBUF_ATTR_NONE; /* rimebuf_attrs[i].type = RIMEBUF_ATTR_NONE; */
rimebuf_attrs[i].val = 0;
} }
for(i = 0; i < RIMEBUF_NUM_ADDRS; ++i) { for(i = 0; i < RIMEBUF_NUM_ADDRS; ++i) {
rimebuf_addrs[i].type = RIMEBUF_ATTR_NONE; /* rimebuf_addrs[i].type = RIMEBUF_ATTR_NONE; */
rimeaddr_copy(&rimebuf_addrs[i].addr, &rimeaddr_null); rimeaddr_copy(&rimebuf_addrs[i].addr, &rimeaddr_null);
} }
} }
@ -288,7 +294,7 @@ rimebuf_attr_copyfrom(struct rimebuf_attr *attrs,
int int
rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val) rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val)
{ {
rimebuf_attrs[type].type = type; /* rimebuf_attrs[type].type = type; */
rimebuf_attrs[type].val = val; rimebuf_attrs[type].val = val;
return 1; return 1;
} }
@ -302,15 +308,15 @@ rimebuf_attr(uint8_t type)
int int
rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr) rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr)
{ {
rimebuf_addrs[type].type = type; /* rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].type = type; */
rimeaddr_copy(&rimebuf_addrs[type].addr, addr); rimeaddr_copy(&rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].addr, addr);
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
const rimeaddr_t * const rimeaddr_t *
rimebuf_addr(uint8_t type) rimebuf_addr(uint8_t type)
{ {
return &rimebuf_addrs[type].addr; return &rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].addr;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* RIMEBUF_CONF_ATTRS_INLINE */ #endif /* RIMEBUF_CONF_ATTRS_INLINE */

View File

@ -40,7 +40,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rimebuf.h,v 1.13 2008/02/25 02:14:35 adamdunkels Exp $ * $Id: rimebuf.h,v 1.14 2008/04/02 14:49:21 nifi Exp $
*/ */
/** /**
@ -304,11 +304,11 @@ int rimebuf_hdrreduce(int size);
typedef uint16_t rimebuf_attr_t; typedef uint16_t rimebuf_attr_t;
struct rimebuf_attr { struct rimebuf_attr {
uint8_t type; /* uint8_t type; */
rimebuf_attr_t val; rimebuf_attr_t val;
}; };
struct rimebuf_addr { struct rimebuf_addr {
uint8_t type; /* uint8_t type; */
rimeaddr_t addr; rimeaddr_t addr;
}; };
@ -337,11 +337,12 @@ enum {
RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDR_ESENDER,
RIMEBUF_ADDR_ERECEIVER, RIMEBUF_ADDR_ERECEIVER,
RIMEBUF_ATTR_MAX, RIMEBUF_ATTR_MAX
}; };
#define RIMEBUF_NUM_ADDRS 4 #define RIMEBUF_NUM_ADDRS 4
#define RIMEBUF_NUM_ATTRS (RIMEBUF_ATTR_MAX - RIMEBUF_NUM_ADDRS) #define RIMEBUF_NUM_ATTRS (RIMEBUF_ATTR_MAX - RIMEBUF_NUM_ADDRS)
#define RIMEBUF_ADDR_FIRST RIMEBUF_ADDR_SENDER
#if RIMEBUF_CONF_ATTRS_INLINE #if RIMEBUF_CONF_ATTRS_INLINE
@ -357,7 +358,7 @@ static const rimeaddr_t *rimebuf_addr(uint8_t type);
static inline int static inline int
rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val) rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val)
{ {
rimebuf_attrs[type].type = type; /* rimebuf_attrs[type].type = type; */
rimebuf_attrs[type].val = val; rimebuf_attrs[type].val = val;
return 1; return 1;
} }
@ -370,15 +371,15 @@ rimebuf_attr(uint8_t type)
static inline int static inline int
rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr) rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr)
{ {
rimebuf_addrs[type].type = type; /* rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].type = type; */
rimeaddr_copy(&rimebuf_addrs[type].addr, addr); rimeaddr_copy(&rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].addr, addr);
return 1; return 1;
} }
static inline const rimeaddr_t * static inline const rimeaddr_t *
rimebuf_addr(uint8_t type) rimebuf_addr(uint8_t type)
{ {
return &rimebuf_addrs[type].addr; return &rimebuf_addrs[type - RIMEBUF_ADDR_FIRST].addr;
} }
#else /* RIMEBUF_CONF_ATTRS_INLINE */ #else /* RIMEBUF_CONF_ATTRS_INLINE */
int rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val); int rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val);