mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Rename SerialBridge to RS232Bridge
This commit is contained in:
parent
375093f78d
commit
5843a12c71
6 changed files with 46 additions and 38 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "SerialBridge.h"
|
||||
#include "RS232Bridge.h"
|
||||
#include <HardwareSerial.h>
|
||||
#include <RTClib.h>
|
||||
|
||||
#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 {
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
#include "helpers/SimpleMeshTables.h"
|
||||
#include <Stream.h>
|
||||
|
||||
#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;
|
||||
|
|
@ -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}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<helpers/bridges/RS232Bridge.cpp>
|
||||
+<../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}
|
||||
+<helpers/bridges/RS232Bridge.cpp>
|
||||
+<../examples/simple_repeater>
|
||||
lib_deps =
|
||||
${Heltec_lora32_v3.lib_deps}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<helpers/bridges/RS232Bridge.cpp>
|
||||
+<../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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
+<helpers/bridges/RS232Bridge.cpp>
|
||||
+<../examples/simple_repeater>
|
||||
|
||||
[env:waveshare_rp2040_lora_room_server]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue