From 2797ca0d1b9c2656a1f1c12c3dc39ff56eee34a3 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 7 Jul 2025 22:12:18 +0200 Subject: [PATCH] Make sniffer more robust against loop() not keeping up. Eliminate fetch flag as the list size does say it all --- Sniffer.cpp | 18 ++++++++++++------ Sniffer.h | 4 ---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Sniffer.cpp b/Sniffer.cpp index 77d1464..2a57afe 100644 --- a/Sniffer.cpp +++ b/Sniffer.cpp @@ -196,19 +196,25 @@ void IRAM_ATTR Sniffer::processInterrupt(int32_t capticks, bool posedge) { inpacket = false; dcclen = currentbyte+1; debugfield = bitfield; - // put it into the out packet - if (fetchflag) { - // not good, should have been fetched - // blink_diag(1); - packeterror(); // or better? + // We have something we want to give to the outpacket queue + // Check length of outpacket queue + if (outpacket.size() > 3) { + // not good, these should have been fetched + // the arbitraty number to check is THREE (see the holy grail) + // blink_diag(1); DO NOT DO THIS HERE -> will crash + packeterror(); // or what to do better? + // take emergency action: + while (!outpacket.empty()) { + outpacket.pop_front(); + } } lastendofpacket = millis(); DCCPacket temppacket(dccbytes, dcclen); if (!(temppacket == prevpacket)) { // we have something new to offer to the fetch routine + // put it into the outpacket queue outpacket.push_back(temppacket); prevpacket = temppacket; - fetchflag = true; } return; } diff --git a/Sniffer.h b/Sniffer.h index 5994c79..10064d7 100644 --- a/Sniffer.h +++ b/Sniffer.h @@ -51,9 +51,6 @@ public: p = outpacket.front(); outpacket.pop_front(); } - if (fetchflag) { - fetchflag = false; // (data has been fetched) - } interrupts(); return p; }; @@ -71,7 +68,6 @@ private: bool inpacket = false; // these vars are used as interface to other parts of sniffer byte halfbitcounter = 0; - bool fetchflag = false; std::list outpacket; DCCPacket prevpacket; volatile unsigned long lastendofpacket = 0; // timestamp millis