From 6941790683442bb995857b3b2fae4508251bcb52 Mon Sep 17 00:00:00 2001 From: ricardo-casallas <77841255+ricardo-casallas@users.noreply.github.com> Date: Fri, 4 Jun 2021 10:53:22 -0400 Subject: [PATCH] Shell example: OT-CLI compilation error fixed for EFR32 boards. (#7275) Preprocessor guards added to prevent conflicts different Openthread versions in other platforms. --- examples/shell/shell_common/cmd_otcli.cpp | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/examples/shell/shell_common/cmd_otcli.cpp b/examples/shell/shell_common/cmd_otcli.cpp index c74dacbd1d0e60..89b6d2f3e589f2 100644 --- a/examples/shell/shell_common/cmd_otcli.cpp +++ b/examples/shell/shell_common/cmd_otcli.cpp @@ -39,6 +39,13 @@ #include #include #include +#ifdef EFR32_OPENTHREAD_API +#ifndef SHELL_OTCLI_TX_BUFFER_SIZE +#define SHELL_OTCLI_TX_BUFFER_SIZE 1024 +#endif +static char sTxBuffer[SHELL_OTCLI_TX_BUFFER_SIZE]; +static constexpr uint16_t sTxLength = SHELL_OTCLI_TX_BUFFER_SIZE; +#endif #else #include #include @@ -98,8 +105,11 @@ int cmd_otcli_dispatch(int argc, char ** argv) } } buff_ptr = 0; - +#ifdef EFR32_OPENTHREAD_API + otCliInputLine(buff); +#else otCliConsoleInputLine(buff, buff_ptr - buff); +#endif exit: return error; } @@ -156,11 +166,22 @@ int cmd_otcli_dispatch(int argc, char ** argv) static const shell_command_t cmds_otcli_root = { &cmd_otcli_dispatch, "otcli", "Dispatch OpenThread CLI command" }; #if CHIP_TARGET_STYLE_EMBEDDED +#ifdef EFR32_OPENTHREAD_API +static int OnOtCliOutput(void * aContext, const char * aFormat, va_list aArguments) +{ + int rval = vsnprintf(sTxBuffer, sTxLength, aFormat, aArguments); + VerifyOrExit(rval >= 0 && rval < sTxLength, rval = CHIP_ERROR_BUFFER_TOO_SMALL); + return streamer_write(streamer_get(), (const char *) sTxBuffer, rval); +exit: + return rval; +} +#else static int OnOtCliOutput(const char * aBuf, uint16_t aBufLength, void * aContext) { return streamer_write(streamer_get(), aBuf, aBufLength); } #endif +#endif #endif // CHIP_ENABLE_OPENTHREAD @@ -168,7 +189,11 @@ void cmd_otcli_init() { #if CHIP_ENABLE_OPENTHREAD #if CHIP_TARGET_STYLE_EMBEDDED +#ifdef EFR32_OPENTHREAD_API + otCliInit(otInstanceInitSingle(), &OnOtCliOutput, NULL); +#else otCliConsoleInit(otInstanceInitSingle(), &OnOtCliOutput, NULL); +#endif #endif // Register the root otcli command with the top-level shell.