mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
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.
This commit is contained in:
parent
9fd7e9427a
commit
1948d284a0
4 changed files with 171 additions and 98 deletions
30
src/helpers/SerialBridge.h
Normal file
30
src/helpers/SerialBridge.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue