7878
7979/* ------------------------------ Code -------------------------------- */
8080
81- #define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
82- #define REQ_TYPE_KEEP_ALIVE 0x02
83- #define REQ_TYPE_GET_TELEMETRY_DATA 0x03
84-
85- #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ
86-
87- struct RepeaterStats {
88- uint16_t batt_milli_volts;
89- uint16_t curr_tx_queue_len;
90- int16_t noise_floor;
91- int16_t last_rssi;
92- uint32_t n_packets_recv;
93- uint32_t n_packets_sent;
94- uint32_t total_air_time_secs;
95- uint32_t total_up_time_secs;
96- uint32_t n_sent_flood, n_sent_direct;
97- uint32_t n_recv_flood, n_recv_direct;
98- uint16_t err_events; // was 'n_full_events'
99- int16_t last_snr; // x 4
100- uint16_t n_direct_dups, n_flood_dups;
101- uint32_t total_rx_air_time_secs;
102- };
81+ #ifdef WITH_RS232_BRIDGE
82+ #include " helpers/bridges/RS232Bridge.h"
83+ #define WITH_BRIDGE
84+ #endif
85+
86+ #ifdef WITH_ESPNOW_BRIDGE
87+ #include " helpers/bridges/ESPNowBridge.h"
88+ #define WITH_BRIDGE
89+ #endif
90+
91+ #define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
92+ #define REQ_TYPE_KEEP_ALIVE 0x02
93+ #define REQ_TYPE_GET_TELEMETRY_DATA 0x03
94+
95+ #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ
96+
97+ struct RepeaterStats {
98+ uint16_t batt_milli_volts;
99+ uint16_t curr_tx_queue_len;
100+ int16_t noise_floor;
101+ int16_t last_rssi;
102+ uint32_t n_packets_recv;
103+ uint32_t n_packets_sent;
104+ uint32_t total_air_time_secs;
105+ uint32_t total_up_time_secs;
106+ uint32_t n_sent_flood, n_sent_direct;
107+ uint32_t n_recv_flood, n_recv_direct;
108+ uint16_t err_events; // was 'n_full_events'
109+ int16_t last_snr; // x 4
110+ uint16_t n_direct_dups, n_flood_dups;
111+ uint32_t total_rx_air_time_secs;
112+ };
103113
104114struct ClientInfo {
105115 mesh::Identity id;
@@ -114,6 +124,10 @@ struct ClientInfo {
114124 #define MAX_CLIENTS 32
115125#endif
116126
127+ #ifdef WITH_BRIDGE
128+ AbstractBridge* bridge;
129+ #endif
130+
117131struct NeighbourInfo {
118132 mesh::Identity id;
119133 uint32_t advert_timestamp;
@@ -300,6 +314,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
300314 }
301315 }
302316 void logTx (mesh::Packet* pkt, int len) override {
317+ #ifdef WITH_BRIDGE
318+ bridge->onPacketTransmitted (pkt);
319+ #endif
303320 if (_logging) {
304321 File f = openAppend (PACKET_LOG_FILE);
305322 if (f) {
@@ -364,9 +381,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
364381 } else if (strcmp ((char *) &data[4 ], _prefs.guest_password ) == 0 ) { // check guest password
365382 is_admin = false ;
366383 } else {
367- #if MESH_DEBUG
384+ #if MESH_DEBUG
368385 MESH_DEBUG_PRINTLN (" Invalid password: %s" , &data[4 ]);
369- #endif
386+ #endif
370387 return ;
371388 }
372389
@@ -384,15 +401,15 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
384401
385402 uint32_t now = getRTCClock ()->getCurrentTimeUnique ();
386403 memcpy (reply_data, &now, 4 ); // response packets always prefixed with timestamp
387- #if 0
404+ #if 0
388405 memcpy(&reply_data[4], "OK", 2); // legacy response
389- #else
406+ #else
390407 reply_data[4 ] = RESP_SERVER_LOGIN_OK;
391408 reply_data[5 ] = 0 ; // NEW: recommended keep-alive interval (secs / 16)
392409 reply_data[6 ] = is_admin ? 1 : 0 ;
393410 reply_data[7 ] = 0 ; // FUTURE: reserved
394411 getRNG ()->random (&reply_data[8 ], 4 ); // random blob to help packet-hash uniqueness
395- #endif
412+ #endif
396413
397414 if (packet->isRouteFlood ()) {
398415 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
@@ -565,14 +582,23 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
565582 : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32 ), tables),
566583 _cli (board, rtc, &_prefs, this ), telemetry(MAX_PACKET_PAYLOAD - 4 )
567584 {
585+ #ifdef WITH_BRIDGE
586+ #if defined(WITH_RS232_BRIDGE)
587+ bridge = new RS232Bridge (WITH_RS232_BRIDGE, _mgr, &rtc);
588+ #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
593+ #endif
568594 memset (known_clients, 0 , sizeof (known_clients));
569595 next_local_advert = next_flood_advert = 0 ;
570596 set_radio_at = revert_radio_at = 0 ;
571597 _logging = false ;
572598
573- #if MAX_NEIGHBOURS
599+ #if MAX_NEIGHBOURS
574600 memset (neighbours, 0 , sizeof (neighbours));
575- #endif
601+ #endif
576602
577603 // defaults
578604 memset (&_prefs, 0 , sizeof (_prefs));
@@ -765,6 +791,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
765791 }
766792
767793 void loop () {
794+ #ifdef WITH_BRIDGE
795+ bridge->loop ();
796+ #endif
797+
768798 mesh::Mesh::loop ();
769799
770800 if (next_flood_advert && millisHasNowPassed (next_flood_advert)) {
@@ -813,6 +843,10 @@ void setup() {
813843 Serial.begin (115200 );
814844 delay (1000 );
815845
846+ #ifdef WITH_BRIDGE
847+ bridge->begin ();
848+ #endif
849+
816850 board.begin ();
817851
818852#ifdef DISPLAY_CLASS
@@ -824,7 +858,9 @@ void setup() {
824858 }
825859#endif
826860
827- if (!radio_init ()) { halt (); }
861+ if (!radio_init ()) {
862+ halt ();
863+ }
828864
829865 fast_rng.begin (radio_get_rng_seed ());
830866
0 commit comments