[cli] fix router table command (#2747)

This commit is contained in:
Jonathan Hui
2018-05-29 16:30:43 -07:00
committed by GitHub
parent 45d360fcd3
commit 64fed1ed4d
6 changed files with 78 additions and 25 deletions
+26 -23
View File
@@ -2333,6 +2333,8 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
if (isTable || strcmp(argv[0], "list") == 0)
{
uint8_t maxRouterId;
if (isTable)
{
mServer->OutputFormat(
@@ -2341,40 +2343,41 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
"+----+--------+----------+-----------+-------+--------+-----+------------------+\r\n");
}
for (uint8_t i = 0;; i++)
maxRouterId = otThreadGetMaxRouterId(mInstance);
for (uint8_t i = 0; i <= maxRouterId; i++)
{
if (otThreadGetRouterInfo(mInstance, i, &routerInfo) != OT_ERROR_NONE)
{
mServer->OutputFormat("\r\n");
ExitNow();
continue;
}
if (routerInfo.mAllocated)
if (isTable)
{
if (isTable)
{
mServer->OutputFormat("| %2d ", routerInfo.mRouterId);
mServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16);
mServer->OutputFormat("| %8d ", routerInfo.mNextHop);
mServer->OutputFormat("| %9d ", routerInfo.mPathCost);
mServer->OutputFormat("| %5d ", routerInfo.mLinkQualityIn);
mServer->OutputFormat("| %6d ", routerInfo.mLinkQualityOut);
mServer->OutputFormat("| %3d ", routerInfo.mAge);
mServer->OutputFormat("| ");
mServer->OutputFormat("| %2d ", routerInfo.mRouterId);
mServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16);
mServer->OutputFormat("| %8d ", routerInfo.mNextHop);
mServer->OutputFormat("| %9d ", routerInfo.mPathCost);
mServer->OutputFormat("| %5d ", routerInfo.mLinkQualityIn);
mServer->OutputFormat("| %6d ", routerInfo.mLinkQualityOut);
mServer->OutputFormat("| %3d ", routerInfo.mAge);
mServer->OutputFormat("| ");
for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++)
{
mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]);
}
mServer->OutputFormat(" |\r\n");
}
else
for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++)
{
mServer->OutputFormat("%d ", i);
mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]);
}
mServer->OutputFormat(" |\r\n");
}
else
{
mServer->OutputFormat("%d ", i);
}
}
mServer->OutputFormat("\r\n");
ExitNow();
}
SuccessOrExit(error = ParseLong(argv[0], value));