diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 93d3656f..7b16ab20 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -78,8 +78,8 @@ /* ------------------------------ Code -------------------------------- */ -#ifdef BRIDGE_OVER_SERIAL -#include "helpers/SerialBridge.h" +#ifdef WITH_RS232_BRIDGE +#include "helpers/bridges/RS232Bridge.h" #endif #define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS @@ -118,7 +118,7 @@ struct ClientInfo { #define MAX_CLIENTS 32 #endif -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE AbstractBridge* bridge; #endif @@ -308,7 +308,7 @@ protected: } } void logTx(mesh::Packet* pkt, int len) override { -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE if (!pkt->isMarkedDoNotRetransmit()) { bridge->onPacketTransmitted(pkt); } @@ -578,8 +578,8 @@ public: : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), _cli(board, rtc, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4) { -#ifdef BRIDGE_OVER_SERIAL - bridge = new SerialBridge(BRIDGE_OVER_SERIAL, _mgr, &rtc); +#ifdef WITH_RS232_BRIDGE + bridge = new RS232Bridge(WITH_RS232_BRIDGE, _mgr, &rtc); #endif memset(known_clients, 0, sizeof(known_clients)); next_local_advert = next_flood_advert = 0; @@ -781,7 +781,7 @@ public: } void loop() { -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE bridge->loop(); #endif @@ -833,7 +833,7 @@ void setup() { Serial.begin(115200); delay(1000); -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE bridge->begin(); #endif diff --git a/src/helpers/SerialBridge.cpp b/src/helpers/bridges/RS232Bridge.cpp similarity index 73% rename from src/helpers/SerialBridge.cpp rename to src/helpers/bridges/RS232Bridge.cpp index eefd751a..801bcc5c 100644 --- a/src/helpers/SerialBridge.cpp +++ b/src/helpers/bridges/RS232Bridge.cpp @@ -1,8 +1,8 @@ -#include "SerialBridge.h" +#include "RS232Bridge.h" #include #include -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE // Fletcher-16 // https://en.wikipedia.org/wiki/Fletcher%27s_checksum @@ -17,7 +17,7 @@ inline static uint16_t fletcher16(const uint8_t *bytes, const size_t len) { return (sum2 << 8) | sum1; }; -const char* SerialBridge::getLogDateTime() { +const char* RS232Bridge::getLogDateTime() { static char tmp[32]; uint32_t now = _rtc->getCurrentTime(); DateTime dt = DateTime(now); @@ -25,26 +25,30 @@ const char* SerialBridge::getLogDateTime() { return tmp; } -SerialBridge::SerialBridge(Stream& serial, mesh::PacketManager* mgr, mesh::RTCClock* rtc) : _serial(&serial), _mgr(mgr), _rtc(rtc) {} +RS232Bridge::RS232Bridge(Stream& serial, mesh::PacketManager* mgr, mesh::RTCClock* rtc) : _serial(&serial), _mgr(mgr), _rtc(rtc) {} + +void RS232Bridge::begin() { +#if !defined(WITH_RS232_BRIDGE_RX) || !defined(WITH_RS232_BRIDGE_TX) +#error "WITH_RS232_BRIDGE_RX and WITH_RS232_BRIDGE_TX must be defined" +#endif -void SerialBridge::begin() { #if defined(ESP32) - ((HardwareSerial *)_serial)->setPins(BRIDGE_OVER_SERIAL_RX, BRIDGE_OVER_SERIAL_TX); + ((HardwareSerial *)_serial)->setPins(WITH_RS232_BRIDGE_RX, WITH_RS232_BRIDGE_TX); #elif defined(NRF52_PLATFORM) - ((HardwareSerial *)_serial)->setPins(BRIDGE_OVER_SERIAL_RX, BRIDGE_OVER_SERIAL_TX); + ((HardwareSerial *)_serial)->setPins(WITH_RS232_BRIDGE_RX, WITH_RS232_BRIDGE_TX); #elif defined(RP2040_PLATFORM) - ((SerialUART *)_serial)->setRX(BRIDGE_OVER_SERIAL_RX); - ((SerialUART *)_serial)->setTX(BRIDGE_OVER_SERIAL_TX); + ((SerialUART *)_serial)->setRX(WITH_RS232_BRIDGE_RX); + ((SerialUART *)_serial)->setTX(WITH_RS232_BRIDGE_TX); #elif defined(STM32_PLATFORM) - ((HardwareSerial *)_serial)->setRx(BRIDGE_OVER_SERIAL_RX); - ((HardwareSerial *)_serial)->setTx(BRIDGE_OVER_SERIAL_TX); + ((HardwareSerial *)_serial)->setRx(WITH_RS232_BRIDGE_RX); + ((HardwareSerial *)_serial)->setTx(WITH_RS232_BRIDGE_TX); #else -#error SerialBridge was not tested on the current platform +#error RS232Bridge was not tested on the current platform #endif ((HardwareSerial*)_serial)->begin(115200); } -void SerialBridge::onPacketTransmitted(mesh::Packet* packet) { +void RS232Bridge::onPacketTransmitted(mesh::Packet* packet) { if (!_seen_packets.hasSeen(packet)) { uint8_t buffer[MAX_SERIAL_PACKET_SIZE]; uint16_t len = packet->writeTo(buffer + 4); @@ -66,7 +70,7 @@ void SerialBridge::onPacketTransmitted(mesh::Packet* packet) { } } -void SerialBridge::loop() { +void RS232Bridge::loop() { while (_serial->available()) { uint8_t b = _serial->read(); @@ -108,7 +112,7 @@ void SerialBridge::loop() { } } -void SerialBridge::onPacketReceived(mesh::Packet* packet) { +void RS232Bridge::onPacketReceived(mesh::Packet* packet) { if (!_seen_packets.hasSeen(packet)) { _mgr->queueInbound(packet, 0); } else { diff --git a/src/helpers/SerialBridge.h b/src/helpers/bridges/RS232Bridge.h similarity index 92% rename from src/helpers/SerialBridge.h rename to src/helpers/bridges/RS232Bridge.h index cc837d5e..0e99040f 100644 --- a/src/helpers/SerialBridge.h +++ b/src/helpers/bridges/RS232Bridge.h @@ -4,12 +4,12 @@ #include "helpers/SimpleMeshTables.h" #include -#ifdef BRIDGE_OVER_SERIAL +#ifdef WITH_RS232_BRIDGE /** * @brief A bridge implementation that uses a serial port to connect two mesh networks. */ -class SerialBridge : public AbstractBridge { +class RS232Bridge : public AbstractBridge { public: /** * @brief Construct a new Serial Bridge object @@ -18,7 +18,7 @@ public: * @param mgr A pointer to the packet manager. * @param rtc A pointer to the RTC clock. */ - SerialBridge(Stream& serial, mesh::PacketManager* mgr, mesh::RTCClock* rtc); + RS232Bridge(Stream& serial, mesh::PacketManager* mgr, mesh::RTCClock* rtc); void begin() override; void loop() override; void onPacketTransmitted(mesh::Packet* packet) override; diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index 3e7524c9..4ffb11ba 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -59,13 +59,14 @@ build_flags = -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=8 - -D BRIDGE_OVER_SERIAL=Serial2 - -D BRIDGE_OVER_SERIAL_RX=5 - -D BRIDGE_OVER_SERIAL_TX=6 + -D WITH_RS232_BRIDGE=Serial2 + -D WITH_RS232_BRIDGE_RX=5 + -D WITH_RS232_BRIDGE_TX=6 -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + +<../examples/simple_repeater> lib_deps = ${Heltec_lora32_v3.lib_deps} @@ -217,12 +218,13 @@ build_flags = -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=8 - -D BRIDGE_OVER_SERIAL=Serial2 - -D BRIDGE_OVER_SERIAL_RX=5 - -D BRIDGE_OVER_SERIAL_TX=6 + -D WITH_RS232_BRIDGE=Serial2 + -D WITH_RS232_BRIDGE_RX=5 + -D WITH_RS232_BRIDGE_TX=6 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + +<../examples/simple_repeater> lib_deps = ${Heltec_lora32_v3.lib_deps} diff --git a/variants/lilygo_tlora_v2_1/platformio.ini b/variants/lilygo_tlora_v2_1/platformio.ini index 4e146cf6..313b9844 100644 --- a/variants/lilygo_tlora_v2_1/platformio.ini +++ b/variants/lilygo_tlora_v2_1/platformio.ini @@ -68,6 +68,7 @@ lib_deps = extends = LilyGo_TLora_V2_1_1_6 build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter} + + + +<../examples/simple_repeater> build_flags = ${LilyGo_TLora_V2_1_1_6.build_flags} @@ -76,9 +77,9 @@ build_flags = -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=8 - -D BRIDGE_OVER_SERIAL=Serial2 - -D BRIDGE_OVER_SERIAL_RX=34 - -D BRIDGE_OVER_SERIAL_TX=25 + -D WITH_RS232_BRIDGE=Serial2 + -D WITH_RS232_BRIDGE_RX=34 + -D WITH_RS232_BRIDGE_TX=25 -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 ; -D CORE_DEBUG_LEVEL=3 diff --git a/variants/waveshare_rp2040_lora/platformio.ini b/variants/waveshare_rp2040_lora/platformio.ini index 0ec745ff..8824ddbd 100644 --- a/variants/waveshare_rp2040_lora/platformio.ini +++ b/variants/waveshare_rp2040_lora/platformio.ini @@ -48,12 +48,13 @@ build_flags = ${waveshare_rp2040_lora.build_flags} -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=8 - -D BRIDGE_OVER_SERIAL=Serial2 - -D BRIDGE_OVER_SERIAL_RX=9 - -D BRIDGE_OVER_SERIAL_TX=8 + -D WITH_RS232_BRIDGE=Serial2 + -D WITH_RS232_BRIDGE_RX=9 + -D WITH_RS232_BRIDGE_TX=8 -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${waveshare_rp2040_lora.build_src_filter} + + +<../examples/simple_repeater> [env:waveshare_rp2040_lora_room_server]