Browse Source
Add BRIDGE_DELAY as a buffer to prevent immediate processing conflicts in the mesh network
pull/454/head
João Brázio
9 months ago
No known key found for this signature in database
GPG Key ID: 56A1490716A324DD
3 changed files with
15 additions and
5 deletions
-
src/helpers/bridges/BridgeBase.cpp
-
src/helpers/bridges/BridgeBase.h
-
src/helpers/bridges/RS232Bridge.cpp
|
|
|
@ -1,5 +1,7 @@ |
|
|
|
#include "BridgeBase.h" |
|
|
|
|
|
|
|
#include <Arduino.h> |
|
|
|
|
|
|
|
const char *BridgeBase::getLogDateTime() { |
|
|
|
static char tmp[32]; |
|
|
|
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) { |
|
|
|
if (!_seen_packets.hasSeen(packet)) { |
|
|
|
_mgr->queueInbound(packet, 0); |
|
|
|
_mgr->queueInbound(packet, millis() + BRIDGE_DELAY); |
|
|
|
} else { |
|
|
|
_mgr->free(packet); |
|
|
|
} |
|
|
|
|
|
|
|
@ -23,7 +23,7 @@ public: |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Common magic number used by all bridge implementations for packet identification |
|
|
|
* |
|
|
|
* |
|
|
|
* This magic number is placed at the beginning of bridge packets to identify |
|
|
|
* them as mesh bridge packets and provide frame synchronization. |
|
|
|
*/ |
|
|
|
@ -31,7 +31,7 @@ public: |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Common field sizes used by bridge implementations |
|
|
|
* |
|
|
|
* |
|
|
|
* These constants define the size of common packet fields used across bridges. |
|
|
|
* BRIDGE_MAGIC_SIZE is used by all bridges for packet identification. |
|
|
|
* BRIDGE_LENGTH_SIZE is used by bridges that need explicit length fields (like RS232). |
|
|
|
@ -41,6 +41,14 @@ public: |
|
|
|
static constexpr uint16_t BRIDGE_LENGTH_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: |
|
|
|
/** Packet manager for allocating and queuing mesh packets */ |
|
|
|
mesh::PacketManager *_mgr; |
|
|
|
|
|
|
|
@ -54,8 +54,8 @@ void RS232Bridge::onPacketTransmitted(mesh::Packet *packet) { |
|
|
|
// Build packet header
|
|
|
|
buffer[0] = (BRIDGE_PACKET_MAGIC >> 8) & 0xFF; // Magic high byte
|
|
|
|
buffer[1] = BRIDGE_PACKET_MAGIC & 0xFF; // Magic low byte
|
|
|
|
buffer[2] = (len >> 8) & 0xFF; // Length high byte
|
|
|
|
buffer[3] = len & 0xFF; // Length low byte
|
|
|
|
buffer[2] = (len >> 8) & 0xFF; // Length high byte
|
|
|
|
buffer[3] = len & 0xFF; // Length low byte
|
|
|
|
|
|
|
|
// Calculate checksum over the payload
|
|
|
|
uint16_t checksum = fletcher16(buffer + 4, len); |
|
|
|
|