Added support for configurable logging on the ESP32 platform. (#10)
Because the ESP-IDF supports [runtime log level control](https://docs.espressif.com/projects/esp-idf/en/v5.5.2/esp32s3/api-reference/system/log.html#log-level-control), SystemK required some tweak to take full advantage of this.
This PR makes the following changes to SystemK:
- On the ESP32 platform, the highest logging level *compiled in* to the app is now controlable by Kconfig, as "SystemK maximum log level".
- [Protocols.c](272618d49d/Protocols/Protocols.c) was refactored, and the `DEBUG_PACKET_[EN/DE]CODE` #defines were renamed to make it clear that they now only apply to the PSoC platform.
- Some decoding warnings in the Test Protocol were downgraded to debug, since they were a nuisance most of the time.
Co-authored-by: Joe Kearney <joe@clubk.club>
Reviewed-on: #10
This commit is contained in:
parent
f80cb59828
commit
c4350ebd27
5 changed files with 75 additions and 29 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* 🛡️ <https://ktag.clubk.club> 🃞
|
||||
*
|
||||
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
|
||||
* Copyright © 2016-2026 Joseph P. Kearney and the KTag developers.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
|
|
@ -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,10 +222,15 @@ TimedPulseTrain_T *PROTOCOLS_EncodePacket(TagPacket_T *packet)
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PACKET_ENCODE
|
||||
KLOG_DEBUG(KLOG_TAG, "\nEncoded %s packet (%u):", ProtocolNameAsString(packet->protocol), result->count);
|
||||
PrintPulseTrainToConsole(result);
|
||||
#endif // 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
|
||||
{
|
||||
KLOG_DEBUG(KLOG_TAG, "\nEncoded %s packet (%u):", ProtocolNameAsString(packet->protocol), result->count);
|
||||
PrintPulseTrainToConsole(result);
|
||||
}
|
||||
#endif // ((defined PSoC_DEBUG_PACKET_ENCODE) || (defined ESP_PLATFORM))
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -250,7 +257,7 @@ DecodedPacket_T *PROTOCOLS_MaybeDecodePacket(TimedPulseTrain_T *packet)
|
|||
if (result != NULL)
|
||||
{
|
||||
// Many NEC remotes repeat packets when the button is held down.
|
||||
// Too avoid double-counting, endure 500ms of silence between packets.
|
||||
// Too avoid double-counting, ensure 500ms of silence between packets.
|
||||
static TickType_t lastPacketTime = 0;
|
||||
const TickType_t minimumInterval = pdMS_TO_TICKS(500);
|
||||
|
||||
|
|
@ -328,31 +335,33 @@ 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
|
||||
esp_log_level_set(KLOG_TAG, ESP_LOG_DEBUG);
|
||||
if (esp_log_level_get(KLOG_TAG) >= ESP_LOG_DEBUG)
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
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));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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
|
||||
#endif // ((defined PSoC_DEBUG_PACKET_DECODE) || (defined ESP_PLATFORM))
|
||||
|
||||
// Remember which receiver saw the packet.
|
||||
if (result != NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue