From f974f3815583d4275b48142a110d4e067481b6a8 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Mon, 21 Sep 2020 12:46:19 -0300 Subject: [PATCH] [cli] implement setting/getting cca threshold (#5532) This commit adds a command to the CLI to be able to set (and get) the CCA threshold. This is useful when there is a LNA in the radio's RX path. --- src/cli/README.md | 20 ++++++++++++++++++++ src/cli/cli.cpp | 23 +++++++++++++++++++++++ src/cli/cli.hpp | 9 ++++++--- tests/scripts/expect/cli-misc.exp | 6 ++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/cli/README.md b/src/cli/README.md index 74c93f417..83e8fd833 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -23,6 +23,7 @@ Done - [bbr](#bbr) - [bufferinfo](#bufferinfo) +- [ccathreshold](#ccathreshold) - [channel](#channel) - [child](#child-list) - [childip](#childip) @@ -321,6 +322,25 @@ coap: 0 0 Done ``` +### ccathreshold + +Get the CCA threshold in dBm. + +```bash +> ccathreshold +-75 dBm +Done +``` + +### ccathreshold \ + +Set the CCA threshold. + +```bash +> ccathreshold -62 +Done +``` + ### channel Get the IEEE 802.15.4 Channel value. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 79392d2e3..4184dd336 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -678,6 +678,29 @@ otError Interpreter::ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]) return OT_ERROR_NONE; } +otError Interpreter::ProcessCcaThreshold(uint8_t aArgsLength, char *aArgs[]) +{ + otError error = OT_ERROR_NONE; + + if (aArgsLength == 0) + { + int8_t cca; + + SuccessOrExit(error = otPlatRadioGetCcaEnergyDetectThreshold(mInstance, &cca)); + OutputLine("%d dBm", cca); + } + else + { + long value; + + SuccessOrExit(error = ParseLong(aArgs[0], value)); + SuccessOrExit(error = otPlatRadioSetCcaEnergyDetectThreshold(mInstance, static_cast(value))); + } + +exit: + return error; +} + otError Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) { otError error = OT_ERROR_NONE; diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index f726fcbd6..bdd98fff0 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -278,9 +278,11 @@ private: const Command *FindCommand(const char *aName) const; otError ParsePingInterval(const char *aString, uint32_t &aInterval); static otError ParseJoinerDiscerner(char *aString, otJoinerDiscerner &aJoinerDiscerner); - otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]); - otError ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]); - otError ProcessChannel(uint8_t aArgsLength, char *aArgs[]); + + otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]); + otError ProcessCcaThreshold(uint8_t aArgsLength, char *aArgs[]); + otError ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]); + otError ProcessChannel(uint8_t aArgsLength, char *aArgs[]); #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) otError ProcessBackboneRouter(uint8_t aArgsLength, char *aArgs[]); @@ -549,6 +551,7 @@ private: {"bbr", &Interpreter::ProcessBackboneRouter}, #endif {"bufferinfo", &Interpreter::ProcessBufferInfo}, + {"ccathreshold", &Interpreter::ProcessCcaThreshold}, {"channel", &Interpreter::ProcessChannel}, #if OPENTHREAD_FTD {"child", &Interpreter::ProcessChild}, diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 6b49fa8e6..f85c58f14 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -47,6 +47,12 @@ expect "Done" send "bufferinfo\n" expect "Done" +send "ccathreshold -62\n" +expect "Done" +send "ccathreshold\n" +expect -- "-62 dBm" +expect "Done" + send "parent\n" expect "Done"