mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 06:37:46 +00:00
[cli] refine CLI APIs (#3501)
This commit is contained in:
@@ -110,7 +110,7 @@ void otCliUartInit(otInstance *aInstance);
|
||||
* @param[in] aUserCommands A pointer to an array with user commands.
|
||||
* @param[in] aLength @p aUserCommands length.
|
||||
*/
|
||||
void otCliUartSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength);
|
||||
void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* Write a number of bytes to the CLI console as a hex string.
|
||||
@@ -118,7 +118,7 @@ void otCliUartSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength
|
||||
* @param[in] aBytes A pointer to data which should be printed.
|
||||
* @param[in] aLength @p aBytes length.
|
||||
*/
|
||||
void otCliUartOutputBytes(const uint8_t *aBytes, uint8_t aLength);
|
||||
void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* Write formatted string to the CLI console
|
||||
@@ -126,7 +126,7 @@ void otCliUartOutputBytes(const uint8_t *aBytes, uint8_t aLength);
|
||||
* @param[in] aFmt A pointer to the format string.
|
||||
* @param[in] ... A matching list of arguments.
|
||||
*/
|
||||
void otCliUartOutputFormat(const char *aFmt, ...);
|
||||
void otCliOutputFormat(const char *aFmt, ...);
|
||||
|
||||
/**
|
||||
* Write string to the CLI console
|
||||
@@ -134,14 +134,14 @@ void otCliUartOutputFormat(const char *aFmt, ...);
|
||||
* @param[in] aString A pointer to the string, which may not be null-terminated.
|
||||
* @param[in] aLength Number of bytes.
|
||||
*/
|
||||
void otCliUartOutput(const char *aString, uint16_t aLength);
|
||||
void otCliOutput(const char *aString, uint16_t aLength);
|
||||
|
||||
/**
|
||||
* Write error code to the CLI console
|
||||
*
|
||||
* @param[in] aError Error code value.
|
||||
*/
|
||||
void otCliUartAppendResult(otError aError);
|
||||
void otCliAppendResult(otError aError);
|
||||
|
||||
/**
|
||||
* Callback to write the OpenThread Log to the CLI console
|
||||
|
||||
+43
-1
@@ -73,7 +73,6 @@
|
||||
#endif
|
||||
|
||||
#include "cli_dataset.hpp"
|
||||
#include "cli_uart.hpp"
|
||||
|
||||
#if OPENTHREAD_ENABLE_APPLICATION_COAP
|
||||
#include "cli_coap.hpp"
|
||||
@@ -95,6 +94,7 @@
|
||||
#include <openthread/platform/debug_uart.h>
|
||||
#endif
|
||||
|
||||
#include "cli_server.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::HostSwap16;
|
||||
@@ -3902,5 +3902,47 @@ Interpreter &Interpreter::GetOwner(OwnerLocator &aOwnerLocator)
|
||||
return interpreter;
|
||||
}
|
||||
|
||||
extern "C" void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength)
|
||||
{
|
||||
Server::sServer->GetInterpreter().SetUserCommands(aUserCommands, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength)
|
||||
{
|
||||
Server::sServer->GetInterpreter().OutputBytes(aBytes, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputFormat(const char *aFmt, ...)
|
||||
{
|
||||
va_list aAp;
|
||||
va_start(aAp, aFmt);
|
||||
Server::sServer->OutputFormatV(aFmt, aAp);
|
||||
va_end(aAp);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutput(const char *aString, uint16_t aLength)
|
||||
{
|
||||
Server::sServer->Output(aString, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliAppendResult(otError aError)
|
||||
{
|
||||
Server::sServer->GetInterpreter().AppendResult(aError);
|
||||
}
|
||||
|
||||
extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
VerifyOrExit(Server::sServer != NULL);
|
||||
|
||||
Server::sServer->OutputFormatV(aFormat, aArgs);
|
||||
Server::sServer->OutputFormat("\r\n");
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
@@ -96,34 +96,6 @@ extern "C" void otCliUartInit(otInstance *aInstance)
|
||||
Server::sServer = new (&sCliUartRaw) Uart(instance);
|
||||
}
|
||||
|
||||
extern "C" void otCliUartSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength)
|
||||
{
|
||||
Server::sServer->GetInterpreter().SetUserCommands(aUserCommands, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliUartOutputBytes(const uint8_t *aBytes, uint8_t aLength)
|
||||
{
|
||||
Server::sServer->GetInterpreter().OutputBytes(aBytes, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliUartOutputFormat(const char *aFmt, ...)
|
||||
{
|
||||
va_list aAp;
|
||||
va_start(aAp, aFmt);
|
||||
static_cast<Uart *>(Server::sServer)->OutputFormatV(aFmt, aAp);
|
||||
va_end(aAp);
|
||||
}
|
||||
|
||||
extern "C" void otCliUartOutput(const char *aString, uint16_t aLength)
|
||||
{
|
||||
Server::sServer->Output(aString, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliUartAppendResult(otError aError)
|
||||
{
|
||||
Server::sServer->GetInterpreter().AppendResult(aError);
|
||||
}
|
||||
|
||||
Uart::Uart(Instance *aInstance)
|
||||
: Server(aInstance)
|
||||
{
|
||||
@@ -328,19 +300,5 @@ void Uart::SendDoneTask(void)
|
||||
Send();
|
||||
}
|
||||
|
||||
extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
VerifyOrExit(Server::sServer != NULL);
|
||||
|
||||
static_cast<Uart *>(Server::sServer)->OutputFormatV(aFormat, aArgs);
|
||||
Server::sServer->OutputFormat("\r\n");
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
Reference in New Issue
Block a user