Skip to content

Commit 29be7e2

Browse files
authored
Merge pull request #1877 from DanielNovak/fix-countbefore-sentinel-regression
Fix countBefore regression: replace sentinel with getOutboundTotal()
2 parents aad56bb + 0d87dcc commit 29be7e2

7 files changed

Lines changed: 13 additions & 5 deletions

File tree

examples/companion_radio/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ void MyMesh::handleCmdFrame(size_t len) {
17161716
out_frame[i++] = STATS_TYPE_CORE;
17171717
uint16_t battery_mv = board.getBattMilliVolts();
17181718
uint32_t uptime_secs = _ms->getMillis() / 1000;
1719-
uint8_t queue_len = (uint8_t)_mgr->getOutboundCount(0xFFFFFFFF);
1719+
uint8_t queue_len = (uint8_t)_mgr->getOutboundTotal();
17201720
memcpy(&out_frame[i], &battery_mv, 2); i += 2;
17211721
memcpy(&out_frame[i], &uptime_secs, 4); i += 4;
17221722
memcpy(&out_frame[i], &_err_flags, 2); i += 2;

examples/simple_repeater/MyMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
219219
if (payload[0] == REQ_TYPE_GET_STATUS) { // guests can also access this now
220220
RepeaterStats stats;
221221
stats.batt_milli_volts = board.getBattMilliVolts();
222-
stats.curr_tx_queue_len = _mgr->getOutboundCount(0xFFFFFFFF);
222+
stats.curr_tx_queue_len = _mgr->getOutboundTotal();
223223
stats.noise_floor = (int16_t)_radio->getNoiseFloor();
224224
stats.last_rssi = (int16_t)radio_driver.getLastRSSI();
225225
stats.n_packets_recv = radio_driver.getPacketsRecv();
@@ -1321,5 +1321,5 @@ bool MyMesh::hasPendingWork() const {
13211321
#if defined(WITH_BRIDGE)
13221322
if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep
13231323
#endif
1324-
return _mgr->getOutboundCount(0xFFFFFFFF) > 0;
1324+
return _mgr->getOutboundTotal() > 0;
13251325
}

examples/simple_room_server/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
140140
if (payload[0] == REQ_TYPE_GET_STATUS) {
141141
ServerStats stats;
142142
stats.batt_milli_volts = board.getBattMilliVolts();
143-
stats.curr_tx_queue_len = _mgr->getOutboundCount(0xFFFFFFFF);
143+
stats.curr_tx_queue_len = _mgr->getOutboundTotal();
144144
stats.noise_floor = (int16_t)_radio->getNoiseFloor();
145145
stats.last_rssi = (int16_t)radio_driver.getLastRSSI();
146146
stats.n_packets_recv = radio_driver.getPacketsRecv();

src/Dispatcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class PacketManager {
9090
virtual void queueOutbound(Packet* packet, uint8_t priority, uint32_t scheduled_for) = 0;
9191
virtual Packet* getNextOutbound(uint32_t now) = 0; // by priority
9292
virtual int getOutboundCount(uint32_t now) const = 0;
93+
virtual int getOutboundTotal() const = 0;
9394
virtual int getFreeCount() const = 0;
9495
virtual Packet* getOutboundByIdx(int i) = 0;
9596
virtual Packet* removeOutboundByIdx(int i) = 0;

src/helpers/StaticPoolPacketManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PacketQueue::PacketQueue(int max_entries) {
99
}
1010

1111
int PacketQueue::countBefore(uint32_t now) const {
12+
if (now == 0xFFFFFFFF) return _num; // sentinel: count all entries regardless of schedule
13+
1214
int n = 0;
1315
for (int j = 0; j < _num; j++) {
1416
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
@@ -97,6 +99,10 @@ int StaticPoolPacketManager::getOutboundCount(uint32_t now) const {
9799
return send_queue.countBefore(now);
98100
}
99101

102+
int StaticPoolPacketManager::getOutboundTotal() const {
103+
return send_queue.count();
104+
}
105+
100106
int StaticPoolPacketManager::getFreeCount() const {
101107
return unused.count();
102108
}

src/helpers/StaticPoolPacketManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class StaticPoolPacketManager : public mesh::PacketManager {
2929
void queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) override;
3030
mesh::Packet* getNextOutbound(uint32_t now) override;
3131
int getOutboundCount(uint32_t now) const override;
32+
int getOutboundTotal() const override;
3233
int getFreeCount() const override;
3334
mesh::Packet* getOutboundByIdx(int i) override;
3435
mesh::Packet* removeOutboundByIdx(int i) override;

src/helpers/StatsFormatHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class StatsFormatHelper {
1414
board.getBattMilliVolts(),
1515
ms.getMillis() / 1000,
1616
err_flags,
17-
mgr->getOutboundCount(0xFFFFFFFF)
17+
mgr->getOutboundTotal()
1818
);
1919
}
2020

0 commit comments

Comments
 (0)