diff --git a/src/cli/README.md b/src/cli/README.md index 7da9da0bb..e52206466 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -1825,7 +1825,7 @@ Perform an IEEE 802.15.4 Active Scan. Done ``` -### scan energy \[duration\] +### scan energy \[duration\] \[channel\] Perform an IEEE 802.15.4 Energy Scan. @@ -1854,6 +1854,14 @@ Perform an IEEE 802.15.4 Energy Scan. Done ``` +```bash +> scan energy 10 20 +| Ch | RSSI | ++----+------+ +| 20 | -82 | +Done +``` + ### service Module for controlling service registration in Network Data. Each change in service registration must be sent to leader by `netdata register` command before taking effect. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 7083e0efa..c6896b579 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -3355,23 +3355,26 @@ otError Interpreter::ProcessScan(uint8_t aArgsLength, char *aArgs[]) uint32_t scanChannels = 0; uint16_t scanDuration = 0; bool energyScan = false; + uint8_t index = 0; if (aArgsLength > 0) { - if (strcmp(aArgs[0], "energy") == 0) + if (strcmp(aArgs[index], "energy") == 0) { energyScan = true; + index++; if (aArgsLength > 1) { - SuccessOrExit(error = ParseAsUint16(aArgs[1], scanDuration)); + SuccessOrExit(error = ParseAsUint16(aArgs[index++], scanDuration)); } } - else + + if (index < aArgsLength) { uint8_t channel; - SuccessOrExit(error = ParseAsUint8(aArgs[0], channel)); + SuccessOrExit(error = ParseAsUint8(aArgs[index++], channel)); VerifyOrExit(channel < sizeof(scanChannels) * CHAR_BIT, error = OT_ERROR_INVALID_ARGS); scanChannels = 1 << channel; } diff --git a/tests/scripts/expect/cli-scan-discover.exp b/tests/scripts/expect/cli-scan-discover.exp index b157ed19b..fd9061ee4 100755 --- a/tests/scripts/expect/cli-scan-discover.exp +++ b/tests/scripts/expect/cli-scan-discover.exp @@ -75,6 +75,11 @@ for {set i 11} {$i <= 26} {incr i} { expect -re "\\| +$i \\| +-?\\d+ \\|" } expect "Done" +send "scan energy 100 $channel\n" +expect "| Ch | RSSI |" +expect "+----+------+" +expect -re "\\| +$channel \\| +-?\\d+ \\|" +expect "Done" switch_node 3 send "ifconfig up\n"