From 61088c77820ca16f32b52dda2d22983add642cdf Mon Sep 17 00:00:00 2001 From: Piotr Koziar <44554861+piotrkoziar@users.noreply.github.com> Date: Wed, 20 Nov 2019 03:35:06 +0100 Subject: [PATCH] [cli] mac/mle counters reset (#4341) * Add counters reset cli command --- src/cli/README.md | 13 ++++++++++++- src/cli/cli.cpp | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cli/README.md b/src/cli/README.md index 2ba7a3f48..8e7756954 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -247,7 +247,7 @@ Done Get the supported counter names. ```bash ->counters +> counters mac mle Done @@ -304,6 +304,17 @@ Parent Changes: 0 Done ``` +### counters \ reset + +Reset the counter value. + +```bash +> counters mac reset +Done +> counters mle reset +Done +``` + ### networktime Get the Thread network time and the time sync parameters. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index ef3cf7231..d0af6b84c 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -892,9 +892,9 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) mServer->OutputFormat("mac\r\n"); mServer->OutputFormat("mle\r\n"); } - else if (argc == 1) + else if (strcmp(argv[0], "mac") == 0) { - if (strcmp(argv[0], "mac") == 0) + if (argc == 1) { const otMacCounters *macCounters = otLinkGetCounters(mInstance); @@ -930,7 +930,18 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) mServer->OutputFormat(" RxErrFcs: %d\r\n", macCounters->mRxErrFcs); mServer->OutputFormat(" RxErrOther: %d\r\n", macCounters->mRxErrOther); } - else if (strcmp(argv[0], "mle") == 0) + else if ((argc == 2) && (strcmp(argv[0], "reset") == 0)) + { + otLinkResetCounters(mInstance); + } + else + { + ExitNow(error = OT_ERROR_INVALID_ARGS); + } + } + else if (strcmp(argv[0], "mle") == 0) + { + if (argc == 1) { const otMleCounters *mleCounters = otThreadGetMleCounters(mInstance); @@ -945,6 +956,10 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) mleCounters->mBetterPartitionAttachAttempts); mServer->OutputFormat("Parent Changes: %d\r\n", mleCounters->mParentChanges); } + else if ((argc == 2) && (strcmp(argv[0], "reset") == 0)) + { + otThreadResetMleCounters(mInstance); + } else { ExitNow(error = OT_ERROR_INVALID_ARGS);