mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
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.
30 lines
692 B
C++
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
|