mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-07-28 22:19:25 +00:00
Commit 22eb9b87 ("Revert 'Merge remote-tracking branch origin/dev...'")
reverted an entire upstream merge to escape a bad merge state, dropping
860 lines across 66 files. Among the collateral never reconciled on a
later re-merge was eb4fa032's token-bucket duty-cycle enforcement — the
mechanism that keeps nodes under a configured airtime budget (and EU
868 MHz nodes under the legally-mandated duty cycle). The fork had fallen
back to fixed per-packet spacing (getAirtimeBudgetFactor reverted to 2.0),
losing the windowed enforcement.
This was never an intentional design choice, so restoring it re-aligns the
fork with upstream and REDUCES the merge-conflict surface: Dispatcher.{h,cpp}
now diverge from upstream by watchdog additions only (77 insertions, 0
deletions) instead of rewriting checkSend()/loop().
Restored from upstream: updateTxBudget/tx_budget_ms/duty_cycle_window_ms/
getRemainingTxBudget/getDutyCycleWindowMs and the windowed budget logic in
Dispatcher; getOutboundTotal() and the 0xFFFFFFFF count-all sentinel in
StaticPoolPacketManager; the getOutboundTotal() call in StatsFormatHelper.
Re-applied the fork's MQTT radio-watchdog on top as pure additions
(#ifdef WITH_MQTT_BRIDGE), keeping formatRadioDiag.
Stored airtime_factor settings keep their meaning: fork's t*factor spacing
and upstream's 1/(1+factor) windowed budget yield the same steady-state
duty cycle; upstream additionally allows short bursts within the window.
Phase 2 (CAD / radio_fem_rxgain, which touch NodePrefs persistence and
per-board FEM wiring) is documented in RESTORE_UPSTREAM_NOTES.md, not done
here. Builds: Heltec_v3 observer + plain repeater. NEEDS ON-DEVICE
duty-cycle validation before merge.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
126 lines
3.5 KiB
C++
126 lines
3.5 KiB
C++
#include "StaticPoolPacketManager.h"
|
|
|
|
PacketQueue::PacketQueue(int max_entries) {
|
|
_table = new mesh::Packet*[max_entries];
|
|
_pri_table = new uint8_t[max_entries];
|
|
_schedule_table = new uint32_t[max_entries];
|
|
_size = max_entries;
|
|
_num = 0;
|
|
}
|
|
|
|
int PacketQueue::countBefore(uint32_t now) const {
|
|
if (now == 0xFFFFFFFF) return _num; // sentinel: count all entries regardless of schedule
|
|
|
|
int n = 0;
|
|
for (int j = 0; j < _num; j++) {
|
|
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
|
n++;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
mesh::Packet* PacketQueue::get(uint32_t now) {
|
|
uint8_t min_pri = 0xFF;
|
|
int best_idx = -1;
|
|
for (int j = 0; j < _num; j++) {
|
|
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
|
if (_pri_table[j] < min_pri) { // select most important priority amongst non-future entries
|
|
min_pri = _pri_table[j];
|
|
best_idx = j;
|
|
}
|
|
}
|
|
if (best_idx < 0) return NULL; // empty, or all items are still in the future
|
|
|
|
mesh::Packet* top = _table[best_idx];
|
|
int i = best_idx;
|
|
_num--;
|
|
while (i < _num) {
|
|
_table[i] = _table[i+1];
|
|
_pri_table[i] = _pri_table[i+1];
|
|
_schedule_table[i] = _schedule_table[i+1];
|
|
i++;
|
|
}
|
|
return top;
|
|
}
|
|
|
|
mesh::Packet* PacketQueue::removeByIdx(int i) {
|
|
if (i >= _num) return NULL; // invalid index
|
|
|
|
mesh::Packet* item = _table[i];
|
|
_num--;
|
|
while (i < _num) {
|
|
_table[i] = _table[i+1];
|
|
_pri_table[i] = _pri_table[i+1];
|
|
_schedule_table[i] = _schedule_table[i+1];
|
|
i++;
|
|
}
|
|
return item;
|
|
}
|
|
|
|
bool PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
|
if (_num == _size) {
|
|
return false;
|
|
}
|
|
_table[_num] = packet;
|
|
_pri_table[_num] = priority;
|
|
_schedule_table[_num] = scheduled_for;
|
|
_num++;
|
|
return true;
|
|
}
|
|
|
|
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size): unused(pool_size), send_queue(pool_size), rx_queue(pool_size) {
|
|
// load up our unusued Packet pool
|
|
for (int i = 0; i < pool_size; i++) {
|
|
unused.add(new mesh::Packet(), 0, 0);
|
|
}
|
|
}
|
|
|
|
mesh::Packet* StaticPoolPacketManager::allocNew() {
|
|
return unused.removeByIdx(0); // just get first one (returns NULL if empty)
|
|
}
|
|
|
|
void StaticPoolPacketManager::free(mesh::Packet* packet) {
|
|
unused.add(packet, 0, 0);
|
|
}
|
|
|
|
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
|
if (!send_queue.add(packet, priority, scheduled_for)) {
|
|
MESH_DEBUG_PRINTLN("queueOutbound: send queue full, dropping packet");
|
|
free(packet);
|
|
}
|
|
}
|
|
|
|
mesh::Packet* StaticPoolPacketManager::getNextOutbound(uint32_t now) {
|
|
//send_queue.sort(); // sort by scheduled_for/priority first
|
|
return send_queue.get(now);
|
|
}
|
|
|
|
int StaticPoolPacketManager::getOutboundCount(uint32_t now) const {
|
|
return send_queue.countBefore(now);
|
|
}
|
|
|
|
int StaticPoolPacketManager::getOutboundTotal() const {
|
|
return send_queue.count();
|
|
}
|
|
|
|
int StaticPoolPacketManager::getFreeCount() const {
|
|
return unused.count();
|
|
}
|
|
|
|
mesh::Packet* StaticPoolPacketManager::getOutboundByIdx(int i) {
|
|
return send_queue.itemAt(i);
|
|
}
|
|
mesh::Packet* StaticPoolPacketManager::removeOutboundByIdx(int i) {
|
|
return send_queue.removeByIdx(i);
|
|
}
|
|
|
|
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
|
if (!rx_queue.add(packet, 0, scheduled_for)) {
|
|
MESH_DEBUG_PRINTLN("queueInbound: rx queue full, dropping packet");
|
|
free(packet);
|
|
}
|
|
}
|
|
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
|
return rx_queue.get(now);
|
|
}
|