From e62f243e86ab0636121ded3f8197da2a8be40976 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Thu, 8 Jan 2026 21:37:49 -0600 Subject: [PATCH 1/2] Added log level configuration to Kconfig. --- CMakeLists.txt | 7 +++++++ Kconfig | 30 ++++++++++++++++++++++++++++++ Protocols/Protocols.c | 40 ++++++++++++++++++++++++++-------------- Protocols/Test.c | 4 ++-- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 592d9f6..15bef15 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,3 +72,10 @@ idf_component_register( "Settings" "States" ) + +# This ensures LOG_LOCAL_LEVEL is defined before any header files are included. +idf_build_set_property(COMPILE_DEFINITIONS + "-DLOG_LOCAL_LEVEL=${CONFIG_SYSTEMK_LOG_LEVEL}" + APPEND +) + diff --git a/Kconfig b/Kconfig index ee22b03..d8ea13c 100644 --- a/Kconfig +++ b/Kconfig @@ -35,4 +35,34 @@ menu "KTag SystemK" help Value of audio volume representing the minimum volume possible for this device. + config SYSTEMK_LOG_LEVEL + int + default 0 if SYSTEMK_LOG_LEVEL_NONE + default 1 if SYSTEMK_LOG_LEVEL_ERROR + default 2 if SYSTEMK_LOG_LEVEL_WARN + default 3 if SYSTEMK_LOG_LEVEL_INFO + default 4 if SYSTEMK_LOG_LEVEL_DEBUG + default 5 if SYSTEMK_LOG_LEVEL_VERBOSE + + choice SYSTEMK_LOG_LEVEL_CHOICE + bool "SystemK maximum log level" + default SYSTEMK_LOG_LEVEL_VERBOSE + help + Set the maximum compiled log level for SystemK. + Messages at higher levels will be removed at compile time. + + config SYSTEMK_LOG_LEVEL_NONE + bool "No output" + config SYSTEMK_LOG_LEVEL_ERROR + bool "Error" + config SYSTEMK_LOG_LEVEL_WARN + bool "Warning" + config SYSTEMK_LOG_LEVEL_INFO + bool "Info" + config SYSTEMK_LOG_LEVEL_DEBUG + bool "Debug" + config SYSTEMK_LOG_LEVEL_VERBOSE + bool "Verbose" + endchoice + endmenu \ No newline at end of file diff --git a/Protocols/Protocols.c b/Protocols/Protocols.c index 019fa42..46b0baa 100644 --- a/Protocols/Protocols.c +++ b/Protocols/Protocols.c @@ -24,7 +24,7 @@ #include "SystemK.h" -// #define DEBUG_PACKET_ENCODE +#define DEBUG_PACKET_ENCODE #define DEBUG_PACKET_DECODE static const char *KLOG_TAG = "Protocols"; @@ -221,8 +221,13 @@ TimedPulseTrain_T *PROTOCOLS_EncodePacket(TagPacket_T *packet) } #ifdef DEBUG_PACKET_ENCODE - KLOG_DEBUG(KLOG_TAG, "\nEncoded %s packet (%u):", ProtocolNameAsString(packet->protocol), result->count); - PrintPulseTrainToConsole(result); +#ifdef ESP_PLATFORM + if (esp_log_level_get(KLOG_TAG) >= ESP_LOG_DEBUG) +#endif // ESP_PLATFORM + { + KLOG_DEBUG(KLOG_TAG, "\nEncoded %s packet (%u):", ProtocolNameAsString(packet->protocol), result->count); + PrintPulseTrainToConsole(result); + } #endif // DEBUG_PACKET_ENCODE return result; @@ -329,23 +334,30 @@ DecodedPacket_T *PROTOCOLS_MaybeDecodePacket(TimedPulseTrain_T *packet) } #ifdef DEBUG_PACKET_DECODE - if (result != NULL) +#ifdef ESP_PLATFORM + if (esp_log_level_get(KLOG_TAG) >= ESP_LOG_DEBUG) +#endif // ESP_PLATFORM { - KLOG_DEBUG(KLOG_TAG, "Successfully decoded packet as %s: %s", DecodedPacketTypeAsString(result->Generic.type), ProtocolNameAsString(result->Generic.protocol)); vTaskDelay(pdMS_TO_TICKS(10)); - if (result->Generic.type == DECODED_PACKET_TYPE_COMMAND_RECEIVED) + if (result != NULL) { - KLOG_DEBUG(KLOG_TAG, "Command data: %lu", result->Command.data); + KLOG_DEBUG(KLOG_TAG, "Successfully decoded packet as %s: %s", DecodedPacketTypeAsString(result->Generic.type), ProtocolNameAsString(result->Generic.protocol)); vTaskDelay(pdMS_TO_TICKS(10)); - } - } - else - { - KLOG_DEBUG(KLOG_TAG, "Couldn't decode packet. Size was %d symbols:", packet->count); - vTaskDelay(pdMS_TO_TICKS(10)); - PrintPulseTrainToConsole(packet); + if (result->Generic.type == DECODED_PACKET_TYPE_COMMAND_RECEIVED) + { + KLOG_DEBUG(KLOG_TAG, "Command data: %lu", result->Command.data); + vTaskDelay(pdMS_TO_TICKS(10)); + } + } + else + { + KLOG_DEBUG(KLOG_TAG, "Couldn't decode packet. Size was %d symbols:", packet->count); + vTaskDelay(pdMS_TO_TICKS(10)); + + PrintPulseTrainToConsole(packet); + } } #endif // DEBUG_PACKET_DECODE diff --git a/Protocols/Test.c b/Protocols/Test.c index f9c1964..9b58cf7 100644 --- a/Protocols/Test.c +++ b/Protocols/Test.c @@ -118,12 +118,12 @@ DecodedPacket_T *TEST_MaybeDecodePacket(TimedPulseTrain_T *packet) if (packet->bitstream[index].duration < (expected_pulse_duration_in_us - TEST_TOLERANCE_IN_us)) { - KLOG_WARN(KLOG_TAG, "Pulse %u is too short! Expected %lu; received %u.", index, expected_pulse_duration_in_us, packet->bitstream[index].duration); + KLOG_DEBUG(KLOG_TAG, "Pulse %u is too short! Expected %lu; received %u.", index, expected_pulse_duration_in_us, packet->bitstream[index].duration); return NULL; } if (packet->bitstream[index].duration > (expected_pulse_duration_in_us + TEST_TOLERANCE_IN_us)) { - KLOG_WARN(KLOG_TAG, "Pulse %u is too long! Expected %lu; received %u.", index, expected_pulse_duration_in_us, packet->bitstream[index].duration); + KLOG_DEBUG(KLOG_TAG, "Pulse %u is too long! Expected %lu; received %u.", index, expected_pulse_duration_in_us, packet->bitstream[index].duration); return NULL; } } From 3d87f2b53070b181d9811f19daf606d5896e3932 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 10 Jan 2026 15:59:31 -0600 Subject: [PATCH 2/2] Cleanup. --- Protocols/Protocols.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Protocols/Protocols.c b/Protocols/Protocols.c index 46b0baa..8114743 100644 --- a/Protocols/Protocols.c +++ b/Protocols/Protocols.c @@ -24,8 +24,10 @@ #include "SystemK.h" -#define DEBUG_PACKET_ENCODE -#define DEBUG_PACKET_DECODE +// Use these defines to enable detailed debug logging of packet encoding and decoding on the PSoC platform. +// Debug logging is always available on the ESP32 platform, and can be configured with the console. +//#define PSoC_DEBUG_PACKET_ENCODE +//#define PSoC_DEBUG_PACKET_DECODE static const char *KLOG_TAG = "Protocols"; @@ -220,7 +222,7 @@ TimedPulseTrain_T *PROTOCOLS_EncodePacket(TagPacket_T *packet) break; } -#ifdef DEBUG_PACKET_ENCODE +#if ((defined PSoC_DEBUG_PACKET_ENCODE) || (defined ESP_PLATFORM)) #ifdef ESP_PLATFORM if (esp_log_level_get(KLOG_TAG) >= ESP_LOG_DEBUG) #endif // ESP_PLATFORM @@ -228,7 +230,7 @@ TimedPulseTrain_T *PROTOCOLS_EncodePacket(TagPacket_T *packet) KLOG_DEBUG(KLOG_TAG, "\nEncoded %s packet (%u):", ProtocolNameAsString(packet->protocol), result->count); PrintPulseTrainToConsole(result); } -#endif // DEBUG_PACKET_ENCODE +#endif // ((defined PSoC_DEBUG_PACKET_ENCODE) || (defined ESP_PLATFORM)) return result; } @@ -333,7 +335,7 @@ DecodedPacket_T *PROTOCOLS_MaybeDecodePacket(TimedPulseTrain_T *packet) result = TEST_MaybeDecodePacket(packet); } -#ifdef DEBUG_PACKET_DECODE +#if ((defined PSoC_DEBUG_PACKET_DECODE) || (defined ESP_PLATFORM)) #ifdef ESP_PLATFORM if (esp_log_level_get(KLOG_TAG) >= ESP_LOG_DEBUG) #endif // ESP_PLATFORM @@ -359,7 +361,7 @@ DecodedPacket_T *PROTOCOLS_MaybeDecodePacket(TimedPulseTrain_T *packet) PrintPulseTrainToConsole(packet); } } -#endif // DEBUG_PACKET_DECODE +#endif // ((defined PSoC_DEBUG_PACKET_DECODE) || (defined ESP_PLATFORM)) // Remember which receiver saw the packet. if (result != NULL)