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

Revert "[shell] enable shell as an optional module in apps (#7080)" #7204

Closed
Closed
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
7 changes: 0 additions & 7 deletions config/esp32/components/chip/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ COMPONENT_ADD_INCLUDEDIRS = project-config \
COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib/ \
-lCHIP

ifdef CONFIG_ENABLE_CHIP_SHELL
COMPONENT_ADD_LDFLAGS += -lCHIPShell
endif

ifdef CONFIG_ENABLE_PW_RPC
COMPONENT_ADD_LDFLAGS += -lPwRpc
endif
Expand Down Expand Up @@ -139,9 +135,6 @@ endif
echo "pw_sys_io_BACKEND = \"//third_party/connectedhomeip/examples/platform/esp32/pw_sys_io:pw_sys_io_esp32\"" >> $(OUTPUT_DIR)/args.gn ;\
echo "dir_pw_third_party_nanopb = \"//third_party/connectedhomeip/third_party/nanopb/repo\"" >>$(OUTPUT_DIR)/args.gn ;\
fi
if [[ "$(CONFIG_ENABLE_CHIP_SHELL)" = "y" ]]; then \
echo "chip_build_libshell = true" >> $(OUTPUT_DIR)/args.gn ;\
fi
if [[ "$(CONFIG_USE_MINIMAL_MDNS)" = "n" ]]; then \
echo "chip_mdns = platform" >> $(OUTPUT_DIR)/args.gn ;\
fi
Expand Down
12 changes: 0 additions & 12 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include <app/server/Mdns.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <lib/shell/Engine.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
Expand Down Expand Up @@ -546,13 +545,6 @@ class AppCallbacks : public AppDelegate
void OnPairingWindowClosed() override { pairingWindowLED.Set(false); }
};

#if CONFIG_ENABLE_CHIP_SHELL
void ChipShellTask(void * args)
{
chip::Shell::Engine::Root().RunMainLoop();
}
#endif // CONFIG_ENABLE_CHIP_SHELL

} // namespace

extern "C" void app_main()
Expand Down Expand Up @@ -607,10 +599,6 @@ extern "C" void app_main()
AppCallbacks callbacks;
InitServer(&callbacks);

#if CONFIG_ENABLE_CHIP_SHELL
xTaskCreate(&ChipShellTask, "chip_shell", 2048, NULL, 5, NULL);
#endif

SetupPretendDevices();

std::string qrCodeText = createSetupPayload();
Expand Down
3 changes: 0 additions & 3 deletions examples/all-clusters-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,3 @@ CONFIG_DEVICE_PRODUCT_ID=0x4541
# Main task needs a bit more stack than the default
# default is 3584, bump this up to 4k.
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096

#enable debug shell
CONFIG_ENABLE_CHIP_SHELL=y
9 changes: 0 additions & 9 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <core/CHIPError.h>
#include <lib/shell/Engine.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
Expand All @@ -41,7 +40,6 @@ using namespace chip;
using namespace chip::Inet;
using namespace chip::Transport;
using namespace chip::DeviceLayer;
using chip::Shell::Engine;

namespace {
void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
Expand Down Expand Up @@ -112,15 +110,8 @@ int ChipLinuxAppInit(int argc, char ** argv)

void ChipLinuxAppMainLoop()
{
#if CHIP_ENABLE_SHELL
std::thread shellThread([]() { Engine::Root().RunMainLoop(); });
#endif

// Init ZCL Data Model and CHIP App Server
InitServer();

chip::DeviceLayer::PlatformMgr().RunEventLoop();
#if CHIP_ENABLE_SHELL
shellThread.join();
#endif
}
13 changes: 1 addition & 12 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ config("app-main-config") {
include_dirs = [ "." ]
}

declare_args() {
chip_enable_shell = false
}

source_set("app-main") {
sources = [
"AppMain.cpp",
Expand All @@ -31,21 +27,14 @@ source_set("app-main") {
"Options.h",
]

defines = []

if (chip_enable_pw_rpc) {
defines += [ "PW_RPC_ENABLED" ]
defines = [ "PW_RPC_ENABLED" ]
}

public_deps = [
"${chip_root}/src/app/server",
"${chip_root}/src/lib",
]

if (chip_enable_shell) {
defines += [ "CHIP_ENABLE_SHELL" ]
public_deps += [ "${chip_root}/src/lib/shell" ]
}

public_configs = [ ":app-main-config" ]
}
67 changes: 60 additions & 7 deletions examples/shell/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,80 @@
* limitations under the License.
*/

#include "esp_console.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "linenoise/linenoise.h"
#include "nvs_flash.h"
#include "support/CHIPMem.h"
#include "support/ErrorStr.h"

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

using chip::Shell::Engine;
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); }

