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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2022-11-30 16:03:58 +01:00 committed by Carles Cufí
commit 7a2c8d2ab8
5 changed files with 53 additions and 94 deletions

View file

@ -3,7 +3,6 @@
zephyr_library_named(zperf)
zephyr_library_sources(
shell_utils.c
zperf_common.c
zperf_session.c
zperf_shell.c

View file

@ -1,66 +0,0 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <zephyr/kernel.h>
#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;
}

View file

@ -1,25 +0,0 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __SHELL_UTILS_H
#define __SHELL_UTILS_H
#include <zephyr/shell/shell.h>
#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 */

View file

@ -16,7 +16,6 @@
#include <zephyr/net/net_core.h>
#include "zperf_internal.h"
#include "shell_utils.h"
/* Type definition */
enum state {

View file

@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
@ -20,7 +21,6 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
#include <zephyr/net/zperf.h>
#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;