improved log_uart_hex

This commit is contained in:
ElVit
2025-02-16 11:38:15 +01:00
parent b148b465f4
commit a869f41672
3 changed files with 41 additions and 11 deletions
+4
View File
@@ -546,6 +546,10 @@ select:
name: "Set Bivalent Mode"
```
## Known Issues
When the ESP controller is connected initially to the heatpump, the heatpump may not respond to any request messages. If the CZ-TAW1 is also connected to the ESP controller you will probably see some requests like 31 05 10 01 ... These are initial request messages. If the heatpump is not responding, it may help to turn off and on the power of the heatpump (switching the heatpump off is not enough). After a power on the heatpump should respond to the requests.
## Sources
:heart: A big THANKS to [Egyras](https://github.com/Egyras) and the work done on the repository [HeishaMon](https://github.com/Egyras/HeishaMon) for decoding the panasonic uart protocol and providing information to build hardware based on an ESP Chip.
@@ -78,7 +78,7 @@ namespace esphome
// Check if message is complete
if (this->response_message_.size() > 2 && this->response_message_.size() == this->response_payload_length_ + 3)
{
this->log_uart_hex("<<<", this->response_message_, ',');
this->log_uart_hex(UART_LOG_RX, this->response_message_, ',');
this->decode_response(this->response_message_);
this->response_message_.clear();
this->response_receiving_ = false;
@@ -92,7 +92,7 @@ namespace esphome
if (this->next_request_ == 2) // command
{
this->log_uart_hex(">>>", this->command_message_, ',');
this->log_uart_hex(UART_LOG_RX, this->command_message_, ',');
this->write_array(this->command_message_);
this->flush();
return;
@@ -103,13 +103,13 @@ namespace esphome
if (this->next_request_ == 0) // initial
{
// Probably not necessary but CZ-TAW1 sends this query on boot
this->log_uart_hex(">>>", PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE, ',');
this->log_uart_hex(UART_LOG_RX, PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE, ',');
this->write_array(PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE);
this->flush();
}
else if (this->next_request_ == 1) // polling
{
this->log_uart_hex(">>>", PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE, ',');
this->log_uart_hex(UART_LOG_RX, PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE, ',');
this->write_array(PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE);
this->flush();
}
@@ -155,20 +155,40 @@ namespace esphome
// Check if message is complete
if (this->request_message_.size() > 2 && this->request_message_.size() == this->request_payload_length_ + 3)
{
this->log_uart_hex(">>>", this->request_message_, ',');
this->log_uart_hex(UART_LOG_TX, this->request_message_, ',');
this->request_message_.clear();
this->request_receiving_ = false;
}
}
}
void PanasonicHeatpumpComponent::log_uart_hex(std::string prefix, const uint8_t *data, size_t length, uint8_t separator)
void PanasonicHeatpumpComponent::log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator)
{
if (this->log_uart_msg_ == false) return;
std::string logStr;
std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<";
std::string msgType = "response";
if (direction == UART_LOG_TX)
{
switch(data[0])
{
case 0x31:
msgType = "initial_request";
break;
case 0x71:
msgType = "polling_request";
break;
case 0xF1:
msgType = "command_request";
break;
default:
msgType = "request";
};
}
logStr = "[" + std::to_string(length) + "]";
ESP_LOGI(TAG, "%s %s", prefix.c_str(), logStr.c_str());
ESP_LOGI(TAG, "%s %s%s", msgDir.c_str(), msgType.c_str(), logStr.c_str());
delay(10);
logStr = "";
@@ -183,7 +203,7 @@ namespace esphome
size_t chunkSize = 90;
for (size_t i = 0; i < logStr.length(); i += chunkSize)
{
ESP_LOGI(TAG, "%s %s", prefix.c_str(), logStr.substr(i, chunkSize).c_str());
ESP_LOGD(TAG, "%s %s", msgDir.c_str(), logStr.substr(i, chunkSize).c_str());
delay(10);
}
}
@@ -32,6 +32,12 @@ namespace esphome
{
namespace panasonic_heatpump
{
enum UartLogDirection
{
UART_LOG_RX,
UART_LOG_TX,
};
class PanasonicHeatpumpComponent : public PollingComponent, public uart::UARTDevice
{
public:
@@ -284,11 +290,11 @@ namespace esphome
void publish_number(std::vector<uint8_t> bytes);
void publish_select(std::vector<uint8_t> bytes);
void publish_switch(std::vector<uint8_t> bytes);
void log_uart_hex(std::string prefix, const std::vector<uint8_t> &data, uint8_t separator)
void log_uart_hex(UartLogDirection direction, const std::vector<uint8_t> &data, uint8_t separator)
{
this->log_uart_hex(prefix, &data[0], data.size(), separator);
this->log_uart_hex(direction, &data[0], data.size(), separator);
}
void log_uart_hex(std::string prefix, const uint8_t *data, size_t length, uint8_t separator);
void log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator);
};
} // namespace panasonic_heatpump
} // namespace esphome