Add dropped packet count to LocalStats (#8207)

* Add dropped packet count to LocalStats
In case the transmit queue was full

* Trunked

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
GUVWAF 2025-10-04 15:13:58 +02:00 committed by GitHub
parent fe4fb085e6
commit 888692a373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 34 additions and 7 deletions

View File

@ -65,7 +65,7 @@ void fixPriority(meshtastic_MeshPacket *p)
} }
/** enqueue a packet, return false if full */ /** enqueue a packet, return false if full */
bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p) bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p, bool *dropped)
{ {
// no space - try to replace a lower priority packet in the queue // no space - try to replace a lower priority packet in the queue
if (queue.size() >= maxLen) { if (queue.size() >= maxLen) {
@ -73,9 +73,16 @@ bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p)
if (!replaced) { if (!replaced) {
LOG_WARN("TX queue is full, and there is no lower-priority packet available to evict in favour of 0x%08x", p->id); LOG_WARN("TX queue is full, and there is no lower-priority packet available to evict in favour of 0x%08x", p->id);
} }
if (dropped) {
*dropped = true;
}
return replaced; return replaced;
} }
if (dropped) {
*dropped = false;
}
// Find the correct position using upper_bound to maintain a stable order // Find the correct position using upper_bound to maintain a stable order
auto it = std::upper_bound(queue.begin(), queue.end(), p, CompareMeshPacketFunc); auto it = std::upper_bound(queue.begin(), queue.end(), p, CompareMeshPacketFunc);
queue.insert(it, p); // Insert packet at the found position queue.insert(it, p); // Insert packet at the found position

View File

@ -19,8 +19,10 @@ class MeshPacketQueue
public: public:
explicit MeshPacketQueue(size_t _maxLen); explicit MeshPacketQueue(size_t _maxLen);
/** enqueue a packet, return false if full */ /** enqueue a packet, return false if full
bool enqueue(meshtastic_MeshPacket *p); * @param dropped Optional pointer to a bool that will be set to true if a packet was dropped
*/
bool enqueue(meshtastic_MeshPacket *p, bool *dropped = nullptr);
/** return true if the queue is empty */ /** return true if the queue is empty */
bool empty(); bool empty();

View File

@ -177,7 +177,12 @@ ErrorCode RadioLibInterface::send(meshtastic_MeshPacket *p)
printPacket("enqueue for send", p); printPacket("enqueue for send", p);
LOG_DEBUG("txGood=%d,txRelay=%d,rxGood=%d,rxBad=%d", txGood, txRelay, rxGood, rxBad); LOG_DEBUG("txGood=%d,txRelay=%d,rxGood=%d,rxBad=%d", txGood, txRelay, rxGood, rxBad);
ErrorCode res = txQueue.enqueue(p) ? ERRNO_OK : ERRNO_UNKNOWN; bool dropped = false;
ErrorCode res = txQueue.enqueue(p, &dropped) ? ERRNO_OK : ERRNO_UNKNOWN;
if (dropped) {
txDrop++;
}
if (res != ERRNO_OK) { // we weren't able to queue it, so we must drop it to prevent leaks if (res != ERRNO_OK) { // we weren't able to queue it, so we must drop it to prevent leaks
packetPool.release(p); packetPool.release(p);
@ -359,11 +364,15 @@ void RadioLibInterface::clampToLateRebroadcastWindow(NodeNum from, PacketId id)
meshtastic_MeshPacket *p = txQueue.remove(from, id, true, false); meshtastic_MeshPacket *p = txQueue.remove(from, id, true, false);
if (p) { if (p) {
p->tx_after = millis() + getTxDelayMsecWeightedWorst(p->rx_snr); p->tx_after = millis() + getTxDelayMsecWeightedWorst(p->rx_snr);
if (txQueue.enqueue(p)) { bool dropped = false;
if (txQueue.enqueue(p, &dropped)) {
LOG_DEBUG("Move existing queued packet to the late rebroadcast window %dms from now", p->tx_after - millis()); LOG_DEBUG("Move existing queued packet to the late rebroadcast window %dms from now", p->tx_after - millis());
} else { } else {
packetPool.release(p); packetPool.release(p);
} }
if (dropped) {
txDrop++;
}
} }
} }

View File

