Skip to content

Commit

Permalink
Add silabs specific CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs committed Apr 15, 2024
1 parent fd72eae commit 87b6867
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/platform/silabs/matter_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
*/

#include "matter_shell.h"
#include "sl_component_catalog.h"
#include <ChipShellCollection.h>
#include <cmsis_os2.h>
#include <lib/core/CHIPCore.h>
#include <lib/shell/Engine.h>
#include <sl_cmsis_os2_common.h>
#ifdef SL_CATALOG_CLI_PRESENT
#include "sl_cli.h"
#include "sl_cli_config.h"
#include "sli_cli_io.h"
#endif

using namespace ::chip;
using chip::Shell::Engine;
Expand Down Expand Up @@ -60,6 +66,51 @@ void WaitForShellActivity()
osThreadFlagsWait(kShellProcessFlag, osFlagsWaitAny, osWaitForever);
}

#ifdef SL_CATALOG_CLI_PRESENT

CHIP_ERROR CmdSilabsDispatch(int argc, char ** argv)
{
CHIP_ERROR error = CHIP_NO_ERROR;

char buff[SL_CLI_INPUT_BUFFER_SIZE] = { 0 };
char * buff_ptr = buff;
int i = 0;

VerifyOrExit(argc > 0, error = CHIP_ERROR_INVALID_ARGUMENT);

for (i = 0; i < argc; i++)
{
size_t arg_len = strlen(argv[i]);

/* Make sure that the next argument won't overflow the buffer */
VerifyOrExit(buff_ptr + arg_len < buff + kMaxLineLength, error = CHIP_ERROR_BUFFER_TOO_SMALL);

strncpy(buff_ptr, argv[i], arg_len);
buff_ptr += arg_len;

/* Make sure that there is enough buffer for a space char */
if (buff_ptr + sizeof(char) < buff + kMaxLineLength)
{
strncpy(buff_ptr, " ", sizeof(char));
buff_ptr++;
}
}
buff_ptr = 0;
sl_cli_handle_input(sl_cli_default_handle, buff);
exit:
return error;
}

static const Shell::shell_command_t cmds_silabs_root = { &CmdSilabsDispatch, "silabs", "Dispatch Silicon Labs CLI command" };

void cmdSilabsInit()
{
// Register the root otcli command with the top-level shell.
Engine::Root().RegisterCommands(&cmds_silabs_root, 1);
}

#endif // SL_CATALOG_CLI_PRESENT

void startShellTask()
{
int status = chip::Shell::Engine::Root().Init();
Expand All @@ -68,7 +119,13 @@ void startShellTask()
// For now also register commands from shell_common (shell app).
// TODO move at least OTCLI to default commands in lib/shell/commands
cmd_misc_init();
#ifndef SL_WIFI
cmd_otcli_init();
#endif

#ifdef SL_CATALOG_CLI_PRESENT
cmdSilabsInit();
#endif

shellTaskHandle = osThreadNew(MatterShellTask, nullptr, &kShellTaskAttr);
VerifyOrDie(shellTaskHandle);
Expand Down
8 changes: 8 additions & 0 deletions src/platform/silabs/platformAbstraction/GsdkSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extern "C" {
#include "sl_component_catalog.h"
#include "sl_mbedtls.h"
#if SILABS_LOG_OUT_UART || ENABLE_CHIP_SHELL || CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
#ifdef SL_CATALOG_CLI_PRESENT
#include "sl_iostream.h"
#include "sl_iostream_stdio.h"
#endif //
#include "uart.h"
#endif

Expand All @@ -71,6 +75,10 @@ CHIP_ERROR SilabsPlatform::Init(void)
// Clear register so it does accumualate the causes of each reset
RMU_ResetCauseClear();

#if SILABS_LOG_OUT_UART && defined(SL_CATALOG_CLI_PRESENT)
sl_iostream_set_default(sl_iostream_stdio_handle);
#endif

#if CHIP_ENABLE_OPENTHREAD
sl_ot_sys_init();
#endif
Expand Down

0 comments on commit 87b6867

Please sign in to comment.