From d09c54fe8e58c47b2451b87e41e07ad47f52a99f Mon Sep 17 00:00:00 2001
From: George Oikonomou <george@contiki-ng.org>
Date: Sun, 29 Oct 2017 03:08:30 +0000
Subject: [PATCH] Use logging

---
 examples/rpl-border-router/border-router.c | 22 ++++++++-----
 examples/rpl-border-router/slip-bridge.c   | 38 ++++++++++++----------
 2 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/examples/rpl-border-router/border-router.c b/examples/rpl-border-router/border-router.c
index 9aeb2d7c45..ada1a78880 100644
--- a/examples/rpl-border-router/border-router.c
+++ b/examples/rpl-border-router/border-router.c
@@ -51,15 +51,18 @@
 #include "net/netstack.h"
 #include "dev/button-sensor.h"
 #include "dev/slip.h"
+#include "net/ipv6/uip-debug.h"
 /*---------------------------------------------------------------------------*/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.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
+/*---------------------------------------------------------------------------*/
 static uip_ipaddr_t prefix;
 static uint8_t prefix_set;
 /*---------------------------------------------------------------------------*/
@@ -352,14 +355,14 @@ print_local_addresses(void)
   int i;
   uint8_t state;
 
-  PRINTA("Server IPv6 addresses:\n");
+  printf("Server IPv6 addresses:\n");
   for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
     state = uip_ds6_if.addr_list[i].state;
     if(uip_ds6_if.addr_list[i].isused &&
        (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
-      PRINTA(" ");
+      printf(" ");
       uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
-      PRINTA("\n");
+      printf("\n");
     }
   }
 }
@@ -402,13 +405,14 @@ PROCESS_THREAD(border_router_process, ev, data)
 
   SENSORS_ACTIVATE(button_sensor);
 
-  PRINTF("RPL-Border router started\n");
+  printf("RPL-Border router started\n");
 
   /* Request prefix until it has been received */
   while(!prefix_set) {
     etimer_set(&et, CLOCK_SECOND);
     request_prefix();
     PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
+    LOG_INFO("Waiting for prefix\n");
   }
 
   NETSTACK_MAC.on();
@@ -420,7 +424,7 @@ PROCESS_THREAD(border_router_process, ev, data)
   while(1) {
     PROCESS_YIELD();
     if (ev == sensors_event && data == &button_sensor) {
-      PRINTF("Initiating global repair\n");
+      LOG_INFO("Initiating global repair\n");
 #if UIP_CONF_IPV6_RPL_LITE
       rpl_global_repair();
 #else
diff --git a/examples/rpl-border-router/slip-bridge.c b/examples/rpl-border-router/slip-bridge.c
index c5126adc1b..a975b22d8d 100644
--- a/examples/rpl-border-router/slip-bridge.c
+++ b/examples/rpl-border-router/slip-bridge.c
@@ -37,17 +37,19 @@
  *         Joel Hoglund <joel@sics.se>
  *         Nicolas Tsiftes <nvt@sics.se>
  */
-
+/*---------------------------------------------------------------------------*/
 #include "net/ipv6/uip.h"
 #include "net/ipv6/uip-ds6.h"
 #include "dev/slip.h"
 #include <string.h>
-
+/*---------------------------------------------------------------------------*/
 #define UIP_IP_BUF        ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
-
-#define DEBUG DEBUG_PRINT
-#include "net/ipv6/uip-debug.h"
-
+/*---------------------------------------------------------------------------*/
+/* Log configuration */
+#include "sys/log.h"
+#define LOG_MODULE "SLIP"
+#define LOG_LEVEL LOG_LEVEL_NONE
+/*---------------------------------------------------------------------------*/
 void set_prefix_64(uip_ipaddr_t *);
 
 static uip_ipaddr_t last_sender;
@@ -55,22 +57,22 @@ static uip_ipaddr_t last_sender;
 static void
 slip_input_callback(void)
 {
-  PRINTF("SIN: %u\n", uip_len);
+  LOG_DBG("SIN: %u\n", uip_len);
   if(uip_buf[0] == '!') {
-    PRINTF("Got configuration message of type %c\n", uip_buf[1]);
+    LOG_INFO("Got configuration message of type %c\n", uip_buf[1]);
     uip_clear_buf();
     if(uip_buf[1] == 'P') {
       uip_ipaddr_t prefix;
       /* Here we set a prefix !!! */
       memset(&prefix, 0, 16);
       memcpy(&prefix, &uip_buf[2], 8);
-      PRINTF("Setting prefix ");
-      PRINT6ADDR(&prefix);
-      PRINTF("\n");
+      LOG_INFO("Setting prefix ");
+      LOG_INFO_6ADDR(&prefix);
+      LOG_INFO_("\n");
       set_prefix_64(&prefix);
     }
   } else if(uip_buf[0] == '?') {
-    PRINTF("Got request message of type %c\n", uip_buf[1]);
+    LOG_INFO("Got request message of type %c\n", uip_buf[1]);
     if(uip_buf[1] == 'M') {
       char *hexchar = "0123456789abcdef";
       int j;
@@ -104,13 +106,13 @@ output(void)
   if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
     /* Do not bounce packets back over SLIP if the packet was received
        over SLIP */
-    PRINTF("slip-bridge: Destination off-link but no route src=");
-    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
-    PRINTF(" dst=");
-    PRINT6ADDR(&UIP_IP_BUF->destipaddr);
-    PRINTF("\n");
+    LOG_ERR("slip-bridge: Destination off-link but no route src=");
+    LOG_ERR_6ADDR(&UIP_IP_BUF->srcipaddr);
+    LOG_ERR_(" dst=");
+    LOG_ERR_6ADDR(&UIP_IP_BUF->destipaddr);
+    LOG_ERR_("\n");
   } else {
-    PRINTF("SUT: %u\n", uip_len);
+    LOG_DBG("SUT: %u\n", uip_len);
     slip_send();
   }
   return 0;
-- 
GitLab