diff --git a/Android.mk b/Android.mk index ff9a6754d..8decf8db3 100644 --- a/Android.mk +++ b/Android.mk @@ -139,7 +139,6 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \ LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_SRC_FILES := \ @@ -351,7 +350,6 @@ LOCAL_CFLAGS := \ LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_SRC_FILES := \ @@ -362,7 +360,6 @@ LOCAL_SRC_FILES := \ src/cli/cli_console.cpp \ src/cli/cli_dataset.cpp \ src/cli/cli_joiner.cpp \ - src/cli/cli_server.cpp \ src/cli/cli_uart.cpp \ src/cli/cli_udp.cpp \ $(NULL) @@ -396,7 +393,6 @@ LOCAL_CFLAGS := \ LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_LDLIBS := \ @@ -436,7 +432,6 @@ LOCAL_CFLAGS := \ LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_SRC_FILES := \ @@ -478,7 +473,6 @@ LOCAL_CFLAGS := \ LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_SRC_FILES := \ @@ -502,7 +496,6 @@ LOCAL_MODULE_TAGS := eng LOCAL_CPPFLAGS := \ -std=c++11 \ -pedantic-errors \ - -Wno-non-virtual-dtor \ $(NULL) LOCAL_CFLAGS := \ diff --git a/BUILD.gn b/BUILD.gn index b9aa6cc31..5e03ad26b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -38,8 +38,6 @@ config("openthread_config") { "${root_gen_dir}/include", "include", ] - - cflags_cc = [ "-Wno-non-virtual-dtor" ] } config("openthread_ftd_config") { diff --git a/examples/apps/cli/Makefile.am b/examples/apps/cli/Makefile.am index 28282e64e..0d3e74115 100644 --- a/examples/apps/cli/Makefile.am +++ b/examples/apps/cli/Makefile.am @@ -34,6 +34,7 @@ bin_PROGRAMS = \ CPPFLAGS_COMMON += \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ -I$(top_srcdir)/src/core \ -I$(top_srcdir)/examples/platforms \ $(NULL) diff --git a/examples/apps/cli/main.c b/examples/apps/cli/main.c index 5257df5b6..184cbd79a 100644 --- a/examples/apps/cli/main.c +++ b/examples/apps/cli/main.c @@ -36,6 +36,7 @@ #include #include "openthread-system.h" +#include "cli/cli_config.h" #if OPENTHREAD_EXAMPLES_SIMULATION #include @@ -106,7 +107,9 @@ pseudo_reset: #endif assert(instance); +#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART otCliUartInit(instance); +#endif while (!otSysPseudoResetWasRequested()) { diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 623dec833..7fc052f3f 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -40,6 +40,7 @@ COVERAGE ?= 0 CHANNEL_MANAGER ?= 0 CHANNEL_MONITOR ?= 0 CHILD_SUPERVISION ?= 0 +CLI_TRANSPORT ?= UART DEBUG ?= 0 DHCP6_CLIENT ?= 0 DHCP6_SERVER ?= 0 @@ -125,6 +126,10 @@ ifeq ($(CHILD_SUPERVISION),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1 endif +ifneq ($(CLI_TRANSPORT),) +COMMONCFLAGS += -DOPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_$(CLI_TRANSPORT) +endif + ifeq ($(CSL_RECEIVER),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1 endif diff --git a/script/check-posix-pty b/script/check-posix-pty index 78fde388f..86fa33f84 100755 --- a/script/check-posix-pty +++ b/script/check-posix-pty @@ -139,7 +139,7 @@ EOF netstat -an | grep -q 61631 || die 'TMF port is not available!' - extaddr=$(awk '/extaddr/{getline; print}' $OT_OUTPUT | tr -d '\r\n') + extaddr=$(grep -aoE '[0-9a-z]{16}' $OT_OUTPUT) echo "Extended address is: ${extaddr}" if [[ ${DAEMON} == 1 ]]; then diff --git a/src/cli/BUILD.gn b/src/cli/BUILD.gn index e4a88618f..6ed4a8129 100644 --- a/src/cli/BUILD.gn +++ b/src/cli/BUILD.gn @@ -41,8 +41,6 @@ openthread_cli_sources = [ "cli_dataset.hpp", "cli_joiner.cpp", "cli_joiner.hpp", - "cli_server.cpp", - "cli_server.hpp", "cli_uart.cpp", "cli_uart.hpp", "cli_udp.cpp", diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 2dbbde310..2122c202a 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -29,6 +29,13 @@ add_library(openthread-cli-ftd) add_library(openthread-cli-mtd) +set(OT_CLI_TRANSPORT "UART" CACHE STRING "set the CLI transport") +set(OT_CLI_TRANSPORT_VALUES + "UART" + "CONSOLE" +) +set_property(CACHE OT_CLI_TRANSPORT PROPERTY STRINGS ${OT_CLI_TRANSPORT_VALUES}) + set_target_properties( openthread-cli-ftd openthread-cli-mtd PROPERTIES @@ -36,12 +43,18 @@ set_target_properties( CXX_STANDARD 11 ) -target_compile_definitions(openthread-cli-ftd PRIVATE - OPENTHREAD_FTD=1 +target_compile_definitions(openthread-cli-ftd + PRIVATE + OPENTHREAD_FTD=1 + PUBLIC + "OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_${OT_CLI_TRANSPORT}" ) -target_compile_definitions(openthread-cli-mtd PRIVATE - OPENTHREAD_MTD=1 +target_compile_definitions(openthread-cli-mtd + PRIVATE + OPENTHREAD_MTD=1 + PUBLIC + "OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_${OT_CLI_TRANSPORT}" ) target_compile_options(openthread-cli-ftd PRIVATE @@ -65,7 +78,6 @@ set(COMMON_SOURCES cli_console.cpp cli_dataset.cpp cli_joiner.cpp - cli_server.cpp cli_uart.cpp cli_udp.cpp ) diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index a39cebf8c..fb881d9d5 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -157,7 +157,6 @@ SOURCES_COMMON = \ cli_console.cpp \ cli_dataset.cpp \ cli_joiner.cpp \ - cli_server.cpp \ cli_uart.cpp \ cli_udp.cpp \ $(NULL) @@ -179,7 +178,6 @@ noinst_HEADERS = \ cli_console.hpp \ cli_dataset.hpp \ cli_joiner.hpp \ - cli_server.hpp \ cli_uart.hpp \ cli_udp.hpp \ x509_cert_key.hpp \ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 0fdbbcca2..1f66809df 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -92,7 +92,6 @@ #include #endif -#include "cli_server.hpp" #include "common/encoding.hpp" #include "common/string.hpp" @@ -255,7 +254,6 @@ const struct Command Interpreter::sCommands[] = { Interpreter::Interpreter(Instance *aInstance) : mUserCommands(nullptr) , mUserCommandsLength(0) - , mServer(nullptr) , mPingLength(kDefaultPingLength) , mPingCount(kDefaultPingCount) , mPingInterval(kDefaultPingInterval) @@ -362,29 +360,29 @@ exit: return rval; } -void Interpreter::AppendResult(otError aError) const +void Interpreter::AppendResult(otError aError) { if (aError == OT_ERROR_NONE) { - mServer->OutputFormat("Done\r\n"); + OutputFormat("Done\r\n"); } else { - mServer->OutputFormat("Error %d: %s\r\n", aError, otThreadErrorToString(aError)); + OutputFormat("Error %d: %s\r\n", aError, otThreadErrorToString(aError)); } } -void Interpreter::OutputBytes(const uint8_t *aBytes, uint8_t aLength) const +void Interpreter::OutputBytes(const uint8_t *aBytes, uint8_t aLength) { for (int i = 0; i < aLength; i++) { - mServer->OutputFormat("%02x", aBytes[i]); + OutputFormat("%02x", aBytes[i]); } } -int Interpreter::OutputIp6Address(const otIp6Address &aAddress) const +int Interpreter::OutputIp6Address(const otIp6Address &aAddress) { - return mServer->OutputFormat( + return OutputFormat( "%x:%x:%x:%x:%x:%x:%x:%x", HostSwap16(aAddress.mFields.m16[0]), HostSwap16(aAddress.mFields.m16[1]), HostSwap16(aAddress.mFields.m16[2]), HostSwap16(aAddress.mFields.m16[3]), HostSwap16(aAddress.mFields.m16[4]), HostSwap16(aAddress.mFields.m16[5]), HostSwap16(aAddress.mFields.m16[6]), HostSwap16(aAddress.mFields.m16[7])); @@ -481,12 +479,12 @@ void Interpreter::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mServer->OutputFormat("%s\r\n", command.mName); + OutputFormat("%s\r\n", command.mName); } for (uint8_t i = 0; i < mUserCommandsLength; i++) { - mServer->OutputFormat("%s\r\n", mUserCommands[i].mName); + OutputFormat("%s\r\n", mUserCommands[i].mName); } AppendResult(OT_ERROR_NONE); @@ -503,15 +501,15 @@ void Interpreter::ProcessBackboneRouter(uint8_t aArgsLength, char *aArgs[]) { if (otBackboneRouterGetPrimary(mInstance, &config) == OT_ERROR_NONE) { - mServer->OutputFormat("BBR Primary:\r\n"); - mServer->OutputFormat("server16: 0x%04X\r\n", config.mServer16); - mServer->OutputFormat("seqno: %d\r\n", config.mSequenceNumber); - mServer->OutputFormat("delay: %d secs\r\n", config.mReregistrationDelay); - mServer->OutputFormat("timeout: %d secs\r\n", config.mMlrTimeout); + 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); } else { - mServer->OutputFormat("BBR Primary: None\r\n"); + OutputFormat("BBR Primary: None\r\n"); } error = OT_ERROR_NONE; @@ -573,7 +571,7 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otBackboneRouterGetRegistrationJitter(mInstance)); + OutputFormat("%d\r\n", otBackboneRouterGetRegistrationJitter(mInstance)); } else if (aArgsLength == 2) { @@ -590,13 +588,13 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs switch (otBackboneRouterGetState(mInstance)) { case OT_BACKBONE_ROUTER_STATE_DISABLED: - mServer->OutputFormat("Disabled\r\n"); + OutputFormat("Disabled\r\n"); break; case OT_BACKBONE_ROUTER_STATE_SECONDARY: - mServer->OutputFormat("Secondary\r\n"); + OutputFormat("Secondary\r\n"); break; case OT_BACKBONE_ROUTER_STATE_PRIMARY: - mServer->OutputFormat("Primary\r\n"); + OutputFormat("Primary\r\n"); break; } } @@ -606,9 +604,9 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs if (aArgsLength == 1) { - mServer->OutputFormat("seqno: %d\r\n", config.mSequenceNumber); - mServer->OutputFormat("delay: %d secs\r\n", config.mReregistrationDelay); - mServer->OutputFormat("timeout: %d secs\r\n", config.mMlrTimeout); + OutputFormat("seqno: %d\r\n", config.mSequenceNumber); + OutputFormat("delay: %d secs\r\n", config.mReregistrationDelay); + OutputFormat("timeout: %d secs\r\n", config.mMlrTimeout); } else { @@ -658,7 +656,7 @@ void Interpreter::ProcessDomainName(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { const char *domainName = otThreadGetDomainName(mInstance); - mServer->OutputFormat("%s\r\n", static_cast(domainName)); + OutputFormat("%s\r\n", static_cast(domainName)); } else { @@ -685,7 +683,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) if (iid != nullptr) { OutputBytes(iid->mFields.m8, sizeof(otIp6InterfaceIdentifier)); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } break; } @@ -725,18 +723,18 @@ void Interpreter::ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]) otMessageGetBufferInfo(mInstance, &bufferInfo); - mServer->OutputFormat("total: %d\r\n", bufferInfo.mTotalBuffers); - mServer->OutputFormat("free: %d\r\n", bufferInfo.mFreeBuffers); - mServer->OutputFormat("6lo send: %d %d\r\n", bufferInfo.m6loSendMessages, bufferInfo.m6loSendBuffers); - mServer->OutputFormat("6lo reas: %d %d\r\n", bufferInfo.m6loReassemblyMessages, bufferInfo.m6loReassemblyBuffers); - mServer->OutputFormat("ip6: %d %d\r\n", bufferInfo.mIp6Messages, bufferInfo.mIp6Buffers); - mServer->OutputFormat("mpl: %d %d\r\n", bufferInfo.mMplMessages, bufferInfo.mMplBuffers); - mServer->OutputFormat("mle: %d %d\r\n", bufferInfo.mMleMessages, bufferInfo.mMleBuffers); - mServer->OutputFormat("arp: %d %d\r\n", bufferInfo.mArpMessages, bufferInfo.mArpBuffers); - mServer->OutputFormat("coap: %d %d\r\n", bufferInfo.mCoapMessages, bufferInfo.mCoapBuffers); - mServer->OutputFormat("coap secure: %d %d\r\n", bufferInfo.mCoapSecureMessages, bufferInfo.mCoapSecureBuffers); - mServer->OutputFormat("application coap: %d %d\r\n", bufferInfo.mApplicationCoapMessages, - bufferInfo.mApplicationCoapBuffers); + 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); AppendResult(OT_ERROR_NONE); } @@ -748,33 +746,33 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otLinkGetChannel(mInstance)); + OutputFormat("%d\r\n", otLinkGetChannel(mInstance)); } else if (strcmp(aArgs[0], "supported") == 0) { - mServer->OutputFormat("0x%x\r\n", otPlatRadioGetSupportedChannelMask(mInstance)); + OutputFormat("0x%x\r\n", otPlatRadioGetSupportedChannelMask(mInstance)); } else if (strcmp(aArgs[0], "preferred") == 0) { - mServer->OutputFormat("0x%x\r\n", otPlatRadioGetPreferredChannelMask(mInstance)); + OutputFormat("0x%x\r\n", otPlatRadioGetPreferredChannelMask(mInstance)); } #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE else if (strcmp(aArgs[0], "monitor") == 0) { if (aArgsLength == 1) { - mServer->OutputFormat("enabled: %d\r\n", otChannelMonitorIsEnabled(mInstance)); + OutputFormat("enabled: %d\r\n", otChannelMonitorIsEnabled(mInstance)); if (otChannelMonitorIsEnabled(mInstance)) { uint32_t channelMask = otLinkGetSupportedChannelMask(mInstance); uint8_t channelNum = sizeof(channelMask) * CHAR_BIT; - mServer->OutputFormat("interval: %u\r\n", otChannelMonitorGetSampleInterval(mInstance)); - mServer->OutputFormat("threshold: %d\r\n", otChannelMonitorGetRssiThreshold(mInstance)); - mServer->OutputFormat("window: %u\r\n", otChannelMonitorGetSampleWindow(mInstance)); - mServer->OutputFormat("count: %u\r\n", otChannelMonitorGetSampleCount(mInstance)); + 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)); - mServer->OutputFormat("occupancies:\r\n"); + OutputFormat("occupancies:\r\n"); for (uint8_t channel = 0; channel < channelNum; channel++) { uint32_t occupancy = 0; @@ -786,11 +784,11 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) occupancy = otChannelMonitorGetChannelOccupancy(mInstance, channel); - mServer->OutputFormat("ch %d (0x%04x) ", channel, occupancy); + OutputFormat("ch %d (0x%04x) ", channel, occupancy); occupancy = (occupancy * 10000) / 0xffff; - mServer->OutputFormat("%2d.%02d%% busy\r\n", occupancy / 100, occupancy % 100); + OutputFormat("%2d.%02d%% busy\r\n", occupancy / 100, occupancy % 100); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } } else if (strcmp(aArgs[1], "start") == 0) @@ -812,18 +810,18 @@ void Interpreter::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("channel: %d\r\n", otChannelManagerGetRequestedChannel(mInstance)); - mServer->OutputFormat("auto: %d\r\n", otChannelManagerGetAutoChannelSelectionEnabled(mInstance)); + OutputFormat("channel: %d\r\n", otChannelManagerGetRequestedChannel(mInstance)); + OutputFormat("auto: %d\r\n", otChannelManagerGetAutoChannelSelectionEnabled(mInstance)); if (otChannelManagerGetAutoChannelSelectionEnabled(mInstance)) { Mac::ChannelMask supportedMask(otChannelManagerGetSupportedChannels(mInstance)); Mac::ChannelMask favoredMask(otChannelManagerGetFavoredChannels(mInstance)); - mServer->OutputFormat("delay: %d\r\n", otChannelManagerGetDelay(mInstance)); - mServer->OutputFormat("interval: %lu\r\n", otChannelManagerGetAutoChannelSelectionInterval(mInstance)); - mServer->OutputFormat("supported: %s\r\n", supportedMask.ToString().AsCString()); - mServer->OutputFormat("favored: %s\r\n", supportedMask.ToString().AsCString()); + OutputFormat("delay: %d\r\n", otChannelManagerGetDelay(mInstance)); + OutputFormat("interval: %lu\r\n", otChannelManagerGetAutoChannelSelectionInterval(mInstance)); + OutputFormat("supported: %s\r\n", supportedMask.ToString().AsCString()); + OutputFormat("favored: %s\r\n", supportedMask.ToString().AsCString()); } } else if (strcmp(aArgs[1], "change") == 0) @@ -904,10 +902,8 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - mServer->OutputFormat( - "| ID | RLOC16 | Timeout | Age | LQ In | C_VN |R|S|D|N| Extended MAC |\r\n"); - mServer->OutputFormat( - "+-----+--------+------------+------------+-------+------+-+-+-+-+------------------+\r\n"); + OutputFormat("| ID | RLOC16 | Timeout | Age | LQ In | C_VN |R|S|D|N| Extended MAC |\r\n"); + OutputFormat("+-----+--------+------------+------------+-------+------+-+-+-+-+------------------+\r\n"); } maxChildren = otThreadGetMaxAllowedChildren(mInstance); @@ -921,77 +917,77 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - mServer->OutputFormat("| %3d ", childInfo.mChildId); - mServer->OutputFormat("| 0x%04x ", childInfo.mRloc16); - mServer->OutputFormat("| %10d ", childInfo.mTimeout); - mServer->OutputFormat("| %10d ", childInfo.mAge); - mServer->OutputFormat("| %5d ", childInfo.mLinkQualityIn); - mServer->OutputFormat("| %4d ", childInfo.mNetworkDataVersion); - mServer->OutputFormat("|%1d", childInfo.mRxOnWhenIdle); - mServer->OutputFormat("|%1d", childInfo.mSecureDataRequest); - mServer->OutputFormat("|%1d", childInfo.mFullThreadDevice); - mServer->OutputFormat("|%1d", childInfo.mFullNetworkData); - mServer->OutputFormat("| "); + OutputFormat("| %3d ", childInfo.mChildId); + OutputFormat("| 0x%04x ", childInfo.mRloc16); + OutputFormat("| %10d ", childInfo.mTimeout); + OutputFormat("| %10d ", childInfo.mAge); + OutputFormat("| %5d ", childInfo.mLinkQualityIn); + OutputFormat("| %4d ", childInfo.mNetworkDataVersion); + OutputFormat("|%1d", childInfo.mRxOnWhenIdle); + OutputFormat("|%1d", childInfo.mSecureDataRequest); + OutputFormat("|%1d", childInfo.mFullThreadDevice); + OutputFormat("|%1d", childInfo.mFullNetworkData); + OutputFormat("| "); for (uint8_t b : childInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat(" |\r\n"); + OutputFormat(" |\r\n"); } else { - mServer->OutputFormat("%d ", childInfo.mChildId); + OutputFormat("%d ", childInfo.mChildId); } } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); ExitNow(); } SuccessOrExit(error = ParseLong(aArgs[0], value)); SuccessOrExit(error = otThreadGetChildInfoById(mInstance, static_cast(value), &childInfo)); - mServer->OutputFormat("Child ID: %d\r\n", childInfo.mChildId); - mServer->OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16); - mServer->OutputFormat("Ext Addr: "); + OutputFormat("Child ID: %d\r\n", childInfo.mChildId); + OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16); + OutputFormat("Ext Addr: "); for (uint8_t b : childInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat("\r\n"); - mServer->OutputFormat("Mode: "); + OutputFormat("\r\n"); + OutputFormat("Mode: "); if (childInfo.mRxOnWhenIdle) { - mServer->OutputFormat("r"); + OutputFormat("r"); } if (childInfo.mSecureDataRequest) { - mServer->OutputFormat("s"); + OutputFormat("s"); } if (childInfo.mFullThreadDevice) { - mServer->OutputFormat("d"); + OutputFormat("d"); } if (childInfo.mFullNetworkData) { - mServer->OutputFormat("n"); + OutputFormat("n"); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); - mServer->OutputFormat("Net Data: %d\r\n", childInfo.mNetworkDataVersion); - mServer->OutputFormat("Timeout: %d\r\n", childInfo.mTimeout); - mServer->OutputFormat("Age: %d\r\n", childInfo.mAge); - mServer->OutputFormat("Link Quality In: %d\r\n", childInfo.mLinkQualityIn); - mServer->OutputFormat("RSSI: %d\r\n", childInfo.mAverageRssi); + 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); exit: AppendResult(error); @@ -1022,9 +1018,9 @@ void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) while (otThreadGetChildNextIp6Address(mInstance, childIndex, &iterator, &ip6Address) == OT_ERROR_NONE) { - mServer->OutputFormat("%04x: ", childInfo.mRloc16); + OutputFormat("%04x: ", childInfo.mRloc16); OutputIp6Address(ip6Address); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } } } @@ -1032,7 +1028,7 @@ void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otThreadGetMaxChildIpAddresses(mInstance)); + OutputFormat("%d\r\n", otThreadGetMaxChildIpAddresses(mInstance)); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE else if (aArgsLength == 2) @@ -1065,7 +1061,7 @@ void Interpreter::ProcessChildMax(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetMaxAllowedChildren(mInstance)); + OutputFormat("%d\r\n", otThreadGetMaxAllowedChildren(mInstance)); } else { @@ -1085,7 +1081,7 @@ void Interpreter::ProcessChildTimeout(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetChildTimeout(mInstance)); + OutputFormat("%d\r\n", otThreadGetChildTimeout(mInstance)); } else { @@ -1126,7 +1122,7 @@ void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%s\r\n", otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled"); + OutputFormat("%s\r\n", otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled"); } else if (strcmp(aArgs[0], "enable") == 0) { @@ -1142,29 +1138,27 @@ void Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otPlatRadioGetCoexMetrics(mInstance, &metrics)); - mServer->OutputFormat("Stopped: %s\r\n", metrics.mStopped ? "true" : "false"); - mServer->OutputFormat("Grant Glitch: %u\r\n", metrics.mNumGrantGlitch); - mServer->OutputFormat("Transmit metrics\r\n"); - mServer->OutputFormat(" Request: %u\r\n", metrics.mNumTxRequest); - mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumTxGrantImmediate); - mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumTxGrantWait); - mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumTxGrantWaitActivated); - mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumTxGrantWaitTimeout); - mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n", - metrics.mNumTxGrantDeactivatedDuringRequest); - mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumTxDelayedGrant); - mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgTxRequestToGrantTime); - mServer->OutputFormat("Receive metrics\r\n"); - mServer->OutputFormat(" Request: %u\r\n", metrics.mNumRxRequest); - mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumRxGrantImmediate); - mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumRxGrantWait); - mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumRxGrantWaitActivated); - mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumRxGrantWaitTimeout); - mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n", - metrics.mNumRxGrantDeactivatedDuringRequest); - mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumRxDelayedGrant); - mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgRxRequestToGrantTime); - mServer->OutputFormat(" Grant None: %u\r\n", metrics.mNumRxGrantNone); + 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); } else { @@ -1184,7 +1178,7 @@ void Interpreter::ProcessContextIdReuseDelay(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetContextIdReuseDelay(mInstance)); + OutputFormat("%d\r\n", otThreadGetContextIdReuseDelay(mInstance)); } else { @@ -1203,8 +1197,8 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("mac\r\n"); - mServer->OutputFormat("mle\r\n"); + OutputFormat("mac\r\n"); + OutputFormat("mle\r\n"); } else if (strcmp(aArgs[0], "mac") == 0) { @@ -1212,37 +1206,37 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) { const otMacCounters *macCounters = otLinkGetCounters(mInstance); - mServer->OutputFormat("TxTotal: %d\r\n", macCounters->mTxTotal); - mServer->OutputFormat(" TxUnicast: %d\r\n", macCounters->mTxUnicast); - mServer->OutputFormat(" TxBroadcast: %d\r\n", macCounters->mTxBroadcast); - mServer->OutputFormat(" TxAckRequested: %d\r\n", macCounters->mTxAckRequested); - mServer->OutputFormat(" TxAcked: %d\r\n", macCounters->mTxAcked); - mServer->OutputFormat(" TxNoAckRequested: %d\r\n", macCounters->mTxNoAckRequested); - mServer->OutputFormat(" TxData: %d\r\n", macCounters->mTxData); - mServer->OutputFormat(" TxDataPoll: %d\r\n", macCounters->mTxDataPoll); - mServer->OutputFormat(" TxBeacon: %d\r\n", macCounters->mTxBeacon); - mServer->OutputFormat(" TxBeaconRequest: %d\r\n", macCounters->mTxBeaconRequest); - mServer->OutputFormat(" TxOther: %d\r\n", macCounters->mTxOther); - mServer->OutputFormat(" TxRetry: %d\r\n", macCounters->mTxRetry); - mServer->OutputFormat(" TxErrCca: %d\r\n", macCounters->mTxErrCca); - mServer->OutputFormat(" TxErrBusyChannel: %d\r\n", macCounters->mTxErrBusyChannel); - mServer->OutputFormat("RxTotal: %d\r\n", macCounters->mRxTotal); - mServer->OutputFormat(" RxUnicast: %d\r\n", macCounters->mRxUnicast); - mServer->OutputFormat(" RxBroadcast: %d\r\n", macCounters->mRxBroadcast); - mServer->OutputFormat(" RxData: %d\r\n", macCounters->mRxData); - mServer->OutputFormat(" RxDataPoll: %d\r\n", macCounters->mRxDataPoll); - mServer->OutputFormat(" RxBeacon: %d\r\n", macCounters->mRxBeacon); - mServer->OutputFormat(" RxBeaconRequest: %d\r\n", macCounters->mRxBeaconRequest); - mServer->OutputFormat(" RxOther: %d\r\n", macCounters->mRxOther); - mServer->OutputFormat(" RxAddressFiltered: %d\r\n", macCounters->mRxAddressFiltered); - mServer->OutputFormat(" RxDestAddrFiltered: %d\r\n", macCounters->mRxDestAddrFiltered); - mServer->OutputFormat(" RxDuplicated: %d\r\n", macCounters->mRxDuplicated); - mServer->OutputFormat(" RxErrNoFrame: %d\r\n", macCounters->mRxErrNoFrame); - mServer->OutputFormat(" RxErrNoUnknownNeighbor: %d\r\n", macCounters->mRxErrUnknownNeighbor); - mServer->OutputFormat(" RxErrInvalidSrcAddr: %d\r\n", macCounters->mRxErrInvalidSrcAddr); - mServer->OutputFormat(" RxErrSec: %d\r\n", macCounters->mRxErrSec); - mServer->OutputFormat(" RxErrFcs: %d\r\n", macCounters->mRxErrFcs); - mServer->OutputFormat(" RxErrOther: %d\r\n", macCounters->mRxErrOther); + 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); } else if ((aArgsLength == 2) && (strcmp(aArgs[1], "reset") == 0)) { @@ -1259,16 +1253,15 @@ void Interpreter::ProcessCounters(uint8_t aArgsLength, char *aArgs[]) { const otMleCounters *mleCounters = otThreadGetMleCounters(mInstance); - mServer->OutputFormat("Role Disabled: %d\r\n", mleCounters->mDisabledRole); - mServer->OutputFormat("Role Detached: %d\r\n", mleCounters->mDetachedRole); - mServer->OutputFormat("Role Child: %d\r\n", mleCounters->mChildRole); - mServer->OutputFormat("Role Router: %d\r\n", mleCounters->mRouterRole); - mServer->OutputFormat("Role Leader: %d\r\n", mleCounters->mLeaderRole); - mServer->OutputFormat("Attach Attempts: %d\r\n", mleCounters->mAttachAttempts); - mServer->OutputFormat("Partition Id Changes: %d\r\n", mleCounters->mPartitionIdChanges); - mServer->OutputFormat("Better Partition Attach Attempts: %d\r\n", - mleCounters->mBetterPartitionAttachAttempts); - mServer->OutputFormat("Parent Changes: %d\r\n", mleCounters->mParentChanges); + 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); } else if ((aArgsLength == 2) && (strcmp(aArgs[1], "reset") == 0)) { @@ -1295,7 +1288,7 @@ void Interpreter::ProcessDelayTimerMin(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", (otDatasetGetDelayTimerMinimal(mInstance) / 1000)); + OutputFormat("%d\r\n", (otDatasetGetDelayTimerMinimal(mInstance) / 1000)); } else if (aArgsLength == 1) { @@ -1329,8 +1322,8 @@ void Interpreter::ProcessDiscover(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otThreadDiscover(mInstance, scanChannels, OT_PANID_BROADCAST, false, false, &Interpreter::HandleActiveScanResult, this)); - mServer->OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); - mServer->OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); + OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); + OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); exit: if (error != OT_ERROR_NONE) @@ -1406,7 +1399,7 @@ void Interpreter::HandleDnsResponse(void * aContext, void Interpreter::HandleDnsResponse(const char *aHostname, const Ip6::Address *aAddress, uint32_t aTtl, otError aResult) { - mServer->OutputFormat("DNS response for %s - ", aHostname); + OutputFormat("DNS response for %s - ", aHostname); if (aResult == OT_ERROR_NONE) { @@ -1414,7 +1407,7 @@ void Interpreter::HandleDnsResponse(const char *aHostname, const Ip6::Address *a { OutputIp6Address(*aAddress); } - mServer->OutputFormat(" TTL: %d\r\n", aTtl); + OutputFormat(" TTL: %d\r\n", aTtl); } AppendResult(aResult); @@ -1439,7 +1432,7 @@ void Interpreter::ProcessEidCache(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(otThreadGetNextCacheEntry(mInstance, &entry, &iterator)); OutputIp6Address(entry.mTarget); - mServer->OutputFormat(" %04x\r\n", entry.mRloc16); + OutputFormat(" %04x\r\n", entry.mRloc16); } exit: @@ -1458,7 +1451,7 @@ void Interpreter::ProcessEui64(uint8_t aArgsLength, char *aArgs[]) otLinkGetFactoryAssignedIeeeEui64(mInstance, &extAddress); OutputBytes(extAddress.m8, OT_EXT_ADDRESS_SIZE); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); exit: AppendResult(error); @@ -1472,7 +1465,7 @@ void Interpreter::ProcessExtAddress(uint8_t aArgsLength, char *aArgs[]) { const uint8_t *extAddress = reinterpret_cast(otLinkGetExtendedAddress(mInstance)); OutputBytes(extAddress, OT_EXT_ADDRESS_SIZE); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -1509,7 +1502,7 @@ void Interpreter::ProcessLog(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otLoggingGetLevel()); + OutputFormat("%d\r\n", otLoggingGetLevel()); } #if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE else if (aArgsLength == 2) @@ -1549,7 +1542,7 @@ void Interpreter::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]) { const uint8_t *extPanId = reinterpret_cast(otThreadGetExtendedPanId(mInstance)); OutputBytes(extPanId, OT_EXT_PAN_ID_SIZE); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -1581,11 +1574,11 @@ void Interpreter::ProcessIfconfig(uint8_t aArgsLength, char *aArgs[]) { if (otIp6IsEnabled(mInstance)) { - mServer->OutputFormat("up\r\n"); + OutputFormat("up\r\n"); } else { - mServer->OutputFormat("down\r\n"); + OutputFormat("down\r\n"); } } else if (strcmp(aArgs[0], "up") == 0) @@ -1648,7 +1641,7 @@ void Interpreter::ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]) for (const otNetifAddress *addr = unicastAddrs; addr; addr = addr->mNext) { OutputIp6Address(addr->mAddress); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } } else @@ -1664,17 +1657,17 @@ void Interpreter::ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]) else if (strcmp(aArgs[0], "linklocal") == 0) { OutputIp6Address(*otThreadGetLinkLocalIp6Address(mInstance)); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else if (strcmp(aArgs[0], "rloc") == 0) { OutputIp6Address(*otThreadGetRloc(mInstance)); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else if (strcmp(aArgs[0], "mleid") == 0) { OutputIp6Address(*otThreadGetMeshLocalEid(mInstance)); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -1722,11 +1715,11 @@ otError Interpreter::ProcessMulticastPromiscuous(uint8_t aArgsLength, char *aArg { if (otIp6IsMulticastPromiscuousEnabled(mInstance)) { - mServer->OutputFormat("Enabled\r\n"); + OutputFormat("Enabled\r\n"); } else { - mServer->OutputFormat("Disabled\r\n"); + OutputFormat("Disabled\r\n"); } } else @@ -1758,7 +1751,7 @@ void Interpreter::ProcessIpMulticastAddr(uint8_t aArgsLength, char *aArgs[]) for (const otNetifMulticastAddress *addr = otIp6GetMulticastAddresses(mInstance); addr; addr = addr->mNext) { OutputIp6Address(addr->mAddress); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } } else @@ -1796,7 +1789,7 @@ void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otThreadGetKeySequenceCounter(mInstance)); + OutputFormat("%d\r\n", otThreadGetKeySequenceCounter(mInstance)); } else { @@ -1808,7 +1801,7 @@ void Interpreter::ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otThreadGetKeySwitchGuardTime(mInstance)); + OutputFormat("%d\r\n", otThreadGetKeySwitchGuardTime(mInstance)); } else { @@ -1835,11 +1828,11 @@ void Interpreter::ProcessLeaderData(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otThreadGetLeaderData(mInstance, &leaderData)); - mServer->OutputFormat("Partition ID: %u\r\n", leaderData.mPartitionId); - mServer->OutputFormat("Weighting: %d\r\n", leaderData.mWeighting); - mServer->OutputFormat("Data Version: %d\r\n", leaderData.mDataVersion); - mServer->OutputFormat("Stable Data Version: %d\r\n", leaderData.mStableDataVersion); - mServer->OutputFormat("Leader Router ID: %d\r\n", leaderData.mLeaderRouterId); + 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); exit: AppendResult(error); @@ -1853,7 +1846,7 @@ void Interpreter::ProcessLeaderPartitionId(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%u\r\n", otThreadGetLocalLeaderPartitionId(mInstance)); + OutputFormat("%u\r\n", otThreadGetLocalLeaderPartitionId(mInstance)); } else { @@ -1872,7 +1865,7 @@ void Interpreter::ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetLocalLeaderWeight(mInstance)); + OutputFormat("%d\r\n", otThreadGetLocalLeaderWeight(mInstance)); } else { @@ -1896,10 +1889,10 @@ void Interpreter::ProcessPskc(uint8_t aArgsLength, char *aArgs[]) for (uint8_t b : pskc->m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -1938,10 +1931,10 @@ void Interpreter::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]) for (int i = 0; i < OT_MASTER_KEY_SIZE; i++) { - mServer->OutputFormat("%02x", key[i]); + OutputFormat("%02x", key[i]); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -1968,25 +1961,25 @@ void Interpreter::ProcessMode(uint8_t aArgsLength, char *aArgs[]) if (linkMode.mRxOnWhenIdle) { - mServer->OutputFormat("r"); + OutputFormat("r"); } if (linkMode.mSecureDataRequests) { - mServer->OutputFormat("s"); + OutputFormat("s"); } if (linkMode.mDeviceType) { - mServer->OutputFormat("d"); + OutputFormat("d"); } if (linkMode.mNetworkData) { - mServer->OutputFormat("n"); + OutputFormat("n"); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -2038,39 +2031,39 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) { if (isTable) { - mServer->OutputFormat("| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |\r\n"); - mServer->OutputFormat("+------+--------+-----+----------+-----------+-+-+-+-+------------------+\r\n"); + OutputFormat("| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC |\r\n"); + OutputFormat("+------+--------+-----+----------+-----------+-+-+-+-+------------------+\r\n"); } while (otThreadGetNextNeighborInfo(mInstance, &iterator, &neighborInfo) == OT_ERROR_NONE) { if (isTable) { - mServer->OutputFormat("| %3c ", neighborInfo.mIsChild ? 'C' : 'R'); - mServer->OutputFormat("| 0x%04x ", neighborInfo.mRloc16); - mServer->OutputFormat("| %3d ", neighborInfo.mAge); - mServer->OutputFormat("| %8d ", neighborInfo.mAverageRssi); - mServer->OutputFormat("| %9d ", neighborInfo.mLastRssi); - mServer->OutputFormat("|%1d", neighborInfo.mRxOnWhenIdle); - mServer->OutputFormat("|%1d", neighborInfo.mSecureDataRequest); - mServer->OutputFormat("|%1d", neighborInfo.mFullThreadDevice); - mServer->OutputFormat("|%1d", neighborInfo.mFullNetworkData); - mServer->OutputFormat("| "); + OutputFormat("| %3c ", neighborInfo.mIsChild ? 'C' : 'R'); + OutputFormat("| 0x%04x ", neighborInfo.mRloc16); + OutputFormat("| %3d ", neighborInfo.mAge); + OutputFormat("| %8d ", neighborInfo.mAverageRssi); + OutputFormat("| %9d ", neighborInfo.mLastRssi); + OutputFormat("|%1d", neighborInfo.mRxOnWhenIdle); + OutputFormat("|%1d", neighborInfo.mSecureDataRequest); + OutputFormat("|%1d", neighborInfo.mFullThreadDevice); + OutputFormat("|%1d", neighborInfo.mFullNetworkData); + OutputFormat("| "); for (uint8_t b : neighborInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat(" |\r\n"); + OutputFormat(" |\r\n"); } else { - mServer->OutputFormat("0x%04x ", neighborInfo.mRloc16); + OutputFormat("0x%04x ", neighborInfo.mRloc16); } } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -2094,7 +2087,7 @@ void Interpreter::ProcessNetworkDataShow(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otNetDataGet(mInstance, false, data, &len)); OutputBytes(data, static_cast(len)); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); exit: AppendResult(error); @@ -2112,7 +2105,7 @@ void Interpreter::ProcessNetif(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otPlatGetNetif(mInstance, &netif, &netifidx)); - mServer->OutputFormat("%s:%u\r\n", netif ? netif : "(null)", netifidx); + OutputFormat("%s:%u\r\n", netif ? netif : "(null)", netifidx); exit: AppendResult(error); @@ -2126,31 +2119,29 @@ void Interpreter::ProcessNetstat(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - mServer->OutputFormat( - "| Local Address | Peer Address |\n"); - mServer->OutputFormat( - "+-----------------------------------------------+-----------------------------------------------+\n"); + OutputFormat("| Local Address | Peer Address |\n"); + OutputFormat("+-----------------------------------------------+-----------------------------------------------+\n"); while (socket) { constexpr int kMaxOutputLength = 45; int outputLength; - mServer->OutputFormat("| "); + OutputFormat("| "); outputLength = OutputSocketAddress(socket->mSockName); for (int i = outputLength; 0 <= i && i < kMaxOutputLength; ++i) { - mServer->OutputFormat(" "); + OutputFormat(" "); } - mServer->OutputFormat(" | "); + OutputFormat(" | "); outputLength = OutputSocketAddress(socket->mPeerName); for (int i = outputLength; 0 <= i && i < kMaxOutputLength; ++i) { - mServer->OutputFormat(" "); + OutputFormat(" "); } - mServer->OutputFormat(" |\n"); + OutputFormat(" |\n"); socket = socket->mNext; } @@ -2166,16 +2157,16 @@ int Interpreter::OutputSocketAddress(const otSockAddr &aAddress) VerifyOrExit((outputLength = OutputIp6Address(aAddress.mAddress)) >= 0, result = -1); result += outputLength; - VerifyOrExit((outputLength = mServer->OutputFormat(":")) >= 0, result = -1); + VerifyOrExit((outputLength = OutputFormat(":")) >= 0, result = -1); result += outputLength; if (aAddress.mPort == 0) { - VerifyOrExit((outputLength = mServer->OutputFormat("*")) >= 0, result = -1); + VerifyOrExit((outputLength = OutputFormat("*")) >= 0, result = -1); result += outputLength; } else { - VerifyOrExit((outputLength = mServer->OutputFormat("%d", aAddress.mPort)) >= 0, result = -1); + VerifyOrExit((outputLength = OutputFormat("%d", aAddress.mPort)) >= 0, result = -1); result += outputLength; } @@ -2305,7 +2296,7 @@ void Interpreter::ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetNetworkIdTimeout(mInstance)); + OutputFormat("%d\r\n", otThreadGetNetworkIdTimeout(mInstance)); } else { @@ -2325,7 +2316,7 @@ void Interpreter::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { const char *networkName = otThreadGetNetworkName(mInstance); - mServer->OutputFormat("%s\r\n", static_cast(networkName)); + OutputFormat("%s\r\n", static_cast(networkName)); } else { @@ -2349,28 +2340,28 @@ void Interpreter::ProcessNetworkTime(uint8_t aArgsLength, char *aArgs[]) networkTimeStatus = otNetworkTimeGet(mInstance, &time); - mServer->OutputFormat("Network Time: %luus", time); + OutputFormat("Network Time: %luus", time); switch (networkTimeStatus) { case OT_NETWORK_TIME_UNSYNCHRONIZED: - mServer->OutputFormat(" (unsynchronized)\r\n"); + OutputFormat(" (unsynchronized)\r\n"); break; case OT_NETWORK_TIME_RESYNC_NEEDED: - mServer->OutputFormat(" (resync needed)\r\n"); + OutputFormat(" (resync needed)\r\n"); break; case OT_NETWORK_TIME_SYNCHRONIZED: - mServer->OutputFormat(" (synchronized)\r\n"); + OutputFormat(" (synchronized)\r\n"); break; default: break; } - mServer->OutputFormat("Time Sync Period: %ds\r\n", otNetworkTimeGetSyncPeriod(mInstance)); - mServer->OutputFormat("XTAL Threshold: %dppm\r\n", otNetworkTimeGetXtalThreshold(mInstance)); + OutputFormat("Time Sync Period: %ds\r\n", otNetworkTimeGetSyncPeriod(mInstance)); + OutputFormat("XTAL Threshold: %dppm\r\n", otNetworkTimeGetXtalThreshold(mInstance)); } else if (aArgsLength == 2) { @@ -2397,7 +2388,7 @@ void Interpreter::ProcessPanId(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("0x%04x\r\n", otLinkGetPanId(mInstance)); + OutputFormat("0x%04x\r\n", otLinkGetPanId(mInstance)); } else { @@ -2418,19 +2409,19 @@ void Interpreter::ProcessParent(uint8_t aArgsLength, char *aArgs[]) otRouterInfo parentInfo; SuccessOrExit(error = otThreadGetParentInfo(mInstance, &parentInfo)); - mServer->OutputFormat("Ext Addr: "); + OutputFormat("Ext Addr: "); for (uint8_t b : parentInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); - mServer->OutputFormat("Rloc: %x\r\n", parentInfo.mRloc16); - mServer->OutputFormat("Link Quality In: %d\r\n", parentInfo.mLinkQualityIn); - mServer->OutputFormat("Link Quality Out: %d\r\n", parentInfo.mLinkQualityOut); - mServer->OutputFormat("Age: %d\r\n", parentInfo.mAge); + 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); exit: AppendResult(error); @@ -2444,7 +2435,7 @@ void Interpreter::ProcessParentPriority(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetParentPriority(mInstance)); + OutputFormat("%d\r\n", otThreadGetParentPriority(mInstance)); } else { @@ -2476,18 +2467,18 @@ void Interpreter::HandleIcmpReceive(otMessage * aMessage, VerifyOrExit((mPingIdentifier != 0) && (mPingIdentifier == HostSwap16(aIcmpHeader->mData.m16[0])), OT_NOOP); dataSize = otMessageGetLength(aMessage) - otMessageGetOffset(aMessage); - mServer->OutputFormat("%u bytes from ", dataSize + static_cast(sizeof(otIcmp6Header))); + OutputFormat("%u bytes from ", dataSize + static_cast(sizeof(otIcmp6Header))); OutputIp6Address(aMessageInfo->mPeerAddr); - mServer->OutputFormat(": icmp_seq=%d hlim=%d", HostSwap16(aIcmpHeader->mData.m16[1]), aMessageInfo->mHopLimit); + OutputFormat(": icmp_seq=%d hlim=%d", HostSwap16(aIcmpHeader->mData.m16[1]), aMessageInfo->mHopLimit); if (otMessageRead(aMessage, otMessageGetOffset(aMessage), ×tamp, sizeof(uint32_t)) == sizeof(uint32_t)) { - mServer->OutputFormat(" time=%dms", TimerMilli::GetNow().GetValue() - HostSwap32(timestamp)); + OutputFormat(" time=%dms", TimerMilli::GetNow().GetValue() - HostSwap32(timestamp)); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); SignalPingReply(static_cast(aMessageInfo)->GetPeerAddr(), dataSize, HostSwap32(timestamp), aMessageInfo->mHopLimit); @@ -2617,7 +2608,7 @@ void Interpreter::ProcessPollPeriod(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otLinkGetPollPeriod(mInstance)); + OutputFormat("%d\r\n", otLinkGetPollPeriod(mInstance)); } else { @@ -2637,11 +2628,11 @@ void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) { if (otLinkIsPromiscuous(mInstance) && otPlatRadioGetPromiscuous(mInstance)) { - mServer->OutputFormat("Enabled\r\n"); + OutputFormat("Enabled\r\n"); } else { - mServer->OutputFormat("Disabled\r\n"); + OutputFormat("Disabled\r\n"); } } else @@ -2675,39 +2666,39 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) { OT_UNUSED_VARIABLE(aIsTx); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); for (size_t i = 0; i < 44; i++) { - mServer->OutputFormat("="); + OutputFormat("="); } - mServer->OutputFormat("[len = %3u]", aFrame->mLength); + OutputFormat("[len = %3u]", aFrame->mLength); for (size_t i = 0; i < 28; i++) { - mServer->OutputFormat("="); + OutputFormat("="); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); for (size_t i = 0; i < aFrame->mLength; i += 16) { - mServer->OutputFormat("|"); + OutputFormat("|"); for (size_t j = 0; j < 16; j++) { if (i + j < aFrame->mLength) { - mServer->OutputFormat(" %02X", aFrame->mPsdu[i + j]); + OutputFormat(" %02X", aFrame->mPsdu[i + j]); } else { - mServer->OutputFormat(" .."); + OutputFormat(" .."); } } - mServer->OutputFormat("|"); + OutputFormat("|"); for (size_t j = 0; j < 16; j++) { @@ -2715,28 +2706,28 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx) { if (31 < aFrame->mPsdu[i + j] && aFrame->mPsdu[i + j] < 127) { - mServer->OutputFormat(" %c", aFrame->mPsdu[i + j]); + OutputFormat(" %c", aFrame->mPsdu[i + j]); } else { - mServer->OutputFormat(" ?"); + OutputFormat(" ?"); } } else { - mServer->OutputFormat(" ."); + OutputFormat(" ."); } } - mServer->OutputFormat("|\r\n"); + OutputFormat("|\r\n"); } for (size_t i = 0; i < 83; i++) { - mServer->OutputFormat("-"); + OutputFormat("-"); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE @@ -2876,72 +2867,71 @@ exit: void Interpreter::OutputPrefix(otBorderRouterConfig &aConfig) { - mServer->OutputFormat("%x:%x:%x:%x::/%d ", HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[0]), - HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[1]), - HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[2]), - HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[3]), aConfig.mPrefix.mLength); + OutputFormat("%x:%x:%x:%x::/%d ", HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[0]), + HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[1]), HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[2]), + HostSwap16(aConfig.mPrefix.mPrefix.mFields.m16[3]), aConfig.mPrefix.mLength); if (aConfig.mPreferred) { - mServer->OutputFormat("p"); + OutputFormat("p"); } if (aConfig.mSlaac) { - mServer->OutputFormat("a"); + OutputFormat("a"); } if (aConfig.mDhcp) { - mServer->OutputFormat("d"); + OutputFormat("d"); } if (aConfig.mConfigure) { - mServer->OutputFormat("c"); + OutputFormat("c"); } if (aConfig.mDefaultRoute) { - mServer->OutputFormat("r"); + OutputFormat("r"); } if (aConfig.mOnMesh) { - mServer->OutputFormat("o"); + OutputFormat("o"); } if (aConfig.mStable) { - mServer->OutputFormat("s"); + OutputFormat("s"); } if (aConfig.mNdDns) { - mServer->OutputFormat("n"); + OutputFormat("n"); } if (aConfig.mDp) { - mServer->OutputFormat("D"); + OutputFormat("D"); } switch (aConfig.mPreference) { case OT_ROUTE_PREFERENCE_LOW: - mServer->OutputFormat(" low"); + OutputFormat(" low"); break; case OT_ROUTE_PREFERENCE_MED: - mServer->OutputFormat(" med"); + OutputFormat(" med"); break; case OT_ROUTE_PREFERENCE_HIGH: - mServer->OutputFormat(" high"); + OutputFormat(" high"); break; } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } otError Interpreter::ProcessPrefixList(void) @@ -2958,7 +2948,7 @@ otError Interpreter::ProcessPrefixList(void) if (otBackboneRouterGetState(mInstance) == OT_BACKBONE_ROUTER_STATE_DISABLED) { SuccessOrExit(otBackboneRouterGetDomainPrefix(mInstance, &config)); - mServer->OutputFormat("- "); + OutputFormat("- "); OutputPrefix(config); } // Else already printed via above while loop. @@ -3019,7 +3009,7 @@ void Interpreter::ProcessRcp(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[0], "version") == 0) { - mServer->OutputFormat("%s\r\n", version); + OutputFormat("%s\r\n", version); } else { @@ -3059,7 +3049,7 @@ void Interpreter::ProcessRloc16(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - mServer->OutputFormat("%04x\r\n", otThreadGetRloc16(mInstance)); + OutputFormat("%04x\r\n", otThreadGetRloc16(mInstance)); AppendResult(OT_ERROR_NONE); } @@ -3163,28 +3153,28 @@ otError Interpreter::ProcessRouteList(void) while (otBorderRouterGetNextRoute(mInstance, &iterator, &config) == OT_ERROR_NONE) { - mServer->OutputFormat("%x:%x:%x:%x::/%d ", HostSwap16(config.mPrefix.mPrefix.mFields.m16[0]), - HostSwap16(config.mPrefix.mPrefix.mFields.m16[1]), - HostSwap16(config.mPrefix.mPrefix.mFields.m16[2]), - HostSwap16(config.mPrefix.mPrefix.mFields.m16[3]), config.mPrefix.mLength); + OutputFormat("%x:%x:%x:%x::/%d ", HostSwap16(config.mPrefix.mPrefix.mFields.m16[0]), + HostSwap16(config.mPrefix.mPrefix.mFields.m16[1]), + HostSwap16(config.mPrefix.mPrefix.mFields.m16[2]), + HostSwap16(config.mPrefix.mPrefix.mFields.m16[3]), config.mPrefix.mLength); if (config.mStable) { - mServer->OutputFormat("s"); + OutputFormat("s"); } switch (config.mPreference) { case OT_ROUTE_PREFERENCE_LOW: - mServer->OutputFormat(" low\r\n"); + OutputFormat(" low\r\n"); break; case OT_ROUTE_PREFERENCE_MED: - mServer->OutputFormat(" med\r\n"); + OutputFormat(" med\r\n"); break; case OT_ROUTE_PREFERENCE_HIGH: - mServer->OutputFormat(" high\r\n"); + OutputFormat(" high\r\n"); break; } } @@ -3236,10 +3226,8 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - mServer->OutputFormat( - "| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |\r\n"); - mServer->OutputFormat( - "+----+--------+----------+-----------+-------+--------+-----+------------------+\r\n"); + OutputFormat("| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |\r\n"); + OutputFormat("+----+--------+----------+-----------+-------+--------+-----+------------------+\r\n"); } maxRouterId = otThreadGetMaxRouterId(mInstance); @@ -3253,58 +3241,58 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[]) if (isTable) { - mServer->OutputFormat("| %2d ", routerInfo.mRouterId); - mServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16); - mServer->OutputFormat("| %8d ", routerInfo.mNextHop); - mServer->OutputFormat("| %9d ", routerInfo.mPathCost); - mServer->OutputFormat("| %5d ", routerInfo.mLinkQualityIn); - mServer->OutputFormat("| %6d ", routerInfo.mLinkQualityOut); - mServer->OutputFormat("| %3d ", routerInfo.mAge); - mServer->OutputFormat("| "); + OutputFormat("| %2d ", routerInfo.mRouterId); + OutputFormat("| 0x%04x ", routerInfo.mRloc16); + OutputFormat("| %8d ", routerInfo.mNextHop); + OutputFormat("| %9d ", routerInfo.mPathCost); + OutputFormat("| %5d ", routerInfo.mLinkQualityIn); + OutputFormat("| %6d ", routerInfo.mLinkQualityOut); + OutputFormat("| %3d ", routerInfo.mAge); + OutputFormat("| "); for (uint8_t b : routerInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat(" |\r\n"); + OutputFormat(" |\r\n"); } else { - mServer->OutputFormat("%d ", i); + OutputFormat("%d ", i); } } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); ExitNow(); } SuccessOrExit(error = ParseLong(aArgs[0], value)); SuccessOrExit(error = otThreadGetRouterInfo(mInstance, static_cast(value), &routerInfo)); - mServer->OutputFormat("Alloc: %d\r\n", routerInfo.mAllocated); + OutputFormat("Alloc: %d\r\n", routerInfo.mAllocated); if (routerInfo.mAllocated) { - mServer->OutputFormat("Router ID: %d\r\n", routerInfo.mRouterId); - mServer->OutputFormat("Rloc: %04x\r\n", routerInfo.mRloc16); - mServer->OutputFormat("Next Hop: %04x\r\n", static_cast(routerInfo.mNextHop) << 10); - mServer->OutputFormat("Link: %d\r\n", routerInfo.mLinkEstablished); + 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); if (routerInfo.mLinkEstablished) { - mServer->OutputFormat("Ext Addr: "); + OutputFormat("Ext Addr: "); for (uint8_t b : routerInfo.mExtAddress.m8) { - mServer->OutputFormat("%02x", b); + OutputFormat("%02x", b); } - mServer->OutputFormat("\r\n"); - mServer->OutputFormat("Cost: %d\r\n", routerInfo.mPathCost); - mServer->OutputFormat("Link Quality In: %d\r\n", routerInfo.mLinkQualityIn); - mServer->OutputFormat("Link Quality Out: %d\r\n", routerInfo.mLinkQualityOut); - mServer->OutputFormat("Age: %d\r\n", routerInfo.mAge); + 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); } } @@ -3319,7 +3307,7 @@ void Interpreter::ProcessRouterDowngradeThreshold(uint8_t aArgsLength, char *aAr if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetRouterDowngradeThreshold(mInstance)); + OutputFormat("%d\r\n", otThreadGetRouterDowngradeThreshold(mInstance)); } else { @@ -3339,11 +3327,11 @@ void Interpreter::ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]) { if (otThreadIsRouterEligible(mInstance)) { - mServer->OutputFormat("Enabled\r\n"); + OutputFormat("Enabled\r\n"); } else { - mServer->OutputFormat("Disabled\r\n"); + OutputFormat("Disabled\r\n"); } } else if (strcmp(aArgs[0], "enable") == 0) @@ -3370,7 +3358,7 @@ void Interpreter::ProcessRouterSelectionJitter(uint8_t aArgsLength, char *aArgs[ if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetRouterSelectionJitter(mInstance)); + OutputFormat("%d\r\n", otThreadGetRouterSelectionJitter(mInstance)); } else { @@ -3390,7 +3378,7 @@ void Interpreter::ProcessRouterUpgradeThreshold(uint8_t aArgsLength, char *aArgs if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetRouterUpgradeThreshold(mInstance)); + OutputFormat("%d\r\n", otThreadGetRouterUpgradeThreshold(mInstance)); } else { @@ -3434,17 +3422,15 @@ void Interpreter::ProcessScan(uint8_t aArgsLength, char *aArgs[]) if (energyScan) { - mServer->OutputFormat("| Ch | RSSI |\r\n"); - mServer->OutputFormat("+----+------+\r\n"); + OutputFormat("| Ch | RSSI |\r\n"); + OutputFormat("+----+------+\r\n"); SuccessOrExit(error = otLinkEnergyScan(mInstance, scanChannels, scanDuration, &Interpreter::HandleEnergyScanResult, this)); } else { - mServer->OutputFormat( - "| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); - mServer->OutputFormat( - "+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); + OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); + OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); SuccessOrExit(error = otLinkActiveScan(mInstance, scanChannels, scanDuration, &Interpreter::HandleActiveScanResult, this)); } @@ -3469,19 +3455,19 @@ void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult) ExitNow(); } - mServer->OutputFormat("| %d ", aResult->mIsJoinable); + OutputFormat("| %d ", aResult->mIsJoinable); - mServer->OutputFormat("| %-16s ", aResult->mNetworkName.m8); + OutputFormat("| %-16s ", aResult->mNetworkName.m8); - mServer->OutputFormat("| "); + OutputFormat("| "); OutputBytes(aResult->mExtendedPanId.m8, OT_EXT_PAN_ID_SIZE); - mServer->OutputFormat(" "); + OutputFormat(" "); - mServer->OutputFormat("| %04x | ", aResult->mPanId); + OutputFormat("| %04x | ", aResult->mPanId); OutputBytes(aResult->mExtAddress.m8, OT_EXT_ADDRESS_SIZE); - mServer->OutputFormat(" | %2d ", aResult->mChannel); - mServer->OutputFormat("| %3d ", aResult->mRssi); - mServer->OutputFormat("| %3d |\r\n", aResult->mLqi); + OutputFormat(" | %2d ", aResult->mChannel); + OutputFormat("| %3d ", aResult->mRssi); + OutputFormat("| %3d |\r\n", aResult->mLqi); exit: return; @@ -3500,7 +3486,7 @@ void Interpreter::HandleEnergyScanResult(otEnergyScanResult *aResult) ExitNow(); } - mServer->OutputFormat("| %2d | %4d |\r\n", aResult->mChannel, aResult->mMaxRssi); + OutputFormat("| %2d | %4d |\r\n", aResult->mChannel, aResult->mMaxRssi); exit: return; @@ -3515,11 +3501,11 @@ void Interpreter::ProcessSingleton(uint8_t aArgsLength, char *aArgs[]) if (otThreadIsSingleton(mInstance)) { - mServer->OutputFormat("true\r\n"); + OutputFormat("true\r\n"); } else { - mServer->OutputFormat("false\r\n"); + OutputFormat("false\r\n"); } AppendResult(error); @@ -3585,12 +3571,12 @@ 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. - mServer->OutputFormat("SNTP response - Unix time: %u (era: %u)\r\n", static_cast(aTime), - static_cast(aTime >> 32)); + OutputFormat("SNTP response - Unix time: %u (era: %u)\r\n", static_cast(aTime), + static_cast(aTime >> 32)); } else { - mServer->OutputFormat("SNTP error - %s\r\n", otThreadErrorToString(aResult)); + OutputFormat("SNTP error - %s\r\n", otThreadErrorToString(aResult)); } mSntpQueryingInProgress = false; @@ -3608,30 +3594,30 @@ void Interpreter::ProcessState(uint8_t aArgsLength, char *aArgs[]) switch (otThreadGetDeviceRole(mInstance)) { case OT_DEVICE_ROLE_DISABLED: - mServer->OutputFormat("disabled\r\n"); + OutputFormat("disabled\r\n"); break; case OT_DEVICE_ROLE_DETACHED: - mServer->OutputFormat("detached\r\n"); + OutputFormat("detached\r\n"); break; case OT_DEVICE_ROLE_CHILD: - mServer->OutputFormat("child\r\n"); + OutputFormat("child\r\n"); break; #if OPENTHREAD_FTD case OT_DEVICE_ROLE_ROUTER: - mServer->OutputFormat("router\r\n"); + OutputFormat("router\r\n"); break; case OT_DEVICE_ROLE_LEADER: - mServer->OutputFormat("leader\r\n"); + OutputFormat("leader\r\n"); break; #endif // OPENTHREAD_FTD default: - mServer->OutputFormat("invalid state\r\n"); + OutputFormat("invalid state\r\n"); break; } } @@ -3686,7 +3672,7 @@ void Interpreter::ProcessThread(uint8_t aArgsLength, char *aArgs[]) } else if (strcmp(aArgs[0], "version") == 0) { - mServer->OutputFormat("%u\r\n", otThreadGetVersion()); + OutputFormat("%u\r\n", otThreadGetVersion()); } else { @@ -3713,7 +3699,7 @@ void Interpreter::ProcessTxPower(uint8_t aArgsLength, char *aArgs[]) int8_t power; SuccessOrExit(error = otPlatRadioGetTransmitPower(mInstance, &power)); - mServer->OutputFormat("%d dBm\r\n", power); + OutputFormat("%d dBm\r\n", power); } else { @@ -3777,11 +3763,11 @@ void Interpreter::ProcessUnsecurePort(uint8_t aArgsLength, char *aArgs[]) { for (uint8_t i = 0; i < numPorts; i++) { - mServer->OutputFormat("%d ", ports[i]); + OutputFormat("%d ", ports[i]); } } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } else { @@ -3798,7 +3784,7 @@ void Interpreter::ProcessVersion(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgs); const char *version = otGetVersionString(); - mServer->OutputFormat("%s\r\n", static_cast(version)); + OutputFormat("%s\r\n", static_cast(version)); AppendResult(OT_ERROR_NONE); } @@ -3832,7 +3818,7 @@ void Interpreter::ProcessJoinerPort(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mServer->OutputFormat("%d\r\n", otThreadGetJoinerUdpPort(mInstance)); + OutputFormat("%d\r\n", otThreadGetJoinerUdpPort(mInstance)); } else { @@ -3881,15 +3867,15 @@ void Interpreter::PrintMacFilter(void) if (mode == OT_MAC_FILTER_ADDRESS_MODE_DISABLED) { - mServer->OutputFormat("Address Mode: Disabled\r\n"); + OutputFormat("Address Mode: Disabled\r\n"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_WHITELIST) { - mServer->OutputFormat("Address Mode: Whitelist\r\n"); + OutputFormat("Address Mode: Whitelist\r\n"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_BLACKLIST) { - mServer->OutputFormat("Address Mode: Blacklist\r\n"); + OutputFormat("Address Mode: Blacklist\r\n"); } while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) @@ -3898,15 +3884,14 @@ void Interpreter::PrintMacFilter(void) if (entry.mRssIn != OT_MAC_FILTER_FIXED_RSS_DISABLED) { - mServer->OutputFormat(" : rss %d (lqi %d)", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat(" : rss %d (lqi %d)", entry.mRssIn, otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } iterator = OT_MAC_FILTER_ITERATOR_INIT; - mServer->OutputFormat("RssIn List:\r\n"); + OutputFormat("RssIn List:\r\n"); while (otLinkFilterGetNextRssIn(mInstance, &iterator, &entry) == OT_ERROR_NONE) { @@ -3922,14 +3907,14 @@ void Interpreter::PrintMacFilter(void) if (i == OT_EXT_ADDRESS_SIZE) { - mServer->OutputFormat("Default rss : %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat("Default rss : %d (lqi %d)\r\n", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } else { OutputBytes(entry.mExtAddress.m8, OT_EXT_ADDRESS_SIZE); - mServer->OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } } } @@ -3947,15 +3932,15 @@ otError Interpreter::ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]) { if (mode == OT_MAC_FILTER_ADDRESS_MODE_DISABLED) { - mServer->OutputFormat("Disabled\r\n"); + OutputFormat("Disabled\r\n"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_WHITELIST) { - mServer->OutputFormat("Whitelist\r\n"); + OutputFormat("Whitelist\r\n"); } else if (mode == OT_MAC_FILTER_ADDRESS_MODE_BLACKLIST) { - mServer->OutputFormat("Blacklist\r\n"); + OutputFormat("Blacklist\r\n"); } while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) @@ -3964,11 +3949,11 @@ otError Interpreter::ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]) if (entry.mRssIn != OT_MAC_FILTER_FIXED_RSS_DISABLED) { - mServer->OutputFormat(" : rss %d (lqi %d)", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat(" : rss %d (lqi %d)", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } } else @@ -4054,14 +4039,14 @@ otError Interpreter::ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]) if (i == OT_EXT_ADDRESS_SIZE) { - mServer->OutputFormat("Default rss: %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat("Default rss: %d (lqi %d)\r\n", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } else { OutputBytes(entry.mExtAddress.m8, OT_EXT_ADDRESS_SIZE); - mServer->OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, - otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); + OutputFormat(" : rss %d (lqi %d)\r\n", entry.mRssIn, + otLinkConvertRssToLinkQuality(mInstance, entry.mRssIn)); } } } @@ -4167,7 +4152,7 @@ otError Interpreter::ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesDirect(mInstance)); + OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesDirect(mInstance)); } else { @@ -4184,7 +4169,7 @@ otError Interpreter::ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]) { if (aArgsLength == 1) { - mServer->OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesIndirect(mInstance)); + OutputFormat("%d\r\n", otLinkGetMaxFrameRetriesIndirect(mInstance)); } else { @@ -4217,32 +4202,29 @@ void Interpreter::ProcessDiag(uint8_t aArgsLength, char *aArgs[]) output[sizeof(output) - 1] = '\0'; error = otDiagProcessCmd(mInstance, aArgsLength, aArgs, output, sizeof(output) - 1); - mServer->Output(output, static_cast(strlen(output))); + Output(output, static_cast(strlen(output))); AppendResult(error); } #endif -void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer) +void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength) { char * aArgs[kMaxArgs] = {nullptr}; char * cmd; uint8_t aArgsLength = 0; size_t i = 0; - mServer = &aServer; - VerifyOrExit(aBuf != nullptr && StringLength(aBuf, aBufLength + 1) <= aBufLength, OT_NOOP); VerifyOrExit(Utils::CmdLineParser::ParseCmd(aBuf, aArgsLength, aArgs, kMaxArgs) == OT_ERROR_NONE, - mServer->OutputFormat("Error: too many args (max %d)\r\n", kMaxArgs)); - VerifyOrExit(aArgsLength >= 1, mServer->OutputFormat("Error: no given command.\r\n")); + OutputFormat("Error: too many args (max %d)\r\n", kMaxArgs)); + VerifyOrExit(aArgsLength >= 1, OutputFormat("Error: no given command.\r\n")); cmd = aArgs[0]; #if OPENTHREAD_CONFIG_DIAG_ENABLE - VerifyOrExit( - (!otDiagIsEnabled(mInstance) || (strcmp(cmd, "diag") == 0)), - mServer->OutputFormat("under diagnostics mode, execute 'diag stop' before running any other commands.\r\n")); + VerifyOrExit((!otDiagIsEnabled(mInstance) || (strcmp(cmd, "diag") == 0)), + OutputFormat("under diagnostics mode, execute 'diag stop' before running any other commands.\r\n")); #endif for (i = 0; i < OT_ARRAY_LENGTH(sCommands); i++) @@ -4338,7 +4320,7 @@ void Interpreter::HandleDiagnosticGetResponse(const otMessage &aMessage, const I otNetworkDiagIterator iterator = OT_NETWORK_DIAGNOSTIC_ITERATOR_INIT; otError error = OT_ERROR_NONE; - mServer->OutputFormat("DIAG_GET.rsp/ans: "); + OutputFormat("DIAG_GET.rsp/ans: "); while (length > 0) { @@ -4351,7 +4333,7 @@ void Interpreter::HandleDiagnosticGetResponse(const otMessage &aMessage, const I bytesPrinted += bytesToPrint; } - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); // Output Network Diagnostic TLV values in standard YAML format. while ((error = otThreadGetNextDiagnosticTlv(&aMessage, &iterator, &diagTlv)) == OT_ERROR_NONE) @@ -4360,73 +4342,73 @@ void Interpreter::HandleDiagnosticGetResponse(const otMessage &aMessage, const I switch (diagTlv.mType) { case OT_NETWORK_DIAGNOSTIC_TLV_EXT_ADDRESS: - mServer->OutputFormat("Ext Address: '"); + OutputFormat("Ext Address: '"); OutputBytes(diagTlv.mData.mExtAddress.m8, sizeof(diagTlv.mData.mExtAddress.m8)); - mServer->OutputFormat("'\r\n"); + OutputFormat("'\r\n"); break; case OT_NETWORK_DIAGNOSTIC_TLV_SHORT_ADDRESS: - mServer->OutputFormat("Rloc16: 0x%04x\r\n", diagTlv.mData.mAddr16); + OutputFormat("Rloc16: 0x%04x\r\n", diagTlv.mData.mAddr16); break; case OT_NETWORK_DIAGNOSTIC_TLV_MODE: - mServer->OutputFormat("Mode:\r\n"); + OutputFormat("Mode:\r\n"); OutputMode(diagTlv.mData.mMode, column + INDENT_SIZE); break; case OT_NETWORK_DIAGNOSTIC_TLV_TIMEOUT: - mServer->OutputFormat("Timeout: %u\r\n", diagTlv.mData.mTimeout); + OutputFormat("Timeout: %u\r\n", diagTlv.mData.mTimeout); break; case OT_NETWORK_DIAGNOSTIC_TLV_CONNECTIVITY: - mServer->OutputFormat("Connectivity:\r\n"); + OutputFormat("Connectivity:\r\n"); OutputConnectivity(diagTlv.mData.mConnectivity, column + INDENT_SIZE); break; case OT_NETWORK_DIAGNOSTIC_TLV_ROUTE: - mServer->OutputFormat("Route:\r\n"); + OutputFormat("Route:\r\n"); OutputRoute(diagTlv.mData.mRoute, column + INDENT_SIZE); break; case OT_NETWORK_DIAGNOSTIC_TLV_LEADER_DATA: - mServer->OutputFormat("Leader Data:\r\n"); + OutputFormat("Leader Data:\r\n"); OutputLeaderData(diagTlv.mData.mLeaderData, column + INDENT_SIZE); break; case OT_NETWORK_DIAGNOSTIC_TLV_NETWORK_DATA: - mServer->OutputFormat("Network Data: '"); + OutputFormat("Network Data: '"); OutputBytes(diagTlv.mData.mNetworkData.m8, diagTlv.mData.mNetworkData.mCount); - mServer->OutputFormat("'\r\n"); + OutputFormat("'\r\n"); break; case OT_NETWORK_DIAGNOSTIC_TLV_IP6_ADDR_LIST: - mServer->OutputFormat("IP6 Address List:\r\n"); + OutputFormat("IP6 Address List:\r\n"); for (uint16_t i = 0; i < diagTlv.mData.mIp6AddrList.mCount; ++i) { OutputSpaces(column + INDENT_SIZE); - mServer->OutputFormat("- "); + OutputFormat("- "); OutputIp6Address(diagTlv.mData.mIp6AddrList.mList[i]); - mServer->OutputFormat("\r\n"); + OutputFormat("\r\n"); } break; case OT_NETWORK_DIAGNOSTIC_TLV_MAC_COUNTERS: - mServer->OutputFormat("MAC Counters:\r\n"); + OutputFormat("MAC Counters:\r\n"); OutputNetworkDiagMacCounters(diagTlv.mData.mMacCounters, column + INDENT_SIZE); break; case OT_NETWORK_DIAGNOSTIC_TLV_BATTERY_LEVEL: - mServer->OutputFormat("Battery Level: %u%%\r\n", diagTlv.mData.mBatteryLevel); + OutputFormat("Battery Level: %u%%\r\n", diagTlv.mData.mBatteryLevel); break; case OT_NETWORK_DIAGNOSTIC_TLV_SUPPLY_VOLTAGE: - mServer->OutputFormat("Supply Voltage: %umV\r\n", diagTlv.mData.mSupplyVoltage); + OutputFormat("Supply Voltage: %umV\r\n", diagTlv.mData.mSupplyVoltage); break; case OT_NETWORK_DIAGNOSTIC_TLV_CHILD_TABLE: - mServer->OutputFormat("Child Table:\r\n"); + OutputFormat("Child Table:\r\n"); for (uint16_t i = 0; i < diagTlv.mData.mChildTable.mCount; ++i) { OutputSpaces(column + INDENT_SIZE); - mServer->OutputFormat("- "); + OutputFormat("- "); OutputChildTableEntry(diagTlv.mData.mChildTable.mTable[i], column + INDENT_SIZE + 2); } break; case OT_NETWORK_DIAGNOSTIC_TLV_CHANNEL_PAGES: - mServer->OutputFormat("Channel Pages: '"); + OutputFormat("Channel Pages: '"); OutputBytes(diagTlv.mData.mChannelPages.m8, diagTlv.mData.mChannelPages.mCount); - mServer->OutputFormat("'\r\n"); + OutputFormat("'\r\n"); break; case OT_NETWORK_DIAGNOSTIC_TLV_MAX_CHILD_TIMEOUT: - mServer->OutputFormat("Max Child Timeout: %u\r\n", diagTlv.mData.mMaxChildTimeout); + OutputFormat("Max Child Timeout: %u\r\n", diagTlv.mData.mMaxChildTimeout); break; } } @@ -4445,68 +4427,68 @@ void Interpreter::OutputSpaces(uint16_t aCount) for (uint16_t i = 0; i < aCount; i += kSpaceStrLen) { uint16_t idx = (i + kSpaceStrLen <= aCount) ? 0 : (i + kSpaceStrLen - aCount); - mServer->OutputFormat(&spaceStr[idx]); + OutputFormat(&spaceStr[idx]); } } void Interpreter::OutputMode(const otLinkModeConfig &aMode, uint16_t aColumn) { OutputSpaces(aColumn); - mServer->OutputFormat("RxOnWhenIdle: %d\r\n", aMode.mRxOnWhenIdle); + OutputFormat("RxOnWhenIdle: %d\r\n", aMode.mRxOnWhenIdle); OutputSpaces(aColumn); - mServer->OutputFormat("SecureDataRequests: %d\r\n", aMode.mSecureDataRequests); + OutputFormat("SecureDataRequests: %d\r\n", aMode.mSecureDataRequests); OutputSpaces(aColumn); - mServer->OutputFormat("DeviceType: %d\r\n", aMode.mDeviceType); + OutputFormat("DeviceType: %d\r\n", aMode.mDeviceType); OutputSpaces(aColumn); - mServer->OutputFormat("NetworkData: %d\r\n", aMode.mNetworkData); + OutputFormat("NetworkData: %d\r\n", aMode.mNetworkData); } void Interpreter::OutputConnectivity(const otNetworkDiagConnectivity &aConnectivity, uint16_t aColumn) { OutputSpaces(aColumn); - mServer->OutputFormat("ParentPriority: %d\r\n", aConnectivity.mParentPriority); + OutputFormat("ParentPriority: %d\r\n", aConnectivity.mParentPriority); OutputSpaces(aColumn); - mServer->OutputFormat("LinkQuality3: %u\r\n", aConnectivity.mLinkQuality3); + OutputFormat("LinkQuality3: %u\r\n", aConnectivity.mLinkQuality3); OutputSpaces(aColumn); - mServer->OutputFormat("LinkQuality2: %u\r\n", aConnectivity.mLinkQuality2); + OutputFormat("LinkQuality2: %u\r\n", aConnectivity.mLinkQuality2); OutputSpaces(aColumn); - mServer->OutputFormat("LinkQuality1: %u\r\n", aConnectivity.mLinkQuality1); + OutputFormat("LinkQuality1: %u\r\n", aConnectivity.mLinkQuality1); OutputSpaces(aColumn); - mServer->OutputFormat("LeaderCost: %u\r\n", aConnectivity.mLeaderCost); + OutputFormat("LeaderCost: %u\r\n", aConnectivity.mLeaderCost); OutputSpaces(aColumn); - mServer->OutputFormat("IdSequence: %u\r\n", aConnectivity.mIdSequence); + OutputFormat("IdSequence: %u\r\n", aConnectivity.mIdSequence); OutputSpaces(aColumn); - mServer->OutputFormat("ActiveRouters: %u\r\n", aConnectivity.mActiveRouters); + OutputFormat("ActiveRouters: %u\r\n", aConnectivity.mActiveRouters); OutputSpaces(aColumn); - mServer->OutputFormat("SedBufferSize: %u\r\n", aConnectivity.mSedBufferSize); + OutputFormat("SedBufferSize: %u\r\n", aConnectivity.mSedBufferSize); OutputSpaces(aColumn); - mServer->OutputFormat("SedDatagramCount: %u\r\n", aConnectivity.mSedDatagramCount); + OutputFormat("SedDatagramCount: %u\r\n", aConnectivity.mSedDatagramCount); } void Interpreter::OutputRoute(const otNetworkDiagRoute &aRoute, uint16_t aColumn) { OutputSpaces(aColumn); - mServer->OutputFormat("IdSequence: %u\r\n", aRoute.mIdSequence); + OutputFormat("IdSequence: %u\r\n", aRoute.mIdSequence); OutputSpaces(aColumn); - mServer->OutputFormat("RouteData:\r\n"); + OutputFormat("RouteData:\r\n"); aColumn += INDENT_SIZE; for (uint16_t i = 0; i < aRoute.mRouteCount; ++i) { OutputSpaces(aColumn); - mServer->OutputFormat("- "); + OutputFormat("- "); OutputRouteData(aRoute.mRouteData[i], aColumn + 2); } @@ -4514,75 +4496,75 @@ void Interpreter::OutputRoute(const otNetworkDiagRoute &aRoute, uint16_t aColumn void Interpreter::OutputRouteData(const otNetworkDiagRouteData &aRouteData, uint16_t aColumn) { - mServer->OutputFormat("RouteId: 0x%02x\r\n", aRouteData.mRouterId); + OutputFormat("RouteId: 0x%02x\r\n", aRouteData.mRouterId); OutputSpaces(aColumn); - mServer->OutputFormat("LinkQualityOut: %u\r\n", aRouteData.mLinkQualityOut); + OutputFormat("LinkQualityOut: %u\r\n", aRouteData.mLinkQualityOut); OutputSpaces(aColumn); - mServer->OutputFormat("LinkQualityIn: %u\r\n", aRouteData.mLinkQualityIn); + OutputFormat("LinkQualityIn: %u\r\n", aRouteData.mLinkQualityIn); OutputSpaces(aColumn); - mServer->OutputFormat("RouteCost: %u\r\n", aRouteData.mRouteCost); + OutputFormat("RouteCost: %u\r\n", aRouteData.mRouteCost); } void Interpreter::OutputLeaderData(const otLeaderData &aLeaderData, uint16_t aColumn) { OutputSpaces(aColumn); - mServer->OutputFormat("PartitionId: 0x%08x\r\n", aLeaderData.mPartitionId); + OutputFormat("PartitionId: 0x%08x\r\n", aLeaderData.mPartitionId); OutputSpaces(aColumn); - mServer->OutputFormat("Weighting: %u\r\n", aLeaderData.mWeighting); + OutputFormat("Weighting: %u\r\n", aLeaderData.mWeighting); OutputSpaces(aColumn); - mServer->OutputFormat("DataVersion: %u\r\n", aLeaderData.mDataVersion); + OutputFormat("DataVersion: %u\r\n", aLeaderData.mDataVersion); OutputSpaces(aColumn); - mServer->OutputFormat("StableDataVersion: %u\r\n", aLeaderData.mStableDataVersion); + OutputFormat("StableDataVersion: %u\r\n", aLeaderData.mStableDataVersion); OutputSpaces(aColumn); - mServer->OutputFormat("LeaderRouterId: 0x%02x\r\n", aLeaderData.mLeaderRouterId); + OutputFormat("LeaderRouterId: 0x%02x\r\n", aLeaderData.mLeaderRouterId); } void Interpreter::OutputNetworkDiagMacCounters(const otNetworkDiagMacCounters &aMacCounters, uint16_t aColumn) { OutputSpaces(aColumn); - mServer->OutputFormat("IfInUnknownProtos: %u\r\n", aMacCounters.mIfInUnknownProtos); + OutputFormat("IfInUnknownProtos: %u\r\n", aMacCounters.mIfInUnknownProtos); OutputSpaces(aColumn); - mServer->OutputFormat("IfInErrors: %u\r\n", aMacCounters.mIfInErrors); + OutputFormat("IfInErrors: %u\r\n", aMacCounters.mIfInErrors); OutputSpaces(aColumn); - mServer->OutputFormat("IfOutErrors: %u\r\n", aMacCounters.mIfOutErrors); + OutputFormat("IfOutErrors: %u\r\n", aMacCounters.mIfOutErrors); OutputSpaces(aColumn); - mServer->OutputFormat("IfInUcastPkts: %u\r\n", aMacCounters.mIfInUcastPkts); + OutputFormat("IfInUcastPkts: %u\r\n", aMacCounters.mIfInUcastPkts); OutputSpaces(aColumn); - mServer->OutputFormat("IfInBroadcastPkts: %u\r\n", aMacCounters.mIfInBroadcastPkts); + OutputFormat("IfInBroadcastPkts: %u\r\n", aMacCounters.mIfInBroadcastPkts); OutputSpaces(aColumn); - mServer->OutputFormat("IfInDiscards: %u\r\n", aMacCounters.mIfInDiscards); + OutputFormat("IfInDiscards: %u\r\n", aMacCounters.mIfInDiscards); OutputSpaces(aColumn); - mServer->OutputFormat("IfOutUcastPkts: %u\r\n", aMacCounters.mIfOutUcastPkts); + OutputFormat("IfOutUcastPkts: %u\r\n", aMacCounters.mIfOutUcastPkts); OutputSpaces(aColumn); - mServer->OutputFormat("IfOutBroadcastPkts: %u\r\n", aMacCounters.mIfOutBroadcastPkts); + OutputFormat("IfOutBroadcastPkts: %u\r\n", aMacCounters.mIfOutBroadcastPkts); OutputSpaces(aColumn); - mServer->OutputFormat("IfOutDiscards: %u\r\n", aMacCounters.mIfOutDiscards); + OutputFormat("IfOutDiscards: %u\r\n", aMacCounters.mIfOutDiscards); } void Interpreter::OutputChildTableEntry(const otNetworkDiagChildEntry &aChildEntry, uint16_t aColumn) { - mServer->OutputFormat("ChildId: 0x%04x\r\n", aChildEntry.mChildId); + OutputFormat("ChildId: 0x%04x\r\n", aChildEntry.mChildId); OutputSpaces(aColumn); - mServer->OutputFormat("Timeout: %u\r\n", aChildEntry.mTimeout); + OutputFormat("Timeout: %u\r\n", aChildEntry.mTimeout); OutputSpaces(aColumn); - mServer->OutputFormat("Mode:\r\n"); + OutputFormat("Mode:\r\n"); OutputMode(aChildEntry.mMode, aColumn + INDENT_SIZE); } @@ -4601,7 +4583,7 @@ Interpreter &Interpreter::GetOwner(OwnerLocator &aOwnerLocator) #else OT_UNUSED_VARIABLE(aOwnerLocator); - Interpreter &interpreter = Server::sServer->GetInterpreter(); + Interpreter &interpreter = Interpreter::GetInterpreter(); #endif return interpreter; } @@ -4638,37 +4620,58 @@ void Interpreter::SignalPingReply(const Ip6::Address &aPeerAddress, void Interpreter::HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aInfo) { - mServer->OutputFormat("~ Discovery Request from "); + OutputFormat("~ Discovery Request from "); OutputBytes(aInfo.mExtAddress.m8, sizeof(aInfo.mExtAddress.m8)); - mServer->OutputFormat(": version=%u,joiner=%d\r\n", aInfo.mVersion, aInfo.mIsJoiner); + OutputFormat(": version=%u,joiner=%d\r\n", aInfo.mVersion, aInfo.mIsJoiner); +} + +int Interpreter::OutputFormat(const char *aFormat, ...) +{ + int rval; + va_list ap; + + va_start(ap, aFormat); + rval = OutputFormatV(aFormat, ap); + va_end(ap); + + return rval; +} + +int Interpreter::OutputFormatV(const char *aFormat, va_list aArguments) +{ + char buf[kMaxLineLength]; + + vsnprintf(buf, sizeof(buf), aFormat, aArguments); + + return Output(buf, static_cast(strlen(buf))); } extern "C" void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength) { - Server::sServer->GetInterpreter().SetUserCommands(aUserCommands, aLength); + Interpreter::GetInterpreter().SetUserCommands(aUserCommands, aLength); } extern "C" void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength) { - Server::sServer->GetInterpreter().OutputBytes(aBytes, aLength); + Interpreter::GetInterpreter().OutputBytes(aBytes, aLength); } extern "C" void otCliOutputFormat(const char *aFmt, ...) { va_list aAp; va_start(aAp, aFmt); - Server::sServer->OutputFormatV(aFmt, aAp); + Interpreter::GetInterpreter().OutputFormatV(aFmt, aAp); va_end(aAp); } extern "C" void otCliOutput(const char *aString, uint16_t aLength) { - Server::sServer->Output(aString, aLength); + Interpreter::GetInterpreter().Output(aString, aLength); } extern "C" void otCliAppendResult(otError aError) { - Server::sServer->GetInterpreter().AppendResult(aError); + Interpreter::GetInterpreter().AppendResult(aError); } extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs) @@ -4676,13 +4679,8 @@ extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, cons OT_UNUSED_VARIABLE(aLogLevel); OT_UNUSED_VARIABLE(aLogRegion); - VerifyOrExit(Server::sServer != nullptr, OT_NOOP); - - Server::sServer->OutputFormatV(aFormat, aArgs); - Server::sServer->OutputFormat("\r\n"); - -exit: - return; + Interpreter::GetInterpreter().OutputFormatV(aFormat, aArgs); + Interpreter::GetInterpreter().OutputFormat("\r\n"); } } // namespace Cli diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index a0ce44905..51ae3f508 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -77,7 +77,6 @@ namespace ot { namespace Cli { class Interpreter; -class Server; /** * This structure represents a CLI command. @@ -110,15 +109,22 @@ public: */ explicit Interpreter(Instance *aInstance); + /** + * This method returns a reference to the interpreter object. + * + * @returns A reference to the interpreter object. + * + */ + static Interpreter &GetInterpreter(void); + /** * This method interprets a CLI command. * * @param[in] aBuf A pointer to a string. * @param[in] aBufLength The length of the string in bytes. - * @param[in] aServer A reference to the CLI server. * */ - void ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer); + void ProcessLine(char *aBuf, uint16_t aBufLength); /** * This method parses an ASCII string as a long. @@ -163,7 +169,20 @@ public: * * @param[in] aError Error code value. */ - void AppendResult(otError aError) const; + void AppendResult(otError aError); + + /** + * This method delivers raw characters to the client. + * + * @param[in] aBuf A pointer to a buffer. + * @param[in] aBufLength Number of bytes in the buffer. + * + * @returns The number of bytes placed in the output queue. + * + * @retval -1 Driver is broken. + * + */ + int Output(const char *aBuf, uint16_t aBufLength); /** * Write a number of bytes to the CLI console as a hex string. @@ -171,7 +190,31 @@ public: * @param[in] aBytes A pointer to data which should be printed. * @param[in] aLength @p aBytes length. */ - void OutputBytes(const uint8_t *aBytes, uint8_t aLength) const; + void OutputBytes(const uint8_t *aBytes, uint8_t aLength); + + /** + * This method delivers formatted output to the client. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... A variable list of arguments to format. + * + * @returns The number of bytes placed in the output queue. + * + * @retval -1 Driver is broken. + * + */ + int OutputFormat(const char *aFormat, ...); + + /** + * This method delivers formatted output to the client. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] aArguments A variable list of arguments for format. + * + * @returns The number of bytes placed in the output queue. + * + */ + int OutputFormatV(const char *aFormat, va_list aArguments); /** * Write an IPv6 address to the CLI console. @@ -183,7 +226,7 @@ public: * @retval -1 Driver is broken. * */ - int OutputIp6Address(const otIp6Address &aAddress) const; + int OutputIp6Address(const otIp6Address &aAddress); /** * Set a user command table. @@ -202,6 +245,8 @@ private: kDefaultPingInterval = 1000, // (in mses) kDefaultPingLength = 8, // (in bytes) kDefaultPingCount = 1, + + kMaxLineLength = OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH, }; otError ParsePingInterval(const char *aString, uint32_t &aInterval); @@ -439,7 +484,6 @@ private: static const struct Command sCommands[]; const otCliCommand * mUserCommands; uint8_t mUserCommandsLength; - Server * mServer; uint16_t mPingLength; uint16_t mPingCount; uint32_t mPingInterval; diff --git a/src/cli/cli_coap.cpp b/src/cli/cli_coap.cpp index d06b88cc6..f79c2b3af 100644 --- a/src/cli/cli_coap.cpp +++ b/src/cli/cli_coap.cpp @@ -38,7 +38,6 @@ #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" #include "coap/coap_message.hpp" namespace ot { @@ -141,7 +140,7 @@ void Coap::PrintPayload(otMessage *aMessage) const if (length > 0) { - mInterpreter.mServer->OutputFormat(" with payload: "); + mInterpreter.OutputFormat(" with payload: "); while (length > 0) { @@ -155,7 +154,7 @@ void Coap::PrintPayload(otMessage *aMessage) const } } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE @@ -175,7 +174,7 @@ otError Coap::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -198,7 +197,7 @@ otError Coap::ProcessResource(uint8_t aArgsLength, char *aArgs[]) } else { - mInterpreter.mServer->OutputFormat("%s\r\n", mResource.mUriPath); + mInterpreter.OutputFormat("%s\r\n", mResource.mUriPath); } exit: @@ -227,9 +226,9 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[]) messageInfo.mPeerAddr = mSubscriberSock.mAddress; messageInfo.mPeerPort = mSubscriberSock.mPort; - mInterpreter.mServer->OutputFormat("sending coap notification to "); + mInterpreter.OutputFormat("sending coap notification to "); mInterpreter.OutputIp6Address(mSubscriberSock.mAddress); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); notificationMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr); VerifyOrExit(notificationMessage != nullptr, error = OT_ERROR_NO_BUFS); @@ -252,7 +251,7 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[]) } else { - mInterpreter.mServer->OutputFormat("%s\r\n", mResourceContent); + mInterpreter.OutputFormat("%s\r\n", mResourceContent); } exit: @@ -342,16 +341,16 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[]) } } - mInterpreter.mServer->OutputFormat("Transmission parameters for %s:\r\n", aArgs[1]); + mInterpreter.OutputFormat("Transmission parameters for %s:\r\n", aArgs[1]); if (*defaultTxParameters) { - mInterpreter.mServer->OutputFormat("default\r\n"); + mInterpreter.OutputFormat("default\r\n"); } else { - mInterpreter.mServer->OutputFormat("ACK_TIMEOUT=%u ms, ACK_RANDOM_FACTOR=%u/%u, MAX_RETRANSMIT=%u\r\n", - txParameters->mAckTimeout, txParameters->mAckRandomFactorNumerator, - txParameters->mAckRandomFactorDenominator, txParameters->mMaxRetransmit); + mInterpreter.OutputFormat("ACK_TIMEOUT=%u ms, ACK_RANDOM_FACTOR=%u/%u, MAX_RETRANSMIT=%u\r\n", + txParameters->mAckTimeout, txParameters->mAckRandomFactorNumerator, + txParameters->mAckRandomFactorDenominator, txParameters->mMaxRetransmit); } exit: @@ -552,14 +551,14 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) otCoapOptionIterator iterator; #endif - mInterpreter.mServer->OutputFormat("coap request from "); + mInterpreter.OutputFormat("coap request from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); - mInterpreter.mServer->OutputFormat(" "); + mInterpreter.OutputFormat(" "); switch (otCoapMessageGetCode(aMessage)) { case OT_COAP_CODE_GET: - mInterpreter.mServer->OutputFormat("GET"); + mInterpreter.OutputFormat("GET"); #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE SuccessOrExit(error = otCoapOptionIteratorInit(&iterator, aMessage)); if (otCoapOptionIteratorGetFirstOptionMatching(&iterator, OT_COAP_OPTION_OBSERVE) != nullptr) @@ -567,25 +566,25 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) SuccessOrExit(error = otCoapOptionIteratorGetOptionUintValue(&iterator, &observe)); observePresent = true; - mInterpreter.mServer->OutputFormat(" OBS=%lu", static_cast(observe)); + mInterpreter.OutputFormat(" OBS=%lu", static_cast(observe)); } #endif break; case OT_COAP_CODE_DELETE: - mInterpreter.mServer->OutputFormat("DELETE"); + mInterpreter.OutputFormat("DELETE"); break; case OT_COAP_CODE_PUT: - mInterpreter.mServer->OutputFormat("PUT"); + mInterpreter.OutputFormat("PUT"); break; case OT_COAP_CODE_POST: - mInterpreter.mServer->OutputFormat("POST"); + mInterpreter.OutputFormat("POST"); break; default: - mInterpreter.mServer->OutputFormat("Undefined\r\n"); + mInterpreter.OutputFormat("Undefined\r\n"); ExitNow(error = OT_ERROR_PARSE); } @@ -611,7 +610,7 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) if (observe == 0) { // New subscriber - mInterpreter.mServer->OutputFormat("Subscribing client\r\n"); + mInterpreter.OutputFormat("Subscribing client\r\n"); mSubscriberSock.mAddress = aMessageInfo->mPeerAddr; mSubscriberSock.mPort = aMessageInfo->mPeerPort; mSubscriberTokenLength = otCoapMessageGetTokenLength(aMessage); @@ -674,14 +673,13 @@ exit: { if (responseMessage != nullptr) { - mInterpreter.mServer->OutputFormat("coap send response error %d: %s\r\n", error, - otThreadErrorToString(error)); + mInterpreter.OutputFormat("coap send response error %d: %s\r\n", error, otThreadErrorToString(error)); otMessageFree(responseMessage); } } else if (responseCode >= OT_COAP_CODE_RESPONSE_MIN) { - mInterpreter.mServer->OutputFormat("coap response sent\r\n"); + mInterpreter.OutputFormat("coap response sent\r\n"); } } @@ -703,15 +701,15 @@ void Coap::HandleNotificationResponse(otMessage *aMessage, const otMessageInfo * case OT_ERROR_NONE: if (aMessageInfo != nullptr) { - mInterpreter.mServer->OutputFormat("Received ACK in reply to notification from "); + mInterpreter.OutputFormat("Received ACK in reply to notification from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } break; default: - mInterpreter.mServer->OutputFormat("coap receive notification response error %d: %s\r\n", aError, - otThreadErrorToString(aError)); + mInterpreter.OutputFormat("coap receive notification response error %d: %s\r\n", aError, + otThreadErrorToString(aError)); CancelSubscriber(); break; } @@ -727,8 +725,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo { if (aError != OT_ERROR_NONE) { - mInterpreter.mServer->OutputFormat("coap receive response error %d: %s\r\n", aError, - otThreadErrorToString(aError)); + mInterpreter.OutputFormat("coap receive response error %d: %s\r\n", aError, otThreadErrorToString(aError)); } else if ((aMessageInfo != nullptr) && (aMessage != nullptr)) { @@ -736,7 +733,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo otCoapOptionIterator iterator; #endif - mInterpreter.mServer->OutputFormat("coap response from "); + mInterpreter.OutputFormat("coap response from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE @@ -752,7 +749,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo if (error == OT_ERROR_NONE) { - mInterpreter.mServer->OutputFormat(" OBS=%u", observeVal); + mInterpreter.OutputFormat(" OBS=%u", observeVal); } } } diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index fbbbd4e56..754be2c8a 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -39,7 +39,6 @@ #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" // header for place your x509 certificate and private key #include "x509_cert_key.hpp" @@ -84,7 +83,7 @@ void CoapSecure::PrintPayload(otMessage *aMessage) const if (length > 0) { - mInterpreter.mServer->OutputFormat(" with payload: "); + mInterpreter.OutputFormat(" with payload: "); while (length > 0) { @@ -98,7 +97,7 @@ void CoapSecure::PrintPayload(otMessage *aMessage) const } } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) @@ -108,7 +107,7 @@ otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -131,7 +130,7 @@ otError CoapSecure::ProcessResource(uint8_t aArgsLength, char *aArgs[]) } else { - mInterpreter.mServer->OutputFormat("%s\r\n", mResource.mUriPath); + mInterpreter.OutputFormat("%s\r\n", mResource.mUriPath); } exit: @@ -150,7 +149,7 @@ otError CoapSecure::ProcessSet(uint8_t aArgsLength, char *aArgs[]) } else { - mInterpreter.mServer->OutputFormat("%s\r\n", mResourceContent); + mInterpreter.OutputFormat("%s\r\n", mResourceContent); } exit: @@ -448,11 +447,11 @@ void CoapSecure::HandleConnected(bool aConnected) { if (aConnected) { - mInterpreter.mServer->OutputFormat("coaps connected\r\n"); + mInterpreter.OutputFormat("coaps connected\r\n"); } else { - mInterpreter.mServer->OutputFormat("coaps disconnected\r\n"); + mInterpreter.OutputFormat("coaps disconnected\r\n"); if (mShutdownFlag) { @@ -473,30 +472,30 @@ void CoapSecure::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessag otMessage *responseMessage = nullptr; otCoapCode responseCode = OT_COAP_CODE_EMPTY; - mInterpreter.mServer->OutputFormat("coaps request from "); + mInterpreter.OutputFormat("coaps request from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); - mInterpreter.mServer->OutputFormat(" "); + mInterpreter.OutputFormat(" "); switch (otCoapMessageGetCode(aMessage)) { case OT_COAP_CODE_GET: - mInterpreter.mServer->OutputFormat("GET"); + mInterpreter.OutputFormat("GET"); break; case OT_COAP_CODE_DELETE: - mInterpreter.mServer->OutputFormat("DELETE"); + mInterpreter.OutputFormat("DELETE"); break; case OT_COAP_CODE_PUT: - mInterpreter.mServer->OutputFormat("PUT"); + mInterpreter.OutputFormat("PUT"); break; case OT_COAP_CODE_POST: - mInterpreter.mServer->OutputFormat("POST"); + mInterpreter.OutputFormat("POST"); break; default: - mInterpreter.mServer->OutputFormat("Undefined\r\n"); + mInterpreter.OutputFormat("Undefined\r\n"); return; } @@ -540,14 +539,13 @@ exit: { if (responseMessage != nullptr) { - mInterpreter.mServer->OutputFormat("coaps send response error %d: %s\r\n", error, - otThreadErrorToString(error)); + mInterpreter.OutputFormat("coaps send response error %d: %s\r\n", error, otThreadErrorToString(error)); otMessageFree(responseMessage); } } else if (responseCode >= OT_COAP_CODE_RESPONSE_MIN) { - mInterpreter.mServer->OutputFormat("coaps response sent\r\n"); + mInterpreter.OutputFormat("coaps response sent\r\n"); } } @@ -562,12 +560,11 @@ void CoapSecure::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessa if (aError != OT_ERROR_NONE) { - mInterpreter.mServer->OutputFormat("coaps receive response error %d: %s\r\n", aError, - otThreadErrorToString(aError)); + mInterpreter.OutputFormat("coaps receive response error %d: %s\r\n", aError, otThreadErrorToString(aError)); } else { - mInterpreter.mServer->OutputFormat("coaps response from "); + mInterpreter.OutputFormat("coaps response from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); PrintPayload(aMessage); diff --git a/src/cli/cli_commissioner.cpp b/src/cli/cli_commissioner.cpp index 7505a7cf7..38a778ba3 100644 --- a/src/cli/cli_commissioner.cpp +++ b/src/cli/cli_commissioner.cpp @@ -34,7 +34,6 @@ #include "cli_commissioner.hpp" #include "cli/cli.hpp" -#include "cli/cli_server.hpp" #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD @@ -57,7 +56,7 @@ otError Commissioner::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -330,7 +329,7 @@ otError Commissioner::ProcessSessionId(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - mInterpreter.mServer->OutputFormat("%d\r\n", otCommissionerGetSessionId(mInterpreter.mInstance)); + mInterpreter.OutputFormat("%d\r\n", otCommissionerGetSessionId(mInterpreter.mInstance)); return OT_ERROR_NONE; } @@ -351,7 +350,7 @@ void Commissioner::HandleStateChanged(otCommissionerState aState, void *aContext void Commissioner::HandleStateChanged(otCommissionerState aState) { - mInterpreter.mServer->OutputFormat("Commissioner: %s\r\n", StateToString(aState)); + mInterpreter.OutputFormat("Commissioner: %s\r\n", StateToString(aState)); } const char *Commissioner::StateToString(otCommissionerState aState) @@ -388,24 +387,24 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent, { OT_UNUSED_VARIABLE(aJoinerInfo); - mInterpreter.mServer->OutputFormat("Commissioner: Joiner "); + mInterpreter.OutputFormat("Commissioner: Joiner "); switch (aEvent) { case OT_COMMISSIONER_JOINER_START: - mInterpreter.mServer->OutputFormat("start "); + mInterpreter.OutputFormat("start "); break; case OT_COMMISSIONER_JOINER_CONNECTED: - mInterpreter.mServer->OutputFormat("connect "); + mInterpreter.OutputFormat("connect "); break; case OT_COMMISSIONER_JOINER_FINALIZE: - mInterpreter.mServer->OutputFormat("finalize "); + mInterpreter.OutputFormat("finalize "); break; case OT_COMMISSIONER_JOINER_END: - mInterpreter.mServer->OutputFormat("end "); + mInterpreter.OutputFormat("end "); break; case OT_COMMISSIONER_JOINER_REMOVED: - mInterpreter.mServer->OutputFormat("remove "); + mInterpreter.OutputFormat("remove "); break; } @@ -414,7 +413,7 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent, mInterpreter.OutputBytes(aJoinerId->m8, sizeof(*aJoinerId)); } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } otError Commissioner::ProcessStop(uint8_t aArgsLength, char *aArgs[]) @@ -430,7 +429,7 @@ otError Commissioner::ProcessState(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgsLength); OT_UNUSED_VARIABLE(aArgs); - mInterpreter.mServer->OutputFormat("%s\r\n", StateToString(otCommissionerGetState(mInterpreter.mInstance))); + mInterpreter.OutputFormat("%s\r\n", StateToString(otCommissionerGetState(mInterpreter.mInstance))); return OT_ERROR_NONE; } @@ -468,14 +467,14 @@ void Commissioner::HandleEnergyReport(uint32_t aChannelMask, void Commissioner::HandleEnergyReport(uint32_t aChannelMask, const uint8_t *aEnergyList, uint8_t aEnergyListLength) { - mInterpreter.mServer->OutputFormat("Energy: %08x ", aChannelMask); + mInterpreter.OutputFormat("Energy: %08x ", aChannelMask); for (uint8_t i = 0; i < aEnergyListLength; i++) { - mInterpreter.mServer->OutputFormat("%d ", static_cast(aEnergyList[i])); + mInterpreter.OutputFormat("%d ", static_cast(aEnergyList[i])); } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask, void *aContext) @@ -485,7 +484,7 @@ void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask, v void Commissioner::HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask) { - mInterpreter.mServer->OutputFormat("Conflict: %04x, %08x\r\n", aPanId, aChannelMask); + mInterpreter.OutputFormat("Conflict: %04x, %08x\r\n", aPanId, aChannelMask); } } // namespace Cli diff --git a/src/cli/cli_config.h b/src/cli/cli_config.h index cd77e2b7c..3316cc341 100644 --- a/src/cli/cli_config.h +++ b/src/cli/cli_config.h @@ -35,6 +35,8 @@ #ifndef CONFIG_CLI_H_ #define CONFIG_CLI_H_ +#include + /** * @def OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH * @@ -75,4 +77,22 @@ #define OPENTHREAD_CONFIG_UART_CLI_RAW 0 #endif +#define OT_CLI_TRANSPORT_UART (1) +#define OT_CLI_TRANSPORT_CONSOLE (2) + +/** + * @def OPENTHREAD_CONFIG_CLI_TRANSPORT + * + * The transport of the CLI. + * + */ +#ifndef OPENTHREAD_CONFIG_CLI_TRANSPORT +#define OPENTHREAD_CONFIG_CLI_TRANSPORT OT_CLI_TRANSPORT_UART +#endif + +#if OPENTHREAD_CONFIG_CLI_TRANSPORT != OT_CLI_TRANSPORT_UART && \ + OPENTHREAD_CONFIG_CLI_TRANSPORT != OT_CLI_TRANSPORT_CONSOLE +#error "Unsupported CLI transport!" +#endif + #endif // CONFIG_CLI_H_ diff --git a/src/cli/cli_console.cpp b/src/cli/cli_console.cpp index 97fdcbd32..b2f5647a6 100644 --- a/src/cli/cli_console.cpp +++ b/src/cli/cli_console.cpp @@ -28,11 +28,13 @@ /** * @file - * This file implements the CLI server on the CONSOLE service. + * This file implements the CLI interpreter on the CONSOLE service. */ #include "cli_console.hpp" +#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE + #include #include #include @@ -48,38 +50,49 @@ static OT_DEFINE_ALIGNED_VAR(sCliConsoleRaw, sizeof(Console), uint64_t); extern "C" void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext) { - Instance *instance = static_cast(aInstance); - - Server::sServer = new (&sCliConsoleRaw) Console(instance); - static_cast(Server::sServer)->SetOutputCallback(aCallback); - static_cast(Server::sServer)->SetContext(aContext); + Console::Initialize(aInstance, aCallback, aContext); } extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength) { - static_cast(Server::sServer)->ReceiveTask(aBuf, aBufLength); + Interpreter::GetInterpreter().ProcessLine(aBuf, aBufLength); } -Console::Console(Instance *aInstance) - : Server(aInstance) - , mCallback(nullptr) - , mContext(nullptr) +// Add stubs for simulation +extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) +{ + OT_UNUSED_VARIABLE(aBuf); + OT_UNUSED_VARIABLE(aBufLength); +} + +extern "C" void otPlatUartSendDone(void) { } -void Console::SetContext(void *aContext) +Console *Console::sConsole = nullptr; + +Interpreter &Interpreter::GetInterpreter(void) { - mContext = aContext; + return *Console::sConsole; } -void Console::SetOutputCallback(otCliConsoleOutputCallback aCallback) +void Console::Initialize(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext) { - mCallback = aCallback; + Instance *instance = static_cast(aInstance); + + sConsole = new (&sCliConsoleRaw) Console(instance, aCallback, aContext); } -void Console::ReceiveTask(char *aBuf, uint16_t aBufLength) +Console::Console(Instance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext) + : Interpreter(aInstance) + , mCallback(aCallback) + , mContext(aContext) { - mInterpreter.ProcessLine(aBuf, aBufLength, *this); +} + +int Interpreter::Output(const char *aBuf, uint16_t aBufLength) +{ + return static_cast(this)->Output(aBuf, aBufLength); } int Console::Output(const char *aBuf, uint16_t aBufLength) @@ -89,3 +102,5 @@ int Console::Output(const char *aBuf, uint16_t aBufLength) } // namespace Cli } // namespace ot + +#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE diff --git a/src/cli/cli_console.hpp b/src/cli/cli_console.hpp index 80587c9c8..b9937781d 100644 --- a/src/cli/cli_console.hpp +++ b/src/cli/cli_console.hpp @@ -28,36 +28,38 @@ /** * @file - * This file contains definitions for a CLI server on the CONSOLE service. + * This file contains definitions for a CLI interpreter on the CONSOLE service. */ #ifndef CLI_CONSOLE_HPP_ #define CLI_CONSOLE_HPP_ +#include "cli_config.h" #include "openthread-core-config.h" #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" namespace ot { namespace Cli { /** - * This class implements the CLI server on top of the CONSOLE platform abstraction. + * This class implements the CLI interpreter on top of the CONSOLE platform abstraction. * */ -class Console : public Server +class Console : public Interpreter { public: /** - * Constructor + * This method initializes the Console interpreter. * * @param[in] aInstance The OpenThread instance structure. + * @param[in] aCallback A pointer to a callback method. + * @param[in] aContext A pointer to a user context. * */ - explicit Console(Instance *aInstance); + static void Initialize(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext); /** * This method delivers raw characters to the client. @@ -68,29 +70,17 @@ public: * @returns The number of bytes placed in the output queue. * */ - virtual int Output(const char *aBuf, uint16_t aBufLength); - - /** - * This method sets a callback that is called when console has some output. - * - * @param[in] aCallback A pointer to a callback method. - * - */ - void SetOutputCallback(otCliConsoleOutputCallback aCallback); - - /** - * This method sets a context that is returned with the callback. - * - * @param[in] aContext A pointer to a user context. - * - */ - void SetContext(void *aContext); - - void ReceiveTask(char *aBuf, uint16_t aBufLength); + int Output(const char *aBuf, uint16_t aBufLength); private: + explicit Console(Instance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext); + otCliConsoleOutputCallback mCallback; void * mContext; + + static Console *sConsole; + + friend class Interpreter; }; } // namespace Cli diff --git a/src/cli/cli_dataset.cpp b/src/cli/cli_dataset.cpp index 974a29027..580b40742 100644 --- a/src/cli/cli_dataset.cpp +++ b/src/cli/cli_dataset.cpp @@ -40,7 +40,6 @@ #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" namespace ot { namespace Cli { @@ -75,7 +74,7 @@ void Dataset::OutputBytes(const uint8_t *aBytes, uint8_t aLength) { for (int i = 0; i < aLength; i++) { - mInterpreter.mServer->OutputFormat("%02x", aBytes[i]); + mInterpreter.OutputFormat("%02x", aBytes[i]); } } @@ -83,40 +82,40 @@ otError Dataset::Print(otOperationalDataset &aDataset) { if (aDataset.mComponents.mIsPendingTimestampPresent) { - mInterpreter.mServer->OutputFormat("Pending Timestamp: %lu\r\n", aDataset.mPendingTimestamp); + mInterpreter.OutputFormat("Pending Timestamp: %lu\r\n", aDataset.mPendingTimestamp); } if (aDataset.mComponents.mIsActiveTimestampPresent) { - mInterpreter.mServer->OutputFormat("Active Timestamp: %lu\r\n", aDataset.mActiveTimestamp); + mInterpreter.OutputFormat("Active Timestamp: %lu\r\n", aDataset.mActiveTimestamp); } if (aDataset.mComponents.mIsChannelPresent) { - mInterpreter.mServer->OutputFormat("Channel: %d\r\n", aDataset.mChannel); + mInterpreter.OutputFormat("Channel: %d\r\n", aDataset.mChannel); } if (aDataset.mComponents.mIsChannelMaskPresent) { - mInterpreter.mServer->OutputFormat("Channel Mask: 0x%08x\r\n", aDataset.mChannelMask); + mInterpreter.OutputFormat("Channel Mask: 0x%08x\r\n", aDataset.mChannelMask); } if (aDataset.mComponents.mIsDelayPresent) { - mInterpreter.mServer->OutputFormat("Delay: %d\r\n", aDataset.mDelay); + mInterpreter.OutputFormat("Delay: %d\r\n", aDataset.mDelay); } if (aDataset.mComponents.mIsExtendedPanIdPresent) { - mInterpreter.mServer->OutputFormat("Ext PAN ID: "); + mInterpreter.OutputFormat("Ext PAN ID: "); OutputBytes(aDataset.mExtendedPanId.m8, sizeof(aDataset.mExtendedPanId)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } if (aDataset.mComponents.mIsMeshLocalPrefixPresent) { const uint8_t *prefix = aDataset.mMeshLocalPrefix.m8; - mInterpreter.mServer->OutputFormat( + 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]); @@ -124,60 +123,60 @@ otError Dataset::Print(otOperationalDataset &aDataset) if (aDataset.mComponents.mIsMasterKeyPresent) { - mInterpreter.mServer->OutputFormat("Master Key: "); + mInterpreter.OutputFormat("Master Key: "); OutputBytes(aDataset.mMasterKey.m8, sizeof(aDataset.mMasterKey)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } if (aDataset.mComponents.mIsNetworkNamePresent) { - mInterpreter.mServer->OutputFormat("Network Name: "); - mInterpreter.mServer->OutputFormat("%.*s\r\n", static_cast(sizeof(aDataset.mNetworkName)), - aDataset.mNetworkName.m8); + mInterpreter.OutputFormat("Network Name: "); + mInterpreter.OutputFormat("%.*s\r\n", static_cast(sizeof(aDataset.mNetworkName)), + aDataset.mNetworkName.m8); } if (aDataset.mComponents.mIsPanIdPresent) { - mInterpreter.mServer->OutputFormat("PAN ID: 0x%04x\r\n", aDataset.mPanId); + mInterpreter.OutputFormat("PAN ID: 0x%04x\r\n", aDataset.mPanId); } if (aDataset.mComponents.mIsPskcPresent) { - mInterpreter.mServer->OutputFormat("PSKc: "); + mInterpreter.OutputFormat("PSKc: "); OutputBytes(aDataset.mPskc.m8, sizeof(aDataset.mPskc.m8)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } if (aDataset.mComponents.mIsSecurityPolicyPresent) { - mInterpreter.mServer->OutputFormat("Security Policy: %d, ", aDataset.mSecurityPolicy.mRotationTime); + mInterpreter.OutputFormat("Security Policy: %d, ", aDataset.mSecurityPolicy.mRotationTime); if (aDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY) { - mInterpreter.mServer->OutputFormat("o"); + mInterpreter.OutputFormat("o"); } if (aDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_NATIVE_COMMISSIONING) { - mInterpreter.mServer->OutputFormat("n"); + mInterpreter.OutputFormat("n"); } if (aDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_ROUTERS) { - mInterpreter.mServer->OutputFormat("r"); + mInterpreter.OutputFormat("r"); } if (aDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_EXTERNAL_COMMISSIONER) { - mInterpreter.mServer->OutputFormat("c"); + mInterpreter.OutputFormat("c"); } if (aDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_BEACONS) { - mInterpreter.mServer->OutputFormat("b"); + mInterpreter.OutputFormat("b"); } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } return OT_ERROR_NONE; @@ -212,7 +211,7 @@ otError Dataset::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -266,7 +265,7 @@ otError Dataset::ProcessActive(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otDatasetGetActiveTlvs(mInterpreter.mInstance, &dataset)); mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } else { @@ -296,7 +295,7 @@ otError Dataset::ProcessPending(uint8_t aArgsLength, char *aArgs[]) SuccessOrExit(error = otDatasetGetPendingTlvs(mInterpreter.mInstance, &dataset)); mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } else { @@ -315,7 +314,7 @@ otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsActiveTimestampPresent) { - mInterpreter.mServer->OutputFormat("%lu\r\n", sDataset.mActiveTimestamp); + mInterpreter.OutputFormat("%lu\r\n", sDataset.mActiveTimestamp); } } else @@ -339,7 +338,7 @@ otError Dataset::ProcessChannel(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsChannelPresent) { - mInterpreter.mServer->OutputFormat("%d\r\n", sDataset.mChannel); + mInterpreter.OutputFormat("%d\r\n", sDataset.mChannel); } } else @@ -363,7 +362,7 @@ otError Dataset::ProcessChannelMask(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsChannelMaskPresent) { - mInterpreter.mServer->OutputFormat("0x%08x\r\n", sDataset.mChannelMask); + mInterpreter.OutputFormat("0x%08x\r\n", sDataset.mChannelMask); } } else @@ -419,7 +418,7 @@ otError Dataset::ProcessDelay(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsDelayPresent) { - mInterpreter.mServer->OutputFormat("%d\r\n", sDataset.mDelay); + mInterpreter.OutputFormat("%d\r\n", sDataset.mDelay); } } else @@ -444,7 +443,7 @@ otError Dataset::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]) if (sDataset.mComponents.mIsExtendedPanIdPresent) { OutputBytes(sDataset.mExtendedPanId.m8, sizeof(sDataset.mExtendedPanId)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } } else @@ -471,7 +470,7 @@ otError Dataset::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]) if (sDataset.mComponents.mIsMasterKeyPresent) { OutputBytes(sDataset.mMasterKey.m8, sizeof(sDataset.mMasterKey)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } } else @@ -498,11 +497,11 @@ otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, char *aArgs[]) if (sDataset.mComponents.mIsMeshLocalPrefixPresent) { const uint8_t *prefix = sDataset.mMeshLocalPrefix.m8; - mInterpreter.mServer->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.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]); } } else @@ -527,8 +526,8 @@ otError Dataset::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsNetworkNamePresent) { - mInterpreter.mServer->OutputFormat("%.*s\r\n", static_cast(sizeof(sDataset.mNetworkName)), - sDataset.mNetworkName.m8); + mInterpreter.OutputFormat("%.*s\r\n", static_cast(sizeof(sDataset.mNetworkName)), + sDataset.mNetworkName.m8); } } else @@ -554,7 +553,7 @@ otError Dataset::ProcessPanId(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsPanIdPresent) { - mInterpreter.mServer->OutputFormat("0x%04x\r\n", sDataset.mPanId); + mInterpreter.OutputFormat("0x%04x\r\n", sDataset.mPanId); } } else @@ -578,7 +577,7 @@ otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsPendingTimestampPresent) { - mInterpreter.mServer->OutputFormat("%lu\r\n", sDataset.mPendingTimestamp); + mInterpreter.OutputFormat("%lu\r\n", sDataset.mPendingTimestamp); } } else @@ -824,7 +823,7 @@ otError Dataset::ProcessPskc(uint8_t aArgsLength, char *aArgs[]) if (sDataset.mComponents.mIsPskcPresent) { OutputBytes(sDataset.mPskc.m8, sizeof(sDataset.mPskc.m8)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } } else if (aArgsLength == 1) @@ -866,34 +865,34 @@ otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, char *aArgs[]) { if (sDataset.mComponents.mIsSecurityPolicyPresent) { - mInterpreter.mServer->OutputFormat("%d ", sDataset.mSecurityPolicy.mRotationTime); + mInterpreter.OutputFormat("%d ", sDataset.mSecurityPolicy.mRotationTime); if (sDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY) { - mInterpreter.mServer->OutputFormat("o"); + mInterpreter.OutputFormat("o"); } if (sDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_NATIVE_COMMISSIONING) { - mInterpreter.mServer->OutputFormat("n"); + mInterpreter.OutputFormat("n"); } if (sDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_ROUTERS) { - mInterpreter.mServer->OutputFormat("r"); + mInterpreter.OutputFormat("r"); } if (sDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_EXTERNAL_COMMISSIONER) { - mInterpreter.mServer->OutputFormat("c"); + mInterpreter.OutputFormat("c"); } if (sDataset.mSecurityPolicy.mFlags & OT_SECURITY_POLICY_BEACONS) { - mInterpreter.mServer->OutputFormat("b"); + mInterpreter.OutputFormat("b"); } - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); } } else diff --git a/src/cli/cli_joiner.cpp b/src/cli/cli_joiner.cpp index 0cf4dc8af..a3464e39f 100644 --- a/src/cli/cli_joiner.cpp +++ b/src/cli/cli_joiner.cpp @@ -36,7 +36,6 @@ #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" #if OPENTHREAD_CONFIG_JOINER_ENABLE @@ -74,7 +73,7 @@ otError Joiner::ProcessDiscerner(uint8_t aArgsLength, char *aArgs[]) VerifyOrExit(discerner != nullptr, error = OT_ERROR_NOT_FOUND); - mInterpreter.mServer->OutputFormat("0x%" PRIx64 "/%u\r\n", discerner->mValue, discerner->mLength); + mInterpreter.OutputFormat("0x%" PRIx64 "/%u\r\n", discerner->mValue, discerner->mLength); } else { @@ -92,7 +91,7 @@ otError Joiner::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -108,7 +107,7 @@ otError Joiner::ProcessId(uint8_t aArgsLength, char *aArgs[]) joinerId = otJoinerGetId(mInterpreter.mInstance); mInterpreter.OutputBytes(joinerId->m8, sizeof(otExtAddress)); - mInterpreter.mServer->OutputFormat("\r\n"); + mInterpreter.OutputFormat("\r\n"); return OT_ERROR_NONE; } @@ -175,11 +174,11 @@ void Joiner::HandleCallback(otError aError) switch (aError) { case OT_ERROR_NONE: - mInterpreter.mServer->OutputFormat("Join success\r\n"); + mInterpreter.OutputFormat("Join success\r\n"); break; default: - mInterpreter.mServer->OutputFormat("Join failed [%s]\r\n", otThreadErrorToString(aError)); + mInterpreter.OutputFormat("Join failed [%s]\r\n", otThreadErrorToString(aError)); break; } } diff --git a/src/cli/cli_server.cpp b/src/cli/cli_server.cpp deleted file mode 100644 index 0339c1fad..000000000 --- a/src/cli/cli_server.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2019, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file provides the static fields for CLI server. - */ - -#include "cli_server.hpp" - -namespace ot { -namespace Cli { - -Server *Server::sServer = nullptr; - -int Server::OutputFormat(const char *aFormat, ...) -{ - int rval; - va_list ap; - - va_start(ap, aFormat); - rval = OutputFormatV(aFormat, ap); - va_end(ap); - - return rval; -} - -int Server::OutputFormatV(const char *aFormat, va_list aArguments) -{ - char buf[kMaxLineLength]; - - vsnprintf(buf, sizeof(buf), aFormat, aArguments); - - return Output(buf, static_cast(strlen(buf))); -} - -} // namespace Cli -} // namespace ot diff --git a/src/cli/cli_server.hpp b/src/cli/cli_server.hpp deleted file mode 100644 index 0744aa61f..000000000 --- a/src/cli/cli_server.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file contains definitions for adding a CLI command to the CLI server. - */ - -#ifndef CLI_SERVER_HPP_ -#define CLI_SERVER_HPP_ - -#include "openthread-core-config.h" - -#include "cli/cli.hpp" - -namespace ot { -namespace Cli { - -/** - * This class implements the CLI server. - * - */ -class Server -{ -public: - explicit Server(Instance *aInstance) - : mInterpreter(aInstance) - { - } - - /** - * This method delivers raw characters to the client. - * - * @param[in] aBuf A pointer to a buffer. - * @param[in] aBufLength Number of bytes in the buffer. - * - * @returns The number of bytes placed in the output queue. - * - * @retval -1 Driver is broken. - * - */ - virtual int Output(const char *aBuf, uint16_t aBufLength) - { - OT_UNUSED_VARIABLE(aBuf); - OT_UNUSED_VARIABLE(aBufLength); - return -1; - } - - /** - * This method delivers formatted output to the client. - * - * @param[in] aFormat A pointer to the format string. - * @param[in] ... A variable list of arguments to format. - * - * @returns The number of bytes placed in the output queue. - * - * @retval -1 Driver is broken. - * - */ - int OutputFormat(const char *aFormat, ...); - - /** - * This method delivers formatted output to the client. - * - * @param[in] aFormat A pointer to the format string. - * @param[in] aArguments A variable list of arguments for format. - * - * @returns The number of bytes placed in the output queue. - * - */ - int OutputFormatV(const char *aFormat, va_list aArguments); - - /** - * This method returns a reference to the interpreter object. - * - * @returns A reference to the interpreter object. - * - */ - Interpreter &GetInterpreter(void) { return mInterpreter; } - - static Server *sServer; - -protected: - enum - { - kMaxLineLength = OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH, - }; - - Interpreter mInterpreter; -}; - -} // namespace Cli -} // namespace ot - -#endif // CLI_SERVER_HPP_ diff --git a/src/cli/cli_uart.cpp b/src/cli/cli_uart.cpp index c35b34dcc..d9dd2bbd4 100644 --- a/src/cli/cli_uart.cpp +++ b/src/cli/cli_uart.cpp @@ -28,11 +28,13 @@ /** * @file - * This file implements the CLI server on the UART service. + * This file implements the CLI interpreter on the UART service. */ #include "cli_uart.hpp" +#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART + #include #include #include @@ -103,15 +105,21 @@ namespace Cli { static OT_DEFINE_ALIGNED_VAR(sCliUartRaw, sizeof(Uart), uint64_t); -extern "C" void otCliUartInit(otInstance *aInstance) +Uart *Uart::sUart = nullptr; + +Interpreter &Interpreter::GetInterpreter(void) +{ + return *Uart::sUart; +} + +void Uart::Initialize(otInstance *aInstance) { Instance *instance = static_cast(aInstance); - - Server::sServer = new (&sCliUartRaw) Uart(instance); + sUart = new (&sCliUartRaw) Uart(instance); } Uart::Uart(Instance *aInstance) - : Server(aInstance) + : Interpreter(aInstance) { mRxLength = 0; mTxHead = 0; @@ -121,11 +129,6 @@ Uart::Uart(Instance *aInstance) IgnoreError(otPlatUartEnable()); } -extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) -{ - static_cast(Server::sServer)->ReceiveTask(aBuf, aBufLength); -} - void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) { #if !OPENTHREAD_CONFIG_UART_CLI_RAW @@ -232,7 +235,7 @@ otError Uart::ProcessCommand(void) #endif if (mRxLength > 0) { - mInterpreter.ProcessLine(mRxBuffer, mRxLength, *this); + ProcessLine(mRxBuffer, mRxLength); } mRxLength = 0; @@ -240,6 +243,11 @@ otError Uart::ProcessCommand(void) return error; } +int Interpreter::Output(const char *aBuf, uint16_t aBufLength) +{ + return static_cast(this)->Output(aBuf, aBufLength); +} + int Uart::Output(const char *aBuf, uint16_t aBufLength) { OT_CLI_UART_OUTPUT_LOCK(); @@ -317,11 +325,6 @@ exit: return; } -extern "C" void otPlatUartSendDone(void) -{ - static_cast(Server::sServer)->SendDoneTask(); -} - void Uart::SendDoneTask(void) { mTxHead = (mTxHead + mSendLength) % kTxBufferSize; @@ -331,5 +334,22 @@ void Uart::SendDoneTask(void) Send(); } +extern "C" void otCliUartInit(otInstance *aInstance) +{ + Uart::Initialize(aInstance); +} + +extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) +{ + static_cast(Interpreter::GetInterpreter()).ReceiveTask(aBuf, aBufLength); +} + +extern "C" void otPlatUartSendDone(void) +{ + static_cast(Interpreter::GetInterpreter()).SendDoneTask(); +} + } // namespace Cli } // namespace ot + +#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART diff --git a/src/cli/cli_uart.hpp b/src/cli/cli_uart.hpp index f5a7b747a..33164d530 100644 --- a/src/cli/cli_uart.hpp +++ b/src/cli/cli_uart.hpp @@ -28,7 +28,7 @@ /** * @file - * This file contains definitions for a CLI server on the UART service. + * This file contains definitions for a CLI interpreter on the UART service. */ #ifndef CLI_UART_HPP_ @@ -37,7 +37,6 @@ #include "openthread-core-config.h" #include "cli/cli.hpp" -#include "cli/cli_server.hpp" #include "common/instance.hpp" #include "common/tasklet.hpp" @@ -45,19 +44,13 @@ namespace ot { namespace Cli { /** - * This class implements the CLI server on top of the UART platform abstraction. + * This class implements the CLI interpreter on top of the UART platform abstraction. * */ -class Uart : public Server +class Uart : public Interpreter { public: - /** - * Constructor - * - * @param[in] aInstance The OpenThread instance structure. - * - */ - explicit Uart(Instance *aInstance); + static void Initialize(otInstance *aInstance); /** * This method delivers raw characters to the client. @@ -68,12 +61,20 @@ public: * @returns The number of bytes placed in the output queue. * */ - virtual int Output(const char *aBuf, uint16_t aBufLength); + int Output(const char *aBuf, uint16_t aBufLength); void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength); void SendDoneTask(void); private: + /** + * Constructor + * + * @param[in] aInstance The OpenThread instance structure. + * + */ + explicit Uart(Instance *aInstance); + enum { kRxBufferSize = OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE, @@ -90,7 +91,8 @@ private: uint16_t mTxHead; uint16_t mTxLength; - uint16_t mSendLength; + uint16_t mSendLength; + static Uart *sUart; friend class Interpreter; }; diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index b82db157e..57cee96d5 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -37,7 +37,6 @@ #include #include "cli/cli.hpp" -#include "cli/cli_server.hpp" #include "common/encoding.hpp" using ot::Encoding::BigEndian::HostSwap16; @@ -67,7 +66,7 @@ otError UdpExample::ProcessHelp(uint8_t aArgsLength, char *aArgs[]) for (const Command &command : sCommands) { - mInterpreter.mServer->OutputFormat("%s\r\n", command.mName); + mInterpreter.OutputFormat("%s\r\n", command.mName); } return OT_ERROR_NONE; @@ -242,7 +241,7 @@ otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mInterpreter.mServer->OutputFormat("%s\r\n", mLinkSecurityEnabled ? "Enabled" : "Disabled"); + mInterpreter.OutputFormat("%s\r\n", mLinkSecurityEnabled ? "Enabled" : "Disabled"); } else if (strcmp(aArgs[0], "enable") == 0) { @@ -321,14 +320,14 @@ void UdpExample::HandleUdpReceive(otMessage *aMessage, const otMessageInfo *aMes uint8_t buf[1500]; int length; - mInterpreter.mServer->OutputFormat("%d bytes from ", otMessageGetLength(aMessage) - otMessageGetOffset(aMessage)); + mInterpreter.OutputFormat("%d bytes from ", otMessageGetLength(aMessage) - otMessageGetOffset(aMessage)); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); - mInterpreter.mServer->OutputFormat(" %d ", aMessageInfo->mPeerPort); + mInterpreter.OutputFormat(" %d ", aMessageInfo->mPeerPort); length = otMessageRead(aMessage, otMessageGetOffset(aMessage), buf, sizeof(buf) - 1); buf[length] = '\0'; - mInterpreter.mServer->OutputFormat("%s\r\n", buf); + mInterpreter.OutputFormat("%s\r\n", buf); } } // namespace Cli diff --git a/src/posix/Makefile-posix b/src/posix/Makefile-posix index 73384f36c..3fa95e940 100644 --- a/src/posix/Makefile-posix +++ b/src/posix/Makefile-posix @@ -109,6 +109,7 @@ endif ifneq ($(READLINE),) configure_OPTIONS += --with-readline=$(READLINE) +CLI_TRANSPORT = $(if $(and $(filter-out no,$(READLINE)),$(filter 0,$(DAEMON))),CONSOLE,UART) endif ifeq ($(RCP_BUS),spi) diff --git a/src/posix/cli.cmake b/src/posix/cli.cmake index 51e5303ed..46c19f2a6 100644 --- a/src/posix/cli.cmake +++ b/src/posix/cli.cmake @@ -44,6 +44,10 @@ set_target_properties( target_include_directories(ot-cli PRIVATE ${COMMON_INCLUDES}) +if(OT_READLINE) + set(OT_CLI_TRANSPORT "CONSOLE" CACHE STRING "set CLI to use console interpreter" FORCE) +endif() + target_compile_definitions(ot-cli PRIVATE $<$:HAVE_LIB$=1> OPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_CLI diff --git a/src/posix/main.c b/src/posix/main.c index d77d114e5..35cded2d5 100644 --- a/src/posix/main.c +++ b/src/posix/main.c @@ -63,14 +63,14 @@ #include #if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP #include -#define OPENTHREAD_USE_CONSOLE 0 #elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI #include -#if (HAVE_LIBEDIT || HAVE_LIBREADLINE) && !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE + +#include "cli/cli_config.h" +#if (HAVE_LIBEDIT || HAVE_LIBREADLINE) && !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE && \ + (OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE) #define OPENTHREAD_USE_CONSOLE 1 #include "console_cli.h" -#else -#define OPENTHREAD_USE_CONSOLE 0 #endif #else #error "Unknown posix app type!" @@ -303,7 +303,7 @@ int main(int argc, char *argv[]) #if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP otNcpInit(instance); #elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI -#if OPENTHREAD_USE_CONSOLE +#ifdef OPENTHREAD_USE_CONSOLE otxConsoleInit(instance); #else otCliUartInit(instance); @@ -324,7 +324,7 @@ int main(int argc, char *argv[]) mainloop.mTimeout.tv_sec = 10; mainloop.mTimeout.tv_usec = 0; -#if OPENTHREAD_USE_CONSOLE +#ifdef OPENTHREAD_USE_CONSOLE otxConsoleUpdate(&mainloop); #endif @@ -333,7 +333,7 @@ int main(int argc, char *argv[]) if (otSysMainloopPoll(&mainloop) >= 0) { otSysMainloopProcess(instance, &mainloop); -#if OPENTHREAD_USE_CONSOLE +#ifdef OPENTHREAD_USE_CONSOLE otxConsoleProcess(&mainloop); #endif } @@ -344,7 +344,7 @@ int main(int argc, char *argv[]) } } -#if OPENTHREAD_USE_CONSOLE +#ifdef OPENTHREAD_USE_CONSOLE otxConsoleDeinit(); #endif otInstanceFinalize(instance);