From a0e0018c9a7ef5ce7f6d2c3ae16aecbbd16a8f67 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 16:18:53 +0200 Subject: Adding upstream version 6.1.0. Signed-off-by: Daniel Baumann --- tc/m_estimator.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tc/m_estimator.c (limited to 'tc/m_estimator.c') diff --git a/tc/m_estimator.c b/tc/m_estimator.c new file mode 100644 index 0000000..b5f4c86 --- /dev/null +++ b/tc/m_estimator.c @@ -0,0 +1,64 @@ +/* + * m_estimator.c Parse/print estimator module options. + * + * This program is free software; you can u32istribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Authors: Alexey Kuznetsov, + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" +#include "tc_common.h" + +static void est_help(void); + +static void est_help(void) +{ + fprintf(stderr, + "Usage: ... estimator INTERVAL TIME-CONST\n" + " INTERVAL is interval between measurements\n" + " TIME-CONST is averaging time constant\n" + "Example: ... est 1sec 8sec\n"); +} + +int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est) +{ + int argc = *p_argc; + char **argv = *p_argv; + unsigned int A, time_const; + + NEXT_ARG(); + if (est->ewma_log) + duparg("estimator", *argv); + if (matches(*argv, "help") == 0) + est_help(); + if (get_time(&A, *argv)) + invarg("estimator", "invalid estimator interval"); + NEXT_ARG(); + if (matches(*argv, "help") == 0) + est_help(); + if (get_time(&time_const, *argv)) + invarg("estimator", "invalid estimator time constant"); + if (tc_setup_estimator(A, time_const, est) < 0) { + fprintf(stderr, "Error: estimator parameters are out of range.\n"); + return -1; + } + if (show_raw) + fprintf(stderr, "[estimator i=%hhd e=%u]\n", est->interval, est->ewma_log); + *p_argc = argc; + *p_argv = argv; + return 0; +} -- cgit v1.2.3