From a0c4d57c32be2a91e4211ee3ce029ff6f1612a02 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:02:43 -0400 Subject: [PATCH] Add silabs specific CLI (#32733) --- examples/platform/silabs/matter_shell.cpp | 57 +++++++++++++++++++ .../silabs/platformAbstraction/GsdkSpam.cpp | 8 +++ 2 files changed, 65 insertions(+) diff --git a/examples/platform/silabs/matter_shell.cpp b/examples/platform/silabs/matter_shell.cpp index 03a50ea7f708cf..a6a8c9f6d6e1ae 100644 --- a/examples/platform/silabs/matter_shell.cpp +++ b/examples/platform/silabs/matter_shell.cpp @@ -16,11 +16,17 @@ */ #include "matter_shell.h" +#include "sl_component_catalog.h" #include #include #include #include #include +#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; @@ -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(); @@ -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); diff --git a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp index 89c56cb6f067cd..76673b001a9c6b 100644 --- a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp +++ b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp @@ -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 @@ -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