Skip to content

Commit

Permalink
Shell example: OT-CLI compilation error fixed for EFR32 boards. (#7275)
Browse files Browse the repository at this point in the history
Preprocessor guards added to prevent conflicts different Openthread versions in other platforms.
  • Loading branch information
rcasallas-silabs authored and pull[bot] committed Aug 21, 2021
1 parent f5c98cd commit 4617507
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion examples/shell/shell_common/cmd_otcli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
#include <openthread/ip6.h>
#include <openthread/link.h>
#include <openthread/thread.h>
#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 <sys/types.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -156,19 +166,34 @@ 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

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.
Expand Down

0 comments on commit 4617507

Please sign in to comment.