From 2273bae1af206aa1d0a4cc1973aacab9ca5934b8 Mon Sep 17 00:00:00 2001 From: Sebastian Birke Date: Fri, 10 Mar 2023 15:34:19 +0100 Subject: [PATCH] [xpcc] Separate the rx handling part of the update fct of the dispatcher Call that separated function instead and have it available as a public function as well. --- src/modm/communication/xpcc/dispatcher.cpp | 27 ++++++++++++------- src/modm/communication/xpcc/dispatcher.hpp.in | 3 +++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/modm/communication/xpcc/dispatcher.cpp b/src/modm/communication/xpcc/dispatcher.cpp index dff6530c89..8fec041790 100644 --- a/src/modm/communication/xpcc/dispatcher.cpp +++ b/src/modm/communication/xpcc/dispatcher.cpp @@ -34,6 +34,20 @@ xpcc::Dispatcher::update() //Check if a new packet was received by the backend while (this->backend->isPacketAvailable()) + { + this->updateOnceRx(); + this->backend->dropPacket(); + } + + // check if there are packets to send + this->handleWaitingMessages(); +} + +void +xpcc::Dispatcher::updateOnceRx() +{ + //Check if a new packet was received by the backend + if (this->backend->isPacketAvailable()) { const Header& header = this->backend->getPacketHeader(); const modm::SmartPointer& payload = this->backend->getPacketPayload(); @@ -46,17 +60,12 @@ xpcc::Dispatcher::update() { const bool is_response = this->handlePacket(header, payload); if (!header.isAcknowledge && header.destination != 0) - { - if (is_response or postman->isComponentAvailable(header.destination)) - this->sendAcknowledge(header); - } + { + if (is_response or postman->isComponentAvailable(header.destination)) + this->sendAcknowledge(header); + } } - - this->backend->dropPacket(); } - - // check if there are packets to send - this->handleWaitingMessages(); } void diff --git a/src/modm/communication/xpcc/dispatcher.hpp.in b/src/modm/communication/xpcc/dispatcher.hpp.in index c495ffc4d2..7a43ed50a3 100644 --- a/src/modm/communication/xpcc/dispatcher.hpp.in +++ b/src/modm/communication/xpcc/dispatcher.hpp.in @@ -48,6 +48,9 @@ namespace xpcc void update(); + void + updateOnceRx(); + private: /// Does not handle requests which are not acknowledge. bool