From 4e7ff0df284afeacb2f543d2c64b70d9f7aaeb96 Mon Sep 17 00:00:00 2001 From: shuguo Date: Thu, 12 Apr 2018 13:26:30 +0800 Subject: [PATCH] gnrc_gomach: enabling duty-cycle printing --- sys/include/net/gnrc/mac/types.h | 7 ++++++ sys/net/gnrc/link_layer/gomach/gomach.c | 29 ++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sys/include/net/gnrc/mac/types.h b/sys/include/net/gnrc/mac/types.h index ed70a61706..c69b301436 100644 --- a/sys/include/net/gnrc/mac/types.h +++ b/sys/include/net/gnrc/mac/types.h @@ -40,6 +40,13 @@ extern "C" { #endif +/** + * @brief MAC message type for getting radio's duty-cycle. + */ +#ifndef GNRC_MAC_TYPE_GET_DUTYCYCLE +#define GNRC_MAC_TYPE_GET_DUTYCYCLE (0x4401) +#endif + /** * @brief definition for device transmission feedback types */ diff --git a/sys/net/gnrc/link_layer/gomach/gomach.c b/sys/net/gnrc/link_layer/gomach/gomach.c index e1ecf5b1dd..a3b6384b1f 100644 --- a/sys/net/gnrc/link_layer/gomach/gomach.c +++ b/sys/net/gnrc/link_layer/gomach/gomach.c @@ -949,15 +949,6 @@ static void gomach_t2k_end(gnrc_netif_t *netif) netif->mac.rx.listen_state = GNRC_GOMACH_LISTEN_SLEEP; gnrc_gomach_set_enter_new_cycle(netif, false); gnrc_gomach_set_update(netif, true); - -#if (GNRC_GOMACH_ENABLE_DUTYCYLE_RECORD == 1) - /* Output duty-cycle ratio */ - uint64_t duty; - duty = xtimer_now_usec64(); - duty = (netif->mac.prot.gomach.awake_duration_sum_ticks) * 100 / - (duty - netif->mac.prot.gomach.system_start_time_ticks); - printf("[GoMacH]: achieved radio duty-cycle: %lu %% \n", (uint32_t)duty); -#endif } static void gomach_t2k_update(gnrc_netif_t *netif) @@ -1406,15 +1397,6 @@ static void gomach_t2u_end(gnrc_netif_t *netif) netif->mac.rx.listen_state = GNRC_GOMACH_LISTEN_SLEEP; gnrc_gomach_set_enter_new_cycle(netif, false); gnrc_gomach_set_update(netif, true); - -#if (GNRC_GOMACH_ENABLE_DUTYCYLE_RECORD == 1) - /* Output duty-cycle ratio */ - uint64_t duty; - duty = xtimer_now_usec64(); - duty = (netif->mac.prot.gomach.awake_duration_sum_ticks) * 100 / - (duty - netif->mac.prot.gomach.system_start_time_ticks); - printf("[GoMacH]: achieved radio duty-cycle: %lu %% \n", (uint32_t)duty); -#endif } static void gomach_t2u_update(gnrc_netif_t *netif) @@ -2004,6 +1986,17 @@ static void _gomach_msg_handler(gnrc_netif_t *netif, msg_t *msg) gnrc_gomach_set_update(netif, true); break; } +#if (GNRC_MAC_ENABLE_DUTYCYCLE_RECORD == 1) + case GNRC_MAC_TYPE_GET_DUTYCYCLE: { + /* Output GoMacH's current radio duty-cycle. */ + uint64_t duty; + duty = xtimer_now_usec64(); + duty = (netif->mac.prot.gomach.awake_duration_sum_ticks) * 100 / + (duty - netif->mac.prot.gomach.system_start_time_ticks); + printf("[GoMacH]: achieved radio duty-cycle: %lu %% \n", (uint32_t)duty); + break; + } +#endif default: { DEBUG("[GoMacH]: Unknown command %" PRIu16 "\n", msg->type); break;