1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-07-10 15:48:54 +02:00

Make sniffer more robust against loop() not keeping up. Eliminate fetch flag as the list size does say it all

This commit is contained in:
Harald Barth 2025-07-07 22:12:18 +02:00
parent a6c86bc294
commit 2797ca0d1b
2 changed files with 12 additions and 10 deletions

View File

@ -196,19 +196,25 @@ void IRAM_ATTR Sniffer::processInterrupt(int32_t capticks, bool posedge) {
inpacket = false; inpacket = false;
dcclen = currentbyte+1; dcclen = currentbyte+1;
debugfield = bitfield; debugfield = bitfield;
// put it into the out packet // We have something we want to give to the outpacket queue
if (fetchflag) { // Check length of outpacket queue
// not good, should have been fetched if (outpacket.size() > 3) {
// blink_diag(1); // not good, these should have been fetched
packeterror(); // or better? // 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(); lastendofpacket = millis();
DCCPacket temppacket(dccbytes, dcclen); DCCPacket temppacket(dccbytes, dcclen);
if (!(temppacket == prevpacket)) { if (!(temppacket == prevpacket)) {
// we have something new to offer to the fetch routine // we have something new to offer to the fetch routine
// put it into the outpacket queue
outpacket.push_back(temppacket); outpacket.push_back(temppacket);
prevpacket = temppacket; prevpacket = temppacket;
fetchflag = true;
} }
return; return;
} }

View File

@ -51,9 +51,6 @@ public:
p = outpacket.front(); p = outpacket.front();
outpacket.pop_front(); outpacket.pop_front();
} }
if (fetchflag) {
fetchflag = false; // (data has been fetched)
}
interrupts(); interrupts();
return p; return p;
}; };
@ -71,7 +68,6 @@ private:
bool inpacket = false; bool inpacket = false;
// these vars are used as interface to other parts of sniffer // these vars are used as interface to other parts of sniffer
byte halfbitcounter = 0; byte halfbitcounter = 0;
bool fetchflag = false;
std::list<DCCPacket> outpacket; std::list<DCCPacket> outpacket;
DCCPacket prevpacket; DCCPacket prevpacket;
volatile unsigned long lastendofpacket = 0; // timestamp millis volatile unsigned long lastendofpacket = 0; // timestamp millis