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. * 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(); channel_init();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if DEBUG
static void static void
printbin(int n, int digits) printbin(int n, int digits)
{ {
@ -98,6 +99,7 @@ printhdr(uint8_t *hdr, int len)
printf("\n"); printf("\n");
} }
} }
#endif /* DEBUG */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
chameleon_input(void) chameleon_input(void)
@ -105,16 +107,20 @@ chameleon_input(void)
struct channel *c; struct channel *c;
PRINTF("%d.%d: chameleon_input\n", PRINTF("%d.%d: chameleon_input\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
/*printhdr(rimebuf_dataptr(), rimebuf_datalen());*/ #if DEBUG
c = header_module->input(); printhdr(rimebuf_dataptr(), rimebuf_datalen());
if(c != NULL) { #endif /* DEBUG */
PRINTF("%d.%d: chameleon_input channel %d\n", if(header_module) {
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], c = header_module->input();
c->channelno); if(c != NULL) {
abc_input(c); PRINTF("%d.%d: chameleon_input channel %d\n",
} else { rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
PRINTF("%d.%d: chameleon_input channel not found for incoming packet\n", c->channelno);
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); abc_input(c);
} else {
PRINTF("%d.%d: chameleon_input channel not found for incoming packet\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
}
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -126,15 +132,17 @@ chameleon_output(struct channel *c)
PRINTF("%d.%d: chameleon_output channel %d\n", PRINTF("%d.%d: chameleon_output channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channelno); c->channelno);
ret = header_module->output(c);
rimebuf_set_attr(RIMEBUF_ATTR_CHANNEL, c->channelno); if(header_module) {
ret = header_module->output(c);
/*printhdr(rimebuf_hdrptr(), rimebuf_hdrlen());*/ rimebuf_set_attr(RIMEBUF_ATTR_CHANNEL, c->channelno);
if(ret) { #if DEBUG
rime_output(); printhdr(rimebuf_hdrptr(), rimebuf_hdrlen());
return 1; #endif /* DEBUG */
if(ret) {
rime_output();
return 1;
}
} }
return 0; return 0;
} }