diff --git a/configure.ac b/configure.ac index 85ab75483..3c7cb3ebf 100644 --- a/configure.ac +++ b/configure.ac @@ -543,6 +543,36 @@ AC_SUBST(OPENTHREAD_ENABLE_DIAG) AM_CONDITIONAL([OPENTHREAD_ENABLE_DIAG], [test "${enable_diag}" = "yes"]) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_DIAG],[${OPENTHREAD_ENABLE_DIAG}],[Define to 1 if you want to use diagnostics module]) +# +# Cli Logging +# + +AC_ARG_ENABLE(cli_logging, + [AS_HELP_STRING([--enable-cli-logging],[Enable cli logging suport @<:@default=no@:>@.])], + [ + case "${enableval}" in + + no|yes) + enable_cli_logging=${enableval} + ;; + + *) + AC_MSG_ERROR([Invalid value ${enable_cli_logging} for --enable-cli-logging]) + ;; + esac + ], + [enable_cli_logging=no]) + +if test "$enable_cli_logging" = "yes"; then + OPENTHREAD_ENABLE_CLI_LOGGING=1 +else + OPENTHREAD_ENABLE_CLI_LOGGING=0 +fi + +AC_SUBST(OPENTHREAD_ENABLE_CLI_LOGGING) +AM_CONDITIONAL([OPENTHREAD_ENABLE_CLI_LOGGING], [test "${enable_cli_logging}" = "yes"]) +AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_CLI_LOGGING],[${OPENTHREAD_ENABLE_CLI_LOGGING}],[Define to 1 if you want to enable cli logging]) + # # Examples # @@ -796,6 +826,7 @@ AC_MSG_NOTICE([ OpenThread Joiner support : ${enable_joiner} OpenThread DTLS support : ${enable_dtls} OpenThread Diagnostics support : ${enable_diag} + OpenThread Cli logging support : ${enable_cli_logging} OpenThread examples : ${OPENTHREAD_EXAMPLES} OpenThread platform information : ${PLATFORM_INFO} diff --git a/examples/platforms/cc2538/logging.c b/examples/platforms/cc2538/logging.c index e7c263580..7354494e8 100644 --- a/examples/platforms/cc2538/logging.c +++ b/examples/platforms/cc2538/logging.c @@ -32,12 +32,36 @@ * */ +#ifdef OPENTHREAD_CONFIG_FILE +#include OPENTHREAD_CONFIG_FILE +#else +#include +#endif + + #include +#if OPENTHREAD_ENABLE_CLI_LOGGING +#include +#include +#include +#include +#include +#include + +#include +#include +#endif void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { +#if OPENTHREAD_ENABLE_CLI_LOGGING + va_list args; + va_start(args, aFormat); + otCliLog(aLogLevel, aLogRegion, aFormat, args); + va_end(args); +#else (void)aLogLevel; (void)aLogRegion; (void)aFormat; +#endif // OPENTHREAD_ENABLE_CLI_LOGGING } - diff --git a/include/cli/cli-uart.h b/include/cli/cli-uart.h index 023afed25..0f6c9b9bd 100644 --- a/include/cli/cli-uart.h +++ b/include/cli/cli-uart.h @@ -36,6 +36,7 @@ #define CLI_UART_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -49,6 +50,19 @@ extern "C" { */ void otCliUartInit(otInstance *aInstance); +#if OPENTHREAD_ENABLE_CLI_LOGGING +/** + * This method delivers formatted log to the client. + * + * @param[in] aLogLevel The log level. + * @param[in] aLogRegion The log region. + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ +void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...); +#endif + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/cli/cli_uart.cpp b/src/cli/cli_uart.cpp index 36695185e..d74f24268 100644 --- a/src/cli/cli_uart.cpp +++ b/src/cli/cli_uart.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include namespace Thread { @@ -214,5 +215,98 @@ void Uart::SendDoneTask(void) Send(); } +#if OPENTHREAD_ENABLE_CLI_LOGGING +#ifdef __cplusplus +extern "C" { +#endif +void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +{ + if (NULL == Uart::sUartServer) + { + return; + } + + switch (aLogLevel) + { + case kLogLevelNone: + Uart::sUartServer->OutputFormat("NONE "); + break; + + case kLogLevelCrit: + Uart::sUartServer->OutputFormat("CRIT "); + break; + + case kLogLevelWarn: + Uart::sUartServer->OutputFormat("WARN "); + break; + + case kLogLevelInfo: + Uart::sUartServer->OutputFormat("INFO "); + break; + + case kLogLevelDebg: + Uart::sUartServer->OutputFormat("DEBG "); + break; + + default: + return; + } + + switch (aLogRegion) + { + case kLogRegionApi: + Uart::sUartServer->OutputFormat("API "); + break; + + case kLogRegionMle: + Uart::sUartServer->OutputFormat("MLE "); + break; + + case kLogRegionArp: + Uart::sUartServer->OutputFormat("ARP "); + break; + + case kLogRegionNetData: + Uart::sUartServer->OutputFormat("NETD "); + break; + + case kLogRegionIp6: + Uart::sUartServer->OutputFormat("IPV6 "); + break; + + case kLogRegionIcmp: + Uart::sUartServer->OutputFormat("ICMP "); + break; + + case kLogRegionMac: + Uart::sUartServer->OutputFormat("MAC "); + break; + + case kLogRegionMem: + Uart::sUartServer->OutputFormat("MEM "); + break; + + case kLogRegionNcp: + Uart::sUartServer->OutputFormat("NCP "); + break; + + case kLogRegionMeshCoP: + Uart::sUartServer->OutputFormat("MCOP "); + break; + + default: + return; + } + + va_list args; + va_start(args, aFormat); + Uart::sUartServer->OutputFormat(aFormat, args); + va_end(args); +} +#ifdef __cplusplus +} // extern "C" +#endif +#endif // OPENTHREAD_ENABLE_CLI_LOGGING + } // namespace Cli } // namespace Thread diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index 491d584b6..cd55a3708 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -258,4 +259,19 @@ void NcpUart::HandleError(ThreadError aError, uint8_t *aBuf, uint16_t aBufLength otNcpStreamWrite(0, reinterpret_cast(hexbuf + 1), static_cast(strlen(hexbuf) - 1)); } +#if OPENTHREAD_ENABLE_CLI_LOGGING +#ifdef __cplusplus +extern "C" { +#endif +void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +{ + (void)aLogLevel; + (void)aLogRegion; + (void)aFormat; +} +#ifdef __cplusplus +} // extern "C" +#endif +#endif // OPENTHREAD_ENABLE_CLI_LOGGING + } // namespace Thread