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
32
src/helpers/AbstractBridge.h
Normal file
32
src/helpers/AbstractBridge.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <Mesh.h>
|
||||
|
||||
class AbstractBridge {
|
||||
public:
|
||||
virtual ~AbstractBridge() {}
|
||||
|
||||
/**
|
||||
* @brief Initializes the bridge.
|
||||
*/
|
||||
virtual void begin() = 0;
|
||||
|
||||
/**
|
||||
* @brief A method to be called on every main loop iteration.
|
||||
* Used for tasks like checking for incoming data.
|
||||
*/
|
||||
virtual void loop() = 0;
|
||||
|
||||
/**
|
||||
* @brief A callback that is triggered when the mesh transmits a packet.
|
||||
* The bridge can use this to forward the packet.
|
||||
*
|
||||
* @param packet The packet that was transmitted.
|
||||
*/
|
||||
virtual void onPacketTransmitted(mesh::Packet* packet) = 0;
|
||||
|
||||
/**
|
||||
* @brief Processes a received packet from the bridge's medium.
|
||||
*/
|
||||
virtual void onPacketReceived() = 0;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue