From ad9012f6ee582dec1490821918427c732291ef08 Mon Sep 17 00:00:00 2001 From: wrfz <77174685+wrfz@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:53:08 +0100 Subject: [PATCH] Improve request/response logging --- .../daikin_rotex_uart/MessageManager.cpp | 20 ++++++++++++++----- components/daikin_rotex_uart/request.h | 10 ++++++++++ examples/full.yaml | 3 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/components/daikin_rotex_uart/MessageManager.cpp b/components/daikin_rotex_uart/MessageManager.cpp index adf02e0..1f80d4f 100644 --- a/components/daikin_rotex_uart/MessageManager.cpp +++ b/components/daikin_rotex_uart/MessageManager.cpp @@ -27,7 +27,7 @@ void TMessageManager::handleResponse(uart::UARTDevice& device) { std::string log_message = m_buffer.read(device); if (m_buffer.size() >= 2 && m_buffer[0] == 0x15 && m_buffer[1] == 0xEA) { - //ESP_LOGI(TAG, "Invalid response: %s", Utils::to_hex(m_buffer.data(), 2).c_str()); + //ESP_LOGI(TAG, "RX: Invalid request => data: %s", Utils::to_hex(m_buffer.data(), 2).c_str()); m_buffer.shift(2); return; } @@ -49,7 +49,7 @@ void TMessageManager::handleResponse(uart::UARTDevice& device) { uint8_t* input = m_buffer.data().data(); const uint8_t message_offset = header_size + message.getOffset(); if (message_offset < 3 || (message_offset + message.getDataSize()) > m_buffer.size()) { - ESP_LOGE(TAG, "Invalid offset! message_offset: %d, message.data_size: %d, buffer.size: %d", message_offset, message.getDataSize(), m_buffer.size()); + ESP_LOGE(TAG, "RX: Invalid offset! message_offset: %d, message.data_size: %d, buffer.size: %d", message_offset, message.getDataSize(), m_buffer.size()); return; } input += message_offset; @@ -59,10 +59,13 @@ void TMessageManager::handleResponse(uart::UARTDevice& device) { } } m_buffer.shift(2 + length); + ESP_LOGI(TAG, "RX: %s", log_message.c_str()); + return; } + ESP_LOGE(TAG, "RX: incomplete buffer: %s", log_message.c_str()); + return; } - - ESP_LOGI(TAG, "RX: %s", log_message.c_str()); + ESP_LOGE(TAG, "RX: incomplete header: %s", log_message.c_str()); } std::shared_ptr TMessageManager::getNextRequestToSend() { @@ -94,6 +97,7 @@ std::shared_ptr TMessageManager::getNextRequestToSend() { void TMessageManager::dumpRequests() { std::string dump; std::list used; + bool first = true; for (auto& message : m_messages) { std::shared_ptr pRequest = message.getRequest(); @@ -103,7 +107,13 @@ void TMessageManager::dumpRequests() { if (!dump.empty()) { dump += "|"; } - dump += Utils::format("%s:%d:%d", Utils::to_hex(pRequest->getRegistryId()).c_str(), pRequest->isInProgress(), pRequest->isRequestRequired()); + const char state = pRequest->isInProgress() ? 'P' : (pRequest->isRequestRequired() ? 'R' : '-'); + if (!first) { + dump += " "; + } + dump += Utils::format("%s:%c|%d|%d", Utils::to_hex(pRequest->getRegistryId()).c_str(), state, + pRequest->getLastRequestTimestamp(), pRequest->getLastResponeTimestamp()); + first = false; } } ESP_LOGI(TAG, "%s", dump.c_str()); diff --git a/components/daikin_rotex_uart/request.h b/components/daikin_rotex_uart/request.h index 12a1e63..d3607c4 100644 --- a/components/daikin_rotex_uart/request.h +++ b/components/daikin_rotex_uart/request.h @@ -20,6 +20,8 @@ class TRequest { bool isRequestRequired() const; void setHandled(); uint8_t getRegistryId() const; + uint32_t getLastRequestTimestamp() const; + uint32_t getLastResponeTimestamp() const; private: static uint8_t getCRC(std::array const& data, uint32_t len); @@ -32,5 +34,13 @@ inline uint8_t TRequest::getRegistryId() const { return m_registryID; } +inline uint32_t TRequest::getLastRequestTimestamp() const { + return m_last_request_timestamp; +} + +inline uint32_t TRequest::getLastResponeTimestamp() const { + return m_last_response_timestamp; +} + } // namespace daikin_rotex_uart } // namespace esphome \ No newline at end of file diff --git a/examples/full.yaml b/examples/full.yaml index 421dcab..97d6b9f 100644 --- a/examples/full.yaml +++ b/examples/full.yaml @@ -92,9 +92,10 @@ uart: daikin_rotex_uart: id: rotext_hpsu_uart uart_id: uart_bus - outdoor_unit: RRLQ008CAV3 + #outdoor_unit: RRLQ008CAV3 #Please comment in your outdoor unit #outdoor_unit: RRLQ011CAW1 #outdoor_unit: ERLQ016CAW1 + #outdoor_unit: ERGA08DAV3 entities: t_liq: name: Temperatur Flüssigkeitsleitung