Skip to content

Commit 5344f04

Browse files
author
Scott Powell
committed
* Repeater: slight refactor of 'bridge' instantiation
1 parent ea33f39 commit 5344f04

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

examples/simple_repeater/main.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ struct ClientInfo {
124124
#define MAX_CLIENTS 32
125125
#endif
126126

127-
#ifdef WITH_BRIDGE
128-
AbstractBridge* bridge;
129-
#endif
130-
131127
struct NeighbourInfo {
132128
mesh::Identity id;
133129
uint32_t advert_timestamp;
@@ -154,6 +150,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
154150
float pending_bw;
155151
uint8_t pending_sf;
156152
uint8_t pending_cr;
153+
#if defined(WITH_RS232_BRIDGE)
154+
RS232Bridge bridge;
155+
#elif defined(WITH_ESPNOW_BRIDGE)
156+
ESPNowBridge bridge;
157+
#endif
157158

158159
ClientInfo* putClient(const mesh::Identity& id) {
159160
uint32_t min_time = 0xFFFFFFFF;
@@ -315,7 +316,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
315316
}
316317
void logTx(mesh::Packet* pkt, int len) override {
317318
#ifdef WITH_BRIDGE
318-
bridge->onPacketTransmitted(pkt);
319+
bridge.onPacketTransmitted(pkt);
319320
#endif
320321
if (_logging) {
321322
File f = openAppend(PACKET_LOG_FILE);
@@ -581,16 +582,12 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
581582
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
582583
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
583584
_cli(board, rtc, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4)
584-
{
585-
#ifdef WITH_BRIDGE
586585
#if defined(WITH_RS232_BRIDGE)
587-
bridge = new RS232Bridge(WITH_RS232_BRIDGE, _mgr, &rtc);
586+
, bridge(WITH_RS232_BRIDGE, _mgr, &rtc)
588587
#elif defined(WITH_ESPNOW_BRIDGE)
589-
bridge = new ESPNowBridge(_mgr, &rtc);
590-
#else
591-
#error "You must choose either RS232 or ESPNow bridge"
592-
#endif
588+
, bridge(_mgr, &rtc)
593589
#endif
590+
{
594591
memset(known_clients, 0, sizeof(known_clients));
595592
next_local_advert = next_flood_advert = 0;
596593
set_radio_at = revert_radio_at = 0;
@@ -626,6 +623,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
626623
// load persisted prefs
627624
_cli.loadPrefs(_fs);
628625

626+
#ifdef WITH_BRIDGE
627+
bridge.begin();
628+
#endif
629+
629630
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
630631
radio_set_tx_power(_prefs.tx_power_dbm);
631632

@@ -792,7 +793,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
792793

793794
void loop() {
794795
#ifdef WITH_BRIDGE
795-
bridge->loop();
796+
bridge.loop();
796797
#endif
797798

798799
mesh::Mesh::loop();
@@ -843,10 +844,6 @@ void setup() {
843844
Serial.begin(115200);
844845
delay(1000);
845846

846-
#ifdef WITH_BRIDGE
847-
bridge->begin();
848-
#endif
849-
850847
board.begin();
851848

852849
#ifdef DISPLAY_CLASS

0 commit comments

Comments
 (0)