RPL native border router: use logging module

This commit is contained in:
Simon Duquennoy 2018-04-22 00:33:31 -07:00
parent aa8d4d0320
commit 3bd6c67e64
4 changed files with 37 additions and 31 deletions

View File

@ -46,8 +46,11 @@
#include "shell.h" #include "shell.h"
#include <stdio.h> #include <stdio.h>
#define DEBUG DEBUG_NONE /*---------------------------------------------------------------------------*/
#include "net/ipv6/uip-debug.h" /* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "BR"
#define LOG_LEVEL LOG_LEVEL_NONE
uint8_t command_context; uint8_t command_context;
@ -115,7 +118,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
{ {
/* handle global repair, etc here */ /* handle global repair, etc here */
if(data[0] == '!') { if(data[0] == '!') {
PRINTF("Got configuration message of type %c\n", data[1]); LOG_DBG("Got configuration message of type %c\n", data[1]);
if(command_context == CMD_CONTEXT_STDIO) { if(command_context == CMD_CONTEXT_STDIO) {
switch(data[1]) { switch(data[1]) {
case 'G': case 'G':
@ -151,7 +154,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
/* We need to know that this is from the slip-radio here. */ /* We need to know that this is from the slip-radio here. */
switch(data[1]) { switch(data[1]) {
case 'M': case 'M':
PRINTF("Setting MAC address\n"); LOG_DBG("Setting MAC address\n");
border_router_set_mac(&data[2]); border_router_set_mac(&data[2]);
return 1; return 1;
case 'V': case 'V':
@ -163,7 +166,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
} }
return 1; return 1;
case 'R': case 'R':
PRINTF("Packet data report for sid:%d st:%d tx:%d\n", LOG_DBG("Packet data report for sid:%d st:%d tx:%d\n",
data[2], data[3], data[4]); data[2], data[3], data[4]);
packet_sent(data[2], data[3], data[4]); packet_sent(data[2], data[3], data[4]);
return 1; return 1;
@ -172,7 +175,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
} }
} }
} else if(data[0] == '?') { } else if(data[0] == '?') {
PRINTF("Got request message of type %c\n", data[1]); LOG_DBG("Got request message of type %c\n", data[1]);
if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) { if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) {
uint8_t buf[20]; uint8_t buf[20];
char *hexchar = "0123456789abcdef"; char *hexchar = "0123456789abcdef";
@ -226,15 +229,14 @@ PROCESS_THREAD(border_router_cmd_process, ev, data)
{ {
static struct pt shell_input_pt; static struct pt shell_input_pt;
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("Started br-cmd process\n");
shell_init(); shell_init();
while(1) { while(1) {
PROCESS_YIELD(); PROCESS_YIELD();
if(ev == serial_line_event_message && data != NULL) { if(ev == serial_line_event_message && data != NULL) {
PRINTF("Got serial data!!! %s of len: %lu\n", LOG_DBG("Got serial data!!! %s of len: %u\n",
(char *)data, strlen((char *)data)); (char *)data, (unsigned)strlen((char *)data));
command_context = CMD_CONTEXT_STDIO; command_context = CMD_CONTEXT_STDIO;
if(cmd_input(data, strlen((char *)data))) { if(cmd_input(data, strlen((char *)data))) {
/* Commnand executed - all is fine */ /* Commnand executed - all is fine */

View File

@ -44,13 +44,11 @@
#include "border-router.h" #include "border-router.h"
#include <string.h> #include <string.h>
#define DEBUG 0 /*---------------------------------------------------------------------------*/
#if DEBUG /* Log configuration */
#include <stdio.h> #include "sys/log.h"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_MODULE "BR"
#else #define LOG_LEVEL LOG_LEVEL_NONE
#define PRINTF(...)
#endif
#define MAX_CALLBACKS 16 #define MAX_CALLBACKS 16
static int callback_pos; static int callback_pos;
@ -76,7 +74,7 @@ packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
packetbuf_attr_copyfrom(callback->attrs, callback->addrs); packetbuf_attr_copyfrom(callback->attrs, callback->addrs);
mac_call_sent_callback(callback->cback, callback->ptr, status, tx); mac_call_sent_callback(callback->cback, callback->ptr, status, tx);
} else { } else {
PRINTF("*** ERROR: too high session id %d\n", sessionid); LOG_ERR("Session id to high (%d)\n", sessionid);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -117,7 +115,7 @@ send_packet(mac_callback_t sent, void *ptr)
if(NETSTACK_FRAMER.create() < 0) { if(NETSTACK_FRAMER.create() < 0) {
/* Failed to allocate space for headers */ /* Failed to allocate space for headers */
PRINTF("br-rdc: send failed, too large header\n"); LOG_WARN("br-rdc: send failed, too large header\n");
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1); mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
} else { } else {
/* here we send the data over SLIP to the radio-chip */ /* here we send the data over SLIP to the radio-chip */
@ -126,7 +124,7 @@ send_packet(mac_callback_t sent, void *ptr)
size = packetutils_serialize_atts(&buf[3], sizeof(buf) - 3); size = packetutils_serialize_atts(&buf[3], sizeof(buf) - 3);
#endif #endif
if(size < 0 || size + packetbuf_totlen() + 3 > sizeof(buf)) { if(size < 0 || size + packetbuf_totlen() + 3 > sizeof(buf)) {
PRINTF("br-rdc: send failed, too large header\n"); LOG_WARN("br-rdc: send failed, too large header\n");
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1); mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
} else { } else {
sid = setup_callback(sent, ptr); sid = setup_callback(sent, ptr);
@ -147,7 +145,7 @@ static void
packet_input(void) packet_input(void)
{ {
if(NETSTACK_FRAMER.parse() < 0) { if(NETSTACK_FRAMER.parse() < 0) {
PRINTF("br-rdc: failed to parse %u\n", packetbuf_datalen()); LOG_DBG("br-rdc: failed to parse %u\n", packetbuf_datalen());
} else { } else {
NETSTACK_NETWORK.input(); NETSTACK_NETWORK.input();
} }

View File

@ -47,8 +47,11 @@
#include "border-router.h" #include "border-router.h"
#include "border-router-cmds.h" #include "border-router-cmds.h"
#define DEBUG DEBUG_FULL /*---------------------------------------------------------------------------*/
#include "net/ipv6/uip-debug.h" /* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "BR"
#define LOG_LEVEL LOG_LEVEL_INFO
#include <stdlib.h> #include <stdlib.h>
@ -106,7 +109,7 @@ PROCESS_THREAD(border_router_process, ev, data)
process_start(&border_router_cmd_process, NULL); process_start(&border_router_cmd_process, NULL);
PRINTF("RPL-Border router started\n"); LOG_INFO("RPL-Border router started\n");
slip_config_handle_arguments(contiki_argc, contiki_argv); slip_config_handle_arguments(contiki_argc, contiki_argv);
@ -123,12 +126,12 @@ PROCESS_THREAD(border_router_process, ev, data)
uip_ipaddr_t prefix; uip_ipaddr_t prefix;
if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) { if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) {
PRINTF("Setting prefix "); LOG_INFO("Setting prefix ");
PRINT6ADDR(&prefix); LOG_INFO_6ADDR(&prefix);
PRINTF("\n"); LOG_INFO_("\n");
set_prefix_64(&prefix); set_prefix_64(&prefix);
} else { } else {
PRINTF("Parse error: %s\n", slip_config_ipaddr); LOG_ERR("Parse error: %s\n", slip_config_ipaddr);
exit(0); exit(0);
} }
} }

View File

@ -50,8 +50,11 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#define DEBUG DEBUG_FULL /*---------------------------------------------------------------------------*/
#include "net/ipv6/uip-debug.h" /* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "BR"
#define LOG_LEVEL LOG_LEVEL_NONE
#ifdef linux #ifdef linux
#include <linux/if.h> #include <linux/if.h>
@ -202,7 +205,7 @@ tun_init()
slip_init(); slip_init();
PRINTF("Opening tun interface:%s\n", slip_config_tundev); LOG_INFO("Opening tun interface:%s\n", slip_config_tundev);
tunfd = tun_alloc(slip_config_tundev); tunfd = tun_alloc(slip_config_tundev);
@ -251,7 +254,7 @@ init(void)
static int static int
output(void) output(void)
{ {
PRINTF("SUT: %u\n", uip_len); LOG_DBG("SUT: %u\n", uip_len);
if(uip_len > 0) { if(uip_len > 0) {
return tun_output(&uip_buf[UIP_LLH_LEN], uip_len); return tun_output(&uip_buf[UIP_LLH_LEN], uip_len);
} }