Add BRIDGE_DELAY as a buffer to prevent immediate processing conflicts in the mesh network

This commit is contained in:
João Brázio
2025-09-08 20:21:33 +01:00
parent 1c93c162a1
commit a55fa8d8ec
3 changed files with 15 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
#include "BridgeBase.h" #include "BridgeBase.h"
#include <Arduino.h>
const char *BridgeBase::getLogDateTime() { const char *BridgeBase::getLogDateTime() {
static char tmp[32]; static char tmp[32];
uint32_t now = _rtc->getCurrentTime(); uint32_t now = _rtc->getCurrentTime();
@@ -27,7 +29,7 @@ bool BridgeBase::validateChecksum(const uint8_t *data, size_t len, uint16_t rece
void BridgeBase::handleReceivedPacket(mesh::Packet *packet) { void BridgeBase::handleReceivedPacket(mesh::Packet *packet) {
if (!_seen_packets.hasSeen(packet)) { if (!_seen_packets.hasSeen(packet)) {
_mgr->queueInbound(packet, 0); _mgr->queueInbound(packet, millis() + BRIDGE_DELAY);
} else { } else {
_mgr->free(packet); _mgr->free(packet);
} }

View File

@@ -41,6 +41,14 @@ public:
static constexpr uint16_t BRIDGE_LENGTH_SIZE = sizeof(uint16_t); static constexpr uint16_t BRIDGE_LENGTH_SIZE = sizeof(uint16_t);
static constexpr uint16_t BRIDGE_CHECKSUM_SIZE = sizeof(uint16_t); static constexpr uint16_t BRIDGE_CHECKSUM_SIZE = sizeof(uint16_t);
/**
* @brief Default delay in milliseconds for scheduling inbound packet processing
*
* It provides a buffer to prevent immediate processing conflicts in the mesh network.
* Used in handleReceivedPacket() as: millis() + BRIDGE_DELAY
*/
static constexpr uint16_t BRIDGE_DELAY = 500; // TODO: maybe too high ?
protected: protected:
/** Packet manager for allocating and queuing mesh packets */ /** Packet manager for allocating and queuing mesh packets */
mesh::PacketManager *_mgr; mesh::PacketManager *_mgr;