mirror of
https://github.com/pelgraine/Meck.git
synced 2026-05-06 13:32:43 +02: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.
33 lines
724 B
C++
33 lines
724 B
C++
#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;
|
|
};
|