static void chip_shell_task(void * args)
private:
char * m_line;
TaskHandle_t m_source_task;
};

static void process_shell_line(intptr_t context)
{
Engine::Root().RunMainLoop();
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();
}

extern "C" void app_main(void)
static void chip_shell_task(void * args)
{
ESP_ERROR_CHECK(nvs_flash_init());
chip::Platform::MemoryInit();
chip::DeviceLayer::PlatformMgr().InitChipStack();
chip::DeviceLayer::PlatformMgr().StartEventLoopTask();
int ret = chip::Shell::streamer_init(chip::Shell::streamer_get());
assert(ret == 0);
cmd_ping_init();
xTaskCreate(&chip_shell_task, "chip_shell", 2048, NULL, 5, NULL);
while (true)
{
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);
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", 4096, NULL, 5, NULL);
}
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ static shell_command_t cmds_misc[] = {

void cmd_misc_init()
{
Engine::Root().RegisterCommands(cmds_misc, ArraySize(cmds_misc));
shell_register(cmds_misc, ArraySize(cmds_misc));
}
4 changes: 2 additions & 2 deletions examples/shell/shell_common/cmd_otcli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using namespace chip::DeviceLayer;
using namespace chip::Logging;
using namespace chip::ArgParser;

static chip::Shell::Engine sShellOtcliSubcommands;
static chip::Shell::Shell sShellOtcliSubcommands;

int cmd_otcli_help_iterator(shell_command_t * command, void * arg)
{
Expand Down Expand Up @@ -172,6 +172,6 @@ void cmd_otcli_init()
#endif

// Register the root otcli command with the top-level shell.
Engine::Root().RegisterCommands(&cmds_otcli_root, 1);
shell_register(&cmds_otcli_root, 1);
#endif // CHIP_ENABLE_OPENTHREAD
}
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,5 +488,5 @@ static shell_command_t cmds_ping[] = {

void cmd_ping_init()
{
Engine::Root().RegisterCommands(cmds_ping, ArraySize(cmds_ping));
shell_register(cmds_ping, ArraySize(cmds_ping));
}
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,5 @@ static shell_command_t cmds_send[] = {

void cmd_send_init()
{
Engine::Root().RegisterCommands(cmds_send, ArraySize(cmds_send));
shell_register(cmds_send, ArraySize(cmds_send));
}
2 changes: 1 addition & 1 deletion examples/shell/standalone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ int main()
cmd_ping_init();
cmd_send_init();

Engine::Root().RunMainLoop();
shell_task(nullptr);
return 0;
}
9 changes: 2 additions & 7 deletions src/lib/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,14 @@ static_library("shell") {
output_name = "libCHIPShell"
output_dir = "${root_out_dir}/lib"

sources = []
sources = [ "Commands.cpp" ]

if (chip_target_style == "unix") {
sources += [ "streamer_stdio.cpp" ]
}

if (chip_device_platform == "esp32") {
sources += [
"MainLoopESP32.cpp",
"streamer_esp32.cpp",
]
} else {
sources += [ "MainLoopDefault.cpp" ]
sources += [ "streamer_esp32.cpp" ]
}

if (current_os == "zephyr") {
Expand Down
41 changes: 41 additions & 0 deletions src/lib/shell/Commands.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <lib/shell/Commands.h>
#include <lib/shell/Engine.h>
#include <platform/CHIPDeviceLayer.h>

namespace chip {
namespace Shell {

void Shell::RegisterDefaultCommands()
{
RegisterBase64Commands();
RegisterMetaCommands();
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
RegisterBLECommands();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
RegisterWiFiCommands();
#endif
#if CONFIG_DEVICE_LAYER
RegisterConfigCommands();
#endif
}

} // namespace Shell
} // namespace chip
Loading