MeshCore/src/helpers/SerialBridge.h
João Brázio 1948d284a0
Extract serial bridge into dedicated classes
This commit refactors the serial bridge functionality out of the `simple_repeater` example and into a more reusable, object-oriented structure.

An `AbstractBridge` interface has been introduced, along with a concrete `SerialBridge` implementation. This encapsulates all the logic for packet framing, checksum calculation, and serial communication, cleaning up the main example file significantly.

The `simple_repeater` example now instantiates and uses the `SerialBridge` class, resulting in better separation of concerns and improved code organization.
2025-09-04 23:43:05 +01:00

30 lines
692 B
C++

#pragma once
#include "helpers/AbstractBridge.h"
#include <Stream.h>
#ifdef BRIDGE_OVER_SERIAL
/**
* @brief A bridge implementation that uses a serial port to connect two mesh networks.
*/
class SerialBridge : 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.
*/
SerialBridge(Stream& serial, mesh::PacketManager* mgr);
void begin() override;
void loop() override;
void onPacketTransmitted(mesh::Packet* packet) override;
void onPacketReceived() override;
private:
Stream* _serial;
mesh::PacketManager* _mgr;
};
#endif