feat: Add callback to log raw packets

- Write raw packet hex to verbose log for debug/RE work
This commit is contained in:
KazWolfe 2023-10-13 10:44:55 -07:00 committed by GitHub
parent 980271337a
commit 945b376663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -444,6 +444,8 @@ void MitsubishiHeatPump::setup() {
this->hpStatusChanged(currentStatus);
}
);
hp->setPacketCallback(this->log_packet);
#endif
ESP_LOGCONFIG(
@ -513,3 +515,16 @@ void MitsubishiHeatPump::dump_state() {
LOG_CLIMATE("", "MitsubishiHeatPump Climate", this);
ESP_LOGI(TAG, "HELLO");
}
void MitsubishiHeatPump::log_packet(byte* packet, unsigned int length, char* packetDirection) {
String packetHex;
char textBuf[15];
for (int i = 0; i < length; i++) {
memset(textBuf, 0, 15);
sprintf(textBuf, "%02X ", packet[i]);
packetHex += textBuf;
}
ESP_LOGV(TAG, "PKT: [%s] %s", packetDirection, packetHex.c_str());
}

View File

@ -129,6 +129,8 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
static void save(float value, ESPPreferenceObject& storage);
static optional<float> load(ESPPreferenceObject& storage);
static void log_packet(byte* packet, unsigned int length, char* packetDirection);
private:
// Retrieve the HardwareSerial pointer from friend and subclasses.
HardwareSerial *hw_serial_;