From aaeccd121c96236e4cee9165e58f0495ff88f712 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Tue, 4 Feb 2025 18:27:13 +1100 Subject: [PATCH 1/2] * repeater and room server, new "set repeat {on|off}" CLI command --- examples/simple_repeater/main.cpp | 11 ++++++++--- examples/simple_room_server/main.cpp | 14 +++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index d9d7db1d..8331c790 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -120,7 +120,8 @@ struct NodePrefs { // persisted to file char password[16]; float freq; uint8_t tx_power_dbm; - uint8_t unused[3]; + uint8_t disable_fwd; + uint8_t unused[2]; }; class MyMesh : public mesh::Mesh { @@ -190,7 +191,7 @@ protected: } bool allowPacketForward(const mesh::Packet* packet) override { - return true; // Yes, allow packet to be forwarded + return !_prefs.disable_fwd; } void onAnonDataRecv(mesh::Packet* packet, uint8_t type, const mesh::Identity& sender, uint8_t* data, size_t len) override { @@ -370,6 +371,7 @@ public: num_clients = 0; // defaults + memset(&_prefs, 0, sizeof(_prefs)); _prefs.airtime_factor = 1.0; // one half strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name)-1); _prefs.node_name[sizeof(_prefs.node_name)-1] = 0; // truncate if necessary @@ -379,7 +381,6 @@ public: _prefs.password[sizeof(_prefs.password)-1] = 0; // truncate if necessary _prefs.freq = LORA_FREQ; _prefs.tx_power_dbm = LORA_TX_POWER; - memset(_prefs.unused, 0, sizeof(_prefs.unused)); } float getFreqPref() const { return _prefs.freq; } @@ -479,6 +480,10 @@ public: _prefs.node_name[sizeof(_prefs.node_name)-1] = 0; // truncate if nec savePrefs(); strcpy(reply, "OK"); + } else if (memcmp(config, "repeat ", 7) == 0) { + _prefs.disable_fwd = memcmp(&config[7], "off", 3) == 0; + savePrefs(); + strcpy(reply, _prefs.disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON"); } else if (memcmp(config, "lat ", 4) == 0) { _prefs.node_lat = atof(&config[4]); savePrefs(); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index b824c1bd..f956ab85 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -137,7 +137,8 @@ struct NodePrefs { // persisted to file char password[16]; float freq; uint8_t tx_power_dbm; - uint8_t unused[3]; + uint8_t disable_fwd; + uint8_t unused[2]; }; class MyMesh : public mesh::Mesh { @@ -246,11 +247,9 @@ protected: return _prefs.airtime_factor; } -#if ROOM_IS_ALSO_REPEATER bool allowPacketForward(const mesh::Packet* packet) override { - return true; // Yes, allow packet to be forwarded + return !_prefs.disable_fwd; } -#endif void onAnonDataRecv(mesh::Packet* packet, uint8_t type, const mesh::Identity& sender, uint8_t* data, size_t len) override { if (type == PAYLOAD_TYPE_ANON_REQ) { // received an initial request by a possible admin client (unknown at this stage) @@ -483,6 +482,7 @@ public: my_radio = &radio; // defaults + memset(&_prefs, 0, sizeof(_prefs)); _prefs.airtime_factor = 1.0; // one half strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name)-1); _prefs.node_name[sizeof(_prefs.node_name)-1] = 0; // truncate if necessary @@ -492,7 +492,7 @@ public: _prefs.password[sizeof(_prefs.password)-1] = 0; // truncate if necessary _prefs.freq = LORA_FREQ; _prefs.tx_power_dbm = LORA_TX_POWER; - memset(_prefs.unused, 0, sizeof(_prefs.unused)); + _prefs.disable_fwd = 1; num_clients = 0; next_post_idx = 0; @@ -592,6 +592,10 @@ public: _prefs.node_name[sizeof(_prefs.node_name)-1] = 0; // truncate if nec savePrefs(); strcpy(reply, "OK"); + } else if (memcmp(config, "repeat ", 7) == 0) { + _prefs.disable_fwd = memcmp(&config[7], "off", 3) == 0; + savePrefs(); + strcpy(reply, _prefs.disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON"); } else if (memcmp(config, "lat ", 4) == 0) { _prefs.node_lat = atof(&config[4]); savePrefs(); From 6cef0564881aae048b47c2c82d9493b7b43a4e1c Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Tue, 4 Feb 2025 19:40:30 +1100 Subject: [PATCH 2/2] * companion radio: offline messages queue --- examples/companion_radio/main.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 1ebec27e..d2ce72ff 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -42,6 +42,10 @@ #define MAX_CONTACTS 100 #endif +#ifndef OFFLINE_QUEUE_SIZE + #define OFFLINE_QUEUE_SIZE 16 +#endif + #include #define SEND_TIMEOUT_BASE_MILLIS 300 @@ -143,6 +147,13 @@ class MyMesh : public BaseChatMesh { uint8_t cmd_frame[MAX_FRAME_SIZE+1]; uint8_t out_frame[MAX_FRAME_SIZE+1]; + struct Frame { + uint8_t len; + uint8_t buf[MAX_FRAME_SIZE]; + }; + int offline_queue_len; + Frame offline_queue[OFFLINE_QUEUE_SIZE]; + void loadContacts() { if (_fs->exists("/contacts3")) { File file = _fs->open("/contacts3"); @@ -254,9 +265,25 @@ class MyMesh : public BaseChatMesh { } void addToOfflineQueue(const uint8_t frame[], int len) { - // TODO + if (offline_queue_len >= OFFLINE_QUEUE_SIZE) { + MESH_DEBUG_PRINTLN("ERROR: offline_queue is full!"); + } else { + offline_queue[offline_queue_len].len = len; + memcpy(offline_queue[offline_queue_len].buf, frame, len); + offline_queue_len++; + } } int getFromOfflineQueue(uint8_t frame[]) { + if (offline_queue_len > 0) { // check offline queue + size_t len = offline_queue[0].len; // take from top of queue + memcpy(frame, offline_queue[0].buf, len); + + offline_queue_len--; + for (int i = 0; i < offline_queue_len; i++) { // delete top item from queue + offline_queue[i] = offline_queue[i + 1]; + } + return len; + } return 0; // queue is empty } @@ -364,6 +391,7 @@ public: : BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL) { _iter_started = false; + offline_queue_len = 0; // defaults memset(&_prefs, 0, sizeof(_prefs));