From 9b7c17605af87f8fd13f3bc81616be49f8a711fa Mon Sep 17 00:00:00 2001 From: DigiH Date: Tue, 28 Feb 2023 20:42:36 +0100 Subject: [PATCH] ascii_from_hex_data --- src/decoder.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/decoder.cpp b/src/decoder.cpp index cbaee835..22c1c2a0 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -899,6 +899,27 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { } jsondata[sanitizeJsonKey(kv.key().c_str())] = value; + success = i_main; + } else if (strstr((const char*)decoder[0], "ascii_from_hex_data") != nullptr) { + const char* src = svc_data; + if (strstr((const char*)decoder[1], MFG_DATA)) { + src = mfg_data; + } + + std::string value(src + decoder[2].as(), decoder[3].as()); + std::string ascii = ""; + + for (size_t i = 0; i < value.length(); i += 2) { + std::string part = value.substr(i, 2); + char ch = stoul(part, nullptr, 16); + + ascii += ch; + } + + if (ascii != "") { + jsondata[sanitizeJsonKey(kv.key().c_str())] = ascii; + } + success = i_main; } }