From f6bd2ea643795aa27fd4c9887732c37de6eaba11 Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 10 Sep 2026 23:58:30 +0200 Subject: [PATCH] [Debug] Make CommandArgParser debug logs better readable --- src/src/DataStructs/ValueStruct.cpp | 6 +++--- src/src/DataStructs/ValueStruct.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/src/DataStructs/ValueStruct.cpp b/src/src/DataStructs/ValueStruct.cpp index 34fcc205c..af968ed3e 100644 --- a/src/src/DataStructs/ValueStruct.cpp +++ b/src/src/DataStructs/ValueStruct.cpp @@ -639,12 +639,12 @@ String ValueStruct::debug() const const String normalStr = toString(); const String unformattedStr = toString(true); String logstr = strformat( - F("t:%d,'%s'"), - static_cast(getValueType()), + F("%s:'%s'"), + toShortStr(getValueType()), normalStr.c_str()); if (!normalStr.equals(unformattedStr)) { - logstr += strformat(F("u:'%s'"), unformattedStr.c_str()); + logstr += strformat(F("/u:'%s'"), unformattedStr.c_str()); } if (!operator bool()) { diff --git a/src/src/DataStructs/ValueStruct.h b/src/src/DataStructs/ValueStruct.h index 2cf9417e7..e74db6521 100644 --- a/src/src/DataStructs/ValueStruct.h +++ b/src/src/DataStructs/ValueStruct.h @@ -12,6 +12,9 @@ class ValueStruct { public: + // Don't just extend these enums as they are part of very tightly packed struct. + // For example if 1 extra bit is needed, the start and length of the SSO must be adjusted. + enum class ValueType : uint8_t { Unset = 0, String, @@ -24,6 +27,18 @@ public: }; + #ifndef BUILD_NO_DEBUG + static const char* toShortStr(ValueType valueType) + { + static const char* shortStrings = "---\0Str\0Fla\0flt\0dbl\0int\0uin\0boo\0"; + constexpr uint8_t index_modulo = static_cast(ValueType::Bool) + 1; + const uint8_t index = static_cast(valueType) % index_modulo; + + return shortStrings + 4*index; + } + + #endif + enum class PreferredFormat : uint8_t { Default = 0, Dec,