Skip to content

Commit a55fa8d

Browse files
committed
Add BRIDGE_DELAY as a buffer to prevent immediate processing conflicts in the mesh network
1 parent 1c93c16 commit a55fa8d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/helpers/bridges/BridgeBase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "BridgeBase.h"
22

3+
#include <Arduino.h>
4+
35
const char *BridgeBase::getLogDateTime() {
46
static char tmp[32];
57
uint32_t now = _rtc->getCurrentTime();
@@ -27,7 +29,7 @@ bool BridgeBase::validateChecksum(const uint8_t *data, size_t len, uint16_t rece
2729

2830
void BridgeBase::handleReceivedPacket(mesh::Packet *packet) {
2931
if (!_seen_packets.hasSeen(packet)) {
30-
_mgr->queueInbound(packet, 0);
32+
_mgr->queueInbound(packet, millis() + BRIDGE_DELAY);
3133
} else {
3234
_mgr->free(packet);
3335
}

src/helpers/bridges/BridgeBase.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class BridgeBase : public AbstractBridge {
2323

2424
/**
2525
* @brief Common magic number used by all bridge implementations for packet identification
26-
*
26+
*
2727
* This magic number is placed at the beginning of bridge packets to identify
2828
* them as mesh bridge packets and provide frame synchronization.
2929
*/
3030
static constexpr uint16_t BRIDGE_PACKET_MAGIC = 0xC03E;
3131

3232
/**
3333
* @brief Common field sizes used by bridge implementations
34-
*
34+
*
3535
* These constants define the size of common packet fields used across bridges.
3636
* BRIDGE_MAGIC_SIZE is used by all bridges for packet identification.
3737
* BRIDGE_LENGTH_SIZE is used by bridges that need explicit length fields (like RS232).
@@ -41,6 +41,14 @@ class BridgeBase : public AbstractBridge {
4141
static constexpr uint16_t BRIDGE_LENGTH_SIZE = sizeof(uint16_t);
4242
static constexpr uint16_t BRIDGE_CHECKSUM_SIZE = sizeof(uint16_t);
4343

44+
/**
45+
* @brief Default delay in milliseconds for scheduling inbound packet processing
46+
*
47+
* It provides a buffer to prevent immediate processing conflicts in the mesh network.
48+
* Used in handleReceivedPacket() as: millis() + BRIDGE_DELAY
49+
*/
50+
static constexpr uint16_t BRIDGE_DELAY = 500; // TODO: maybe too high ?
51+
4452
protected:
4553
/** Packet manager for allocating and queuing mesh packets */
4654
mesh::PacketManager *_mgr;

src/helpers/bridges/RS232Bridge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ void RS232Bridge::onPacketTransmitted(mesh::Packet *packet) {
5454
// Build packet header
5555
buffer[0] = (BRIDGE_PACKET_MAGIC >> 8) & 0xFF; // Magic high byte
5656
buffer[1] = BRIDGE_PACKET_MAGIC & 0xFF; // Magic low byte
57-
buffer[2] = (len >> 8) & 0xFF; // Length high byte
58-
buffer[3] = len & 0xFF; // Length low byte
57+
buffer[2] = (len >> 8) & 0xFF; // Length high byte
58+
buffer[3] = len & 0xFF; // Length low byte
5959

6060
// Calculate checksum over the payload
6161
uint16_t checksum = fletcher16(buffer + 4, len);

0 commit comments

Comments
 (0)