diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index ea8e8443..6452137f 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -184,7 +184,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { case REQ_TYPE_GET_STATUS: { // guests can also access this now RepeaterStats stats; stats.batt_milli_volts = board.getBattMilliVolts(); - stats.curr_tx_queue_len = _mgr->getOutboundCount(); + stats.curr_tx_queue_len = _mgr->getOutboundCount(0xFFFFFFFF); stats.curr_free_queue_len = _mgr->getFreeCount(); stats.last_rssi = (int16_t) radio_driver.getLastRSSI(); stats.n_packets_recv = radio_driver.getPacketsRecv(); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 05a076b3..9849ba25 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -290,7 +290,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { case REQ_TYPE_GET_STATUS: { ServerStats stats; stats.batt_milli_volts = board.getBattMilliVolts(); - stats.curr_tx_queue_len = _mgr->getOutboundCount(); + stats.curr_tx_queue_len = _mgr->getOutboundCount(0xFFFFFFFF); stats.curr_free_queue_len = _mgr->getFreeCount(); stats.last_rssi = (int16_t) radio_driver.getLastRSSI(); stats.n_packets_recv = radio_driver.getPacketsRecv(); diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 53a5b2ad..3d5b04fc 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -205,7 +205,7 @@ void Dispatcher::processRecvPacket(Packet* pkt) { } void Dispatcher::checkSend() { - if (_mgr->getOutboundCount() == 0) return; // nothing waiting to send + if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return; // nothing waiting to send if (!millisHasNowPassed(next_tx_time)) return; // still in 'radio silence' phase (from airtime budget setting) if (_radio->isReceiving()) { // LBT - check if radio is currently mid-receive, or if channel activity if (cad_busy_start == 0) { diff --git a/src/Dispatcher.h b/src/Dispatcher.h index bcfba389..d03c9f73 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -78,7 +78,7 @@ public: virtual void queueOutbound(Packet* packet, uint8_t priority, uint32_t scheduled_for) = 0; virtual Packet* getNextOutbound(uint32_t now) = 0; // by priority - virtual int getOutboundCount() const = 0; + virtual int getOutboundCount(uint32_t now) const = 0; virtual int getFreeCount() const = 0; virtual Packet* getOutboundByIdx(int i) = 0; virtual Packet* removeOutboundByIdx(int i) = 0; diff --git a/src/helpers/StaticPoolPacketManager.cpp b/src/helpers/StaticPoolPacketManager.cpp index 07bc8f2e..4f28eac6 100644 --- a/src/helpers/StaticPoolPacketManager.cpp +++ b/src/helpers/StaticPoolPacketManager.cpp @@ -8,6 +8,15 @@ PacketQueue::PacketQueue(int max_entries) { _num = 0; } +int PacketQueue::countBefore(uint32_t now) const { + int n = 0; + for (int j = 0; j < _num; j++) { + if (_schedule_table[j] > now) 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; @@ -81,8 +90,8 @@ mesh::Packet* StaticPoolPacketManager::getNextOutbound(uint32_t now) { return send_queue.get(now); } -int StaticPoolPacketManager::getOutboundCount() const { - return send_queue.count(); +int StaticPoolPacketManager::getOutboundCount(uint32_t now) const { + return send_queue.countBefore(now); } int StaticPoolPacketManager::getFreeCount() const { diff --git a/src/helpers/StaticPoolPacketManager.h b/src/helpers/StaticPoolPacketManager.h index 09c2fdec..bbf4b193 100644 --- a/src/helpers/StaticPoolPacketManager.h +++ b/src/helpers/StaticPoolPacketManager.h @@ -13,6 +13,7 @@ public: mesh::Packet* get(uint32_t now); void add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for); int count() const { return _num; } + int countBefore(uint32_t now) const; mesh::Packet* itemAt(int i) const { return _table[i]; } mesh::Packet* removeByIdx(int i); }; @@ -27,7 +28,7 @@ public: void free(mesh::Packet* packet) override; void queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) override; mesh::Packet* getNextOutbound(uint32_t now) override; - int getOutboundCount() const override; + int getOutboundCount(uint32_t now) const override; int getFreeCount() const override; mesh::Packet* getOutboundByIdx(int i) override; mesh::Packet* removeOutboundByIdx(int i) override;