mirror of
https://github.com/espressif/openthread.git
synced 2026-07-08 13:20:25 +00:00
[cli] support energy scan command (#3036)
This commit is contained in:
+52
-5
@@ -2570,17 +2570,45 @@ void Interpreter::ProcessScan(int argc, char *argv[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t scanChannels = 0;
|
||||
uint16_t scanDuration = 0;
|
||||
bool energyScan = false;
|
||||
long value;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
SuccessOrExit(error = ParseLong(argv[0], value));
|
||||
scanChannels = 1 << value;
|
||||
if (strcmp(argv[0], "energy") == 0)
|
||||
{
|
||||
energyScan = true;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
SuccessOrExit(error = ParseLong(argv[1], value));
|
||||
scanDuration = static_cast<uint16_t>(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseLong(argv[0], value));
|
||||
scanChannels = 1 << value;
|
||||
}
|
||||
}
|
||||
|
||||
mServer->OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n");
|
||||
mServer->OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n");
|
||||
SuccessOrExit(error = otLinkActiveScan(mInstance, scanChannels, 0, &Interpreter::s_HandleActiveScanResult, this));
|
||||
if (energyScan)
|
||||
{
|
||||
mServer->OutputFormat("| Ch | RSSI |\r\n");
|
||||
mServer->OutputFormat("+----+------+\r\n");
|
||||
SuccessOrExit(error = otLinkEnergyScan(mInstance, scanChannels, scanDuration,
|
||||
&Interpreter::s_HandleEnergyScanResult, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
mServer->OutputFormat(
|
||||
"| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n");
|
||||
mServer->OutputFormat(
|
||||
"+---+------------------+------------------+------+------------------+----+-----+-----+\r\n");
|
||||
SuccessOrExit(error = otLinkActiveScan(mInstance, scanChannels, scanDuration,
|
||||
&Interpreter::s_HandleActiveScanResult, this));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -2619,6 +2647,25 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void OTCALL Interpreter::s_HandleEnergyScanResult(otEnergyScanResult *aResult, void *aContext)
|
||||
{
|
||||
static_cast<Interpreter *>(aContext)->HandleEnergyScanResult(aResult);
|
||||
}
|
||||
|
||||
void Interpreter::HandleEnergyScanResult(otEnergyScanResult *aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
{
|
||||
mServer->OutputFormat("Done\r\n");
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
mServer->OutputFormat("| %2d | %4d |\r\n", aResult->mChannel, aResult->mMaxRssi);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Interpreter::ProcessSingleton(int argc, char *argv[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
Reference in New Issue
Block a user