Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shell] move common shell commands to core library #6765

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (NOT CONFIG_USE_MINIMAL_MDNS)
endif()

if (CONFIG_ENABLE_CHIP_SHELL)
chip_gn_arg_append("chip_build_shell_lib" "true")
chip_gn_arg_append("chip_build_libshell" "true")
endif()


Expand Down
5 changes: 0 additions & 5 deletions config/nrfconnect/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import("${chip_root}/build/chip/tests.gni")
assert(current_os == "zephyr")

declare_args() {
chip_build_libshell = false
chip_build_pw_rpc_lib = false
chip_build_zephyr_shell = false
}
Expand All @@ -32,10 +31,6 @@ group("nrfconnect") {
deps += [ "${chip_root}/src:tests" ]
}

if (chip_build_libshell) {
deps += [ "${chip_root}/src/lib/shell" ]
}

if (chip_build_zephyr_shell) {
deps += [ "${chip_root}/src/platform/nrfconnect/shell:chip-zephyr-shell" ]
}
Expand Down
3 changes: 3 additions & 0 deletions examples/lock-app/esp32/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/sdkconfig
/sdkconfig.old
58 changes: 38 additions & 20 deletions examples/shell/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,44 @@
#include "linenoise/linenoise.h"
#include "nvs_flash.h"
#include "support/CHIPMem.h"
#include "support/ErrorStr.h"

#include <ChipShellCollection.h>
#include <lib/shell/shell_core.h>
#include <lib/shell/Engine.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <platform/CHIPDeviceLayer.h>

class ShellLineArgs
{
public:
ShellLineArgs(char * line, TaskHandle_t source_task) : m_line(line), m_source_task(source_task) {}
char * GetLine() { return m_line; }
void WaitShellProcessDone() { ulTaskNotifyTake(pdTRUE, portMAX_DELAY); }
void NotifyShellProcessDone() { xTaskNotifyGive(m_source_task); }

private:
char * m_line;
TaskHandle_t m_source_task;
};

static void process_shell_line(intptr_t context)
{
ShellLineArgs * shellArgs = reinterpret_cast<ShellLineArgs *>(context);
int ret;
esp_console_run(shellArgs->GetLine(), &ret);
if (ret)
{
printf("Error: %s\r\n", chip::ErrorStr(ret));
}
else
{
printf("Done\r\n");
}

linenoiseFree(shellArgs->GetLine());
shellArgs->NotifyShellProcessDone();
}

static void chip_shell_task(void * args)
{
chip::Platform::MemoryInit();
Expand All @@ -43,34 +75,20 @@ static void chip_shell_task(void * args)
{
const char * prompt = LOG_COLOR_I "> " LOG_RESET_COLOR;
char * line = linenoise(prompt);
printf("\r\n");
if (line == NULL || strlen(line) == 0)
{
continue;
}
ShellLineArgs shellArgs(line, xTaskGetCurrentTaskHandle());
linenoiseHistoryAdd(line);
int ret;
esp_console_run(line, &ret);
if (ret)
{
char errorStr[160];
bool errorStrFound = chip::FormatCHIPError(errorStr, sizeof(errorStr), ret);
if (!errorStrFound)
{
errorStr[0] = 0;
}
printf("Error: %s\n", errorStr);
}
else
{
printf("Done\n");
}

linenoiseFree(line);
chip::DeviceLayer::PlatformMgr().ScheduleWork(process_shell_line, reinterpret_cast<intptr_t>(&shellArgs));
shellArgs.WaitShellProcessDone();
}
}

extern "C" void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
xTaskCreate(&chip_shell_task, "chip_shell", 8192, NULL, 5, NULL);
xTaskCreate(&chip_shell_task, "chip_shell", 4096, NULL, 5, NULL);
}
3 changes: 0 additions & 3 deletions examples/shell/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ target_include_directories(app PRIVATE

target_sources(app PRIVATE
${APP_ROOT}/shell_common/globals.cpp
${APP_ROOT}/shell_common/cmd_base64.cpp
${APP_ROOT}/shell_common/cmd_device.cpp
${APP_ROOT}/shell_common/cmd_misc.cpp
${APP_ROOT}/shell_common/cmd_otcli.cpp
${APP_ROOT}/shell_common/cmd_ping.cpp
${APP_ROOT}/shell_common/cmd_send.cpp
${APP_ROOT}/shell_common/cmd_btp.cpp
${APP_ROOT}/standalone/main.cpp
)

Expand Down
7 changes: 0 additions & 7 deletions examples/shell/shell_common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ config("shell_common_config") {

static_library("shell_common") {
sources = [
"cmd_base64.cpp",
"cmd_btp.cpp",
"cmd_device.cpp",
"cmd_misc.cpp",
"cmd_otcli.cpp",
"cmd_ping.cpp",
Expand All @@ -43,14 +40,10 @@ static_library("shell_common") {
]

public_deps = [
"${chip_root}/src/lib",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/shell",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform",
"${chip_root}/src/protocols",
"${chip_root}/src/setup_payload",
"${chip_root}/src/system",
]

if (chip_enable_openthread &&
Expand Down
114 changes: 0 additions & 114 deletions examples/shell/shell_common/cmd_base64.cpp

This file was deleted.

Loading