From 20d1ca79b8d9a7681c704f4d8f24053e697fe6d1 Mon Sep 17 00:00:00 2001 From: Gustice Date: Thu, 13 Nov 2025 00:25:31 +0100 Subject: [PATCH] cli improvement --- core | 2 +- main/watchMain.cpp | 84 +++++++++++++++++++++++++--------------------- main/watchMain.hpp | 2 ++ sdkconfig | 11 ++++++ 4 files changed, 59 insertions(+), 40 deletions(-) diff --git a/core b/core index 8af1c2f..e09e7dc 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8af1c2f5554b1f3bc16143fb52d51b5c3883653e +Subproject commit e09e7dc576b2440c3a5c02fa9dc1d2192ccd61f1 diff --git a/main/watchMain.cpp b/main/watchMain.cpp index 5f20861..c8ea90d 100644 --- a/main/watchMain.cpp +++ b/main/watchMain.cpp @@ -10,6 +10,11 @@ 4 2 3 */ +// Profiles = 5 (0..4) +// DynRange = +// MinSteps (6..20), MaxSteps (10..40) +// activeState.accel = (min .5 / max 3) +// activeState.speed = (min .5 / max 3) #include "watchMain.hpp" #include "interconConfig.hpp" @@ -73,7 +78,7 @@ void onCommand(std::string name, Cli::CArgs args) { void startUpdate(Cli::CArgs args) { ESP_LOGI(TAG, "Invoking Update"); if (args.size() != 1) { - pShell->write("Need URL to application'\n"); + pShell->writeLine("Need URL to application"); return; } // @ToDo: Start Update here @@ -81,18 +86,18 @@ void startUpdate(Cli::CArgs args) { void getConfig(Cli::CArgs args) { if (args.size() != 1) { - pShell->write("Needs string key for query'\n"); + pShell->writeLine("Needs string key for query"); return; } auto key = args[0]; auto &store = NvsApi::getInstance(); auto val = store.getValue(key); - pShell->write(key + ": " + val + "\n"); + pShell->writeLine(key + ": " + val + ""); } void testPictoIllum(Cli::CArgs args) { if (args.size() != 1) { - pShell->write("Needs position argument for illuminated position 0 for off, 1..6 for pictograms'\n"); + pShell->writeLine("Needs position argument for illuminated position 0 for off, 1..6 for pictograms"); return; } try { @@ -105,30 +110,38 @@ void testPictoIllum(Cli::CArgs args) { void testMovement(Cli::CArgs args) { ESP_LOGI(TAG, "on triggerMovement:"); - if (args.size() != 1) { - pShell->write("need target position (1..6)'\n"); + if (args.size() < 1) { + pShell->writeLine("need target position (1..6)"); + pShell->writeLine("additional optional arguments: Profile (0..4), MinSteps (6..20), MaxSteps (10..40)"); return; } - try { int p = std::stoi(args[0]); - activeState.profile = p; + if (args.size() >= 2) { + activeState.profile = std::min(4, std::stoi(args[1])); + } + if (args.size() >= 3) { + activeState.minJumps = std::min(20, std::stoi(args[2])) ; + } + if (args.size() >= 4) { + activeState.minJumps = std::min(40, std::stoi(args[3])) ; + } commandQueue.enqueue(std::make_unique(MoveType::StepTo, p)); } catch (const std::exception &e) { - ESP_LOGI(TAG, "Failed to parse %s and %s", args[0].c_str(), args[1].c_str()); + ESP_LOGI(TAG, "Failed to parse %s", args[0].c_str()); } } void setConfig(Cli::CArgs args) { if (args.size() != 2) { - pShell->write("Needs string key and value'\n"); + pShell->writeLine("Needs string key and value"); return; } auto key = args[0]; auto val = args[1]; auto &store = NvsApi::getInstance(); - pShell->write(std::string{"Storing value = '"} + val + "'\n"); + pShell->writeLine(std::string{"Storing value = '"} + val + "'"); store.setValue(key, val); } @@ -137,18 +150,18 @@ void setLogServerConfig(Cli::CArgs args) { auto &store = NvsApi::getInstance(); if (args.size() != 1) { auto logger = store.getValue("syslogDst"); - pShell->write(std::string{"syslog destination = '"} + logger + "'\n"); - pShell->write("provide argument to change syslog server'\n"); + pShell->writeLine(std::string{"syslog destination = '"} + logger + "'"); + pShell->writeLine("provide argument to change syslog server"); return; } - pShell->write(std::string{"setting syslog destination to = '"} + args[0] + "'\n"); + pShell->writeLine(std::string{"setting syslog destination to = '"} + args[0] + "'"); store.setValue("syslogDst", args[0]); } void setDynamics(Cli::CArgs args) { ESP_LOGI(TAG, "on setDynamics:"); if (args.size() != 2) { - pShell->write("need float values for velocity and acceleration'\n"); + pShell->writeLine("need float values for velocity and acceleration"); return; } @@ -334,7 +347,7 @@ fos::Semaphore spitProjectFinish; /** Event handler for IP_EVENT_ETH_GOT_IP */ void got_ip_event_handler(void *arg, esp_event_base_t event_base, - int32_t event_id, void *event_data) { + int32_t event_id, void *event_data) { ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; const esp_netif_ip_info_t *ip_info = &event->ip_info; @@ -403,9 +416,8 @@ namespace Effect { void LightingTask() { ESP_LOGI(TAG, "Start Lighting"); - static I2cMaster master(I2C_NUM_0, - { /*sda=*/GPIO_NUM_10, /*scl=*/GPIO_NUM_11} - ); + static I2cMaster master(I2C_NUM_0, + {/*sda=*/GPIO_NUM_10, /*scl=*/GPIO_NUM_11}); // static PmwExpanderPca9685 pca9685(master); static PmwExpanderPca9685 ledDriver1(master, /*iverted=*/false); static PmwExpanderPca9685 ledDriver2(master, /*iverted=*/false, 0x41); @@ -815,18 +827,18 @@ void SpitClientApp() { auto ip = spit::Socket::getAdaptersInfo(); spit::Socket socket(ip); SClient spitClient(ClientName, ProjectName, socket, - { - .onServerEvent = onServerEvent, - .onConnectionStatus = onConnectionStatus, - .onProjectUpdate = onProjectUpdate, - .onSpitType = onSpitType, - .onSpitObject = onSpitObject, - .onPlay = onPlay, - .onPlaySpitType = onPlaySpitType, - .onPlayRemoteObjectStatus = onPlayRemoteObjectStatus, - .onCheckSpitTypeVeto = onCheckSpitTypeVeto, - .onCheckSpitObjectVeto = onCheckSpitObjectVeto, - }); + { + .onServerEvent = onServerEvent, + .onConnectionStatus = onConnectionStatus, + .onProjectUpdate = onProjectUpdate, + .onSpitType = onSpitType, + .onSpitObject = onSpitObject, + .onPlay = onPlay, + .onPlaySpitType = onPlaySpitType, + .onPlayRemoteObjectStatus = onPlayRemoteObjectStatus, + .onCheckSpitTypeVeto = onCheckSpitTypeVeto, + .onCheckSpitObjectVeto = onCheckSpitObjectVeto, + }); for (auto &obj : ProvidedObj) { SType *ptrSPITType1Fix = spitClient.createSPITTypeFixed(obj.iD, obj.groupName, obj.name, 0, 0); @@ -877,19 +889,13 @@ void MqttThread() { if (res->type == ResponseType::StartMoving) { client.publish(MqttTopics.changingPosition, ""); } else if (res->type == ResponseType::StepAt) { - client.publish(MqttTopics.inPosition, std::to_string(res->pos) ); + client.publish(MqttTopics.inPosition, std::to_string(res->pos)); } } } } void app_main(void) { - // esp_err_t ret = nvs_flash_init(); - // if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - // ESP_ERROR_CHECK(nvs_flash_erase()); - // ret = nvs_flash_init(); - // } - // ESP_ERROR_CHECK(ret); // moved to NvsApi::init(); initialize_ethernet(); NvsApi::init(); static fos::Task lightingTask(LightingTask, "Lights", 0x8000uL); @@ -904,7 +910,7 @@ void app_main(void) { static fos::TaskT telnetSocket(telnetSocketTask, ipVersion, "tcpServer", 4096); static fos::TaskT dmxNode(dmxSocketTask, ipVersion, "dmxNode", 4096); // static fos::Task spit(SpitClientApp, "SpitClient"); - static fos::Task mqtt(MqttThread, "MqttEndpoint"); + // static fos::Task mqtt(MqttThread, "MqttEndpoint"); // static Task otaUpdate(SystemFunctions::OtaTaskEntry, "otaTask", 8192); auto &store = NvsApi::getInstance(); diff --git a/main/watchMain.hpp b/main/watchMain.hpp index 6992cba..421d395 100644 --- a/main/watchMain.hpp +++ b/main/watchMain.hpp @@ -29,6 +29,8 @@ #include "cliWrapper.hpp" #include "udpSockets.hpp" #include "tcpSockets.hpp" +#include "syslog.hpp" +#include "telnetServer.hpp" #include "Mutex.hpp" #include "Queue.hpp" #include "Semaphore.hpp" diff --git a/sdkconfig b/sdkconfig index be2a953..1089526 100644 --- a/sdkconfig +++ b/sdkconfig @@ -2145,6 +2145,17 @@ CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT=y # CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL is not set CONFIG_LITTLEFS_ASSERTS=y # end of LittleFS + +# +# Telnet Server +# +CONFIG_TELNET_SERVER_DEFAULT_PORT=23 +CONFIG_TELNET_SERVER_MAX_CONNECTIONS=5 +CONFIG_TELNET_SERVER_STACK_SIZE=4096 +CONFIG_TELNET_SERVER_TASK_PRIORITY=24 +CONFIG_TELNET_SERVER_TASK_CORE=0 +CONFIG_TELNET_SERVER_REDIRECT_LOGS=0 +# end of Telnet Server # end of Component config # CONFIG_IDF_EXPERIMENTAL_FEATURES is not set