Skip to content

Commit 07e58d8

Browse files
committed
Merge branch 'dev' into devt114
2 parents f3b20d5 + 96e786f commit 07e58d8

File tree

12 files changed

+38
-35
lines changed

12 files changed

+38
-35
lines changed

examples/companion_radio/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,5 @@ void loop() {
227227
#ifdef DISPLAY_CLASS
228228
ui_task.loop();
229229
#endif
230+
rtc_clock.tick();
230231
}

examples/simple_repeater/MyMesh.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
397397

398398
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
399399
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
400-
return getRNG()->nextInt(0, 5*t);
400+
return getRNG()->nextInt(0, 5*t + 1);
401401
}
402402
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
403403
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
404-
return getRNG()->nextInt(0, 5*t);
404+
return getRNG()->nextInt(0, 5*t + 1);
405405
}
406406

407407
void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
@@ -610,6 +610,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
610610
_prefs.airtime_factor = 1.0; // one half
611611
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
612612
_prefs.tx_delay_factor = 0.5f; // was 0.25f
613+
_prefs.direct_tx_delay_factor = 0.2f; // was zero
613614
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
614615
_prefs.node_lat = ADVERT_LAT;
615616
_prefs.node_lon = ADVERT_LON;

examples/simple_repeater/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ void loop() {
114114
#ifdef DISPLAY_CLASS
115115
ui_task.loop();
116116
#endif
117+
rtc_clock.tick();
117118
}

examples/simple_room_server/MyMesh.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ const char *MyMesh::getLogDateTime() {
262262

263263
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
264264
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
265-
return getRNG()->nextInt(0, 5*t);
265+
return getRNG()->nextInt(0, 5*t + 1);
266266
}
267267
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
268268
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
269-
return getRNG()->nextInt(0, 5*t);
269+
return getRNG()->nextInt(0, 5*t + 1);
270270
}
271271

272272
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
@@ -593,6 +593,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
593593
_prefs.airtime_factor = 1.0; // one half
594594
_prefs.rx_delay_base = 0.0f; // off by default, was 10.0
595595
_prefs.tx_delay_factor = 0.5f; // was 0.25f;
596+
_prefs.direct_tx_delay_factor = 0.2f; // was zero
596597
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
597598
_prefs.node_lat = ADVERT_LAT;
598599
_prefs.node_lon = ADVERT_LON;

examples/simple_room_server/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ void loop() {
110110
#ifdef DISPLAY_CLASS
111111
ui_task.loop();
112112
#endif
113+
rtc_clock.tick();
113114
}

examples/simple_secure_chat/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
548548

549549
StdRNG fast_rng;
550550
SimpleMeshTables tables;
551-
MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); // TODO: test with 'rtc_clock' in target.cpp
551+
MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables);
552552

553553
void halt() {
554554
while (1) ;
@@ -587,4 +587,5 @@ void setup() {
587587

588588
void loop() {
589589
the_mesh.loop();
590+
rtc_clock.tick();
590591
}

examples/simple_sensor/SensorMesh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise
664664
_prefs.airtime_factor = 1.0; // one half
665665
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
666666
_prefs.tx_delay_factor = 0.5f; // was 0.25f
667+
_prefs.direct_tx_delay_factor = 0.2f; // was zero
667668
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
668669
_prefs.node_lat = ADVERT_LAT;
669670
_prefs.node_lon = ADVERT_LON;

examples/simple_sensor/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@ void loop() {
144144
#ifdef DISPLAY_CLASS
145145
ui_task.loop();
146146
#endif
147+
rtc_clock.tick();
147148
}

src/MeshCore.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class RTCClock {
7272
*/
7373
virtual void setCurrentTime(uint32_t time) = 0;
7474

75+
/**
76+
* override in classes that need to periodically update internal state
77+
*/
78+
virtual void tick() { /* no op */}
79+
7580
uint32_t getCurrentTimeUnique() {
7681
uint32_t t = getCurrentTime();
7782
if (t <= last_unique) {

src/helpers/ArduinoHelpers.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
#include <Arduino.h>
55

66
class VolatileRTCClock : public mesh::RTCClock {
7-
long millis_offset;
7+
uint32_t base_time;
8+
uint64_t accumulator;
9+
unsigned long prev_millis;
810
public:
9-
VolatileRTCClock() { millis_offset = 1715770351; } // 15 May 2024, 8:50pm
10-
uint32_t getCurrentTime() override { return (millis()/1000 + millis_offset); }
11-
void setCurrentTime(uint32_t time) override { millis_offset = time - millis()/1000; }
11+
VolatileRTCClock() { base_time = 1715770351; accumulator = 0; prev_millis = millis(); } // 15 May 2024, 8:50pm
12+
uint32_t getCurrentTime() override { return base_time + accumulator/1000; }
13+
void setCurrentTime(uint32_t time) override { base_time = time; accumulator = 0; prev_millis = millis(); }
14+
15+
void tick() override {
16+
unsigned long now = millis();
17+
accumulator += (now - prev_millis);
18+
prev_millis = now;
19+
}
1220
};
1321

1422
class ArduinoMillis : public mesh::MillisecondClock {

0 commit comments

Comments
 (0)