From 0105338e29d4e67a48cf444e569ce35872c18c18 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 6 Aug 2024 14:17:53 +0200 Subject: [PATCH 1/2] do not close local shell #1926 --- lib/uuid-console/src/shell.cpp | 2 +- lib/uuid-console/src/uuid/console.h | 2 ++ src/console.h | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/uuid-console/src/shell.cpp b/lib/uuid-console/src/shell.cpp index 8005913c1..771806065 100644 --- a/lib/uuid-console/src/shell.cpp +++ b/lib/uuid-console/src/shell.cpp @@ -85,7 +85,7 @@ void Shell::stop() { blocking_data->stop_ = true; } else { - if (running()) { + if (running() && !has_flags(CommandFlags::LOCAL)) { // do not close local shell stopped_ = true; stopped(); } diff --git a/lib/uuid-console/src/uuid/console.h b/lib/uuid-console/src/uuid/console.h index d3c565bd2..e8f54d79e 100644 --- a/lib/uuid-console/src/uuid/console.h +++ b/lib/uuid-console/src/uuid/console.h @@ -55,6 +55,8 @@ #include #endif +enum CommandFlags : uint8_t { USER = 0, ADMIN = (1 << 0), LOCAL = (1 << 1) }; + namespace uuid { /** diff --git a/src/console.h b/src/console.h index a8e7eeaae..01b48e4ce 100644 --- a/src/console.h +++ b/src/console.h @@ -32,8 +32,6 @@ namespace emsesp { -enum CommandFlags : uint8_t { USER = 0, ADMIN = (1 << 0), LOCAL = (1 << 1) }; - enum ShellContext : uint8_t { MAIN = 0, SYSTEM, END }; class EMSESP; From 70b16149d0b997af2516f5bee25538a36aa6c289 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 7 Aug 2024 07:42:30 +0200 Subject: [PATCH 2/2] read custom entity raw from fetched telegrams --- src/web/WebCustomEntityService.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index f9340eb63..c1861c689 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -541,7 +541,7 @@ void WebCustomEntityService::fetch() { const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3, 4}; for (auto & entity : *customEntityItems_) { - if (entity.device_id > 0 && entity.type_id > 0) { // ths excludes also RAM type + if (entity.device_id > 0 && entity.type_id > 0) { // this excludes also RAM type bool needFetch = true; uint8_t fetchblock = entity.type_id > 0x0FF ? 25 : 27; uint8_t start = entity.offset % fetchblock; @@ -572,11 +572,17 @@ bool WebCustomEntityService::get_value(std::shared_ptr telegram) const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3, 4}; for (auto & entity : *customEntityItems_) { if (entity.value_type == DeviceValueType::STRING && telegram->type_id == entity.type_id && telegram->src == entity.device_id - && telegram->offset >= entity.offset) { + && (telegram->offset >= entity.offset || entity.offset < telegram->offset + telegram->message_length)) { + auto message_length = telegram->message_length; + auto message_data = telegram->message_data; + if (telegram->offset < entity.offset) { + message_data = &telegram->message_data[entity.offset - telegram->offset]; + message_length -= entity.offset - telegram->offset; + } auto length = std::min((int)telegram->offset - entity.offset + telegram->message_length, (int)entity.factor); - auto rest = std::min((int)entity.factor - telegram->offset + entity.offset, (int)telegram->message_length); + auto rest = std::min((int)entity.factor - telegram->offset + entity.offset, (int)message_length); if (rest > 0) { - memcpy(&entity.raw[telegram->offset - entity.offset], telegram->message_data, rest); + memcpy(&entity.raw[telegram->offset - entity.offset], message_data, rest); auto data = Helpers::data_to_hex(entity.raw, (uint8_t)length); if (entity.data != data) { entity.data = data;