Renamed log_uart_hex to write_uart_log

This commit is contained in:
ElVit 2026-03-26 20:11:40 +01:00
parent 8f9152e12e
commit 3a9cd04a1e
3 changed files with 16 additions and 19 deletions

View File

@ -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<uint8_t>& data,
const char separator) {
PanasonicHelpers::log_uart_hex(direction, &data[0], data.size(), separator);
void PanasonicHelpers::write_uart_log(UartLogDirection direction, const std::vector<uint8_t>& 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/).

View File

@ -18,8 +18,8 @@ enum UartLogDirection : uint8_t {
class PanasonicHelpers {
public:
static void log_uart_hex(UartLogDirection direction, const std::vector<uint8_t>& 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<uint8_t>& 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<uint8_t>& data, const char separator);
static std::string byte_array_to_hex_string(const uint8_t* data, const size_t length, const char separator);
};

View File

@ -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