cli improvement

This commit is contained in:
2025-11-13 00:25:31 +01:00
parent bd4a593963
commit 20d1ca79b8
4 changed files with 59 additions and 40 deletions
+45 -39
View File
@@ -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<MoveCommand>(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<int> telnetSocket(telnetSocketTask, ipVersion, "tcpServer", 4096);
static fos::TaskT<int> 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();
+2
View File
@@ -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"