Renamed log_uart_hex to write_uart_log
This commit is contained in:
parent
8f9152e12e
commit
3a9cd04a1e
|
|
@ -4,13 +4,13 @@ namespace esphome {
|
||||||
namespace panasonic_heatpump {
|
namespace panasonic_heatpump {
|
||||||
static const char* const TAG = "panasonic_heatpump";
|
static const char* const TAG = "panasonic_heatpump";
|
||||||
|
|
||||||
void PanasonicHelpers::log_uart_hex(UartLogDirection direction, const std::vector<uint8_t>& data,
|
void PanasonicHelpers::write_uart_log(UartLogDirection direction, const std::vector<uint8_t>& data,
|
||||||
const char separator) {
|
const char separator, bool logBytes) {
|
||||||
PanasonicHelpers::log_uart_hex(direction, &data[0], data.size(), separator);
|
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,
|
void PanasonicHelpers::write_uart_log(UartLogDirection direction, const uint8_t* data, const size_t length,
|
||||||
const char separator) {
|
const char separator, bool logBytes) {
|
||||||
std::string logStr = "";
|
std::string logStr = "";
|
||||||
std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<";
|
std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<";
|
||||||
std::string msgType = direction == UART_LOG_TX ? "request" : "response";
|
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);
|
ESP_LOGI(TAG, "%s %s[%i]", msgDir.c_str(), msgType.c_str(), length);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
if (!logBytes)
|
||||||
|
return;
|
||||||
|
|
||||||
logStr += byte_array_to_hex_string(data, length, separator);
|
logStr += byte_array_to_hex_string(data, length, separator);
|
||||||
|
|
||||||
// Log in chunks to avoid ESP_LOG buffer overflow (https://developers.esphome.io/architecture/logging/).
|
// Log in chunks to avoid ESP_LOG buffer overflow (https://developers.esphome.io/architecture/logging/).
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ enum UartLogDirection : uint8_t {
|
||||||
|
|
||||||
class PanasonicHelpers {
|
class PanasonicHelpers {
|
||||||
public:
|
public:
|
||||||
static void log_uart_hex(UartLogDirection direction, const std::vector<uint8_t>& data, const char separator);
|
static void write_uart_log(UartLogDirection direction, const std::vector<uint8_t>& data, const char separator, bool logBytes);
|
||||||
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 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 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);
|
static std::string byte_array_to_hex_string(const uint8_t* data, const size_t length, const char separator);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,7 @@ void PanasonicHeatpumpComponent::read_response() {
|
||||||
if (this->response_message_.size() > 2 && this->response_message_.size() == this->payload_length_ + 3) {
|
if (this->response_message_.size() > 2 && this->response_message_.size() == this->payload_length_ + 3) {
|
||||||
this->response_receiving_ = false;
|
this->response_receiving_ = false;
|
||||||
this->current_response_count_++;
|
this->current_response_count_++;
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_RX, this->response_message_, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_RX, this->response_message_, ',');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,27 +189,23 @@ void PanasonicHeatpumpComponent::read_response() {
|
||||||
void PanasonicHeatpumpComponent::send_request(RequestType requestType) {
|
void PanasonicHeatpumpComponent::send_request(RequestType requestType) {
|
||||||
switch (requestType) {
|
switch (requestType) {
|
||||||
case RequestType::COMMAND:
|
case RequestType::COMMAND:
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_TX, this->command_message_, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_TX, this->command_message_, ',');
|
|
||||||
this->write_array(this->command_message_);
|
this->write_array(this->command_message_);
|
||||||
this->flush();
|
this->flush();
|
||||||
break;
|
break;
|
||||||
case RequestType::INITIAL:
|
case RequestType::INITIAL:
|
||||||
// Probably not necessary but CZ-TAW1 sends this query on boot
|
// Probably not necessary but CZ-TAW1 sends this query on boot
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ',');
|
|
||||||
this->write_array(PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE);
|
this->write_array(PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE);
|
||||||
this->flush();
|
this->flush();
|
||||||
break;
|
break;
|
||||||
case RequestType::POLLING:
|
case RequestType::POLLING:
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ',');
|
|
||||||
this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE);
|
this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE);
|
||||||
this->flush();
|
this->flush();
|
||||||
break;
|
break;
|
||||||
case RequestType::POLLING_EXTRA:
|
case RequestType::POLLING_EXTRA:
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ',');
|
|
||||||
this->write_array(PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE);
|
this->write_array(PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE);
|
||||||
this->flush();
|
this->flush();
|
||||||
break;
|
break;
|
||||||
|
|
@ -267,8 +262,7 @@ void PanasonicHeatpumpComponent::read_request() {
|
||||||
// Check if message is complete
|
// Check if message is complete
|
||||||
if (this->request_message_.size() > 2 && this->request_message_.size() == this->payload_length_ + 3) {
|
if (this->request_message_.size() > 2 && this->request_message_.size() == this->payload_length_ + 3) {
|
||||||
this->request_receiving_ = false;
|
this->request_receiving_ = false;
|
||||||
if (this->log_uart_msg_)
|
PanasonicHelpers::write_uart_log(UART_LOG_TX, this->request_message_, ',', this->log_uart_msg_);
|
||||||
PanasonicHelpers::log_uart_hex(UART_LOG_TX, this->request_message_, ',');
|
|
||||||
|
|
||||||
if (this->request_message_[0] != 0x31) {
|
if (this->request_message_[0] != 0x31) {
|
||||||
// Update last request time when request is complete
|
// Update last request time when request is complete
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue