From 945b376663b27abb36b40d6427574fae9efb4955 Mon Sep 17 00:00:00 2001 From: KazWolfe Date: Fri, 13 Oct 2023 10:44:55 -0700 Subject: [PATCH] feat: Add callback to log raw packets - Write raw packet hex to verbose log for debug/RE work --- components/mitsubishi_heatpump/espmhp.cpp | 15 +++++++++++++++ components/mitsubishi_heatpump/espmhp.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/components/mitsubishi_heatpump/espmhp.cpp b/components/mitsubishi_heatpump/espmhp.cpp index 02223a1..91efd74 100644 --- a/components/mitsubishi_heatpump/espmhp.cpp +++ b/components/mitsubishi_heatpump/espmhp.cpp @@ -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()); +} \ No newline at end of file diff --git a/components/mitsubishi_heatpump/espmhp.h b/components/mitsubishi_heatpump/espmhp.h index 7cb3a27..4ecfe73 100644 --- a/components/mitsubishi_heatpump/espmhp.h +++ b/components/mitsubishi_heatpump/espmhp.h @@ -129,6 +129,8 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate { static void save(float value, ESPPreferenceObject& storage); static optional 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_;