Sensinode: Border router debug without printf

Closes #20
This commit is contained in:
George Oikonomou 2012-09-17 16:26:09 +01:00
parent 53fdb96816
commit 13f20225a6

View file

@ -33,14 +33,30 @@
#include <string.h> #include <string.h>
#define DEBUG DEBUG_NONE #define DEBUG DEBUG_PRINT
#include "net/uip-debug.h" #include "net/uip-debug.h"
#include "net/rpl/rpl.h" #include "net/rpl/rpl.h"
#include "dev/watchdog.h" #include "dev/watchdog.h"
#include "dev/slip.h" #include "dev/slip.h"
#include "dev/leds.h" #include "dev/leds.h"
#include "dev/cc2430_rf.h"
#include "debug.h"
static uint8_t prefix_set; static uint8_t prefix_set;
#if DEBUG
#define PUTSTRING(...) putstring(__VA_ARGS__)
#define PUTHEX(...) puthex(__VA_ARGS__)
#define PUTBIN(...) putbin(__VA_ARGS__)
#define PUTDEC(...) putdec(__VA_ARGS__)
#define PUTCHAR(...) putchar(__VA_ARGS__)
#else
#define PUTSTRING(...)
#define PUTHEX(...)
#define PUTBIN(...)
#define PUTDEC(...)
#define PUTCHAR(...)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(border_router_process, "Border Router process"); PROCESS(border_router_process, "Border Router process");
AUTOSTART_PROCESSES(&border_router_process); AUTOSTART_PROCESSES(&border_router_process);
@ -51,14 +67,14 @@ print_local_addresses(void) CC_NON_BANKED
int i; int i;
uint8_t state; uint8_t state;
PRINTF("Router's IPv6 addresses:\n"); PUTSTRING("Router's IPv6 addresses:\n");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) { for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state; state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
== ADDR_PREFERRED)) { == ADDR_PREFERRED)) {
PRINTF(" "); PUTSTRING(" ");
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n"); PUTCHAR('\n');
if (state == ADDR_TENTATIVE) { if (state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
} }
@ -92,9 +108,9 @@ set_prefix_64(uip_ipaddr_t *prefix_64)
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr); dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr);
if(dag != NULL) { if(dag != NULL) {
rpl_set_prefix(dag, &ipaddr, 64); rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("Created a new RPL dag with ID: "); PUTSTRING("Created a new RPL dag with ID: ");
PRINT6ADDR(&dag->dag_id); PRINT6ADDR(&dag->dag_id);
PRINTF("\n"); PUTCHAR('\n');
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -103,7 +119,7 @@ PROCESS_THREAD(border_router_process, ev, data)
static struct etimer et; static struct etimer et;
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("Border Router started\n"); PUTSTRING("Border Router started\n");
prefix_set = 0; prefix_set = 0;
leds_on(LEDS_RED); leds_on(LEDS_RED);
@ -111,7 +127,7 @@ PROCESS_THREAD(border_router_process, ev, data)
/* Request prefix until it has been received */ /* Request prefix until it has been received */
while(!prefix_set) { while(!prefix_set) {
leds_on(LEDS_GREEN); leds_on(LEDS_GREEN);
PRINTF("Prefix request.\n"); PUTSTRING("Prefix request.\n");
etimer_set(&et, CLOCK_SECOND); etimer_set(&et, CLOCK_SECOND);
request_prefix(); request_prefix();
leds_off(LEDS_GREEN); leds_off(LEDS_GREEN);
@ -119,7 +135,9 @@ PROCESS_THREAD(border_router_process, ev, data)
} }
/* We have created a new DODAG when we reach here */ /* We have created a new DODAG when we reach here */
PRINTF("On Channel %u\n", cc2430_rf_channel_get()); PUTSTRING("On Channel ");
PUTDEC(cc2430_rf_channel_get());
PUTCHAR('\n');
print_local_addresses(); print_local_addresses();