Support ESPNow and improve documentation

This commit is contained in:
João Brázio
2025-09-07 21:39:54 +01:00
parent cb99eb4ae8
commit 5b9d11ac8f
6 changed files with 510 additions and 59 deletions

View File

@@ -7,28 +7,87 @@
#ifdef WITH_RS232_BRIDGE
/**
* @brief A bridge implementation that uses a serial port to connect two mesh networks.
* @brief Bridge implementation using RS232/UART protocol for packet transport
*
* This bridge enables mesh packet transport over serial/UART connections,
* allowing nodes to communicate over wired serial links. It implements a simple
* packet framing protocol with checksums for reliable transfer.
*
* Features:
* - Point-to-point communication over hardware UART
* - Fletcher-16 checksum for data integrity verification
* - Magic header for packet synchronization
* - Configurable RX/TX pins via build defines
* - Baud rate fixed at 115200
*
* Packet Structure:
* [2 bytes] Magic Header (0xCAFE) - Used to identify start of packet
* [2 bytes] Fletcher-16 checksum - Data integrity check
* [1 byte] Payload length
* [n bytes] Packet payload
*
* The Fletcher-16 checksum is used to validate packet integrity and detect
* corrupted or malformed packets. It provides error detection capabilities
* suitable for serial communication where noise or timing issues could
* corrupt data.
*
* Configuration:
* - Define WITH_RS232_BRIDGE to enable this bridge
* - Define WITH_RS232_BRIDGE_RX with the RX pin number
* - Define WITH_RS232_BRIDGE_TX with the TX pin number
*
* Platform Support:
* - ESP32 targets
* - NRF52 targets
* - RP2040 targets
* - STM32 targets
*/
class RS232Bridge : public AbstractBridge {
public:
/**
* @brief Construct a new Serial Bridge object
*
* @param serial The serial port to use for the bridge.
* @param mgr A pointer to the packet manager.
* @param rtc A pointer to the RTC clock.
* @brief Constructs an RS232Bridge instance
*
* @param serial The hardware serial port to use
* @param mgr PacketManager for allocating and queuing packets
* @param rtc RTCClock for timestamping debug messages
*/
RS232Bridge(Stream& serial, mesh::PacketManager* mgr, mesh::RTCClock* rtc);
/**
* Initializes the RS232 bridge
*
* - Configures UART pins based on platform
* - Sets baud rate to 115200
*/
void begin() override;
/**
* @brief Main loop handler
* Processes incoming serial data and builds packets
*/
void loop() override;
/**
* @brief Called when a packet needs to be transmitted over serial
* Formats and sends the packet with proper framing
*
* @param packet The mesh packet to transmit
*/
void onPacketTransmitted(mesh::Packet* packet) override;
/**
* @brief Called when a complete packet has been received from serial
* Queues the packet for mesh processing if checksum is valid
*
* @param packet The received mesh packet
*/
void onPacketReceived(mesh::Packet* packet) override;
private:
/** Helper function to get formatted timestamp for logging */
const char* getLogDateTime();
/**
* @brief The 2-byte magic word used to signify the start of a packet.
*/
/** Magic number to identify start of RS232 packets (0xCAFE) */
static constexpr uint16_t SERIAL_PKT_MAGIC = 0xCAFE;
/**