@ -116,6 +116,7 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
* Debugging counts * Debugging counts
*/ */
uint32_t rxBad = 0, rxGood = 0, txGood = 0, txRelay = 0; uint32_t rxBad = 0, rxGood = 0, txGood = 0, txRelay = 0;
uint16_t txDrop = 0;
public: public:
RadioLibInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RadioLibInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst,

View File

@ -121,6 +121,7 @@ meshtastic_Telemetry DeviceTelemetryModule::getLocalStatsTelemetry()
telemetry.variant.local_stats.num_packets_rx = RadioLibInterface::instance->rxGood + RadioLibInterface::instance->rxBad; telemetry.variant.local_stats.num_packets_rx = RadioLibInterface::instance->rxGood + RadioLibInterface::instance->rxBad;
telemetry.variant.local_stats.num_packets_rx_bad = RadioLibInterface::instance->rxBad; telemetry.variant.local_stats.num_packets_rx_bad = RadioLibInterface::instance->rxBad;
telemetry.variant.local_stats.num_tx_relay = RadioLibInterface::instance->txRelay; telemetry.variant.local_stats.num_tx_relay = RadioLibInterface::instance->txRelay;
telemetry.variant.local_stats.num_tx_dropped = RadioLibInterface::instance->txDrop;
} }
#ifdef ARCH_PORTDUINO #ifdef ARCH_PORTDUINO
if (SimRadio::instance) { if (SimRadio::instance) {
@ -128,6 +129,7 @@ meshtastic_Telemetry DeviceTelemetryModule::getLocalStatsTelemetry()
telemetry.variant.local_stats.num_packets_rx = SimRadio::instance->rxGood + SimRadio::instance->rxBad; telemetry.variant.local_stats.num_packets_rx = SimRadio::instance->rxGood + SimRadio::instance->rxBad;
telemetry.variant.local_stats.num_packets_rx_bad = SimRadio::instance->rxBad; telemetry.variant.local_stats.num_packets_rx_bad = SimRadio::instance->rxBad;
telemetry.variant.local_stats.num_tx_relay = SimRadio::instance->txRelay; telemetry.variant.local_stats.num_tx_relay = SimRadio::instance->txRelay;
telemetry.variant.local_stats.num_tx_dropped = SimRadio::instance->txDrop;
} }
#else #else
telemetry.variant.local_stats.heap_total_bytes = memGet.getHeapSize(); telemetry.variant.local_stats.heap_total_bytes = memGet.getHeapSize();

View File

@ -13,7 +13,12 @@ ErrorCode SimRadio::send(meshtastic_MeshPacket *p)
{ {
printPacket("enqueuing for send", p); printPacket("enqueuing for send", p);
ErrorCode res = txQueue.enqueue(p) ? ERRNO_OK : ERRNO_UNKNOWN; bool dropped = false;
ErrorCode res = txQueue.enqueue(p, &dropped) ? ERRNO_OK : ERRNO_UNKNOWN;
if (dropped) {
txDrop++;
}
if (res != ERRNO_OK) { // we weren't able to queue it, so we must drop it to prevent leaks if (res != ERRNO_OK) { // we weren't able to queue it, so we must drop it to prevent leaks
packetPool.release(p); packetPool.release(p);

View File

@ -52,6 +52,7 @@ class SimRadio : public RadioInterface, protected concurrency::NotifiedWorkerThr
* Debugging counts * Debugging counts
*/ */
uint32_t rxBad = 0, rxGood = 0, txGood = 0, txRelay = 0; uint32_t rxBad = 0, rxGood = 0, txGood = 0, txRelay = 0;
uint16_t txDrop = 0;
protected: protected:
/// are _trying_ to receive a packet currently (note - we might just be waiting for one) /// are _trying_ to receive a packet currently (note - we might just be waiting for one)

View File

@ -145,7 +145,7 @@ static const uint8_t A0 = PIN_A0;
#define PIN_GPS_STANDBY (32 + 13) // wakeup pin #define PIN_GPS_STANDBY (32 + 13) // wakeup pin
#define PIN_GPS_PPS (32 + 15) #define PIN_GPS_PPS (32 + 15)
#define GPS_TX_PIN (32 + 10) // L76K module RX PIN #define GPS_TX_PIN (32 + 10) // L76K module RX PIN
#define GPS_RX_PIN (0 + 29) // L76K module TX PIN #define GPS_RX_PIN (0 + 29) // L76K module TX PIN
#define GPS_THREAD_INTERVAL 50 #define GPS_THREAD_INTERVAL 50