[cli] misc enhancements (#5528)

This commit contains a group of smaller enhancements in Cli modules:
- Add and use OutputLine() helper method which outputs a formatted
  string line (appends newline \r\n).
- Use binary search when finding the command in sCommands array (also
  adds static_assert check to ensure sCommands array is sorted).
- Define Command struct as a private nested type.
- Use enum constants (replacing #define).
- Rename method to OutputResult() (from AppendResult) to harmonize
  with rest of a Output{Something}() methods.
- Remove comments at #endif when within 20 lines of #if
This commit is contained in:
Abtin Keshavarzian
2020-09-15 06:58:14 -07:00
committed by GitHub
parent 8c90ade062
commit b735193857
9 changed files with 779 additions and 736 deletions
+492 -620
View File
File diff suppressed because it is too large Load Diff
+210 -38
View File
@@ -76,18 +76,6 @@ namespace ot {
*/
namespace Cli {
class Interpreter;
/**
* This structure represents a CLI command.
*
*/
struct Command
{
const char *mName; ///< A pointer to the command string.
void (Interpreter::*mCommand)(uint8_t aArgsLength, char *aArgs[]); ///< A function pointer to process the command.
};
/**
* This class implements the CLI interpreter.
*
@@ -177,13 +165,6 @@ public:
*/
static int Hex2Bin(const char *aHex, uint8_t *aBin, uint16_t aBinLength, bool aAllowTruncate = false);
/**
* Write error code the CLI console
*
* @param[in] aError Error code value.
*/
void AppendResult(otError aError);
/**
* This method delivers raw characters to the client.
*
@@ -229,6 +210,15 @@ public:
*/
int OutputFormatV(const char *aFormat, va_list aArguments);
/**
* This method delivers formatted output (to which it also appends newline `\r\n`) to the client.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... A variable list of arguments to format.
*
*/
void OutputLine(const char *aFormat, ...);
/**
* Write an IPv6 address to the CLI console.
*
@@ -242,10 +232,19 @@ public:
int OutputIp6Address(const otIp6Address &aAddress);
/**
* Set a user command table.
* This method delivers a success or error message the client.
*
* @param[in] aError The error code.
*
*/
void OutputResult(otError aError);
/**
* This method sets the user command table.
*
* @param[in] aUserCommands A pointer to an array with user commands.
* @param[in] aLength @p aUserCommands length.
*
*/
void SetUserCommands(const otCliCommand *aCommands, uint8_t aLength);
@@ -255,6 +254,7 @@ protected:
private:
enum
{
kIndentationSize = 4,
kMaxArgs = 32,
kMaxAutoAddresses = 8,
@@ -265,6 +265,13 @@ private:
kMaxLineLength = OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH,
};
struct Command
{
const char *mName;
void (Interpreter::*mCommand)(uint8_t aArgsLength, char *aArgs[]);
};
const Command *FindCommand(const char *aName) const;
otError ParsePingInterval(const char *aString, uint32_t &aInterval);
static otError ParseJoinerDiscerner(char *aString, otJoinerDiscerner &aJoinerDiscerner);
void ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
@@ -297,10 +304,10 @@ private:
void ProcessChildTimeout(uint8_t aArgsLength, char *aArgs[]);
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
void ProcessCoap(uint8_t aArgsLength, char *aArgs[]);
#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE
#endif
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
void ProcessCoapSecure(uint8_t aArgsLength, char *aArgs[]);
#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
void ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]);
#endif
@@ -317,7 +324,7 @@ private:
#endif
#if OPENTHREAD_CONFIG_DIAG_ENABLE
void ProcessDiag(uint8_t aArgsLength, char *aArgs[]);
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
#endif
void ProcessDiscover(uint8_t aArgsLength, char *aArgs[]);
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
void ProcessDns(uint8_t aArgsLength, char *aArgs[]);
@@ -390,7 +397,7 @@ private:
#endif
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
void ProcessNetworkDiagnostic(uint8_t aArgsLength, char *aArgs[]);
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
#endif
#if OPENTHREAD_FTD
void ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]);
#endif
@@ -462,7 +469,7 @@ private:
void PrintMacFilter(void);
otError ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]);
otError ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]);
#endif // OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
#endif
void ProcessMac(uint8_t aArgsLength, char *aArgs[]);
otError ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]);
@@ -486,7 +493,7 @@ private:
void OutputLeaderData(const otLeaderData &aLeaderData, uint16_t aColumn);
void OutputNetworkDiagMacCounters(const otNetworkDiagMacCounters &aMacCounters, uint16_t aColumn);
void OutputChildTableEntry(const otNetworkDiagChildEntry &aChildEntry, uint16_t aColumn);
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
#endif
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
static void HandleDnsResponse(void * aContext,
@@ -519,18 +526,183 @@ private:
}
void HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aInfo);
static const struct Command sCommands[];
const otCliCommand * mUserCommands;
uint8_t mUserCommandsLength;
uint16_t mPingLength;
uint16_t mPingCount;
uint32_t mPingInterval;
uint8_t mPingHopLimit;
bool mPingAllowZeroHopLimit;
uint16_t mPingIdentifier;
otIp6Address mPingDestAddress;
TimerMilli mPingTimer;
otIcmp6Handler mIcmpHandler;
constexpr static bool AreSorted(const char *aFirst, const char *aSecond)
{
return (*aFirst < *aSecond) ? true : ((*aFirst > *aSecond) ? false : AreSorted(aFirst + 1, aSecond + 1));
}
constexpr static bool IsArraySorted(const Interpreter::Command *aList, uint16_t aLength)
{
return (aLength <= 1) ? true
: AreSorted(aList[0].mName, aList[1].mName) && IsArraySorted(aList + 1, aLength - 1);
}
static constexpr Command sCommands[] = {
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
{"bbr", &Interpreter::ProcessBackboneRouter},
#endif
{"bufferinfo", &Interpreter::ProcessBufferInfo},
{"channel", &Interpreter::ProcessChannel},
#if OPENTHREAD_FTD
{"child", &Interpreter::ProcessChild},
{"childip", &Interpreter::ProcessChildIp},
{"childmax", &Interpreter::ProcessChildMax},
#endif
{"childtimeout", &Interpreter::ProcessChildTimeout},
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
{"coap", &Interpreter::ProcessCoap},
#endif
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
{"coaps", &Interpreter::ProcessCoapSecure},
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
{"coex", &Interpreter::ProcessCoexMetrics},
#endif
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
{"commissioner", &Interpreter::ProcessCommissioner},
#endif
#if OPENTHREAD_FTD
{"contextreusedelay", &Interpreter::ProcessContextIdReuseDelay},
#endif
{"counters", &Interpreter::ProcessCounters},
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
{"csl", &Interpreter::ProcessCsl},
#endif
{"dataset", &Interpreter::ProcessDataset},
#if OPENTHREAD_FTD
{"delaytimermin", &Interpreter::ProcessDelayTimerMin},
#endif
#if OPENTHREAD_CONFIG_DIAG_ENABLE
{"diag", &Interpreter::ProcessDiag},
#endif
{"discover", &Interpreter::ProcessDiscover},
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
{"dns", &Interpreter::ProcessDns},
#endif
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
{"domainname", &Interpreter::ProcessDomainName},
#endif
#if OPENTHREAD_CONFIG_DUA_ENABLE
{"dua", &Interpreter::ProcessDua},
#endif
#if OPENTHREAD_FTD
{"eidcache", &Interpreter::ProcessEidCache},
#endif
{"eui64", &Interpreter::ProcessEui64},
#if OPENTHREAD_POSIX
{"exit", &Interpreter::ProcessExit},
#endif
{"extaddr", &Interpreter::ProcessExtAddress},
{"extpanid", &Interpreter::ProcessExtPanId},
{"factoryreset", &Interpreter::ProcessFactoryReset},
{"help", &Interpreter::ProcessHelp},
{"ifconfig", &Interpreter::ProcessIfconfig},
{"ipaddr", &Interpreter::ProcessIpAddr},
{"ipmaddr", &Interpreter::ProcessIpMulticastAddr},
#if OPENTHREAD_CONFIG_JOINER_ENABLE
{"joiner", &Interpreter::ProcessJoiner},
#endif
#if OPENTHREAD_FTD
{"joinerport", &Interpreter::ProcessJoinerPort},
#endif
{"keysequence", &Interpreter::ProcessKeySequence},
{"leaderdata", &Interpreter::ProcessLeaderData},
#if OPENTHREAD_FTD
{"leaderpartitionid", &Interpreter::ProcessLeaderPartitionId},
{"leaderweight", &Interpreter::ProcessLeaderWeight},
#endif
{"log", &Interpreter::ProcessLog},
{"mac", &Interpreter::ProcessMac},
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
{"macfilter", &Interpreter::ProcessMacFilter},
#endif
{"masterkey", &Interpreter::ProcessMasterKey},
#if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
{"mlr", &Interpreter::ProcessMlr},
#endif
{"mode", &Interpreter::ProcessMode},
#if OPENTHREAD_FTD
{"neighbor", &Interpreter::ProcessNeighbor},
#endif
{"netdata", &Interpreter::ProcessNetworkData},
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
{"netdataregister", &Interpreter::ProcessNetworkDataRegister},
#endif
{"netdatashow", &Interpreter::ProcessNetworkDataShow},
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
{"netif", &Interpreter::ProcessNetif},
#endif
{"netstat", &Interpreter::ProcessNetstat},
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
{"networkdiagnostic", &Interpreter::ProcessNetworkDiagnostic},
#endif
#if OPENTHREAD_FTD
{"networkidtimeout", &Interpreter::ProcessNetworkIdTimeout},
#endif
{"networkname", &Interpreter::ProcessNetworkName},
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
{"networktime", &Interpreter::ProcessNetworkTime},
#endif
{"panid", &Interpreter::ProcessPanId},
{"parent", &Interpreter::ProcessParent},
#if OPENTHREAD_FTD
{"parentpriority", &Interpreter::ProcessParentPriority},
#endif
{"ping", &Interpreter::ProcessPing},
{"pollperiod", &Interpreter::ProcessPollPeriod},
#if OPENTHREAD_FTD
{"preferrouterid", &Interpreter::ProcessPreferRouterId},
#endif
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
{"prefix", &Interpreter::ProcessPrefix},
#endif
{"promiscuous", &Interpreter::ProcessPromiscuous},
#if OPENTHREAD_FTD
{"pskc", &Interpreter::ProcessPskc},
#endif
{"rcp", &Interpreter::ProcessRcp},
#if OPENTHREAD_FTD
{"releaserouterid", &Interpreter::ProcessReleaseRouterId},
#endif
{"reset", &Interpreter::ProcessReset},
{"rloc16", &Interpreter::ProcessRloc16},
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
{"route", &Interpreter::ProcessRoute},
#endif
#if OPENTHREAD_FTD
{"router", &Interpreter::ProcessRouter},
{"routerdowngradethreshold", &Interpreter::ProcessRouterDowngradeThreshold},
{"routereligible", &Interpreter::ProcessRouterEligible},
{"routerselectionjitter", &Interpreter::ProcessRouterSelectionJitter},
{"routerupgradethreshold", &Interpreter::ProcessRouterUpgradeThreshold},
#endif
{"scan", &Interpreter::ProcessScan},
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
{"service", &Interpreter::ProcessService},
#endif
{"singleton", &Interpreter::ProcessSingleton},
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
{"sntp", &Interpreter::ProcessSntp},
#endif
{"state", &Interpreter::ProcessState},
{"thread", &Interpreter::ProcessThread},
{"txpower", &Interpreter::ProcessTxPower},
{"udp", &Interpreter::ProcessUdp},
{"unsecureport", &Interpreter::ProcessUnsecurePort},
{"version", &Interpreter::ProcessVersion},
};
const otCliCommand *mUserCommands;
uint8_t mUserCommandsLength;
uint16_t mPingLength;
uint16_t mPingCount;
uint32_t mPingInterval;
uint8_t mPingHopLimit;
bool mPingAllowZeroHopLimit;
uint16_t mPingIdentifier;
otIp6Address mPingDestAddress;
TimerMilli mPingTimer;
otIcmp6Handler mIcmpHandler;
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
bool mResolvingInProgress;
char mResolvingHostname[OT_DNS_MAX_HOSTNAME_LENGTH];
+18 -18
View File
@@ -154,7 +154,7 @@ void Coap::PrintPayload(otMessage *aMessage) const
}
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
@@ -174,7 +174,7 @@ otError Coap::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -197,7 +197,7 @@ otError Coap::ProcessResource(uint8_t aArgsLength, char *aArgs[])
}
else
{
mInterpreter.OutputFormat("%s\r\n", mResource.mUriPath);
mInterpreter.OutputLine("%s", mResource.mUriPath);
}
exit:
@@ -228,7 +228,7 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[])
mInterpreter.OutputFormat("sending coap notification to ");
mInterpreter.OutputIp6Address(mSubscriberSock.mAddress);
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
notificationMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr);
VerifyOrExit(notificationMessage != nullptr, error = OT_ERROR_NO_BUFS);
@@ -251,7 +251,7 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[])
}
else
{
mInterpreter.OutputFormat("%s\r\n", mResourceContent);
mInterpreter.OutputLine("%s", mResourceContent);
}
exit:
@@ -341,16 +341,16 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
}
}
mInterpreter.OutputFormat("Transmission parameters for %s:\r\n", aArgs[1]);
mInterpreter.OutputLine("Transmission parameters for %s:", aArgs[1]);
if (*defaultTxParameters)
{
mInterpreter.OutputFormat("default\r\n");
mInterpreter.OutputLine("default");
}
else
{
mInterpreter.OutputFormat("ACK_TIMEOUT=%u ms, ACK_RANDOM_FACTOR=%u/%u, MAX_RETRANSMIT=%u\r\n",
txParameters->mAckTimeout, txParameters->mAckRandomFactorNumerator,
txParameters->mAckRandomFactorDenominator, txParameters->mMaxRetransmit);
mInterpreter.OutputLine("ACK_TIMEOUT=%u ms, ACK_RANDOM_FACTOR=%u/%u, MAX_RETRANSMIT=%u",
txParameters->mAckTimeout, txParameters->mAckRandomFactorNumerator,
txParameters->mAckRandomFactorDenominator, txParameters->mMaxRetransmit);
}
exit:
@@ -584,7 +584,7 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo)
break;
default:
mInterpreter.OutputFormat("Undefined\r\n");
mInterpreter.OutputLine("Undefined");
ExitNow(error = OT_ERROR_PARSE);
}
@@ -610,7 +610,7 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo)
if (observe == 0)
{
// New subscriber
mInterpreter.OutputFormat("Subscribing client\r\n");
mInterpreter.OutputLine("Subscribing client");
mSubscriberSock.mAddress = aMessageInfo->mPeerAddr;
mSubscriberSock.mPort = aMessageInfo->mPeerPort;
mSubscriberTokenLength = otCoapMessageGetTokenLength(aMessage);
@@ -673,13 +673,13 @@ exit:
{
if (responseMessage != nullptr)
{
mInterpreter.OutputFormat("coap send response error %d: %s\r\n", error, otThreadErrorToString(error));
mInterpreter.OutputLine("coap send response error %d: %s", error, otThreadErrorToString(error));
otMessageFree(responseMessage);
}
}
else if (responseCode >= OT_COAP_CODE_RESPONSE_MIN)
{
mInterpreter.OutputFormat("coap response sent\r\n");
mInterpreter.OutputLine("coap response sent");
}
}
@@ -703,13 +703,13 @@ void Coap::HandleNotificationResponse(otMessage *aMessage, const otMessageInfo *
{
mInterpreter.OutputFormat("Received ACK in reply to notification from ");
mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr);
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
break;
default:
mInterpreter.OutputFormat("coap receive notification response error %d: %s\r\n", aError,
otThreadErrorToString(aError));
mInterpreter.OutputLine("coap receive notification response error %d: %s", aError,
otThreadErrorToString(aError));
CancelSubscriber();
break;
}
@@ -725,7 +725,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo
{
if (aError != OT_ERROR_NONE)
{
mInterpreter.OutputFormat("coap receive response error %d: %s\r\n", aError, otThreadErrorToString(aError));
mInterpreter.OutputLine("coap receive response error %d: %s", aError, otThreadErrorToString(aError));
}
else if ((aMessageInfo != nullptr) && (aMessage != nullptr))
{
+10 -10
View File
@@ -97,7 +97,7 @@ void CoapSecure::PrintPayload(otMessage *aMessage) const
}
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
@@ -107,7 +107,7 @@ otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -130,7 +130,7 @@ otError CoapSecure::ProcessResource(uint8_t aArgsLength, char *aArgs[])
}
else
{
mInterpreter.OutputFormat("%s\r\n", mResource.mUriPath);
mInterpreter.OutputLine("%s", mResource.mUriPath);
}
exit:
@@ -149,7 +149,7 @@ otError CoapSecure::ProcessSet(uint8_t aArgsLength, char *aArgs[])
}
else
{
mInterpreter.OutputFormat("%s\r\n", mResourceContent);
mInterpreter.OutputLine("%s", mResourceContent);
}
exit:
@@ -447,11 +447,11 @@ void CoapSecure::HandleConnected(bool aConnected)
{
if (aConnected)
{
mInterpreter.OutputFormat("coaps connected\r\n");
mInterpreter.OutputLine("coaps connected");
}
else
{
mInterpreter.OutputFormat("coaps disconnected\r\n");
mInterpreter.OutputLine("coaps disconnected");
if (mShutdownFlag)
{
@@ -495,7 +495,7 @@ void CoapSecure::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessag
break;
default:
mInterpreter.OutputFormat("Undefined\r\n");
mInterpreter.OutputLine("Undefined");
return;
}
@@ -539,13 +539,13 @@ exit:
{
if (responseMessage != nullptr)
{
mInterpreter.OutputFormat("coaps send response error %d: %s\r\n", error, otThreadErrorToString(error));
mInterpreter.OutputLine("coaps send response error %d: %s", error, otThreadErrorToString(error));
otMessageFree(responseMessage);
}
}
else if (responseCode >= OT_COAP_CODE_RESPONSE_MIN)
{
mInterpreter.OutputFormat("coaps response sent\r\n");
mInterpreter.OutputLine("coaps response sent");
}
}
@@ -560,7 +560,7 @@ void CoapSecure::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessa
if (aError != OT_ERROR_NONE)
{
mInterpreter.OutputFormat("coaps receive response error %d: %s\r\n", aError, otThreadErrorToString(aError));
mInterpreter.OutputLine("coaps receive response error %d: %s", aError, otThreadErrorToString(aError));
}
else
{
+7 -7
View File
@@ -56,7 +56,7 @@ otError Commissioner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -329,7 +329,7 @@ otError Commissioner::ProcessSessionId(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
mInterpreter.OutputFormat("%d\r\n", otCommissionerGetSessionId(mInterpreter.mInstance));
mInterpreter.OutputLine("%d", otCommissionerGetSessionId(mInterpreter.mInstance));
return OT_ERROR_NONE;
}
@@ -350,7 +350,7 @@ void Commissioner::HandleStateChanged(otCommissionerState aState, void *aContext
void Commissioner::HandleStateChanged(otCommissionerState aState)
{
mInterpreter.OutputFormat("Commissioner: %s\r\n", StateToString(aState));
mInterpreter.OutputLine("Commissioner: %s", StateToString(aState));
}
const char *Commissioner::StateToString(otCommissionerState aState)
@@ -413,7 +413,7 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
mInterpreter.OutputBytes(aJoinerId->m8, sizeof(*aJoinerId));
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
otError Commissioner::ProcessStop(uint8_t aArgsLength, char *aArgs[])
@@ -429,7 +429,7 @@ otError Commissioner::ProcessState(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
mInterpreter.OutputFormat("%s\r\n", StateToString(otCommissionerGetState(mInterpreter.mInstance)));
mInterpreter.OutputLine("%s", StateToString(otCommissionerGetState(mInterpreter.mInstance)));
return OT_ERROR_NONE;
}
@@ -474,7 +474,7 @@ void Commissioner::HandleEnergyReport(uint32_t aChannelMask, const uint8_t *aEne
mInterpreter.OutputFormat("%d ", static_cast<int8_t>(aEnergyList[i]));
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask, void *aContext)
@@ -484,7 +484,7 @@ void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask, v
void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask)
{
mInterpreter.OutputFormat("Conflict: %04x, %08x\r\n", aPanId, aChannelMask);
mInterpreter.OutputLine("Conflict: %04x, %08x", aPanId, aChannelMask);
}
} // namespace Cli
+33 -34
View File
@@ -82,41 +82,41 @@ otError Dataset::Print(otOperationalDataset &aDataset)
{
if (aDataset.mComponents.mIsPendingTimestampPresent)
{
mInterpreter.OutputFormat("Pending Timestamp: %lu\r\n", aDataset.mPendingTimestamp);
mInterpreter.OutputLine("Pending Timestamp: %lu", aDataset.mPendingTimestamp);
}
if (aDataset.mComponents.mIsActiveTimestampPresent)
{
mInterpreter.OutputFormat("Active Timestamp: %lu\r\n", aDataset.mActiveTimestamp);
mInterpreter.OutputLine("Active Timestamp: %lu", aDataset.mActiveTimestamp);
}
if (aDataset.mComponents.mIsChannelPresent)
{
mInterpreter.OutputFormat("Channel: %d\r\n", aDataset.mChannel);
mInterpreter.OutputLine("Channel: %d", aDataset.mChannel);
}
if (aDataset.mComponents.mIsChannelMaskPresent)
{
mInterpreter.OutputFormat("Channel Mask: 0x%08x\r\n", aDataset.mChannelMask);
mInterpreter.OutputLine("Channel Mask: 0x%08x", aDataset.mChannelMask);
}
if (aDataset.mComponents.mIsDelayPresent)
{
mInterpreter.OutputFormat("Delay: %d\r\n", aDataset.mDelay);
mInterpreter.OutputLine("Delay: %d", aDataset.mDelay);
}
if (aDataset.mComponents.mIsExtendedPanIdPresent)
{
mInterpreter.OutputFormat("Ext PAN ID: ");
OutputBytes(aDataset.mExtendedPanId.m8, sizeof(aDataset.mExtendedPanId));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
if (aDataset.mComponents.mIsMeshLocalPrefixPresent)
{
const uint8_t *prefix = aDataset.mMeshLocalPrefix.m8;
mInterpreter.OutputFormat(
"Mesh Local Prefix: %x:%x:%x:%x::/64\r\n", (static_cast<uint16_t>(prefix[0]) << 8) | prefix[1],
mInterpreter.OutputLine(
"Mesh Local Prefix: %x:%x:%x:%x::/64", (static_cast<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3], (static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
}
@@ -125,26 +125,25 @@ otError Dataset::Print(otOperationalDataset &aDataset)
{
mInterpreter.OutputFormat("Master Key: ");
OutputBytes(aDataset.mMasterKey.m8, sizeof(aDataset.mMasterKey));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
if (aDataset.mComponents.mIsNetworkNamePresent)
{
mInterpreter.OutputFormat("Network Name: ");
mInterpreter.OutputFormat("%.*s\r\n", static_cast<uint16_t>(sizeof(aDataset.mNetworkName)),
aDataset.mNetworkName.m8);
mInterpreter.OutputLine("%.*s", static_cast<uint16_t>(sizeof(aDataset.mNetworkName)), aDataset.mNetworkName.m8);
}
if (aDataset.mComponents.mIsPanIdPresent)
{
mInterpreter.OutputFormat("PAN ID: 0x%04x\r\n", aDataset.mPanId);
mInterpreter.OutputLine("PAN ID: 0x%04x", aDataset.mPanId);
}
if (aDataset.mComponents.mIsPskcPresent)
{
mInterpreter.OutputFormat("PSKc: ");
OutputBytes(aDataset.mPskc.m8, sizeof(aDataset.mPskc.m8));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
if (aDataset.mComponents.mIsSecurityPolicyPresent)
@@ -176,7 +175,7 @@ otError Dataset::Print(otOperationalDataset &aDataset)
mInterpreter.OutputFormat("b");
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
return OT_ERROR_NONE;
@@ -211,7 +210,7 @@ otError Dataset::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -265,7 +264,7 @@ otError Dataset::ProcessActive(uint8_t aArgsLength, char *aArgs[])
SuccessOrExit(error = otDatasetGetActiveTlvs(mInterpreter.mInstance, &dataset));
mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength);
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
else
{
@@ -295,7 +294,7 @@ otError Dataset::ProcessPending(uint8_t aArgsLength, char *aArgs[])
SuccessOrExit(error = otDatasetGetPendingTlvs(mInterpreter.mInstance, &dataset));
mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength);
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
else
{
@@ -314,7 +313,7 @@ otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsActiveTimestampPresent)
{
mInterpreter.OutputFormat("%lu\r\n", sDataset.mActiveTimestamp);
mInterpreter.OutputLine("%lu", sDataset.mActiveTimestamp);
}
}
else
@@ -338,7 +337,7 @@ otError Dataset::ProcessChannel(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsChannelPresent)
{
mInterpreter.OutputFormat("%d\r\n", sDataset.mChannel);
mInterpreter.OutputLine("%d", sDataset.mChannel);
}
}
else
@@ -362,7 +361,7 @@ otError Dataset::ProcessChannelMask(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsChannelMaskPresent)
{
mInterpreter.OutputFormat("0x%08x\r\n", sDataset.mChannelMask);
mInterpreter.OutputLine("0x%08x", sDataset.mChannelMask);
}
}
else
@@ -418,7 +417,7 @@ otError Dataset::ProcessDelay(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsDelayPresent)
{
mInterpreter.OutputFormat("%d\r\n", sDataset.mDelay);
mInterpreter.OutputLine("%d", sDataset.mDelay);
}
}
else
@@ -443,7 +442,7 @@ otError Dataset::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[])
if (sDataset.mComponents.mIsExtendedPanIdPresent)
{
OutputBytes(sDataset.mExtendedPanId.m8, sizeof(sDataset.mExtendedPanId));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
}
else
@@ -470,7 +469,7 @@ otError Dataset::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[])
if (sDataset.mComponents.mIsMasterKeyPresent)
{
OutputBytes(sDataset.mMasterKey.m8, sizeof(sDataset.mMasterKey));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
}
else
@@ -497,11 +496,11 @@ otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, char *aArgs[])
if (sDataset.mComponents.mIsMeshLocalPrefixPresent)
{
const uint8_t *prefix = sDataset.mMeshLocalPrefix.m8;
mInterpreter.OutputFormat("Mesh Local Prefix: %x:%x:%x:%x::/64\r\n",
(static_cast<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3],
(static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
mInterpreter.OutputLine("Mesh Local Prefix: %x:%x:%x:%x::/64",
(static_cast<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3],
(static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
}
}
else
@@ -526,8 +525,8 @@ otError Dataset::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsNetworkNamePresent)
{
mInterpreter.OutputFormat("%.*s\r\n", static_cast<uint16_t>(sizeof(sDataset.mNetworkName)),
sDataset.mNetworkName.m8);
mInterpreter.OutputLine("%.*s", static_cast<uint16_t>(sizeof(sDataset.mNetworkName)),
sDataset.mNetworkName.m8);
}
}
else
@@ -553,7 +552,7 @@ otError Dataset::ProcessPanId(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsPanIdPresent)
{
mInterpreter.OutputFormat("0x%04x\r\n", sDataset.mPanId);
mInterpreter.OutputLine("0x%04x", sDataset.mPanId);
}
}
else
@@ -577,7 +576,7 @@ otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, char *aArgs[])
{
if (sDataset.mComponents.mIsPendingTimestampPresent)
{
mInterpreter.OutputFormat("%lu\r\n", sDataset.mPendingTimestamp);
mInterpreter.OutputLine("%lu", sDataset.mPendingTimestamp);
}
}
else
@@ -823,7 +822,7 @@ otError Dataset::ProcessPskc(uint8_t aArgsLength, char *aArgs[])
if (sDataset.mComponents.mIsPskcPresent)
{
OutputBytes(sDataset.mPskc.m8, sizeof(sDataset.mPskc.m8));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
}
else if (aArgsLength == 1)
@@ -892,7 +891,7 @@ otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, char *aArgs[])
mInterpreter.OutputFormat("b");
}
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
}
}
else
+5 -5
View File
@@ -73,7 +73,7 @@ otError Joiner::ProcessDiscerner(uint8_t aArgsLength, char *aArgs[])
VerifyOrExit(discerner != nullptr, error = OT_ERROR_NOT_FOUND);
mInterpreter.OutputFormat("0x%" PRIx64 "/%u\r\n", discerner->mValue, discerner->mLength);
mInterpreter.OutputLine("0x%" PRIx64 "/%u", discerner->mValue, discerner->mLength);
}
else
{
@@ -91,7 +91,7 @@ otError Joiner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -107,7 +107,7 @@ otError Joiner::ProcessId(uint8_t aArgsLength, char *aArgs[])
joinerId = otJoinerGetId(mInterpreter.mInstance);
mInterpreter.OutputBytes(joinerId->m8, sizeof(otExtAddress));
mInterpreter.OutputFormat("\r\n");
mInterpreter.OutputLine("");
return OT_ERROR_NONE;
}
@@ -174,11 +174,11 @@ void Joiner::HandleCallback(otError aError)
switch (aError)
{
case OT_ERROR_NONE:
mInterpreter.OutputFormat("Join success\r\n");
mInterpreter.OutputLine("Join success");
break;
default:
mInterpreter.OutputFormat("Join failed [%s]\r\n", otThreadErrorToString(aError));
mInterpreter.OutputLine("Join failed [%s]", otThreadErrorToString(aError));
break;
}
}
+3 -3
View File
@@ -66,7 +66,7 @@ otError UdpExample::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
for (const Command &command : sCommands)
{
mInterpreter.OutputFormat("%s\r\n", command.mName);
mInterpreter.OutputLine("%s", command.mName);
}
return OT_ERROR_NONE;
@@ -241,7 +241,7 @@ otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, char *aArgs[])
if (aArgsLength == 0)
{
mInterpreter.OutputFormat("%s\r\n", mLinkSecurityEnabled ? "Enabled" : "Disabled");
mInterpreter.OutputLine("%s", mLinkSecurityEnabled ? "Enabled" : "Disabled");
}
else if (strcmp(aArgs[0], "enable") == 0)
{
@@ -327,7 +327,7 @@ void UdpExample::HandleUdpReceive(otMessage *aMessage, const otMessageInfo *aMes
length = otMessageRead(aMessage, otMessageGetOffset(aMessage), buf, sizeof(buf) - 1);
buf[length] = '\0';
mInterpreter.OutputFormat("%s\r\n", buf);
mInterpreter.OutputLine("%s", buf);
}
} // namespace Cli
+1 -1
View File
@@ -151,7 +151,7 @@ case ${build_config} in
echo "Building OpenThread (NCP/CLI for FTD/MTD/RCP mode) with simulation platform using cmake"
echo "===================================================================================================="
cd "${top_builddir}" || die "cd failed"
cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=on -DOT_APP_CLI=off \
cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=on -DOT_APP_CLI=on \
-DOT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
"${top_srcdir}" || die
ninja || die