diff --git a/components/dali_domain/src/dali_domain.cpp b/components/dali_domain/src/dali_domain.cpp index 7ea44a8..a0c5d25 100644 --- a/components/dali_domain/src/dali_domain.cpp +++ b/components/dali_domain/src/dali_domain.cpp @@ -128,6 +128,16 @@ std::vector LegacyQueryResponse(uint8_t status, uint8_t value = 0x00) { return {status, value}; } +void LogQueryRxPacket(const char* transport, int id, const std::vector& packet, + const char* note = nullptr) { + const unsigned first = packet.size() > 0 ? packet[0] : 0; + const unsigned second = packet.size() > 1 ? packet[1] : 0; + ESP_LOGD(TAG, "%s query rx packet id=%d len=%u data=%02x %02x%s%s", + transport == nullptr ? "dali" : transport, id, + static_cast(packet.size()), first, second, + note == nullptr ? "" : " note=", note == nullptr ? "" : note); +} + bool SendHardwareFrame(uint8_t bus_id, const uint8_t* data, size_t len) { if (data == nullptr || len != 3) { return false; @@ -159,7 +169,12 @@ std::vector TransactHardwareFrame(uint8_t bus_id, const uint8_t* data, return {}; } if (len != 3) { - return len > 0 && data[0] == 0x12 ? LegacyQueryResponse(0xFD) : std::vector{}; + if (len > 0 && data[0] == 0x12) { + const auto packet = LegacyQueryResponse(0xFD); + LogQueryRxPacket("hardware", bus_id, packet, "invalid-query-len"); + return packet; + } + return std::vector{}; } switch (data[0]) { @@ -182,15 +197,21 @@ std::vector TransactHardwareFrame(uint8_t bus_id, const uint8_t* data, ClearHardwareQueryRawSuppress(bus_id); if (rx.status != DALI_FRAME_OK || rx.length != 8) { ESP_LOGW(TAG, "hardware query response for bus=%u has invalid status or length", bus_id); - return LegacyQueryResponse(0xFD); + const auto packet = LegacyQueryResponse(0xFD); + LogQueryRxPacket("hardware", bus_id, packet, "invalid-status-or-length"); + return packet; } ESP_LOGD(TAG, "got hardware query response for bus=%u status=%u len=%u data=%02x %02x " "%02x %02x", bus_id, rx.status, rx.length, rx.data[0], rx.data[1], rx.data[2], rx.data[3]); - return {0xFF, rx.data[0]}; + const std::vector packet{0xFF, rx.data[0]}; + LogQueryRxPacket("hardware", bus_id, packet, "ok"); + return packet; } ClearHardwareQueryRawSuppress(bus_id); - return LegacyQueryResponse(0xFE); + const auto packet = LegacyQueryResponse(0xFE); + LogQueryRxPacket("hardware", bus_id, packet, "no-response"); + return packet; } default: return {}; @@ -233,16 +254,22 @@ std::vector TransactSerialFrame(int uart_port, QueueHandle_t queue, uint32_t query_timeout_ms, const uint8_t* data, size_t len) { if (data == nullptr || len == 0) { - return LegacyQueryResponse(0xFD); + const auto packet = LegacyQueryResponse(0xFD); + LogQueryRxPacket("serial", uart_port, packet, "empty-query"); + return packet; } if (data[0] == 0x12 && len != 3) { - return LegacyQueryResponse(0xFD); + const auto packet = LegacyQueryResponse(0xFD); + LogQueryRxPacket("serial", uart_port, packet, "invalid-query-len"); + return packet; } if (data != nullptr && len > 0 && data[0] == 0x12) { DrainSerialQueue(queue); } if (!WriteSerialFrame(uart_port, data, len)) { - return LegacyQueryResponse(0xFD); + const auto packet = LegacyQueryResponse(0xFD); + LogQueryRxPacket("serial", uart_port, packet, "write-failed"); + return packet; } if (data[0] != 0x12) { return {0xFF}; @@ -258,12 +285,17 @@ std::vector TransactSerialFrame(int uart_port, QueueHandle_t queue, break; } auto response = PacketToVector(packet, 2); + LogQueryRxPacket("serial", uart_port, response, "raw"); if (!response.empty() && (response[0] == 0xFF || response[0] == 0xFE || response[0] == 0xFD)) { - return LegacyQueryResponse(response[0], response.size() > 1 ? response[1] : 0x00); + const auto packet = LegacyQueryResponse(response[0], response.size() > 1 ? response[1] : 0x00); + LogQueryRxPacket("serial", uart_port, packet, "accepted"); + return packet; } } - return LegacyQueryResponse(0xFE); + const auto packet = LegacyQueryResponse(0xFE); + LogQueryRxPacket("serial", uart_port, packet, "timeout"); + return packet; } } // namespace @@ -282,7 +314,9 @@ struct DaliDomainService::DaliChannel { }; DaliDomainService::DaliDomainService() - : raw_frame_sink_lock_(xSemaphoreCreateMutex()) {} + : raw_frame_sink_lock_(xSemaphoreCreateMutex()) { + esp_log_level_set(TAG, (esp_log_level_t)CONFIG_DALI_LOG_LEVEL); +} DaliDomainService::~DaliDomainService() = default; diff --git a/components/gateway_bridge/src/gateway_bridge.cpp b/components/gateway_bridge/src/gateway_bridge.cpp index a6fbd11..d9899c7 100644 --- a/components/gateway_bridge/src/gateway_bridge.cpp +++ b/components/gateway_bridge/src/gateway_bridge.cpp @@ -24,6 +24,7 @@ #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG #endif #include "esp_log.h" +#include "sdkconfig.h" #include "freertos/semphr.h" #include "lwip/inet.h" #include "lwip/sockets.h" @@ -69,6 +70,7 @@ void ConfigureDaliCppLogging() { if (configured) return; configured = true; DaliLog::instance().setLevel(LogLevel::debug); + esp_log_level_set(kDaliCppLogTag, (esp_log_level_t)CONFIG_DALI_LOG_LEVEL); DaliLog::instance().setSink([](const std::string& line) { ESP_LOGD(kDaliCppLogTag, "%s", line.c_str()); });