Skip to content

Commit 3139d50

Browse files
authored
Merge branch 'ripplebiz:dev' into dev
2 parents 9485488 + 4689f9b commit 3139d50

File tree

6 files changed

+104
-2
lines changed

6 files changed

+104
-2
lines changed

examples/simple_repeater/main.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct NeighbourInfo {
120120
int8_t snr; // multiplied by 4, user should divide to get float value
121121
};
122122

123-
#define CLI_REPLY_DELAY_MILLIS 1000
123+
#define CLI_REPLY_DELAY_MILLIS 600
124124

125125
class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
126126
FILESYSTEM* _fs;
@@ -134,6 +134,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
134134
NeighbourInfo neighbours[MAX_NEIGHBOURS];
135135
#endif
136136
CayenneLPP telemetry;
137+
unsigned long set_radio_at, revert_radio_at;
138+
float pending_freq;
139+
float pending_bw;
140+
uint8_t pending_sf;
141+
uint8_t pending_cr;
137142

138143
ClientInfo* putClient(const mesh::Identity& id) {
139144
uint32_t min_time = 0xFFFFFFFF;
@@ -558,6 +563,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
558563
{
559564
memset(known_clients, 0, sizeof(known_clients));
560565
next_local_advert = next_flood_advert = 0;
566+
set_radio_at = revert_radio_at = 0;
561567
_logging = false;
562568

563569
#if MAX_NEIGHBOURS
@@ -609,6 +615,16 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
609615
_cli.savePrefs(_fs);
610616
}
611617

618+
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override {
619+
set_radio_at = futureMillis(2000); // give CLI reply some time to be sent back, before applying temp radio params
620+
pending_freq = freq;
621+
pending_bw = bw;
622+
pending_sf = sf;
623+
pending_cr = cr;
624+
625+
revert_radio_at = futureMillis(2000 + timeout_mins*60*1000); // schedule when to revert radio params
626+
}
627+
612628
bool formatFileSystem() override {
613629
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
614630
return InternalFS.format();
@@ -734,6 +750,19 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
734750

735751
updateAdvertTimer(); // schedule next local advert
736752
}
753+
754+
if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params
755+
set_radio_at = 0; // clear timer
756+
radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr);
757+
MESH_DEBUG_PRINTLN("Temp radio params");
758+
}
759+
760+
if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig
761+
revert_radio_at = 0; // clear timer
762+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
763+
MESH_DEBUG_PRINTLN("Radio params restored");
764+
}
765+
737766
#ifdef DISPLAY_CLASS
738767
ui_task.loop();
739768
#endif

examples/simple_room_server/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
165165
int next_post_idx;
166166
PostInfo posts[MAX_UNSYNCED_POSTS]; // cyclic queue
167167
CayenneLPP telemetry;
168+
unsigned long set_radio_at, revert_radio_at;
169+
float pending_freq;
170+
float pending_bw;
171+
uint8_t pending_sf;
172+
uint8_t pending_cr;
168173

169174
ClientInfo* putClient(const mesh::Identity& id) {
170175
for (int i = 0; i < num_clients; i++) {
@@ -721,6 +726,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
721726
{
722727
next_local_advert = next_flood_advert = 0;
723728
_logging = false;
729+
set_radio_at = revert_radio_at = 0;
724730

725731
// defaults
726732
memset(&_prefs, 0, sizeof(_prefs));
@@ -778,6 +784,16 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
778784
_cli.savePrefs(_fs);
779785
}
780786

787+
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override {
788+
set_radio_at = futureMillis(2000); // give CLI reply some time to be sent back, before applying temp radio params
789+
pending_freq = freq;
790+
pending_bw = bw;
791+
pending_sf = sf;
792+
pending_cr = cr;
793+
794+
revert_radio_at = futureMillis(2000 + timeout_mins*60*1000); // schedule when to revert radio params
795+
}
796+
781797
bool formatFileSystem() override {
782798
#if defined(NRF52_PLATFORM)
783799
return InternalFS.format();
@@ -922,6 +938,18 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
922938
updateAdvertTimer(); // schedule next local advert
923939
}
924940

941+
if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params
942+
set_radio_at = 0; // clear timer
943+
radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr);
944+
MESH_DEBUG_PRINTLN("Temp radio params");
945+
}
946+
947+
if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig
948+
revert_radio_at = 0; // clear timer
949+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
950+
MESH_DEBUG_PRINTLN("Radio params restored");
951+
}
952+
925953
#ifdef DISPLAY_CLASS
926954
ui_task.loop();
927955
#endif

