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:
João Brázio 2025-09-04 23:43:05 +01:00
parent 9fd7e9427a
commit 1948d284a0
No known key found for this signature in database
GPG key ID: 56A1490716A324DD
4 changed files with 171 additions and 98 deletions

View 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;
};