From 0ef31255bf607c877a7d5d95f9ce8a88f252b0be Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Tue, 6 Feb 2024 19:37:47 +0100 Subject: [PATCH] Fixing proxy message sending 3 --- include/protocol/haier_protocol.h | 1 + src/protocol/haier_protocol.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/protocol/haier_protocol.h b/include/protocol/haier_protocol.h index 259366e..8b7e184 100644 --- a/include/protocol/haier_protocol.h +++ b/include/protocol/haier_protocol.h @@ -122,6 +122,7 @@ class ProtocolHandler std::chrono::steady_clock::time_point cooldown_time_point_; std::chrono::steady_clock::time_point answer_time_point_; std::chrono::steady_clock::time_point retry_time_point_; + std::chrono::steady_clock::time_point last_message_time_point_; }; diff --git a/src/protocol/haier_protocol.cpp b/src/protocol/haier_protocol.cpp index 8fb8f45..08e2d89 100644 --- a/src/protocol/haier_protocol.cpp +++ b/src/protocol/haier_protocol.cpp @@ -89,7 +89,15 @@ void ProtocolHandler::loop() if (this->write_message_(msg.message, msg.use_crc)) { this->last_message_type_ = msg.message.get_frame_type(); - this->state_ = msg.proxy_message ? ProtocolState::WAITING_FOR_PROXY_ANSWER : ProtocolState::WAITING_FOR_ANSWER; + if (msg.proxy_message) + { + this->state_ = ProtocolState::WAITING_FOR_PROXY_ANSWER; + } + else + { + this->state_ = ProtocolState::WAITING_FOR_ANSWER; + last_message_time_point_ = now; + } this->answer_time_point_ = now + this->answer_timeout_interval_; this->retry_time_point_ = now + msg.retry_interval; } @@ -126,6 +134,8 @@ void ProtocolHandler::loop() } if (this->transport_.available() > 0) { + + HAIER_LOGD("Answer delay: %dms", std::chrono::duration_cast(now - this->last_message_time_point_).count()); TimestampedFrame frame; this->transport_.pop(frame); FrameType msg_type = (FrameType) frame.frame.get_frame_type();