examples/simple_sensor/SensorMesh.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise
722722
dirty_contacts_expiry = 0;
723723
last_read_time = 0;
724724
num_alert_tasks = 0;
725+
set_radio_at = revert_radio_at = 0;
725726

726727
// defaults
727728
memset(&_prefs, 0, sizeof(_prefs));
@@ -772,6 +773,16 @@ bool SensorMesh::formatFileSystem() {
772773
#endif
773774
}
774775

776+
void SensorMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) {
777+
set_radio_at = futureMillis(2000); // give CLI reply some time to be sent back, before applying temp radio params
778+
pending_freq = freq;
779+
pending_bw = bw;
780+
pending_sf = sf;
781+
pending_cr = cr;
782+
783+
revert_radio_at = futureMillis(2000 + timeout_mins*60*1000); // schedule when to revert radio params
784+
}
785+
775786
void SensorMesh::sendSelfAdvertisement(int delay_millis) {
776787
mesh::Packet* pkt = createSelfAdvert();
777788
if (pkt) {
@@ -847,6 +858,18 @@ void SensorMesh::loop() {
847858
updateAdvertTimer(); // schedule next local advert
848859
}
849860

861+
if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params
862+
set_radio_at = 0; // clear timer
863+
radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr);
864+
MESH_DEBUG_PRINTLN("Temp radio params");
865+
}
866+
867+
if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig
868+
revert_radio_at = 0; // clear timer
869+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
870+
MESH_DEBUG_PRINTLN("Radio params restored");
871+
}
872+
850873
uint32_t curr = getRTCClock()->getCurrentTime();
851874
if (curr >= last_read_time + SENSOR_READ_INTERVAL_SECS) {
852875
telemetry.reset();

examples/simple_sensor/SensorMesh.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks {
9090
}
9191
const uint8_t* getSelfIdPubKey() override { return self_id.pub_key; }
9292
void clearStats() override { }
93+
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
9394

9495
float getTelemValue(uint8_t channel, uint8_t type);
9596

@@ -154,6 +155,11 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks {
154155
int matching_peer_indexes[MAX_SEARCH_RESULTS];
155156
int num_alert_tasks;
156157
Trigger* alert_tasks[MAX_CONCURRENT_ALERTS];
158+
unsigned long set_radio_at, revert_radio_at;
159+
float pending_freq;
160+
float pending_bw;
161+
uint8_t pending_sf;
162+
uint8_t pending_cr;
157163

158164
void loadContacts();
159165
void saveContacts();

src/helpers/CommonCLI.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
132132
if (memcmp(command, "reboot", 6) == 0) {
133133
_board->reboot(); // doesn't return
134134
} else if (memcmp(command, "advert", 6) == 0) {
135-
_callbacks->sendSelfAdvertisement(400);
135+
_callbacks->sendSelfAdvertisement(1500); // longer delay, give CLI response time to be sent first
136136
strcpy(reply, "OK - Advert sent");
137137
} else if (memcmp(command, "clock sync", 10) == 0) {
138138
uint32_t curr = getRTCClock()->getCurrentTime();
@@ -165,6 +165,21 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
165165
}
166166
} else if (memcmp(command, "neighbors", 9) == 0) {
167167
_callbacks->formatNeighborsReply(reply);
168+
} else if (memcmp(command, "tempradio ", 10) == 0) {
169+
strcpy(tmp, &command[10]);
170+
const char *parts[5];
171+
int num = mesh::Utils::parseTextParts(tmp, parts, 5);
172+
float freq = num > 0 ? atof(parts[0]) : 0.0f;
173+
float bw = num > 1 ? atof(parts[1]) : 0.0f;
174+
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
175+
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
176+
int temp_timeout_mins = num > 4 ? atoi(parts[4]) : 0;
177+
if (freq >= 300.0f && freq <= 2500.0f && sf >= 7 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f && temp_timeout_mins > 0) {
178+
_callbacks->applyTempRadioParams(freq, bw, sf, cr, temp_timeout_mins);
179+
sprintf(reply, "OK - temp params for %d mins", temp_timeout_mins);
180+
} else {
181+
strcpy(reply, "Error, invalid params");
182+
}
168183
} else if (memcmp(command, "password ", 9) == 0) {
169184
// change admin password
170185
StrHelper::strncpy(_prefs->password, &command[9], sizeof(_prefs->password));

src/helpers/CommonCLI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CommonCLICallbacks {
4545
virtual void formatNeighborsReply(char *reply) = 0;
4646
virtual const uint8_t* getSelfIdPubKey() = 0;
4747
virtual void clearStats() = 0;
48+
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;
4849
};
4950

5051
class CommonCLI {

0 commit comments

Comments
 (0)