[cli] remove multiple servers support (#5387)

This commit is contained in:
Yakun Xu
2020-08-14 22:15:32 -07:00
committed by GitHub
parent 16a5c52d9f
commit 8370395c47
27 changed files with 801 additions and 892 deletions
-7
View File
@@ -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 := \
-2
View File
@@ -38,8 +38,6 @@ config("openthread_config") {
"${root_gen_dir}/include",
"include",
]
cflags_cc = [ "-Wno-non-virtual-dtor" ]
}
config("openthread_ftd_config") {
+1
View File
@@ -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)
+3
View File
@@ -36,6 +36,7 @@
#include <openthread/platform/logging.h>
#include "openthread-system.h"
#include "cli/cli_config.h"
#if OPENTHREAD_EXAMPLES_SIMULATION
#include <setjmp.h>
@@ -106,7 +107,9 @@ pseudo_reset:
#endif
assert(instance);
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART
otCliUartInit(instance);
#endif
while (!otSysPseudoResetWasRequested())
{
+5
View File
@@ -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
+1 -1
View File
@@ -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
-2
View File
@@ -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",
+17 -5
View File
@@ -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
)
-2
View File
@@ -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 \
+469 -471
View File
File diff suppressed because it is too large Load Diff
+51 -7
View File
@@ -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;
+30 -33
View File
@@ -38,7 +38,6 @@
#include <ctype.h>
#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<uint32_t>(observe));
mInterpreter.OutputFormat(" OBS=%lu", static_cast<uint32_t>(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);
}
}
}
+18 -21
View File
@@ -39,7 +39,6 @@
#include <openthread/ip6.h>
#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);
+15 -16
View File
@@ -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<int8_t>(aEnergyList[i]));
mInterpreter.OutputFormat("%d ", static_cast<int8_t>(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
+20
View File
@@ -35,6 +35,8 @@
#ifndef CONFIG_CLI_H_
#define CONFIG_CLI_H_
#include <openthread/config.h>
/**
* @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_
+32 -17
View File
@@ -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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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<Instance *>(aInstance);
Server::sServer = new (&sCliConsoleRaw) Console(instance);
static_cast<Console *>(Server::sServer)->SetOutputCallback(aCallback);
static_cast<Console *>(Server::sServer)->SetContext(aContext);
Console::Initialize(aInstance, aCallback, aContext);
}
extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)
{
static_cast<Console *>(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<Instance *>(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<Console *>(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
+15 -25
View File
@@ -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 <openthread/cli.h>
#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
+50 -51
View File
@@ -40,7 +40,6 @@
#include <openthread/dataset_ftd.h>
#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<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3], (static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
@@ -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<uint16_t>(sizeof(aDataset.mNetworkName)),
aDataset.mNetworkName.m8);
mInterpreter.OutputFormat("Network Name: ");
mInterpreter.OutputFormat("%.*s\r\n", static_cast<uint16_t>(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<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3],
(static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
mInterpreter.OutputFormat("Mesh Local Prefix: %x:%x:%x:%x::/64\r\n",
(static_cast<uint16_t>(prefix[0]) << 8) | prefix[1],
(static_cast<uint16_t>(prefix[2]) << 8) | prefix[3],
(static_cast<uint16_t>(prefix[4]) << 8) | prefix[5],
(static_cast<uint16_t>(prefix[6]) << 8) | prefix[7]);
}
}
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<uint16_t>(sizeof(sDataset.mNetworkName)),
sDataset.mNetworkName.m8);
mInterpreter.OutputFormat("%.*s\r\n", static_cast<uint16_t>(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
+5 -6
View File
@@ -36,7 +36,6 @@
#include <inttypes.h>
#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;
}
}
-63
View File
@@ -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<uint16_t>(strlen(buf)));
}
} // namespace Cli
} // namespace ot
-120
View File
@@ -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_
+36 -16
View File
@@ -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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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<Instance *>(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<Uart *>(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<Uart *>(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<Uart *>(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<Uart &>(Interpreter::GetInterpreter()).ReceiveTask(aBuf, aBufLength);
}
extern "C" void otPlatUartSendDone(void)
{
static_cast<Uart &>(Interpreter::GetInterpreter()).SendDoneTask();
}
} // namespace Cli
} // namespace ot
#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART
+15 -13
View File
@@ -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;
};
+5 -6
View File
@@ -37,7 +37,6 @@
#include <openthread/udp.h>
#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
+1
View File
@@ -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)
+4
View File
@@ -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
$<$<BOOL:${READLINE}>:HAVE_LIB$<UPPER_CASE:${OT_READLINE}>=1>
OPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_CLI
+8 -8
View File
@@ -63,14 +63,14 @@
#include <openthread/platform/radio.h>
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
#include <openthread/ncp.h>
#define OPENTHREAD_USE_CONSOLE 0
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
#include <openthread/cli.h>
#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);