From 7a2c8d2ab884502250a9a010f5b7c0123df108bb Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 30 Nov 2022 16:03:58 +0100 Subject: [PATCH] net: zperf: Shell cleanup Zperf shell functionality is now encapsuled within a single file, therefore it no longer makes sense to have a separate shell_utils file. Signed-off-by: Robert Lubos --- subsys/net/lib/zperf/CMakeLists.txt | 1 - subsys/net/lib/zperf/shell_utils.c | 66 ---------------------------- subsys/net/lib/zperf/shell_utils.h | 25 ----------- subsys/net/lib/zperf/zperf_session.h | 1 - subsys/net/lib/zperf/zperf_shell.c | 54 ++++++++++++++++++++++- 5 files changed, 53 insertions(+), 94 deletions(-) delete mode 100644 subsys/net/lib/zperf/shell_utils.c delete mode 100644 subsys/net/lib/zperf/shell_utils.h diff --git a/subsys/net/lib/zperf/CMakeLists.txt b/subsys/net/lib/zperf/CMakeLists.txt index 3db391f2a71..2ad3076f68b 100644 --- a/subsys/net/lib/zperf/CMakeLists.txt +++ b/subsys/net/lib/zperf/CMakeLists.txt @@ -3,7 +3,6 @@ zephyr_library_named(zperf) zephyr_library_sources( - shell_utils.c zperf_common.c zperf_session.c zperf_shell.c diff --git a/subsys/net/lib/zperf/shell_utils.c b/subsys/net/lib/zperf/shell_utils.c deleted file mode 100644 index 726cf210590..00000000000 --- a/subsys/net/lib/zperf/shell_utils.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include - -#include "shell_utils.h" - -const uint32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 }; -const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" }; -const uint32_t KBPS[] = { 1024, 0 }; -const char *KBPS_UNIT[] = { "Mbps", "Kbps" }; -const uint32_t K[] = { 1024 * 1024, 1024, 0 }; -const char *K_UNIT[] = { "M", "K", "" }; - -void print_number(const struct shell *sh, uint32_t value, - const uint32_t *divisor, const char **units) -{ - const char **unit; - const uint32_t *div; - uint32_t dec, radix; - - unit = units; - div = divisor; - - while (value < *div) { - div++; - unit++; - } - - if (*div != 0U) { - radix = value / *div; - dec = (value % *div) * 100U / *div; - shell_fprintf(sh, SHELL_NORMAL, "%u.%s%u %s", radix, - (dec < 10) ? "0" : "", dec, *unit); - } else { - shell_fprintf(sh, SHELL_NORMAL, "%u %s", value, *unit); - } -} - -long parse_number(const char *string, const uint32_t *divisor, - const char **units) -{ - const char **unit; - const uint32_t *div; - char *suffix; - long dec; - int cmp; - - dec = strtoul(string, &suffix, 10); - unit = units; - div = divisor; - - do { - cmp = strncasecmp(suffix, *unit++, 1); - } while (cmp != 0 && *++div != 0U); - - return (*div == 0U) ? dec : dec * *div; -} diff --git a/subsys/net/lib/zperf/shell_utils.h b/subsys/net/lib/zperf/shell_utils.h deleted file mode 100644 index b8bdb455e88..00000000000 --- a/subsys/net/lib/zperf/shell_utils.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef __SHELL_UTILS_H -#define __SHELL_UTILS_H - -#include - -#define IPV4_STR_LEN_MAX 15 -#define IPV4_STR_LEN_MIN 7 - -extern const uint32_t TIME_US[]; -extern const char *TIME_US_UNIT[]; -extern const uint32_t KBPS[]; -extern const char *KBPS_UNIT[]; -extern const uint32_t K[]; -extern const char *K_UNIT[]; - -extern void print_number(const struct shell *sh, uint32_t value, - const uint32_t *divisor, const char **units); -extern long parse_number(const char *string, const uint32_t *divisor, - const char **units); -#endif /* __SHELL_UTILS_H */ diff --git a/subsys/net/lib/zperf/zperf_session.h b/subsys/net/lib/zperf/zperf_session.h index be0560e195c..7e298c26eb5 100644 --- a/subsys/net/lib/zperf/zperf_session.h +++ b/subsys/net/lib/zperf/zperf_session.h @@ -16,7 +16,6 @@ #include #include "zperf_internal.h" -#include "shell_utils.h" /* Type definition */ enum state { diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index 38376724085..27ffb249b60 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #include #include #include +#include #include #include @@ -20,7 +21,6 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #include #include "zperf_internal.h" -#include "shell_utils.h" #include "zperf_session.h" /* Get some useful debug routings from net_private.h, requires @@ -84,6 +84,58 @@ static struct sockaddr_in in4_addr_dst = { .sin_port = htons(DEF_PORT), }; +const uint32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 }; +const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" }; +const uint32_t KBPS[] = { 1024, 0 }; +const char *KBPS_UNIT[] = { "Mbps", "Kbps" }; +const uint32_t K[] = { 1024 * 1024, 1024, 0 }; +const char *K_UNIT[] = { "M", "K", "" }; + +static void print_number(const struct shell *sh, uint32_t value, + const uint32_t *divisor_arr, const char **units) +{ + const char **unit; + const uint32_t *divisor; + uint32_t dec, radix; + + unit = units; + divisor = divisor_arr; + + while (value < *divisor) { + divisor++; + unit++; + } + + if (*divisor != 0U) { + radix = value / *divisor; + dec = (value % *divisor) * 100U / *divisor; + shell_fprintf(sh, SHELL_NORMAL, "%u.%s%u %s", radix, + (dec < 10) ? "0" : "", dec, *unit); + } else { + shell_fprintf(sh, SHELL_NORMAL, "%u %s", value, *unit); + } +} + +static long parse_number(const char *string, const uint32_t *divisor_arr, + const char **units) +{ + const char **unit; + const uint32_t *divisor; + char *suffix; + long dec; + int cmp; + + dec = strtoul(string, &suffix, 10); + unit = units; + divisor = divisor_arr; + + do { + cmp = strncasecmp(suffix, *unit++, 1); + } while (cmp != 0 && *++divisor != 0U); + + return (*divisor == 0U) ? dec : dec * *divisor; +} + struct sockaddr_in *zperf_get_sin(void) { return &in4_addr_my;