Skip to content

Commit c7568a8

Browse files
committed
Replace 0xFFFFFFFF sentinel with explicit getOutboundTotal()
Instead of overloading getOutboundCount() with a magic sentinel value, add a dedicated getOutboundTotal() method to the PacketManager interface that returns the total queue size without time filtering. This eliminates the fragile convention that caused the regression and makes the two operations — time-filtered count vs total count — explicitly separate in the API.
1 parent c436bd4 commit c7568a8

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

examples/companion_radio/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ void MyMesh::handleCmdFrame(size_t len) {
17121712
out_frame[i++] = STATS_TYPE_CORE;
17131713
uint16_t battery_mv = board.getBattMilliVolts();
17141714
uint32_t uptime_secs = _ms->getMillis() / 1000;
1715-
uint8_t queue_len = (uint8_t)_mgr->getOutboundCount(0xFFFFFFFF);
1715+
uint8_t queue_len = (uint8_t)_mgr->getOutboundTotal();
17161716
memcpy(&out_frame[i], &battery_mv, 2); i += 2;
17171717
memcpy(&out_frame[i], &uptime_secs, 4); i += 4;
17181718
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();
@@ -1290,5 +1290,5 @@ bool MyMesh::hasPendingWork() const {
12901290
#if defined(WITH_BRIDGE)
12911291
if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep
12921292
#endif
1293-
return _mgr->getOutboundCount(0xFFFFFFFF) > 0;
1293+
return _mgr->getOutboundTotal() > 0;
12941294
}

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class PacketManager {
8989

9090
virtual void queueOutbound(Packet* packet, uint8_t priority, uint32_t scheduled_for) = 0;
9191
virtual Packet* getNextOutbound(uint32_t now) = 0; // by priority
92-
virtual int getOutboundCount(uint32_t now) const = 0; // pass now=0xFFFFFFFF to count all
92+
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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
1312
int n = 0;
1413
for (int j = 0; j < _num; j++) {
1514
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
@@ -98,6 +97,10 @@ int StaticPoolPacketManager::getOutboundCount(uint32_t now) const {
9897
return send_queue.countBefore(now);
9998
}
10099

100+
int StaticPoolPacketManager::getOutboundTotal() const {
101+
return send_queue.count();
102+
}
103+
101104
int StaticPoolPacketManager::getFreeCount() const {
102105
return unused.count();
103106
}

src/helpers/StaticPoolPacketManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PacketQueue {
1313
mesh::Packet* get(uint32_t now);
1414
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
1515
int count() const { return _num; }
16-
int countBefore(uint32_t now) const; // pass now=0xFFFFFFFF to count all
16+
int countBefore(uint32_t now) const;
1717
mesh::Packet* itemAt(int i) const { return _table[i]; }
1818
mesh::Packet* removeByIdx(int i);
1919
};
@@ -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)