Ensure that header_module is != NULL before calling it. Define and print headers only if DEBUG is set.

This commit is contained in:
adamdunkels 2008-03-03 20:20:33 +00:00
parent 7d06f1bfe0
commit 39c85118d8

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: chameleon.c,v 1.2 2008/02/27 10:39:17 fros4943 Exp $
* $Id: chameleon.c,v 1.3 2008/03/03 20:20:33 adamdunkels Exp $
*/
/**
@ -63,6 +63,7 @@ chameleon_init(const struct chameleon_module *m)
channel_init();
}
/*---------------------------------------------------------------------------*/
#if DEBUG
static void
printbin(int n, int digits)
{
@ -98,6 +99,7 @@ printhdr(uint8_t *hdr, int len)
printf("\n");
}
}
#endif /* DEBUG */
/*---------------------------------------------------------------------------*/
void
chameleon_input(void)
@ -105,7 +107,10 @@ chameleon_input(void)
struct channel *c;
PRINTF("%d.%d: chameleon_input\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
/*printhdr(rimebuf_dataptr(), rimebuf_datalen());*/
#if DEBUG
printhdr(rimebuf_dataptr(), rimebuf_datalen());
#endif /* DEBUG */
if(header_module) {
c = header_module->input();
if(c != NULL) {
PRINTF("%d.%d: chameleon_input channel %d\n",
@ -117,6 +122,7 @@ chameleon_input(void)
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
}
}
}
/*---------------------------------------------------------------------------*/
int
chameleon_output(struct channel *c)
@ -127,15 +133,17 @@ chameleon_output(struct channel *c)
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channelno);
if(header_module) {
ret = header_module->output(c);
rimebuf_set_attr(RIMEBUF_ATTR_CHANNEL, c->channelno);
/*printhdr(rimebuf_hdrptr(), rimebuf_hdrlen());*/
#if DEBUG
printhdr(rimebuf_hdrptr(), rimebuf_hdrlen());
#endif /* DEBUG */
if(ret) {
rime_output();
return 1;
}
}
return 0;
}
/*---------------------------------------------------------------------------*/