Skip to content

Commit 0e6bb17

Browse files
committed
use std::list to cache outpackets from sniffer
1 parent 0b8d129 commit 0e6bb17

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Sniffer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ void IRAM_ATTR Sniffer::processInterrupt(int32_t capticks, bool posedge) {
192192
packeterror(); // or better?
193193
}
194194
DCCPacket temppacket(dccbytes, dcclen);
195-
if (true) { //if (!(temppacket == outpacket)) {
196-
// we have something new to fetch
197-
outpacket = temppacket;
195+
if (!(temppacket == prevpacket)) {
196+
// we have something new to offer to the fetch routine
197+
outpacket.push_back(temppacket);
198+
prevpacket = temppacket;
198199
fetchflag = true;
199200
}
200201
return;

Sniffer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
#ifdef ARDUINO_ARCH_ESP32
2020
#include <Arduino.h>
21+
#include <list>
2122
#include "driver/mcpwm.h"
2223
#include "soc/mcpwm_struct.h"
2324
#include "soc/mcpwm_reg.h"
@@ -46,8 +47,11 @@ class Sniffer {
4647
// packet with length 0 (which is no packet)
4748
DCCPacket p;
4849
noInterrupts();
50+
if (!outpacket.empty()) {
51+
p = outpacket.front();
52+
outpacket.pop_front();
53+
}
4954
if (fetchflag) {
50-
p = outpacket;
5155
fetchflag = false; // (data has been fetched)
5256
}
5357
interrupts();
@@ -67,6 +71,7 @@ class Sniffer {
6771
// these vars are used as interface to other parts of sniffer
6872
byte halfbitcounter = 0;
6973
bool fetchflag = false;
70-
DCCPacket outpacket;
74+
std::list<DCCPacket> outpacket;
75+
DCCPacket prevpacket;
7176
};
7277
#endif

0 commit comments

Comments
 (0)