From b735193857cdbd490cb71f274c9794e4b8995e39 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 15 Sep 2020 06:58:14 -0700 Subject: [PATCH] [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 --- src/cli/cli.cpp | 1112 +++++++++++++++------------------- src/cli/cli.hpp | 248 ++++++-- src/cli/cli_coap.cpp | 36 +- src/cli/cli_coap_secure.cpp | 20 +- src/cli/cli_commissioner.cpp | 14 +- src/cli/cli_dataset.cpp | 67 +- src/cli/cli_joiner.cpp | 10 +- src/cli/cli_udp.cpp | 6 +- tests/toranj/build.sh | 2 +- 9 files changed, 779 insertions(+), 736 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 3c97064a3..2009fe4a7 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -98,164 +98,11 @@ using ot::Encoding::BigEndian::HostSwap16; using ot::Encoding::BigEndian::HostSwap32; -#define INDENT_SIZE (4) - namespace ot { namespace Cli { -const struct Command Interpreter::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 - {"log", &Interpreter::ProcessLog}, - {"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 - {"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 // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE -#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}, - {"promiscuous", &Interpreter::ProcessPromiscuous}, -#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE - {"prefix", &Interpreter::ProcessPrefix}, -#endif -#if OPENTHREAD_FTD - {"preferrouterid", &Interpreter::ProcessPreferRouterId}, - {"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}, -}; +constexpr Interpreter::Command Interpreter::sCommands[]; Interpreter *Interpreter::sInterpreter = nullptr; @@ -304,7 +151,7 @@ Interpreter::Interpreter(Instance *aInstance) #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE memset(mResolvingHostname, 0, sizeof(mResolvingHostname)); -#endif // OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE +#endif } int Interpreter::Hex2Bin(const char *aHex, uint8_t *aBin, uint16_t aBinLength, bool aAllowTruncate) @@ -368,15 +215,15 @@ exit: return rval; } -void Interpreter::AppendResult(otError aError) +void Interpreter::OutputResult(otError aError) { if (aError == OT_ERROR_NONE) { - OutputFormat("Done\r\n"); + OutputLine("Done"); } else { - OutputFormat("Error %d: %s\r\n", aError, otThreadErrorToString(aError)); + OutputLine("Error %d: %s", aError, otThreadErrorToString(aError)); } } @@ -485,17 +332,19 @@ void Interpreter::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); + static_assert(IsArraySorted(sCommands, OT_ARRAY_LENGTH(sCommands)), "Command list is not sorted"); + for (const Command &command : sCommands) { - OutputFormat("%s\r\n", command.mName); + OutputLine("%s", command.mName); } for (uint8_t i = 0; i < mUserCommandsLength; i++) { - OutputFormat("%s\r\n", mUserCommands[i].mName); + OutputLine("%s", mUserCommands[i].mName); } - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) @@ -509,15 +358,15 @@ void Interpreter::ProcessBackboneRouter(uint8_t aArgsLength, char *aArgs[]) { if (otBackboneRouterGetPrimary(mInstance, &config) == OT_ERROR_NONE) { - OutputFormat("BBR Primary:\r\n"); - OutputFormat("server16: 0x%04X\r\n", config.mServer16); - OutputFormat("seqno: %d\r\n", config.mSequenceNumber); - OutputFormat("delay: %d secs\r\n", config.mReregistrationDelay); - OutputFormat("timeout: %d secs\r\n", config.mMlrTimeout); + OutputLine("BBR Primary:"); + OutputLine("server16: 0x%04X", config.mServer16); + OutputLine("seqno: %d", config.mSequenceNumber); + OutputLine("delay: %d secs", config.mReregistrationDelay); + OutputLine("timeout: %d secs", config.mMlrTimeout); } else { - OutputFormat("BBR Primary: None\r\n"); + OutputLine("BBR Primary: None"); } error = OT_ERROR_NONE; @@ -563,7 +412,7 @@ void Interpreter::ProcessBackboneRouter(uint8_t aArgsLength, char *aArgs[]) exit: #endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE @@ -634,7 +483,7 @@ void Interpreter::PrintMulticastListenersTable(void) while (otBackboneRouterMulticastListenerGetNext(mInstance, &iter, &listenerInfo) == OT_ERROR_NONE) { OutputIp6Address(listenerInfo.mAddress); - OutputFormat(" %u\r\n", listenerInfo.mTimeout); + OutputLine(" %u", listenerInfo.mTimeout); } } @@ -658,7 +507,7 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otBackboneRouterGetRegistrationJitter(mInstance)); + OutputLine("%d", otBackboneRouterGetRegistrationJitter(mInstance)); } else if (aArgsLength == 2) { @@ -675,13 +524,13 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs switch (otBackboneRouterGetState(mInstance)) { case OT_BACKBONE_ROUTER_STATE_DISABLED: - OutputFormat("Disabled\r\n"); + OutputLine("Disabled"); break; case OT_BACKBONE_ROUTER_STATE_SECONDARY: - OutputFormat("Secondary\r\n"); + OutputLine("Secondary"); break; case OT_BACKBONE_ROUTER_STATE_PRIMARY: - OutputFormat("Primary\r\n"); + OutputLine("Primary"); break; } } @@ -691,9 +540,9 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs if (aArgsLength == 1) { - OutputFormat("seqno: %d\r\n", config.mSequenceNumber); - OutputFormat("delay: %d secs\r\n", config.mReregistrationDelay); - OutputFormat("timeout: %d secs\r\n", config.mMlrTimeout); + OutputLine("seqno: %d", config.mSequenceNumber); + OutputLine("delay: %d secs", config.mReregistrationDelay); + OutputLine("timeout: %d secs", config.mMlrTimeout); } else { @@ -743,7 +592,7 @@ void Interpreter::ProcessDomainName(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { const char *domainName = otThreadGetDomainName(mInstance); - OutputFormat("%s\r\n", static_cast(domainName)); + OutputLine("%s", static_cast(domainName)); } else { @@ -751,7 +600,7 @@ void Interpreter::ProcessDomainName(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_DUA_ENABLE @@ -770,7 +619,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) if (iid != nullptr) { OutputBytes(iid->mFields.m8, sizeof(otIp6InterfaceIdentifier)); - OutputFormat("\r\n"); + OutputLine(""); } break; } @@ -795,7 +644,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_DUA_ENABLE @@ -810,20 +659,19 @@ void Interpreter::ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]) otMessageGetBufferInfo(mInstance, &bufferInfo); - OutputFormat("total: %d\r\n", bufferInfo.mTotalBuffers); - OutputFormat("free: %d\r\n", bufferInfo.mFreeBuffers); - OutputFormat("6lo send: %d %d\r\n", bufferInfo.m6loSendMessages, bufferInfo.m6loSendBuffers); - OutputFormat("6lo reas: %d %d\r\n", bufferInfo.m6loReassemblyMessages, bufferInfo.m6loReassemblyBuffers); - OutputFormat("ip6: %d %d\r\n", bufferInfo.mIp6Messages, bufferInfo.mIp6Buffers); - OutputFormat("mpl: %d %d\r\n", bufferInfo.mMplMessages, bufferInfo.mMplBuffers); - OutputFormat("mle: %d %d\r\n", bufferInfo.mMleMessages, bufferInfo.mMleBuffers); - OutputFormat("arp: %d %d\r\n", bufferInfo.mArpMessages, bufferInfo.mArpBuffers); - OutputFormat("coap: %d %d\r\n", bufferInfo.mCoapMessages, bufferInfo.mCoapBuffers); - OutputFormat("coap secure: %d %d\r\n", bufferInfo.mCoapSecureMessages, bufferInfo.mCoapSecureBuffers); - OutputFormat("application coap: %d %d\r\n", bufferInfo.mApplicationCoapMessages, - bufferInfo.mApplicationCoapBuffers); + OutputLine("total: %d", bufferInfo.mTotalBuffers); + OutputLine("free: %d", bufferInfo.mFreeBuffers); + OutputLine("6lo send: %d %d", bufferInfo.m6loSendMessages, bufferInfo.m6loSendBuffers); + OutputLine("6lo reas: %d %d", bufferInfo.m6loReassemblyMessages, bufferInfo.m6loReassemblyBuffers); + OutputLine("ip6: %d %d", bufferInfo.mIp6Messages, bufferInfo.mIp6Buffers); + OutputLine("mpl: %d %d", bufferInfo.mMplMessages, bufferInfo.mMplBuffers); + OutputLine("mle: %d %d", bufferInfo.mMleMessages, bufferInfo.mMleBuffers); + OutputLine("arp: %d %d", bufferInfo.mArpMessages, bufferInfo.mArpBuffers); + OutputLine("coap: %d %d", bufferInfo.mCoapMessages, bufferInfo.mCoapBuffers); + OutputLine("coap secure: %d %d", bufferInfo.mCoapSecureMessages, bufferInfo.mCoapSecureBuffers); + OutputLine("application coap: %d %d", bufferInfo.mApplicationCoapMessages, bufferInfo.mApplicationCoapBuffers); - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) @@ -833,33 +681,33 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otLinkGetChannel(mInstance)); + OutputLine("%d", otLinkGetChannel(mInstance)); } else if (strcmp(aArgs[0], "supported") == 0) { - OutputFormat("0x%x\r\n", otPlatRadioGetSupportedChannelMask(mInstance)); + OutputLine("0x%x", otPlatRadioGetSupportedChannelMask(mInstance)); } else if (strcmp(aArgs[0], "preferred") == 0) { - OutputFormat("0x%x\r\n", otPlatRadioGetPreferredChannelMask(mInstance)); + OutputLine("0x%x", otPlatRadioGetPreferredChannelMask(mInstance)); } #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE else if (strcmp(aArgs[0], "monitor") == 0) { if (aArgsLength == 1) { - OutputFormat("enabled: %d\r\n", otChannelMonitorIsEnabled(mInstance)); + OutputLine("enabled: %d", otChannelMonitorIsEnabled(mInstance)); if (otChannelMonitorIsEnabled(mInstance)) { uint32_t channelMask = otLinkGetSupportedChannelMask(mInstance); uint8_t channelNum = sizeof(channelMask) * CHAR_BIT; - OutputFormat("interval: %u\r\n", otChannelMonitorGetSampleInterval(mInstance)); - OutputFormat("threshold: %d\r\n", otChannelMonitorGetRssiThreshold(mInstance)); - OutputFormat("window: %u\r\n", otChannelMonitorGetSampleWindow(mInstance)); - OutputFormat("count: %u\r\n", otChannelMonitorGetSampleCount(mInstance)); + OutputLine("interval: %u", otChannelMonitorGetSampleInterval(mInstance)); + OutputLine("threshold: %d", otChannelMonitorGetRssiThreshold(mInstance)); + OutputLine("window: %u", otChannelMonitorGetSampleWindow(mInstance)); + OutputLine("count: %u", otChannelMonitorGetSampleCount(mInstance)); - OutputFormat("occupancies:\r\n"); + OutputLine("occupancies:"); for (uint8_t channel = 0; channel < channelNum; channel++) { uint32_t occupancy = 0; @@ -873,9 +721,9 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) OutputFormat("ch %d (0x%04x) ", channel, occupancy); occupancy = (occupancy * 10000) / 0xffff; - OutputFormat("%2d.%02d%% busy\r\n", occupancy / 100, occupancy % 100); + OutputLine("%2d.%02d%% busy", occupancy / 100, occupancy % 100); } - OutputFormat("\r\n"); + OutputLine(""); } } else if (strcmp(aArgs[1], "start") == 0) @@ -897,18 +745,18 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("channel: %d\r\n", otChannelManagerGetRequestedChannel(mInstance)); - OutputFormat("auto: %d\r\n", otChannelManagerGetAutoChannelSelectionEnabled(mInstance)); + OutputLine("channel: %d", otChannelManagerGetRequestedChannel(mInstance)); + OutputLine("auto: %d", otChannelManagerGetAutoChannelSelectionEnabled(mInstance)); if (otChannelManagerGetAutoChannelSelectionEnabled(mInstance)) { Mac::ChannelMask supportedMask(otChannelManagerGetSupportedChannels(mInstance)); Mac::ChannelMask favoredMask(otChannelManagerGetFavoredChannels(mInstance)); - OutputFormat("delay: %d\r\n", otChannelManagerGetDelay(mInstance)); - OutputFormat("interval: %u\r\n", otChannelManagerGetAutoChannelSelectionInterval(mInstance)); - OutputFormat("supported: %s\r\n", supportedMask.ToString().AsCString()); - OutputFormat("favored: %s\r\n", supportedMask.ToString().AsCString()); + OutputLine("delay: %d", otChannelManagerGetDelay(mInstance)); + OutputLine("interval: %u", otChannelManagerGetAutoChannelSelectionInterval(mInstance)); + OutputLine("supported: %s", supportedMask.ToString().AsCString()); + OutputLine("favored: %s", supportedMask.ToString().AsCString()); } } else if (strcmp(aArgs[1], "change") == 0) @@ -968,7 +816,7 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD @@ -989,8 +837,8 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - OutputFormat("| ID | RLOC16 | Timeout | Age | LQ In | C_VN |R|S|D|N| Extended MAC |\r\n"); - OutputFormat("+-----+--------+------------+------------+-------+------+-+-+-+-+------------------+\r\n"); + OutputLine("| ID | RLOC16 | Timeout | Age | LQ In | C_VN |R|S|D|N| Extended MAC |"); + OutputLine("+-----+--------+------------+------------+-------+------+-+-+-+-+------------------+"); } maxChildren = otThreadGetMaxAllowedChildren(mInstance); @@ -1021,7 +869,7 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat(" |\r\n"); + OutputLine(" |"); } else { @@ -1029,15 +877,15 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) } } - OutputFormat("\r\n"); + OutputLine(""); ExitNow(); } SuccessOrExit(error = ParseLong(aArgs[0], value)); SuccessOrExit(error = otThreadGetChildInfoById(mInstance, static_cast(value), &childInfo)); - OutputFormat("Child ID: %d\r\n", childInfo.mChildId); - OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16); + OutputLine("Child ID: %d", childInfo.mChildId); + OutputLine("Rloc: %04x", childInfo.mRloc16); OutputFormat("Ext Addr: "); for (uint8_t b : childInfo.mExtAddress.m8) @@ -1045,7 +893,7 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat("\r\n"); + OutputLine(""); OutputFormat("Mode: "); if (childInfo.mRxOnWhenIdle) @@ -1068,16 +916,16 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) OutputFormat("n"); } - OutputFormat("\r\n"); + OutputLine(""); - OutputFormat("Net Data: %d\r\n", childInfo.mNetworkDataVersion); - OutputFormat("Timeout: %d\r\n", childInfo.mTimeout); - OutputFormat("Age: %d\r\n", childInfo.mAge); - OutputFormat("Link Quality In: %d\r\n", childInfo.mLinkQualityIn); - OutputFormat("RSSI: %d\r\n", childInfo.mAverageRssi); + OutputLine("Net Data: %d", childInfo.mNetworkDataVersion); + OutputLine("Timeout: %d", childInfo.mTimeout); + OutputLine("Age: %d", childInfo.mAge); + OutputLine("Link Quality In: %d", childInfo.mLinkQualityIn); + OutputLine("RSSI: %d", childInfo.mAverageRssi); exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) @@ -1107,7 +955,7 @@ void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) { OutputFormat("%04x: ", childInfo.mRloc16); OutputIp6Address(ip6Address); - OutputFormat("\r\n"); + OutputLine(""); } } } @@ -1115,7 +963,7 @@ void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otThreadGetMaxChildIpAddresses(mInstance)); + OutputLine("%d", otThreadGetMaxChildIpAddresses(mInstance)); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE else if (aArgsLength == 2) @@ -1138,7 +986,7 @@ void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE exit: #endif - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessChildMax(uint8_t aArgsLength, char *aArgs[]) @@ -1148,7 +996,7 @@ void Interpreter::ProcessChildMax(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetMaxAllowedChildren(mInstance)); + OutputLine("%d", otThreadGetMaxAllowedChildren(mInstance)); } else { @@ -1157,7 +1005,7 @@ void Interpreter::ProcessChildMax(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_FTD @@ -1168,7 +1016,7 @@ void Interpreter::ProcessChildTimeout(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetChildTimeout(mInstance)); + OutputLine("%d", otThreadGetChildTimeout(mInstance)); } else { @@ -1177,30 +1025,26 @@ void Interpreter::ProcessChildTimeout(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_COAP_API_ENABLE - void Interpreter::ProcessCoap(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mCoap.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } - -#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE +#endif #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE - void Interpreter::ProcessCoapSecure(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mCoapSecure.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } - -#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#endif #if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) @@ -1209,7 +1053,7 @@ void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%s\r\n", otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled"); + OutputLine("%s", otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled"); } else if (strcmp(aArgs[0], "enable") == 0) { @@ -1225,27 +1069,27 @@ void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otPlatRadioGetCoexMetrics(mInstance, &metrics)); - OutputFormat("Stopped: %s\r\n", metrics.mStopped ? "true" : "false"); - OutputFormat("Grant Glitch: %u\r\n", metrics.mNumGrantGlitch); - OutputFormat("Transmit metrics\r\n"); - OutputFormat(" Request: %u\r\n", metrics.mNumTxRequest); - OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumTxGrantImmediate); - OutputFormat(" Grant Wait: %u\r\n", metrics.mNumTxGrantWait); - OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumTxGrantWaitActivated); - OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumTxGrantWaitTimeout); - OutputFormat(" Grant Deactivated During Request: %u\r\n", metrics.mNumTxGrantDeactivatedDuringRequest); - OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumTxDelayedGrant); - OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgTxRequestToGrantTime); - OutputFormat("Receive metrics\r\n"); - OutputFormat(" Request: %u\r\n", metrics.mNumRxRequest); - OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumRxGrantImmediate); - OutputFormat(" Grant Wait: %u\r\n", metrics.mNumRxGrantWait); - OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumRxGrantWaitActivated); - OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumRxGrantWaitTimeout); - OutputFormat(" Grant Deactivated During Request: %u\r\n", metrics.mNumRxGrantDeactivatedDuringRequest); - OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumRxDelayedGrant); - OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgRxRequestToGrantTime); - OutputFormat(" Grant None: %u\r\n", metrics.mNumRxGrantNone); + OutputLine("Stopped: %s", metrics.mStopped ? "true" : "false"); + OutputLine("Grant Glitch: %u", metrics.mNumGrantGlitch); + OutputLine("Transmit metrics"); + OutputLine(" Request: %u", metrics.mNumTxRequest); + OutputLine(" Grant Immediate: %u", metrics.mNumTxGrantImmediate); + OutputLine(" Grant Wait: %u", metrics.mNumTxGrantWait); + OutputLine(" Grant Wait Activated: %u", metrics.mNumTxGrantWaitActivated); + OutputLine(" Grant Wait Timeout: %u", metrics.mNumTxGrantWaitTimeout); + OutputLine(" Grant Deactivated During Request: %u", metrics.mNumTxGrantDeactivatedDuringRequest); + OutputLine(" Delayed Grant: %u", metrics.mNumTxDelayedGrant); + OutputLine(" Average Request To Grant Time: %u", metrics.mAvgTxRequestToGrantTime); + OutputLine("Receive metrics"); + OutputLine(" Request: %u", metrics.mNumRxRequest); + OutputLine(" Grant Immediate: %u", metrics.mNumRxGrantImmediate); + OutputLine(" Grant Wait: %u", metrics.mNumRxGrantWait); + OutputLine(" Grant Wait Activated: %u", metrics.mNumRxGrantWaitActivated); + OutputLine(" Grant Wait Timeout: %u", metrics.mNumRxGrantWaitTimeout); + OutputLine(" Grant Deactivated During Request: %u", metrics.mNumRxGrantDeactivatedDuringRequest); + OutputLine(" Delayed Grant: %u", metrics.mNumRxDelayedGrant); + OutputLine(" Average Request To Grant Time: %u", metrics.mAvgRxRequestToGrantTime); + OutputLine(" Grant None: %u", metrics.mNumRxGrantNone); } else { @@ -1253,7 +1097,7 @@ void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE @@ -1265,7 +1109,7 @@ void Interpreter::ProcessContextIdReuseDelay(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetContextIdReuseDelay(mInstance)); + OutputLine("%d", otThreadGetContextIdReuseDelay(mInstance)); } else { @@ -1274,9 +1118,9 @@ void Interpreter::ProcessContextIdReuseDelay(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } -#endif // OPENTHREAD_FTD +#endif void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) { @@ -1284,8 +1128,8 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("mac\r\n"); - OutputFormat("mle\r\n"); + OutputLine("mac"); + OutputLine("mle"); } else if (strcmp(aArgs[0], "mac") == 0) { @@ -1293,37 +1137,37 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) { const otMacCounters *macCounters = otLinkGetCounters(mInstance); - OutputFormat("TxTotal: %d\r\n", macCounters->mTxTotal); - OutputFormat(" TxUnicast: %d\r\n", macCounters->mTxUnicast); - OutputFormat(" TxBroadcast: %d\r\n", macCounters->mTxBroadcast); - OutputFormat(" TxAckRequested: %d\r\n", macCounters->mTxAckRequested); - OutputFormat(" TxAcked: %d\r\n", macCounters->mTxAcked); - OutputFormat(" TxNoAckRequested: %d\r\n", macCounters->mTxNoAckRequested); - OutputFormat(" TxData: %d\r\n", macCounters->mTxData); - OutputFormat(" TxDataPoll: %d\r\n", macCounters->mTxDataPoll); - OutputFormat(" TxBeacon: %d\r\n", macCounters->mTxBeacon); - OutputFormat(" TxBeaconRequest: %d\r\n", macCounters->mTxBeaconRequest); - OutputFormat(" TxOther: %d\r\n", macCounters->mTxOther); - OutputFormat(" TxRetry: %d\r\n", macCounters->mTxRetry); - OutputFormat(" TxErrCca: %d\r\n", macCounters->mTxErrCca); - OutputFormat(" TxErrBusyChannel: %d\r\n", macCounters->mTxErrBusyChannel); - OutputFormat("RxTotal: %d\r\n", macCounters->mRxTotal); - OutputFormat(" RxUnicast: %d\r\n", macCounters->mRxUnicast); - OutputFormat(" RxBroadcast: %d\r\n", macCounters->mRxBroadcast); - OutputFormat(" RxData: %d\r\n", macCounters->mRxData); - OutputFormat(" RxDataPoll: %d\r\n", macCounters->mRxDataPoll); - OutputFormat(" RxBeacon: %d\r\n", macCounters->mRxBeacon); - OutputFormat(" RxBeaconRequest: %d\r\n", macCounters->mRxBeaconRequest); - OutputFormat(" RxOther: %d\r\n", macCounters->mRxOther); - OutputFormat(" RxAddressFiltered: %d\r\n", macCounters->mRxAddressFiltered); - OutputFormat(" RxDestAddrFiltered: %d\r\n", macCounters->mRxDestAddrFiltered); - OutputFormat(" RxDuplicated: %d\r\n", macCounters->mRxDuplicated); - OutputFormat(" RxErrNoFrame: %d\r\n", macCounters->mRxErrNoFrame); - OutputFormat(" RxErrNoUnknownNeighbor: %d\r\n", macCounters->mRxErrUnknownNeighbor); - OutputFormat(" RxErrInvalidSrcAddr: %d\r\n", macCounters->mRxErrInvalidSrcAddr); - OutputFormat(" RxErrSec: %d\r\n", macCounters->mRxErrSec); - OutputFormat(" RxErrFcs: %d\r\n", macCounters->mRxErrFcs); - OutputFormat(" RxErrOther: %d\r\n", macCounters->mRxErrOther); + OutputLine("TxTotal: %d", macCounters->mTxTotal); + OutputLine(" TxUnicast: %d", macCounters->mTxUnicast); + OutputLine(" TxBroadcast: %d", macCounters->mTxBroadcast); + OutputLine(" TxAckRequested: %d", macCounters->mTxAckRequested); + OutputLine(" TxAcked: %d", macCounters->mTxAcked); + OutputLine(" TxNoAckRequested: %d", macCounters->mTxNoAckRequested); + OutputLine(" TxData: %d", macCounters->mTxData); + OutputLine(" TxDataPoll: %d", macCounters->mTxDataPoll); + OutputLine(" TxBeacon: %d", macCounters->mTxBeacon); + OutputLine(" TxBeaconRequest: %d", macCounters->mTxBeaconRequest); + OutputLine(" TxOther: %d", macCounters->mTxOther); + OutputLine(" TxRetry: %d", macCounters->mTxRetry); + OutputLine(" TxErrCca: %d", macCounters->mTxErrCca); + OutputLine(" TxErrBusyChannel: %d", macCounters->mTxErrBusyChannel); + OutputLine("RxTotal: %d", macCounters->mRxTotal); + OutputLine(" RxUnicast: %d", macCounters->mRxUnicast); + OutputLine(" RxBroadcast: %d", macCounters->mRxBroadcast); + OutputLine(" RxData: %d", macCounters->mRxData); + OutputLine(" RxDataPoll: %d", macCounters->mRxDataPoll); + OutputLine(" RxBeacon: %d", macCounters->mRxBeacon); + OutputLine(" RxBeaconRequest: %d", macCounters->mRxBeaconRequest); + OutputLine(" RxOther: %d", macCounters->mRxOther); + OutputLine(" RxAddressFiltered: %d", macCounters->mRxAddressFiltered); + OutputLine(" RxDestAddrFiltered: %d", macCounters->mRxDestAddrFiltered); + OutputLine(" RxDuplicated: %d", macCounters->mRxDuplicated); + OutputLine(" RxErrNoFrame: %d", macCounters->mRxErrNoFrame); + OutputLine(" RxErrNoUnknownNeighbor: %d", macCounters->mRxErrUnknownNeighbor); + OutputLine(" RxErrInvalidSrcAddr: %d", macCounters->mRxErrInvalidSrcAddr); + OutputLine(" RxErrSec: %d", macCounters->mRxErrSec); + OutputLine(" RxErrFcs: %d", macCounters->mRxErrFcs); + OutputLine(" RxErrOther: %d", macCounters->mRxErrOther); } else if ((aArgsLength == 2) && (strcmp(aArgs[1], "reset") == 0)) { @@ -1340,15 +1184,15 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) { const otMleCounters *mleCounters = otThreadGetMleCounters(mInstance); - OutputFormat("Role Disabled: %d\r\n", mleCounters->mDisabledRole); - OutputFormat("Role Detached: %d\r\n", mleCounters->mDetachedRole); - OutputFormat("Role Child: %d\r\n", mleCounters->mChildRole); - OutputFormat("Role Router: %d\r\n", mleCounters->mRouterRole); - OutputFormat("Role Leader: %d\r\n", mleCounters->mLeaderRole); - OutputFormat("Attach Attempts: %d\r\n", mleCounters->mAttachAttempts); - OutputFormat("Partition Id Changes: %d\r\n", mleCounters->mPartitionIdChanges); - OutputFormat("Better Partition Attach Attempts: %d\r\n", mleCounters->mBetterPartitionAttachAttempts); - OutputFormat("Parent Changes: %d\r\n", mleCounters->mParentChanges); + OutputLine("Role Disabled: %d", mleCounters->mDisabledRole); + OutputLine("Role Detached: %d", mleCounters->mDetachedRole); + OutputLine("Role Child: %d", mleCounters->mChildRole); + OutputLine("Role Router: %d", mleCounters->mRouterRole); + OutputLine("Role Leader: %d", mleCounters->mLeaderRole); + OutputLine("Attach Attempts: %d", mleCounters->mAttachAttempts); + OutputLine("Partition Id Changes: %d", mleCounters->mPartitionIdChanges); + OutputLine("Better Partition Attach Attempts: %d", mleCounters->mBetterPartitionAttachAttempts); + OutputLine("Parent Changes: %d", mleCounters->mParentChanges); } else if ((aArgsLength == 2) && (strcmp(aArgs[1], "reset") == 0)) { @@ -1365,7 +1209,7 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE @@ -1375,10 +1219,10 @@ void Interpreter::ProcessCsl(uint8_t aArgsLength, char *argv[]) if (aArgsLength == 0) { - OutputFormat("Channel: %u\r\n", otLinkCslGetChannel(mInstance)); - OutputFormat("Period: %u(in units of 10 symbols), %ums\r\n", otLinkCslGetPeriod(mInstance), - otLinkCslGetPeriod(mInstance) * kUsPerTenSymbols / 1000); - OutputFormat("Timeout: %us\r\n", otLinkCslGetTimeout(mInstance)); + OutputLine("Channel: %u", otLinkCslGetChannel(mInstance)); + OutputLine("Period: %u(in units of 10 symbols), %ums", otLinkCslGetPeriod(mInstance), + otLinkCslGetPeriod(mInstance) * kUsPerTenSymbols / 1000); + OutputLine("Timeout: %us", otLinkCslGetTimeout(mInstance)); error = OT_ERROR_NONE; } else if (aArgsLength == 2) @@ -1402,7 +1246,7 @@ void Interpreter::ProcessCsl(uint8_t aArgsLength, char *argv[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE @@ -1413,7 +1257,7 @@ void Interpreter::ProcessDelayTimerMin(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", (otDatasetGetDelayTimerMinimal(mInstance) / 1000)); + OutputLine("%d", (otDatasetGetDelayTimerMinimal(mInstance) / 1000)); } else if (aArgsLength == 1) { @@ -1427,7 +1271,7 @@ void Interpreter::ProcessDelayTimerMin(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -1447,13 +1291,13 @@ void Interpreter::ProcessDiscover(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otThreadDiscover(mInstance, scanChannels, OT_PANID_BROADCAST, false, false, &Interpreter::HandleActiveScanResult, this)); - OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); - OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); + OutputLine("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"); + OutputLine("+---+------------------+------------------+------+------------------+----+-----+-----+"); exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -1508,7 +1352,7 @@ void Interpreter::ProcessDns(uint8_t aArgsLength, char *aArgs[]) exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -1532,10 +1376,10 @@ void Interpreter::HandleDnsResponse(const char *aHostname, const Ip6::Address *a { OutputIp6Address(*aAddress); } - OutputFormat(" TTL: %d\r\n", aTtl); + OutputLine(" TTL: %d", aTtl); } - AppendResult(aResult); + OutputResult(aResult); mResolvingInProgress = false; } @@ -1557,13 +1401,13 @@ void Interpreter::ProcessEidCache(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(otThreadGetNextCacheEntry(mInstance, &entry, &iterator)); OutputIp6Address(entry.mTarget); - OutputFormat(" %04x\r\n", entry.mRloc16); + OutputLine(" %04x", entry.mRloc16); } exit: - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } -#endif // OPENTHREAD_FTD +#endif void Interpreter::ProcessEui64(uint8_t aArgsLength, char *aArgs[]) { @@ -1576,10 +1420,10 @@ void Interpreter::ProcessEui64(uint8_t aArgsLength, char *aArgs[]) otLinkGetFactoryAssignedIeeeEui64(mInstance, &extAddress); OutputBytes(extAddress.m8, OT_EXT_ADDRESS_SIZE); - OutputFormat("\r\n"); + OutputLine(""); exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessExtAddress(uint8_t aArgsLength, char *aArgs[]) @@ -1590,7 +1434,7 @@ void Interpreter::ProcessExtAddress(uint8_t aArgsLength, char *aArgs[]) { const uint8_t *extAddress = reinterpret_cast(otLinkGetExtendedAddress(mInstance)); OutputBytes(extAddress, OT_EXT_ADDRESS_SIZE); - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -1604,7 +1448,7 @@ void Interpreter::ProcessExtAddress(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_POSIX @@ -1627,7 +1471,7 @@ void Interpreter::ProcessLog(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otLoggingGetLevel()); + OutputLine("%d", otLoggingGetLevel()); } #if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE else if (aArgsLength == 2) @@ -1656,7 +1500,7 @@ void Interpreter::ProcessLog(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]) @@ -1667,7 +1511,7 @@ void Interpreter::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]) { const uint8_t *extPanId = reinterpret_cast(otThreadGetExtendedPanId(mInstance)); OutputBytes(extPanId, OT_EXT_PAN_ID_SIZE); - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -1680,7 +1524,7 @@ void Interpreter::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessFactoryReset(uint8_t aArgsLength, char *aArgs[]) @@ -1699,11 +1543,11 @@ void Interpreter::ProcessIfconfig(uint8_t aArgsLength, char *aArgs[]) { if (otIp6IsEnabled(mInstance)) { - OutputFormat("up\r\n"); + OutputLine("up"); } else { - OutputFormat("down\r\n"); + OutputLine("down"); } } else if (strcmp(aArgs[0], "up") == 0) @@ -1720,7 +1564,7 @@ void Interpreter::ProcessIfconfig(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } otError Interpreter::ProcessIpAddrAdd(uint8_t aArgsLength, char *aArgs[]) @@ -1766,7 +1610,7 @@ void Interpreter::ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]) for (const otNetifAddress *addr = unicastAddrs; addr; addr = addr->mNext) { OutputIp6Address(addr->mAddress); - OutputFormat("\r\n"); + OutputLine(""); } } else @@ -1782,17 +1626,17 @@ void Interpreter::ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]) else if (strcmp(aArgs[0], "linklocal") == 0) { OutputIp6Address(*otThreadGetLinkLocalIp6Address(mInstance)); - OutputFormat("\r\n"); + OutputLine(""); } else if (strcmp(aArgs[0], "rloc") == 0) { OutputIp6Address(*otThreadGetRloc(mInstance)); - OutputFormat("\r\n"); + OutputLine(""); } else if (strcmp(aArgs[0], "mleid") == 0) { OutputIp6Address(*otThreadGetMeshLocalEid(mInstance)); - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -1801,7 +1645,7 @@ void Interpreter::ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } otError Interpreter::ProcessIpMulticastAddrAdd(uint8_t aArgsLength, char *aArgs[]) @@ -1840,11 +1684,11 @@ otError Interpreter::ProcessMulticastPromiscuous(uint8_t aArgsLength, char *aArg { if (otIp6IsMulticastPromiscuousEnabled(mInstance)) { - OutputFormat("Enabled\r\n"); + OutputLine("Enabled"); } else { - OutputFormat("Disabled\r\n"); + OutputLine("Disabled"); } } else @@ -1876,7 +1720,7 @@ void Interpreter::ProcessIpMulticastAddr(uint8_t aArgsLength, char *aArgs[]) for (const otNetifMulticastAddress *addr = otIp6GetMulticastAddresses(mInstance); addr; addr = addr->mNext) { OutputIp6Address(addr->mAddress); - OutputFormat("\r\n"); + OutputLine(""); } } else @@ -1900,7 +1744,7 @@ void Interpreter::ProcessIpMulticastAddr(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) @@ -1914,7 +1758,7 @@ void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otThreadGetKeySequenceCounter(mInstance)); + OutputLine("%d", otThreadGetKeySequenceCounter(mInstance)); } else { @@ -1926,7 +1770,7 @@ void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otThreadGetKeySwitchGuardTime(mInstance)); + OutputLine("%d", otThreadGetKeySwitchGuardTime(mInstance)); } else { @@ -1940,7 +1784,7 @@ void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessLeaderData(uint8_t aArgsLength, char *aArgs[]) @@ -1953,14 +1797,14 @@ void Interpreter::ProcessLeaderData(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otThreadGetLeaderData(mInstance, &leaderData)); - OutputFormat("Partition ID: %u\r\n", leaderData.mPartitionId); - OutputFormat("Weighting: %d\r\n", leaderData.mWeighting); - OutputFormat("Data Version: %d\r\n", leaderData.mDataVersion); - OutputFormat("Stable Data Version: %d\r\n", leaderData.mStableDataVersion); - OutputFormat("Leader Router ID: %d\r\n", leaderData.mLeaderRouterId); + OutputLine("Partition ID: %u", leaderData.mPartitionId); + OutputLine("Weighting: %d", leaderData.mWeighting); + OutputLine("Data Version: %d", leaderData.mDataVersion); + OutputLine("Stable Data Version: %d", leaderData.mStableDataVersion); + OutputLine("Leader Router ID: %d", leaderData.mLeaderRouterId); exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD @@ -1971,7 +1815,7 @@ void Interpreter::ProcessLeaderPartitionId(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%u\r\n", otThreadGetLocalLeaderPartitionId(mInstance)); + OutputLine("%u", otThreadGetLocalLeaderPartitionId(mInstance)); } else { @@ -1980,7 +1824,7 @@ void Interpreter::ProcessLeaderPartitionId(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]) @@ -1990,7 +1834,7 @@ void Interpreter::ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetLocalLeaderWeight(mInstance)); + OutputLine("%d", otThreadGetLocalLeaderWeight(mInstance)); } else { @@ -1999,7 +1843,7 @@ void Interpreter::ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_FTD @@ -2017,7 +1861,7 @@ void Interpreter::ProcessPskc(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -2042,7 +1886,7 @@ void Interpreter::ProcessPskc(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -2059,7 +1903,7 @@ void Interpreter::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", key[i]); } - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -2070,7 +1914,7 @@ void Interpreter::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE @@ -2079,7 +1923,7 @@ void Interpreter::ProcessMlr(uint8_t aArgsLength, char **aArgs) { if (aArgsLength == 0) { - AppendResult(OT_ERROR_INVALID_COMMAND); + OutputResult(OT_ERROR_INVALID_COMMAND); } else if (!strcmp(aArgs[0], "reg")) { @@ -2087,7 +1931,7 @@ void Interpreter::ProcessMlr(uint8_t aArgsLength, char **aArgs) } else { - AppendResult(OT_ERROR_INVALID_COMMAND); + OutputResult(OT_ERROR_INVALID_COMMAND); } } @@ -2127,7 +1971,7 @@ void Interpreter::ProcessMlrReg(uint8_t aArgsLength, char *aArgs[]) exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -2147,16 +1991,16 @@ void Interpreter::HandleMlrRegResult(otError aError, { if (aError == OT_ERROR_NONE) { - OutputFormat("status %d, %d failed\r\n", aMlrStatus, aFailedAddressNum); + OutputLine("status %d, %d failed", aMlrStatus, aFailedAddressNum); for (uint8_t i = 0; i < aFailedAddressNum; i++) { OutputIp6Address(aFailedAddresses[i]); - OutputFormat("\r\n"); + OutputLine(""); } } - AppendResult(aError); + OutputResult(aError); } #endif // OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE @@ -2192,7 +2036,7 @@ void Interpreter::ProcessMode(uint8_t aArgsLength, char *aArgs[]) OutputFormat("n"); } - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -2225,7 +2069,7 @@ void Interpreter::ProcessMode(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD @@ -2244,8 +2088,8 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) { if (isTable) { - OutputFormat("| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |\r\n"); - OutputFormat("+------+--------+-----+----------+-----------+-+-+-+-+------------------+\r\n"); + OutputLine("| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |"); + OutputLine("+------+--------+-----+----------+-----------+-+-+-+-+------------------+"); } while (otThreadGetNextNeighborInfo(mInstance, &iterator, &neighborInfo) == OT_ERROR_NONE) @@ -2268,7 +2112,7 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat(" |\r\n"); + OutputLine(" |"); } else { @@ -2276,7 +2120,7 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) } } - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -2284,7 +2128,7 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -2300,10 +2144,10 @@ void Interpreter::ProcessNetworkDataShow(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otNetDataGet(mInstance, false, data, &len)); OutputBytes(data, static_cast(len)); - OutputFormat("\r\n"); + OutputLine(""); exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE @@ -2318,10 +2162,10 @@ void Interpreter::ProcessNetif(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otPlatGetNetif(mInstance, &netif, &netifidx)); - OutputFormat("%s:%u\r\n", netif ? netif : "(null)", netifidx); + OutputLine("%s:%u", netif ? netif : "(null)", netifidx); exit: - AppendResult(error); + OutputResult(error); } #endif @@ -2332,8 +2176,8 @@ void Interpreter::ProcessNetstat(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - OutputFormat("| Local Address | Peer Address |\n"); - OutputFormat("+-----------------------------------------------+-----------------------------------------------+\n"); + OutputLine("| Local Address | Peer Address |"); + OutputLine("+-----------------------------------------------+-----------------------------------------------+"); while (socket) { @@ -2354,12 +2198,12 @@ void Interpreter::ProcessNetstat(uint8_t aArgsLength, char *aArgs[]) { OutputFormat(" "); } - OutputFormat(" |\n"); + OutputLine(" |"); socket = socket->mNext; } - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } int Interpreter::OutputSocketAddress(const otSockAddr &aAddress) @@ -2437,7 +2281,7 @@ void Interpreter::ProcessService(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -2480,7 +2324,7 @@ void Interpreter::ProcessNetworkData(uint8_t aArgsLength, char *aArgs[]) error = OT_ERROR_INVALID_COMMAND; exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE @@ -2497,9 +2341,9 @@ void Interpreter::ProcessNetworkDataRegister(uint8_t aArgsLength, char *aArgs[]) #endif exit: - AppendResult(error); + OutputResult(error); } -#endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE +#endif #if OPENTHREAD_FTD void Interpreter::ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]) @@ -2509,7 +2353,7 @@ void Interpreter::ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetNetworkIdTimeout(mInstance)); + OutputLine("%d", otThreadGetNetworkIdTimeout(mInstance)); } else { @@ -2518,9 +2362,9 @@ void Interpreter::ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } -#endif // OPENTHREAD_FTD +#endif void Interpreter::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]) { @@ -2529,7 +2373,7 @@ void Interpreter::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { const char *networkName = otThreadGetNetworkName(mInstance); - OutputFormat("%s\r\n", static_cast(networkName)); + OutputLine("%s", static_cast(networkName)); } else { @@ -2537,7 +2381,7 @@ void Interpreter::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE @@ -2558,23 +2402,23 @@ void Interpreter::ProcessNetworkTime(uint8_t aArgsLength, char *aArgs[]) switch (networkTimeStatus) { case OT_NETWORK_TIME_UNSYNCHRONIZED: - OutputFormat(" (unsynchronized)\r\n"); + OutputLine(" (unsynchronized)"); break; case OT_NETWORK_TIME_RESYNC_NEEDED: - OutputFormat(" (resync needed)\r\n"); + OutputLine(" (resync needed)"); break; case OT_NETWORK_TIME_SYNCHRONIZED: - OutputFormat(" (synchronized)\r\n"); + OutputLine(" (synchronized)"); break; default: break; } - OutputFormat("Time Sync Period: %ds\r\n", otNetworkTimeGetSyncPeriod(mInstance)); - OutputFormat("XTAL Threshold: %dppm\r\n", otNetworkTimeGetXtalThreshold(mInstance)); + OutputLine("Time Sync Period: %ds", otNetworkTimeGetSyncPeriod(mInstance)); + OutputLine("XTAL Threshold: %dppm", otNetworkTimeGetXtalThreshold(mInstance)); } else if (aArgsLength == 2) { @@ -2590,7 +2434,7 @@ void Interpreter::ProcessNetworkTime(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE @@ -2601,7 +2445,7 @@ void Interpreter::ProcessPanId(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("0x%04x\r\n", otLinkGetPanId(mInstance)); + OutputLine("0x%04x", otLinkGetPanId(mInstance)); } else { @@ -2610,7 +2454,7 @@ void Interpreter::ProcessPanId(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessParent(uint8_t aArgsLength, char *aArgs[]) @@ -2629,15 +2473,15 @@ void Interpreter::ProcessParent(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat("\r\n"); + OutputLine(""); - OutputFormat("Rloc: %x\r\n", parentInfo.mRloc16); - OutputFormat("Link Quality In: %d\r\n", parentInfo.mLinkQualityIn); - OutputFormat("Link Quality Out: %d\r\n", parentInfo.mLinkQualityOut); - OutputFormat("Age: %d\r\n", parentInfo.mAge); + OutputLine("Rloc: %x", parentInfo.mRloc16); + OutputLine("Link Quality In: %d", parentInfo.mLinkQualityIn); + OutputLine("Link Quality Out: %d", parentInfo.mLinkQualityOut); + OutputLine("Age: %d", parentInfo.mAge); exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD @@ -2648,7 +2492,7 @@ void Interpreter::ProcessParentPriority(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetParentPriority(mInstance)); + OutputLine("%d", otThreadGetParentPriority(mInstance)); } else { @@ -2657,7 +2501,7 @@ void Interpreter::ProcessParentPriority(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -2691,7 +2535,7 @@ void Interpreter::HandleIcmpReceive(otMessage * aMessage, OutputFormat(" time=%dms", TimerMilli::GetNow().GetValue() - HostSwap32(timestamp)); } - OutputFormat("\r\n"); + OutputLine(""); SignalPingReply(static_cast(aMessageInfo)->GetPeerAddr(), dataSize, HostSwap32(timestamp), aMessageInfo->mHopLimit); @@ -2771,7 +2615,7 @@ void Interpreter::ProcessPing(uint8_t aArgsLength, char *aArgs[]) SendPing(); exit: - AppendResult(error); + OutputResult(error); } void Interpreter::HandlePingTimer(Timer &aTimer) @@ -2821,7 +2665,7 @@ void Interpreter::ProcessPollPeriod(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otLinkGetPollPeriod(mInstance)); + OutputLine("%d", otLinkGetPollPeriod(mInstance)); } else { @@ -2830,7 +2674,7 @@ void Interpreter::ProcessPollPeriod(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) @@ -2841,11 +2685,11 @@ void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) { if (otLinkIsPromiscuous(mInstance) && otPlatRadioGetPromiscuous(mInstance)) { - OutputFormat("Enabled\r\n"); + OutputLine("Enabled"); } else { - OutputFormat("Disabled\r\n"); + OutputLine("Disabled"); } } else @@ -2867,7 +2711,7 @@ void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx, void *aContext) @@ -2879,7 +2723,7 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) { OT_UNUSED_VARIABLE(aIsTx); - OutputFormat("\r\n"); + OutputLine(""); for (size_t i = 0; i < 44; i++) { @@ -2893,7 +2737,7 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) OutputFormat("="); } - OutputFormat("\r\n"); + OutputLine(""); for (size_t i = 0; i < aFrame->mLength; i += 16) { @@ -2932,7 +2776,7 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) } } - OutputFormat("|\r\n"); + OutputLine("|"); } for (size_t i = 0; i < 83; i++) @@ -2940,7 +2784,7 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) OutputFormat("-"); } - OutputFormat("\r\n"); + OutputLine(""); } #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE @@ -3144,7 +2988,7 @@ void Interpreter::OutputPrefix(otBorderRouterConfig &aConfig) break; } - OutputFormat("\r\n"); + OutputLine(""); } otError Interpreter::ProcessPrefixList(void) @@ -3193,7 +3037,7 @@ void Interpreter::ProcessPrefix(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE @@ -3208,7 +3052,7 @@ void Interpreter::ProcessPreferRouterId(uint8_t aArgsLength, char *aArgs[]) error = otThreadSetPreferredRouterId(mInstance, static_cast(value)); exit: - AppendResult(error); + OutputResult(error); } #endif @@ -3222,7 +3066,7 @@ void Interpreter::ProcessRcp(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[0], "version") == 0) { - OutputFormat("%s\r\n", version); + OutputLine("%s", version); } else { @@ -3230,7 +3074,7 @@ void Interpreter::ProcessRcp(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_FTD @@ -3245,7 +3089,7 @@ void Interpreter::ProcessReleaseRouterId(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otThreadReleaseRouterId(mInstance, static_cast(value))); exit: - AppendResult(error); + OutputResult(error); } #endif @@ -3262,8 +3106,8 @@ void Interpreter::ProcessRloc16(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - OutputFormat("%04x\r\n", otThreadGetRloc16(mInstance)); - AppendResult(OT_ERROR_NONE); + OutputLine("%04x", otThreadGetRloc16(mInstance)); + OutputResult(OT_ERROR_NONE); } #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE @@ -3379,15 +3223,15 @@ otError Interpreter::ProcessRouteList(void) switch (config.mPreference) { case OT_ROUTE_PREFERENCE_LOW: - OutputFormat(" low\r\n"); + OutputLine(" low"); break; case OT_ROUTE_PREFERENCE_MED: - OutputFormat(" med\r\n"); + OutputLine(" med"); break; case OT_ROUTE_PREFERENCE_HIGH: - OutputFormat(" high\r\n"); + OutputLine(" high"); break; } } @@ -3417,7 +3261,7 @@ void Interpreter::ProcessRoute(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE @@ -3439,8 +3283,8 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - OutputFormat("| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |\r\n"); - OutputFormat("+----+--------+----------+-----------+-------+--------+-----+------------------+\r\n"); + OutputLine("| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |"); + OutputLine("+----+--------+----------+-----------+-------+--------+-----+------------------+"); } maxRouterId = otThreadGetMaxRouterId(mInstance); @@ -3468,7 +3312,7 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat(" |\r\n"); + OutputLine(" |"); } else { @@ -3476,21 +3320,21 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) } } - OutputFormat("\r\n"); + OutputLine(""); ExitNow(); } SuccessOrExit(error = ParseLong(aArgs[0], value)); SuccessOrExit(error = otThreadGetRouterInfo(mInstance, static_cast(value), &routerInfo)); - OutputFormat("Alloc: %d\r\n", routerInfo.mAllocated); + OutputLine("Alloc: %d", routerInfo.mAllocated); if (routerInfo.mAllocated) { - OutputFormat("Router ID: %d\r\n", routerInfo.mRouterId); - OutputFormat("Rloc: %04x\r\n", routerInfo.mRloc16); - OutputFormat("Next Hop: %04x\r\n", static_cast(routerInfo.mNextHop) << 10); - OutputFormat("Link: %d\r\n", routerInfo.mLinkEstablished); + OutputLine("Router ID: %d", routerInfo.mRouterId); + OutputLine("Rloc: %04x", routerInfo.mRloc16); + OutputLine("Next Hop: %04x", static_cast(routerInfo.mNextHop) << 10); + OutputLine("Link: %d", routerInfo.mLinkEstablished); if (routerInfo.mLinkEstablished) { @@ -3501,16 +3345,16 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) OutputFormat("%02x", b); } - OutputFormat("\r\n"); - OutputFormat("Cost: %d\r\n", routerInfo.mPathCost); - OutputFormat("Link Quality In: %d\r\n", routerInfo.mLinkQualityIn); - OutputFormat("Link Quality Out: %d\r\n", routerInfo.mLinkQualityOut); - OutputFormat("Age: %d\r\n", routerInfo.mAge); + OutputLine(""); + OutputLine("Cost: %d", routerInfo.mPathCost); + OutputLine("Link Quality In: %d", routerInfo.mLinkQualityIn); + OutputLine("Link Quality Out: %d", routerInfo.mLinkQualityOut); + OutputLine("Age: %d", routerInfo.mAge); } } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessRouterDowngradeThreshold(uint8_t aArgsLength, char *aArgs[]) @@ -3520,7 +3364,7 @@ void Interpreter::ProcessRouterDowngradeThreshold(uint8_t aArgsLength, char *aAr if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetRouterDowngradeThreshold(mInstance)); + OutputLine("%d", otThreadGetRouterDowngradeThreshold(mInstance)); } else { @@ -3529,7 +3373,7 @@ void Interpreter::ProcessRouterDowngradeThreshold(uint8_t aArgsLength, char *aAr } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]) @@ -3540,11 +3384,11 @@ void Interpreter::ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]) { if (otThreadIsRouterEligible(mInstance)) { - OutputFormat("Enabled\r\n"); + OutputLine("Enabled"); } else { - OutputFormat("Disabled\r\n"); + OutputLine("Disabled"); } } else if (strcmp(aArgs[0], "enable") == 0) @@ -3561,7 +3405,7 @@ void Interpreter::ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessRouterSelectionJitter(uint8_t aArgsLength, char *aArgs[]) @@ -3571,7 +3415,7 @@ void Interpreter::ProcessRouterSelectionJitter(uint8_t aArgsLength, char *aArgs[ if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetRouterSelectionJitter(mInstance)); + OutputLine("%d", otThreadGetRouterSelectionJitter(mInstance)); } else { @@ -3581,7 +3425,7 @@ void Interpreter::ProcessRouterSelectionJitter(uint8_t aArgsLength, char *aArgs[ } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessRouterUpgradeThreshold(uint8_t aArgsLength, char *aArgs[]) @@ -3591,7 +3435,7 @@ void Interpreter::ProcessRouterUpgradeThreshold(uint8_t aArgsLength, char *aArgs if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetRouterUpgradeThreshold(mInstance)); + OutputLine("%d", otThreadGetRouterUpgradeThreshold(mInstance)); } else { @@ -3600,7 +3444,7 @@ void Interpreter::ProcessRouterUpgradeThreshold(uint8_t aArgsLength, char *aArgs } exit: - AppendResult(error); + OutputResult(error); } #endif // OPENTHREAD_FTD @@ -3635,15 +3479,15 @@ void Interpreter::ProcessScan(uint8_t aArgsLength, char *aArgs[]) if (energyScan) { - OutputFormat("| Ch | RSSI |\r\n"); - OutputFormat("+----+------+\r\n"); + OutputLine("| Ch | RSSI |"); + OutputLine("+----+------+"); SuccessOrExit(error = otLinkEnergyScan(mInstance, scanChannels, scanDuration, &Interpreter::HandleEnergyScanResult, this)); } else { - OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); - OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); + OutputLine("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"); + OutputLine("+---+------------------+------------------+------+------------------+----+-----+-----+"); SuccessOrExit(error = otLinkActiveScan(mInstance, scanChannels, scanDuration, &Interpreter::HandleActiveScanResult, this)); } @@ -3651,7 +3495,7 @@ void Interpreter::ProcessScan(uint8_t aArgsLength, char *aArgs[]) exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -3664,7 +3508,7 @@ void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult) { if (aResult == nullptr) { - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); ExitNow(); } @@ -3680,7 +3524,7 @@ void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult) OutputBytes(aResult->mExtAddress.m8, OT_EXT_ADDRESS_SIZE); OutputFormat(" | %2d ", aResult->mChannel); OutputFormat("| %3d ", aResult->mRssi); - OutputFormat("| %3d |\r\n", aResult->mLqi); + OutputLine("| %3d |", aResult->mLqi); exit: return; @@ -3695,11 +3539,11 @@ void Interpreter::HandleEnergyScanResult(otEnergyScanResult *aResult) { if (aResult == nullptr) { - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); ExitNow(); } - OutputFormat("| %2d | %4d |\r\n", aResult->mChannel, aResult->mMaxRssi); + OutputLine("| %2d | %4d |", aResult->mChannel, aResult->mMaxRssi); exit: return; @@ -3714,14 +3558,14 @@ void Interpreter::ProcessSingleton(uint8_t aArgsLength, char *aArgs[]) if (otThreadIsSingleton(mInstance)) { - OutputFormat("true\r\n"); + OutputLine("true"); } else { - OutputFormat("false\r\n"); + OutputLine("false"); } - AppendResult(error); + OutputResult(error); } #if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE @@ -3769,7 +3613,7 @@ void Interpreter::ProcessSntp(uint8_t aArgsLength, char *aArgs[]) exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -3784,17 +3628,17 @@ void Interpreter::HandleSntpResponse(uint64_t aTime, otError aResult) { // Some Embedded C libraries do not support printing of 64-bit unsigned integers. // To simplify, unix epoch time and era number are printed separately. - OutputFormat("SNTP response - Unix time: %u (era: %u)\r\n", static_cast(aTime), - static_cast(aTime >> 32)); + OutputLine("SNTP response - Unix time: %u (era: %u)", static_cast(aTime), + static_cast(aTime >> 32)); } else { - OutputFormat("SNTP error - %s\r\n", otThreadErrorToString(aResult)); + OutputLine("SNTP error - %s", otThreadErrorToString(aResult)); } mSntpQueryingInProgress = false; - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } #endif @@ -3807,30 +3651,29 @@ void Interpreter::ProcessState(uint8_t aArgsLength, char *aArgs[]) switch (otThreadGetDeviceRole(mInstance)) { case OT_DEVICE_ROLE_DISABLED: - OutputFormat("disabled\r\n"); + OutputLine("disabled"); break; case OT_DEVICE_ROLE_DETACHED: - OutputFormat("detached\r\n"); + OutputLine("detached"); break; case OT_DEVICE_ROLE_CHILD: - OutputFormat("child\r\n"); + OutputLine("child"); break; #if OPENTHREAD_FTD - case OT_DEVICE_ROLE_ROUTER: - OutputFormat("router\r\n"); + OutputLine("router"); break; case OT_DEVICE_ROLE_LEADER: - OutputFormat("leader\r\n"); + OutputLine("leader"); break; -#endif // OPENTHREAD_FTD +#endif default: - OutputFormat("invalid state\r\n"); + OutputLine("invalid state"); break; } } @@ -3854,8 +3697,7 @@ void Interpreter::ProcessState(uint8_t aArgsLength, char *aArgs[]) { SuccessOrExit(error = otThreadBecomeLeader(mInstance)); } - -#endif // OPENTHREAD_FTD +#endif else { ExitNow(error = OT_ERROR_INVALID_ARGS); @@ -3863,7 +3705,7 @@ void Interpreter::ProcessState(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessThread(uint8_t aArgsLength, char *aArgs[]) @@ -3885,7 +3727,7 @@ void Interpreter::ProcessThread(uint8_t aArgsLength, char *aArgs[]) } else if (strcmp(aArgs[0], "version") == 0) { - OutputFormat("%u\r\n", otThreadGetVersion()); + OutputLine("%u", otThreadGetVersion()); } else { @@ -3893,14 +3735,14 @@ void Interpreter::ProcessThread(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessDataset(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mDataset.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessTxPower(uint8_t aArgsLength, char *aArgs[]) @@ -3912,7 +3754,7 @@ void Interpreter::ProcessTxPower(uint8_t aArgsLength, char *aArgs[]) int8_t power; SuccessOrExit(error = otPlatRadioGetTransmitPower(mInstance, &power)); - OutputFormat("%d dBm\r\n", power); + OutputLine("%d dBm", power); } else { @@ -3923,14 +3765,14 @@ void Interpreter::ProcessTxPower(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessUdp(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mUdp.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessUnsecurePort(uint8_t aArgsLength, char *aArgs[]) @@ -3980,7 +3822,7 @@ void Interpreter::ProcessUnsecurePort(uint8_t aArgsLength, char *aArgs[]) } } - OutputFormat("\r\n"); + OutputLine(""); } else { @@ -3988,7 +3830,7 @@ void Interpreter::ProcessUnsecurePort(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } void Interpreter::ProcessVersion(uint8_t aArgsLength, char *aArgs[]) @@ -3997,8 +3839,8 @@ void Interpreter::ProcessVersion(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgs); const char *version = otGetVersionString(); - OutputFormat("%s\r\n", static_cast(version)); - AppendResult(OT_ERROR_NONE); + OutputLine("%s", static_cast(version)); + OutputResult(OT_ERROR_NONE); } #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD @@ -4007,7 +3849,7 @@ void Interpreter::ProcessCommissioner(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mCommissioner.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } #endif @@ -4018,7 +3860,7 @@ void Interpreter::ProcessJoiner(uint8_t aArgsLength, char *aArgs[]) { otError error; error = mJoiner.Process(aArgsLength, aArgs); - AppendResult(error); + OutputResult(error); } #endif @@ -4031,7 +3873,7 @@ void Interpreter::ProcessJoinerPort(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputFormat("%d\r\n", otThreadGetJoinerUdpPort(mInstance)); + OutputLine("%d", otThreadGetJoinerUdpPort(mInstance)); } else { @@ -4040,7 +3882,7 @@ void Interpreter::ProcessJoinerPort(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } #endif @@ -4069,7 +3911,7 @@ void Interpreter::ProcessMacFilter(uint8_t aArgsLength, char *aArgs[]) } } - AppendResult(error); + OutputResult(error); } void Interpreter::PrintMacFilter(void) @@ -4080,15 +3922,15 @@ void Interpreter::PrintMacFilter(void) if (mode == OT_MAC_FILTER_ADDRESS_MODE_DISABLED) { - OutputFormat("Address Mode: Disabled\r\n"); + OutputLine("Address Mode: Disabled"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_ALLOWLIST) { - OutputFormat("Address Mode: Allowlist\r\n"); + OutputLine("Address Mode: Allowlist"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_DENYLIST) { - OutputFormat("Address Mode: Denylist\r\n"); + OutputLine("Address Mode: Denylist"); } while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) @@ -4100,11 +3942,11 @@ void Interpreter::PrintMacFilter(void) OutputFormat(" : rss %d (lqi %d)", entry.mRssIn, otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } - OutputFormat("\r\n"); + OutputLine(""); } iterator = OT_MAC_FILTER_ITERATOR_INIT; - OutputFormat("RssIn List:\r\n"); + OutputLine("RssIn List:"); while (otLinkFilterGetNextRssIn(mInstance, &iterator, &entry) == OT_ERROR_NONE) { @@ -4120,14 +3962,13 @@ void Interpreter::PrintMacFilter(void) if (i == OT_EXT_ADDRESS_SIZE) { - OutputFormat("Default rss : %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputLine("Default rss : %d (lqi %d)", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } else { OutputBytes(entry.mExtAddress.m8, OT_EXT_ADDRESS_SIZE); - OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputLine(" : rss %d (lqi %d)", entry.mRssIn, otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } } } @@ -4145,15 +3986,15 @@ otError Interpreter::ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]) { if (mode == OT_MAC_FILTER_ADDRESS_MODE_DISABLED) { - OutputFormat("Disabled\r\n"); + OutputLine("Disabled"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_ALLOWLIST) { - OutputFormat("Allowlist\r\n"); + OutputLine("Allowlist"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_DENYLIST) { - OutputFormat("Denylist\r\n"); + OutputLine("Denylist"); } while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) @@ -4166,7 +4007,7 @@ otError Interpreter::ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]) otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } - OutputFormat("\r\n"); + OutputLine(""); } } else @@ -4252,14 +4093,13 @@ otError Interpreter::ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]) if (i == OT_EXT_ADDRESS_SIZE) { - OutputFormat("Default rss: %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputLine("Default rss: %d (lqi %d)", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } else { OutputBytes(entry.mExtAddress.m8, OT_EXT_ADDRESS_SIZE); - OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputLine(" : rss %d (lqi %d)", entry.mRssIn, otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } } } @@ -4352,7 +4192,7 @@ void Interpreter::ProcessMac(uint8_t aArgsLength, char *aArgs[]) } exit: - AppendResult(error); + OutputResult(error); } otError Interpreter::ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]) @@ -4365,7 +4205,7 @@ otError Interpreter::ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesDirect(mInstance)); + OutputLine("%d", otLinkGetMaxFrameRetriesDirect(mInstance)); } else { @@ -4382,7 +4222,7 @@ otError Interpreter::ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesIndirect(mInstance)); + OutputLine("%d", otLinkGetMaxFrameRetriesIndirect(mInstance)); } else { @@ -4416,57 +4256,78 @@ void Interpreter::ProcessDiag(uint8_t aArgsLength, char *aArgs[]) error = otDiagProcessCmd(mInstance, aArgsLength, aArgs, output, sizeof(output) - 1); Output(output, static_cast(strlen(output))); - AppendResult(error); + OutputResult(error); } #endif +const Interpreter::Command *Interpreter::FindCommand(const char *aName) const +{ + const Command *rval = nullptr; + uint16_t left = 0; + uint16_t right = OT_ARRAY_LENGTH(sCommands); + + while (left < right) + { + uint16_t middle = (left + right) / 2; + int compare = strcmp(aName, sCommands[middle].mName); + + if (compare == 0) + { + rval = &sCommands[middle]; + break; + } + else if (compare > 0) + { + left = middle + 1; + } + else + { + right = middle; + } + } + + return rval; +} + void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength) { - char * aArgs[kMaxArgs] = {nullptr}; - char * cmd; - uint8_t aArgsLength = 0; - size_t i = 0; + char * aArgs[kMaxArgs] = {nullptr}; + char * cmdName; + uint8_t aArgsLength = 0; + const Command *command; VerifyOrExit(aBuf != nullptr && StringLength(aBuf, aBufLength + 1) <= aBufLength, OT_NOOP); VerifyOrExit(Utils::CmdLineParser::ParseCmd(aBuf, aArgsLength, aArgs, kMaxArgs) == OT_ERROR_NONE, - OutputFormat("Error: too many args (max %d)\r\n", kMaxArgs)); - VerifyOrExit(aArgsLength >= 1, OutputFormat("Error: no given command.\r\n")); + OutputLine("Error: too many args (max %d)", kMaxArgs)); + VerifyOrExit(aArgsLength >= 1, OutputLine("Error: no given command.")); - cmd = aArgs[0]; + cmdName = aArgs[0]; #if OPENTHREAD_CONFIG_DIAG_ENABLE - VerifyOrExit((!otDiagIsEnabled(mInstance) || (strcmp(cmd, "diag") == 0)), - OutputFormat("under diagnostics mode, execute 'diag stop' before running any other commands.\r\n")); + VerifyOrExit((!otDiagIsEnabled(mInstance) || (strcmp(cmdName, "diag") == 0)), + OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands.")); #endif - for (i = 0; i < OT_ARRAY_LENGTH(sCommands); i++) + command = FindCommand(cmdName); + + if (command != nullptr) { - if (strcmp(cmd, sCommands[i].mName) == 0) + (this->*command->mCommand)(aArgsLength - 1, &aArgs[1]); + ExitNow(); + } + + // Check user defined commands if built-in command has not been found + for (uint8_t i = 0; i < mUserCommandsLength; i++) + { + if (strcmp(cmdName, mUserCommands[i].mName) == 0) { - (this->*sCommands[i].mCommand)(aArgsLength - 1, &aArgs[1]); - break; + mUserCommands[i].mCommand(aArgsLength - 1, &aArgs[1]); + ExitNow(); } } - // Check user defined commands if built-in command - // has not been found - if (i == OT_ARRAY_LENGTH(sCommands)) - { - for (i = 0; i < mUserCommandsLength; i++) - { - if (strcmp(cmd, mUserCommands[i].mName) == 0) - { - mUserCommands[i].mCommand(aArgsLength - 1, &aArgs[1]); - break; - } - } - - if (i == mUserCommandsLength) - { - AppendResult(OT_ERROR_INVALID_COMMAND); - } - } + OutputResult(OT_ERROR_INVALID_COMMAND); exit: return; @@ -4503,7 +4364,7 @@ void Interpreter::ProcessNetworkDiagnostic(uint8_t aArgsLength, char *aArgs[]) else if (strcmp(aArgs[0], "reset") == 0) { IgnoreError(otThreadSendDiagnosticReset(mInstance, &address, tlvTypes, count)); - AppendResult(OT_ERROR_NONE); + OutputResult(OT_ERROR_NONE); } else { @@ -4513,7 +4374,7 @@ void Interpreter::ProcessNetworkDiagnostic(uint8_t aArgsLength, char *aArgs[]) exit: if (error != OT_ERROR_NONE) { - AppendResult(error); + OutputResult(error); } } @@ -4546,7 +4407,7 @@ void Interpreter::HandleDiagnosticGetResponse(const otMessage &aMessage, const I bytesPrinted += bytesToPrint; } - OutputFormat("\r\n"); + OutputLine(""); // Output Network Diagnostic TLV values in standard YAML format. while ((error = otThreadGetNextDiagnosticTlv(&aMessage, &iterator, &diagTlv)) == OT_ERROR_NONE) @@ -4557,76 +4418,76 @@ void Interpreter::HandleDiagnosticGetResponse(const otMessage &aMessage, const I case OT_NETWORK_DIAGNOSTIC_TLV_EXT_ADDRESS: OutputFormat("Ext Address: '"); OutputBytes(diagTlv.mData.mExtAddress.m8, sizeof(diagTlv.mData.mExtAddress.m8)); - OutputFormat("'\r\n"); + OutputLine("'"); break; case OT_NETWORK_DIAGNOSTIC_TLV_SHORT_ADDRESS: - OutputFormat("Rloc16: 0x%04x\r\n", diagTlv.mData.mAddr16); + OutputLine("Rloc16: 0x%04x", diagTlv.mData.mAddr16); break; case OT_NETWORK_DIAGNOSTIC_TLV_MODE: - OutputFormat("Mode:\r\n"); - OutputMode(diagTlv.mData.mMode, column + INDENT_SIZE); + OutputLine("Mode:"); + OutputMode(diagTlv.mData.mMode, column + kIndentationSize); break; case OT_NETWORK_DIAGNOSTIC_TLV_TIMEOUT: - OutputFormat("Timeout: %u\r\n", diagTlv.mData.mTimeout); + OutputLine("Timeout: %u", diagTlv.mData.mTimeout); break; case OT_NETWORK_DIAGNOSTIC_TLV_CONNECTIVITY: - OutputFormat("Connectivity:\r\n"); - OutputConnectivity(diagTlv.mData.mConnectivity, column + INDENT_SIZE); + OutputLine("Connectivity:"); + OutputConnectivity(diagTlv.mData.mConnectivity, column + kIndentationSize); break; case OT_NETWORK_DIAGNOSTIC_TLV_ROUTE: - OutputFormat("Route:\r\n"); - OutputRoute(diagTlv.mData.mRoute, column + INDENT_SIZE); + OutputLine("Route:"); + OutputRoute(diagTlv.mData.mRoute, column + kIndentationSize); break; case OT_NETWORK_DIAGNOSTIC_TLV_LEADER_DATA: - OutputFormat("Leader Data:\r\n"); - OutputLeaderData(diagTlv.mData.mLeaderData, column + INDENT_SIZE); + OutputLine("Leader Data:"); + OutputLeaderData(diagTlv.mData.mLeaderData, column + kIndentationSize); break; case OT_NETWORK_DIAGNOSTIC_TLV_NETWORK_DATA: OutputFormat("Network Data: '"); OutputBytes(diagTlv.mData.mNetworkData.m8, diagTlv.mData.mNetworkData.mCount); - OutputFormat("'\r\n"); + OutputLine("'"); break; case OT_NETWORK_DIAGNOSTIC_TLV_IP6_ADDR_LIST: - OutputFormat("IP6 Address List:\r\n"); + OutputLine("IP6 Address List:"); for (uint16_t i = 0; i < diagTlv.mData.mIp6AddrList.mCount; ++i) { - OutputSpaces(column + INDENT_SIZE); + OutputSpaces(column + kIndentationSize); OutputFormat("- "); OutputIp6Address(diagTlv.mData.mIp6AddrList.mList[i]); - OutputFormat("\r\n"); + OutputLine(""); } break; case OT_NETWORK_DIAGNOSTIC_TLV_MAC_COUNTERS: - OutputFormat("MAC Counters:\r\n"); - OutputNetworkDiagMacCounters(diagTlv.mData.mMacCounters, column + INDENT_SIZE); + OutputLine("MAC Counters:"); + OutputNetworkDiagMacCounters(diagTlv.mData.mMacCounters, column + kIndentationSize); break; case OT_NETWORK_DIAGNOSTIC_TLV_BATTERY_LEVEL: - OutputFormat("Battery Level: %u%%\r\n", diagTlv.mData.mBatteryLevel); + OutputLine("Battery Level: %u%%", diagTlv.mData.mBatteryLevel); break; case OT_NETWORK_DIAGNOSTIC_TLV_SUPPLY_VOLTAGE: - OutputFormat("Supply Voltage: %umV\r\n", diagTlv.mData.mSupplyVoltage); + OutputLine("Supply Voltage: %umV", diagTlv.mData.mSupplyVoltage); break; case OT_NETWORK_DIAGNOSTIC_TLV_CHILD_TABLE: - OutputFormat("Child Table:\r\n"); + OutputLine("Child Table:"); for (uint16_t i = 0; i < diagTlv.mData.mChildTable.mCount; ++i) { - OutputSpaces(column + INDENT_SIZE); + OutputSpaces(column + kIndentationSize); OutputFormat("- "); - OutputChildTableEntry(diagTlv.mData.mChildTable.mTable[i], column + INDENT_SIZE + 2); + OutputChildTableEntry(diagTlv.mData.mChildTable.mTable[i], column + kIndentationSize + 2); } break; case OT_NETWORK_DIAGNOSTIC_TLV_CHANNEL_PAGES: OutputFormat("Channel Pages: '"); OutputBytes(diagTlv.mData.mChannelPages.m8, diagTlv.mData.mChannelPages.mCount); - OutputFormat("'\r\n"); + OutputLine("'"); break; case OT_NETWORK_DIAGNOSTIC_TLV_MAX_CHILD_TIMEOUT: - OutputFormat("Max Child Timeout: %u\r\n", diagTlv.mData.mMaxChildTimeout); + OutputLine("Max Child Timeout: %u", diagTlv.mData.mMaxChildTimeout); break; } } - AppendResult(error == OT_ERROR_NOT_FOUND ? OT_ERROR_NONE : error); + OutputResult(error == OT_ERROR_NOT_FOUND ? OT_ERROR_NONE : error); } void Interpreter::OutputSpaces(uint16_t aCount) @@ -4647,57 +4508,57 @@ void Interpreter::OutputSpaces(uint16_t aCount) void Interpreter::OutputMode(const otLinkModeConfig &aMode, uint16_t aColumn) { OutputSpaces(aColumn); - OutputFormat("RxOnWhenIdle: %d\r\n", aMode.mRxOnWhenIdle); + OutputLine("RxOnWhenIdle: %d", aMode.mRxOnWhenIdle); OutputSpaces(aColumn); - OutputFormat("SecureDataRequests: %d\r\n", aMode.mSecureDataRequests); + OutputLine("SecureDataRequests: %d", aMode.mSecureDataRequests); OutputSpaces(aColumn); - OutputFormat("DeviceType: %d\r\n", aMode.mDeviceType); + OutputLine("DeviceType: %d", aMode.mDeviceType); OutputSpaces(aColumn); - OutputFormat("NetworkData: %d\r\n", aMode.mNetworkData); + OutputLine("NetworkData: %d", aMode.mNetworkData); } void Interpreter::OutputConnectivity(const otNetworkDiagConnectivity &aConnectivity, uint16_t aColumn) { OutputSpaces(aColumn); - OutputFormat("ParentPriority: %d\r\n", aConnectivity.mParentPriority); + OutputLine("ParentPriority: %d", aConnectivity.mParentPriority); OutputSpaces(aColumn); - OutputFormat("LinkQuality3: %u\r\n", aConnectivity.mLinkQuality3); + OutputLine("LinkQuality3: %u", aConnectivity.mLinkQuality3); OutputSpaces(aColumn); - OutputFormat("LinkQuality2: %u\r\n", aConnectivity.mLinkQuality2); + OutputLine("LinkQuality2: %u", aConnectivity.mLinkQuality2); OutputSpaces(aColumn); - OutputFormat("LinkQuality1: %u\r\n", aConnectivity.mLinkQuality1); + OutputLine("LinkQuality1: %u", aConnectivity.mLinkQuality1); OutputSpaces(aColumn); - OutputFormat("LeaderCost: %u\r\n", aConnectivity.mLeaderCost); + OutputLine("LeaderCost: %u", aConnectivity.mLeaderCost); OutputSpaces(aColumn); - OutputFormat("IdSequence: %u\r\n", aConnectivity.mIdSequence); + OutputLine("IdSequence: %u", aConnectivity.mIdSequence); OutputSpaces(aColumn); - OutputFormat("ActiveRouters: %u\r\n", aConnectivity.mActiveRouters); + OutputLine("ActiveRouters: %u", aConnectivity.mActiveRouters); OutputSpaces(aColumn); - OutputFormat("SedBufferSize: %u\r\n", aConnectivity.mSedBufferSize); + OutputLine("SedBufferSize: %u", aConnectivity.mSedBufferSize); OutputSpaces(aColumn); - OutputFormat("SedDatagramCount: %u\r\n", aConnectivity.mSedDatagramCount); + OutputLine("SedDatagramCount: %u", aConnectivity.mSedDatagramCount); } void Interpreter::OutputRoute(const otNetworkDiagRoute &aRoute, uint16_t aColumn) { OutputSpaces(aColumn); - OutputFormat("IdSequence: %u\r\n", aRoute.mIdSequence); + OutputLine("IdSequence: %u", aRoute.mIdSequence); OutputSpaces(aColumn); - OutputFormat("RouteData:\r\n"); + OutputLine("RouteData:"); - aColumn += INDENT_SIZE; + aColumn += kIndentationSize; for (uint16_t i = 0; i < aRoute.mRouteCount; ++i) { OutputSpaces(aColumn); @@ -4709,77 +4570,77 @@ void Interpreter::OutputRoute(const otNetworkDiagRoute &aRoute, uint16_t aColumn void Interpreter::OutputRouteData(const otNetworkDiagRouteData &aRouteData, uint16_t aColumn) { - OutputFormat("RouteId: 0x%02x\r\n", aRouteData.mRouterId); + OutputLine("RouteId: 0x%02x", aRouteData.mRouterId); OutputSpaces(aColumn); - OutputFormat("LinkQualityOut: %u\r\n", aRouteData.mLinkQualityOut); + OutputLine("LinkQualityOut: %u", aRouteData.mLinkQualityOut); OutputSpaces(aColumn); - OutputFormat("LinkQualityIn: %u\r\n", aRouteData.mLinkQualityIn); + OutputLine("LinkQualityIn: %u", aRouteData.mLinkQualityIn); OutputSpaces(aColumn); - OutputFormat("RouteCost: %u\r\n", aRouteData.mRouteCost); + OutputLine("RouteCost: %u", aRouteData.mRouteCost); } void Interpreter::OutputLeaderData(const otLeaderData &aLeaderData, uint16_t aColumn) { OutputSpaces(aColumn); - OutputFormat("PartitionId: 0x%08x\r\n", aLeaderData.mPartitionId); + OutputLine("PartitionId: 0x%08x", aLeaderData.mPartitionId); OutputSpaces(aColumn); - OutputFormat("Weighting: %u\r\n", aLeaderData.mWeighting); + OutputLine("Weighting: %u", aLeaderData.mWeighting); OutputSpaces(aColumn); - OutputFormat("DataVersion: %u\r\n", aLeaderData.mDataVersion); + OutputLine("DataVersion: %u", aLeaderData.mDataVersion); OutputSpaces(aColumn); - OutputFormat("StableDataVersion: %u\r\n", aLeaderData.mStableDataVersion); + OutputLine("StableDataVersion: %u", aLeaderData.mStableDataVersion); OutputSpaces(aColumn); - OutputFormat("LeaderRouterId: 0x%02x\r\n", aLeaderData.mLeaderRouterId); + OutputLine("LeaderRouterId: 0x%02x", aLeaderData.mLeaderRouterId); } void Interpreter::OutputNetworkDiagMacCounters(const otNetworkDiagMacCounters &aMacCounters, uint16_t aColumn) { OutputSpaces(aColumn); - OutputFormat("IfInUnknownProtos: %u\r\n", aMacCounters.mIfInUnknownProtos); + OutputLine("IfInUnknownProtos: %u", aMacCounters.mIfInUnknownProtos); OutputSpaces(aColumn); - OutputFormat("IfInErrors: %u\r\n", aMacCounters.mIfInErrors); + OutputLine("IfInErrors: %u", aMacCounters.mIfInErrors); OutputSpaces(aColumn); - OutputFormat("IfOutErrors: %u\r\n", aMacCounters.mIfOutErrors); + OutputLine("IfOutErrors: %u", aMacCounters.mIfOutErrors); OutputSpaces(aColumn); - OutputFormat("IfInUcastPkts: %u\r\n", aMacCounters.mIfInUcastPkts); + OutputLine("IfInUcastPkts: %u", aMacCounters.mIfInUcastPkts); OutputSpaces(aColumn); - OutputFormat("IfInBroadcastPkts: %u\r\n", aMacCounters.mIfInBroadcastPkts); + OutputLine("IfInBroadcastPkts: %u", aMacCounters.mIfInBroadcastPkts); OutputSpaces(aColumn); - OutputFormat("IfInDiscards: %u\r\n", aMacCounters.mIfInDiscards); + OutputLine("IfInDiscards: %u", aMacCounters.mIfInDiscards); OutputSpaces(aColumn); - OutputFormat("IfOutUcastPkts: %u\r\n", aMacCounters.mIfOutUcastPkts); + OutputLine("IfOutUcastPkts: %u", aMacCounters.mIfOutUcastPkts); OutputSpaces(aColumn); - OutputFormat("IfOutBroadcastPkts: %u\r\n", aMacCounters.mIfOutBroadcastPkts); + OutputLine("IfOutBroadcastPkts: %u", aMacCounters.mIfOutBroadcastPkts); OutputSpaces(aColumn); - OutputFormat("IfOutDiscards: %u\r\n", aMacCounters.mIfOutDiscards); + OutputLine("IfOutDiscards: %u", aMacCounters.mIfOutDiscards); } void Interpreter::OutputChildTableEntry(const otNetworkDiagChildEntry &aChildEntry, uint16_t aColumn) { - OutputFormat("ChildId: 0x%04x\r\n", aChildEntry.mChildId); + OutputLine("ChildId: 0x%04x", aChildEntry.mChildId); OutputSpaces(aColumn); - OutputFormat("Timeout: %u\r\n", aChildEntry.mTimeout); + OutputLine("Timeout: %u", aChildEntry.mTimeout); OutputSpaces(aColumn); - OutputFormat("Mode:\r\n"); + OutputLine("Mode:"); - OutputMode(aChildEntry.mMode, aColumn + INDENT_SIZE); + OutputMode(aChildEntry.mMode, aColumn + kIndentationSize); } #endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE @@ -4835,7 +4696,7 @@ void Interpreter::HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aIn { OutputFormat("~ Discovery Request from "); OutputBytes(aInfo.mExtAddress.m8, sizeof(aInfo.mExtAddress.m8)); - OutputFormat(": version=%u,joiner=%d\r\n", aInfo.mVersion, aInfo.mIsJoiner); + OutputLine(": version=%u,joiner=%d", aInfo.mVersion, aInfo.mIsJoiner); } int Interpreter::OutputFormat(const char *aFormat, ...) @@ -4850,6 +4711,17 @@ int Interpreter::OutputFormat(const char *aFormat, ...) return rval; } +void Interpreter::OutputLine(const char *aFormat, ...) +{ + va_list args; + + va_start(args, aFormat); + OutputFormatV(aFormat, args); + va_end(args); + + OutputFormat("\r\n"); +} + int Interpreter::OutputFormatV(const char *aFormat, va_list aArguments) { char buf[kMaxLineLength]; @@ -4884,7 +4756,7 @@ extern "C" void otCliOutput(const char *aString, uint16_t aLength) extern "C" void otCliAppendResult(otError aError) { - Interpreter::GetInterpreter().AppendResult(aError); + Interpreter::GetInterpreter().OutputResult(aError); } extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs) @@ -4895,7 +4767,7 @@ extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, cons VerifyOrExit(Interpreter::IsInitialized(), OT_NOOP); Interpreter::GetInterpreter().OutputFormatV(aFormat, aArgs); - Interpreter::GetInterpreter().OutputFormat("\r\n"); + Interpreter::GetInterpreter().OutputLine(""); exit: return; } @@ -4918,4 +4790,4 @@ OT_TOOL_WEAK void otNcpHandleLegacyNodeDidJoin(const otExtAddress *aExtAddr) { OT_UNUSED_VARIABLE(aExtAddr); } -#endif // OPENTHREAD_CONFIG_LEGACY_ENABLE +#endif diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 4098957ac..66ccc151d 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -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]; diff --git a/src/cli/cli_coap.cpp b/src/cli/cli_coap.cpp index f3f351917..893eb58eb 100644 --- a/src/cli/cli_coap.cpp +++ b/src/cli/cli_coap.cpp @@ -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)) { diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index f696082f3..f063a7ae6 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -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 { diff --git a/src/cli/cli_commissioner.cpp b/src/cli/cli_commissioner.cpp index 38a778ba3..be9f12135 100644 --- a/src/cli/cli_commissioner.cpp +++ b/src/cli/cli_commissioner.cpp @@ -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(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 diff --git a/src/cli/cli_dataset.cpp b/src/cli/cli_dataset.cpp index 580b40742..f6fb28277 100644 --- a/src/cli/cli_dataset.cpp +++ b/src/cli/cli_dataset.cpp @@ -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(prefix[0]) << 8) | prefix[1], + mInterpreter.OutputLine( + "Mesh Local Prefix: %x:%x:%x:%x::/64", (static_cast(prefix[0]) << 8) | prefix[1], (static_cast(prefix[2]) << 8) | prefix[3], (static_cast(prefix[4]) << 8) | prefix[5], (static_cast(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(sizeof(aDataset.mNetworkName)), - aDataset.mNetworkName.m8); + mInterpreter.OutputLine("%.*s", static_cast(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(prefix[0]) << 8) | prefix[1], - (static_cast(prefix[2]) << 8) | prefix[3], - (static_cast(prefix[4]) << 8) | prefix[5], - (static_cast(prefix[6]) << 8) | prefix[7]); + mInterpreter.OutputLine("Mesh Local Prefix: %x:%x:%x:%x::/64", + (static_cast(prefix[0]) << 8) | prefix[1], + (static_cast(prefix[2]) << 8) | prefix[3], + (static_cast(prefix[4]) << 8) | prefix[5], + (static_cast(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(sizeof(sDataset.mNetworkName)), - sDataset.mNetworkName.m8); + mInterpreter.OutputLine("%.*s", static_cast(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 diff --git a/src/cli/cli_joiner.cpp b/src/cli/cli_joiner.cpp index a3464e39f..d4335fc73 100644 --- a/src/cli/cli_joiner.cpp +++ b/src/cli/cli_joiner.cpp @@ -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; } } diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index 57cee96d5..cca0b0c85 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -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 diff --git a/tests/toranj/build.sh b/tests/toranj/build.sh index c498afa31..792485911 100755 --- a/tests/toranj/build.sh +++ b/tests/toranj/build.sh @@ -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