Skip to content

Commit

Permalink
Improve request/response logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Nov 22, 2024
1 parent cb34ade commit ad9012f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
20 changes: 15 additions & 5 deletions components/daikin_rotex_uart/MessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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<TRequest> TMessageManager::getNextRequestToSend() {
Expand Down Expand Up @@ -94,6 +97,7 @@ std::shared_ptr<TRequest> TMessageManager::getNextRequestToSend() {
void TMessageManager::dumpRequests() {
std::string dump;
std::list<uint8_t> used;
bool first = true;
for (auto& message : m_messages) {
std::shared_ptr<TRequest> pRequest = message.getRequest();

Expand All @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions components/daikin_rotex_uart/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 4> const& data, uint32_t len);

Expand All @@ -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
3 changes: 2 additions & 1 deletion examples/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad9012f

Please sign in to comment.