From 36fccb6459e9d25b4a7ac0230017c2043b62359a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 4 Mar 2023 16:47:32 +0100 Subject: [PATCH] clear message queue on reset. --- components/truma_inetbox/LinBusProtocol.cpp | 12 ++++++++++-- components/truma_inetbox/LinBusProtocol.h | 2 +- components/truma_inetbox/TrumaiNetBoxApp.cpp | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/truma_inetbox/LinBusProtocol.cpp b/components/truma_inetbox/LinBusProtocol.cpp index fd638aa..a3df1bf 100644 --- a/components/truma_inetbox/LinBusProtocol.cpp +++ b/components/truma_inetbox/LinBusProtocol.cpp @@ -19,6 +19,13 @@ static const char *const TAG = "truma_inetbox.LinBusProtocol"; #define LIN_SID_HEARTBEAT 0xB9 #define LIN_SID_HEARTBEAT_RESPONSE (LIN_SID_HEARTBEAT | LIN_SID_RESPONSE) +void LinBusProtocol::lin_reset_device(){ + // clear any messages in send queue of LinBus Protocol handler. + while (!this->updates_to_send_.empty()) { + this->updates_to_send_.pop(); + } +} + bool LinBusProtocol::answer_lin_order_(const u_int8_t pid) { // Send requested answer if (pid == DIAGNOSTIC_FRAME_SLAVE) { @@ -150,11 +157,12 @@ void LinBusProtocol::lin_msg_diag_single_(const u_int8_t *message, u_int8_t leng response[0] = this->lin_node_address_; response[1] = 1; /* bytes length*/ response[2] = LIN_SID_ASSIGN_NAD_RESPONSE; - this->prepare_update_msg_(response); - this->lin_node_address_ = message[7]; // assumption an assign new SID occurs as part of init process. this->lin_reset_device(); + + this->prepare_update_msg_(response); + this->lin_node_address_ = message[7]; } } else { if (my_node_address) { diff --git a/components/truma_inetbox/LinBusProtocol.h b/components/truma_inetbox/LinBusProtocol.h index aa0e6b4..f28b4ab 100644 --- a/components/truma_inetbox/LinBusProtocol.h +++ b/components/truma_inetbox/LinBusProtocol.h @@ -9,7 +9,7 @@ class LinBusProtocol : public LinBusListener { public: virtual const std::array lin_identifier() = 0; virtual void lin_heartbeat() = 0; - virtual void lin_reset_device() = 0; + virtual void lin_reset_device(); protected: const std::array lin_empty_response_ = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; diff --git a/components/truma_inetbox/TrumaiNetBoxApp.cpp b/components/truma_inetbox/TrumaiNetBoxApp.cpp index adf7d73..3c87449 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.cpp +++ b/components/truma_inetbox/TrumaiNetBoxApp.cpp @@ -82,6 +82,7 @@ const std::array TrumaiNetBoxApp::lin_identifier() { void TrumaiNetBoxApp::lin_heartbeat() { this->device_registered_ = micros(); } void TrumaiNetBoxApp::lin_reset_device() { + LinBusProtocol::lin_reset_device(); this->device_registered_ = micros(); this->init_recieved_ = 0;