From 3a9cd04a1ecba7ff77c72a10725e73072ebe5421 Mon Sep 17 00:00:00 2001 From: ElVit Date: Thu, 26 Mar 2026 20:11:40 +0100 Subject: [PATCH] Renamed log_uart_hex to write_uart_log --- components/panasonic_heatpump/helpers.cpp | 13 ++++++++----- components/panasonic_heatpump/helpers.h | 4 ++-- .../panasonic_heatpump/panasonic_heatpump.cpp | 18 ++++++------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/components/panasonic_heatpump/helpers.cpp b/components/panasonic_heatpump/helpers.cpp index 5546ea0..8862fa3 100644 --- a/components/panasonic_heatpump/helpers.cpp +++ b/components/panasonic_heatpump/helpers.cpp @@ -4,13 +4,13 @@ namespace esphome { namespace panasonic_heatpump { static const char* const TAG = "panasonic_heatpump"; -void PanasonicHelpers::log_uart_hex(UartLogDirection direction, const std::vector& data, - const char separator) { - PanasonicHelpers::log_uart_hex(direction, &data[0], data.size(), separator); +void PanasonicHelpers::write_uart_log(UartLogDirection direction, const std::vector& data, + const char separator, bool logBytes) { + PanasonicHelpers::write_uart_log(direction, &data[0], data.size(), separator, logBytes); } -void PanasonicHelpers::log_uart_hex(UartLogDirection direction, const uint8_t* data, const size_t length, - const char separator) { +void PanasonicHelpers::write_uart_log(UartLogDirection direction, const uint8_t* data, const size_t length, + const char separator, bool logBytes) { std::string logStr = ""; std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<"; std::string msgType = direction == UART_LOG_TX ? "request" : "response"; @@ -31,6 +31,9 @@ void PanasonicHelpers::log_uart_hex(UartLogDirection direction, const uint8_t* d ESP_LOGI(TAG, "%s %s[%i]", msgDir.c_str(), msgType.c_str(), length); delay(10); + if (!logBytes) + return; + logStr += byte_array_to_hex_string(data, length, separator); // Log in chunks to avoid ESP_LOG buffer overflow (https://developers.esphome.io/architecture/logging/). diff --git a/components/panasonic_heatpump/helpers.h b/components/panasonic_heatpump/helpers.h index af71f9c..05cc0cf 100644 --- a/components/panasonic_heatpump/helpers.h +++ b/components/panasonic_heatpump/helpers.h @@ -18,8 +18,8 @@ enum UartLogDirection : uint8_t { class PanasonicHelpers { public: - static void log_uart_hex(UartLogDirection direction, const std::vector& data, const char separator); - static void log_uart_hex(UartLogDirection direction, const uint8_t* data, const size_t length, const char separator); + static void write_uart_log(UartLogDirection direction, const std::vector& data, const char separator, bool logBytes); + static void write_uart_log(UartLogDirection direction, const uint8_t* data, const size_t length, const char separator, bool logBytes); static std::string byte_array_to_hex_string(const std::vector& data, const char separator); static std::string byte_array_to_hex_string(const uint8_t* data, const size_t length, const char separator); }; diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 3f10afa..7ebe08e 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -181,8 +181,7 @@ void PanasonicHeatpumpComponent::read_response() { if (this->response_message_.size() > 2 && this->response_message_.size() == this->payload_length_ + 3) { this->response_receiving_ = false; this->current_response_count_++; - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_RX, this->response_message_, ','); + PanasonicHelpers::write_uart_log(UART_LOG_RX, this->response_message_, ',', this->log_uart_msg_); } } } @@ -190,27 +189,23 @@ void PanasonicHeatpumpComponent::read_response() { void PanasonicHeatpumpComponent::send_request(RequestType requestType) { switch (requestType) { case RequestType::COMMAND: - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_TX, this->command_message_, ','); + PanasonicHelpers::write_uart_log(UART_LOG_TX, this->command_message_, ',', this->log_uart_msg_); this->write_array(this->command_message_); this->flush(); break; case RequestType::INITIAL: // Probably not necessary but CZ-TAW1 sends this query on boot - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ','); + PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ',', this->log_uart_msg_); this->write_array(PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE); this->flush(); break; case RequestType::POLLING: - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ','); + PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ',', this->log_uart_msg_); this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE); this->flush(); break; case RequestType::POLLING_EXTRA: - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ','); + PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ',', this->log_uart_msg_); this->write_array(PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE); this->flush(); break; @@ -267,8 +262,7 @@ void PanasonicHeatpumpComponent::read_request() { // Check if message is complete if (this->request_message_.size() > 2 && this->request_message_.size() == this->payload_length_ + 3) { this->request_receiving_ = false; - if (this->log_uart_msg_) - PanasonicHelpers::log_uart_hex(UART_LOG_TX, this->request_message_, ','); + PanasonicHelpers::write_uart_log(UART_LOG_TX, this->request_message_, ',', this->log_uart_msg_); if (this->request_message_[0] != 0x31) { // Update last request time when request is complete