mirror of
https://github.com/espressif/openthread.git
synced 2026-08-09 12:17:47 +00:00
[cli] add neighbor command (#2244)
This commit is contained in:
committed by
Jonathan Hui
parent
6dba17317c
commit
1bfa370f1f
@@ -41,6 +41,7 @@ OpenThread test scripts use the CLI to execute test cases.
|
||||
* [macfilter](#macfilter)
|
||||
* [masterkey](#masterkey)
|
||||
* [mode](#mode)
|
||||
* [neighbor](#neighbor-list)
|
||||
* [netdataregister](#netdataregister)
|
||||
* [networkdiagnostic](#networkdiagnostic-get-addr-type-)
|
||||
* [networkidtimeout](#networkidtimeout)
|
||||
@@ -1091,6 +1092,30 @@ Set the Thread Device Mode value.
|
||||
Done
|
||||
```
|
||||
|
||||
### neighbor list
|
||||
|
||||
List RLOC16 of neighbors.
|
||||
|
||||
```bash
|
||||
> neighbor list
|
||||
0xcc01 0xc800 0xf000
|
||||
Done
|
||||
```
|
||||
|
||||
### neighbor table
|
||||
|
||||
Print table of neighbors.
|
||||
|
||||
```bash
|
||||
> neighbor table
|
||||
| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |
|
||||
+------+--------+-----+----------+-----------+-+-+-+-+------------------+
|
||||
| C | 0xcc01 | 96 | -46 | -46 |1|1|1|1| 1eb9ba8a6522636b |
|
||||
| R | 0xc800 | 2 | -29 | -29 |1|0|1|1| 9a91556102c39ddb |
|
||||
| R | 0xf000 | 3 | -28 | -28 |1|0|1|1| 0ad7ed6beaa6016d |
|
||||
Done
|
||||
```
|
||||
|
||||
### netdataregister
|
||||
|
||||
Register local network data with Thread Leader.
|
||||
|
||||
@@ -162,6 +162,9 @@ const struct Command Interpreter::sCommands[] =
|
||||
#endif
|
||||
{ "masterkey", &Interpreter::ProcessMasterKey },
|
||||
{ "mode", &Interpreter::ProcessMode },
|
||||
#if OPENTHREAD_FTD
|
||||
{ "neighbor", &Interpreter::ProcessNeighbor },
|
||||
#endif
|
||||
#if OPENTHREAD_ENABLE_BORDER_ROUTER
|
||||
{ "netdataregister", &Interpreter::ProcessNetworkDataRegister },
|
||||
#endif
|
||||
@@ -1407,6 +1410,64 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
void Interpreter::ProcessNeighbor(int argc, char *argv[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otNeighborInfo neighborInfo;
|
||||
bool isTable = false;
|
||||
otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT;
|
||||
|
||||
VerifyOrExit(argc > 0, error = OT_ERROR_PARSE);
|
||||
|
||||
if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0)))
|
||||
{
|
||||
if (isTable)
|
||||
{
|
||||
mServer->OutputFormat("| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |\r\n");
|
||||
mServer->OutputFormat("+------+--------+-----+----------+-----------+-+-+-+-+------------------+\r\n");
|
||||
}
|
||||
|
||||
while (otThreadGetNextNeighborInfo(mInstance, &iterator, &neighborInfo) == OT_ERROR_NONE)
|
||||
{
|
||||
if (isTable)
|
||||
{
|
||||
mServer->OutputFormat("| %3c ", neighborInfo.mIsChild ? 'C' : 'R');
|
||||
mServer->OutputFormat("| 0x%04x ", neighborInfo.mRloc16);
|
||||
mServer->OutputFormat("| %3d ", neighborInfo.mAge);
|
||||
mServer->OutputFormat("| %8d ", neighborInfo.mAverageRssi);
|
||||
mServer->OutputFormat("| %9d ", neighborInfo.mLastRssi);
|
||||
mServer->OutputFormat("|%1d", neighborInfo.mRxOnWhenIdle);
|
||||
mServer->OutputFormat("|%1d", neighborInfo.mSecureDataRequest);
|
||||
mServer->OutputFormat("|%1d", neighborInfo.mFullFunction);
|
||||
mServer->OutputFormat("|%1d", neighborInfo.mFullNetworkData);
|
||||
mServer->OutputFormat("| ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(neighborInfo.mExtAddress); j++)
|
||||
{
|
||||
mServer->OutputFormat("%02x", neighborInfo.mExtAddress.m8[j]);
|
||||
}
|
||||
|
||||
mServer->OutputFormat(" |\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
mServer->OutputFormat("0x%04x ", neighborInfo.mRloc16);
|
||||
}
|
||||
}
|
||||
|
||||
mServer->OutputFormat("\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
error = OT_ERROR_PARSE;
|
||||
}
|
||||
|
||||
exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_BORDER_ROUTER
|
||||
void Interpreter::ProcessNetworkDataRegister(int argc, char *argv[])
|
||||
{
|
||||
|
||||
@@ -252,6 +252,9 @@ private:
|
||||
void ProcessLinkQuality(int argc, char *argv[]);
|
||||
void ProcessMasterKey(int argc, char *argv[]);
|
||||
void ProcessMode(int argc, char *argv[]);
|
||||
#if OPENTHREAD_FTD
|
||||
void ProcessNeighbor(int argc, char *argv[]);
|
||||
#endif
|
||||
#if OPENTHREAD_ENABLE_BORDER_ROUTER
|
||||
void ProcessNetworkDataRegister(int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user