From 3609dce47dea7cdeb7c2c80d62776c6596d5f11c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= <cnkgndgn@gmail.com>
Date: Fri, 4 Sep 2015 13:20:49 +0200
Subject: [PATCH] sc_gnrc_rpl: adjust rpl shell for xtimer usage

---
 sys/net/gnrc/routing/rpl/gnrc_rpl.c |  4 ++--
 sys/shell/commands/sc_gnrc_rpl.c    | 20 +++++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/sys/net/gnrc/routing/rpl/gnrc_rpl.c
index 5e975d0424..cc38b578ce 100644
--- a/sys/net/gnrc/routing/rpl/gnrc_rpl.c
+++ b/sys/net/gnrc/routing/rpl/gnrc_rpl.c
@@ -229,8 +229,8 @@ void _update_lifetime(void)
                 gnrc_rpl_parent_update(dodag, NULL);
                 continue;
             }
-            else if ((int64_t)(parent->lifetime - now) <= (int64_t) (GNRC_RPL_LIFETIME_UPDATE_STEP
-                     * SEC_IN_USEC * 2)) {
+            else if ((int64_t)(parent->lifetime - now) <=
+                     (int64_t) (GNRC_RPL_LIFETIME_UPDATE_STEP * SEC_IN_USEC * 2)) {
                 gnrc_rpl_send_DIS(parent->dodag, &parent->addr);
             }
         }
diff --git a/sys/shell/commands/sc_gnrc_rpl.c b/sys/shell/commands/sc_gnrc_rpl.c
index abbda1106b..8d9d29ca47 100644
--- a/sys/shell/commands/sc_gnrc_rpl.c
+++ b/sys/shell/commands/sc_gnrc_rpl.c
@@ -273,9 +273,9 @@ int _gnrc_rpl_dodag_show(void)
 
     gnrc_rpl_dodag_t *dodag = NULL;
     char addr_str[IPV6_ADDR_MAX_STR_LEN];
-    timex_t now, cleanup;
+    uint32_t cleanup;
     uint64_t tc, ti, xnow = xtimer_now64();
-    vtimer_now(&now);
+
     for (uint8_t i = 0; i < GNRC_RPL_INSTANCES_NUMOF; ++i) {
         if (gnrc_rpl_instances[i].state == 0) {
             continue;
@@ -293,19 +293,21 @@ int _gnrc_rpl_dodag_show(void)
                     | dodag->trickle.msg_interval_timer.target) - xnow;
             ti = (int64_t) ti < 0 ? 0 : ti / SEC_IN_USEC;
 
-            cleanup = timex_sub(dodag->cleanup_timer.absolute, now);
-            timex_normalize(&cleanup);
-            printf("\tdodag [%s | R: %d | CL: %" PRIu32 "s | \
-TR(I=[%d,%d], k=%d, c=%d, TC=%" PRIu64 "s, TI=%" PRIu64 "s)]\n",
+            cleanup = dodag->cleanup_timer.target - xtimer_now();
+            cleanup = (int32_t) cleanup < 0 ? 0 : cleanup / SEC_IN_USEC;
+
+            printf("\tdodag [%s | R: %d | CL: %" PRIu32 "s | "
+                   "TR(I=[%d,%d], k=%d, c=%d, TC=%" PRIu64 "s, TI=%" PRIu64 "s)]\n",
                     ipv6_addr_to_str(addr_str, &dodag->dodag_id, sizeof(addr_str)),
-                    dodag->my_rank, ((int32_t) cleanup.seconds) > 0 ? cleanup.seconds : 0,
+                    dodag->my_rank, (((int32_t) cleanup < 0) ? 0 : cleanup/SEC_IN_USEC),
                     (1 << dodag->dio_min), dodag->dio_interval_doubl,
                     dodag->trickle.k, dodag->trickle.c, tc, ti);
             gnrc_rpl_parent_t *parent;
             LL_FOREACH(dodag->parents, parent) {
-                printf("\t\tparent [addr: %s | rank: %d | lifetime: %" PRIu32 "s]\n",
+                printf("\t\tparent [addr: %s | rank: %d | lifetime: %" PRIu64 "s]\n",
                         ipv6_addr_to_str(addr_str, &parent->addr, sizeof(addr_str)),
-                        parent->rank, (parent->lifetime.seconds - now.seconds));
+                        parent->rank, ((int64_t) (parent->lifetime - xnow) < 0 ? 0
+                                       : (parent->lifetime - xnow) / SEC_IN_USEC));
             }
         }
     }
-- 
GitLab