diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino
index 8b612a3..33cc23d 100644
--- a/CommandStation-EX.ino
+++ b/CommandStation-EX.ino
@@ -51,10 +51,12 @@
#include "DCCEX.h"
#include "Display_Implementation.h"
+#ifdef ARDUINO_ARCH_ESP32
#include "Sniffer.h"
#include "DCCDecoder.h"
Sniffer *dccSniffer = NULL;
-DCCDecoder *dccDecoder = NULL;
+bool DCCDecoder::active = false;
+#endif // ARDUINO_ARCH_ESP32
#ifdef CPU_TYPE_ERROR
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h
@@ -128,8 +130,9 @@ void setup()
// Start RMFT aka EX-RAIL (ignored if no automnation)
RMFT::begin();
+#ifdef ARDUINO_ARCH_ESP32
dccSniffer = new Sniffer(BOOSTER_INPUT);
- dccDecoder = new DCCDecoder();
+#endif // ARDUINO_ARCH_ESP32
// Invoke any DCC++EX commands in the form "SETUP("xxxx");"" found in optional file mySetup.h.
// This can be used to create turnouts, outputs, sensors etc. through the normal text commands.
@@ -149,14 +152,16 @@ void setup()
void loop()
{
- if (dccSniffer && dccDecoder) {
+#ifdef ARDUINO_ARCH_ESP32
+ if (dccSniffer) {
DCCPacket p = dccSniffer->fetchPacket();
if (p.len() != 0) {
- if (dccDecoder->parse(p)) {
+ if (DCCDecoder::parse(p)) {
p.print(Serial);
}
}
}
+#endif // ARDUINO_ARCH_ESP32
// The main sketch has responsibilities during loop()
diff --git a/DCCDecoder.cpp b/DCCDecoder.cpp
index 03807e0..fb61bda 100644
--- a/DCCDecoder.cpp
+++ b/DCCDecoder.cpp
@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see .
*/
+#ifdef ARDUINO_ARCH_ESP32
#include "DCCDecoder.h"
#include "LocoTable.h"
#include "DCCEXParser.h"
@@ -23,6 +24,8 @@
#include "DCC.h"
bool DCCDecoder::parse(DCCPacket &p) {
+ if (!active)
+ return false;
const byte DECODER_MOBILE = 1;
const byte DECODER_ACCESSORY = 2;
byte decoderType = 0; // use 0 as none
@@ -170,3 +173,4 @@ bool DCCDecoder::parse(DCCPacket &p) {
}
return false;
}
+#endif // ARDUINO_ARCH_ESP32
diff --git a/DCCDecoder.h b/DCCDecoder.h
index 3713c19..cb2a0ee 100644
--- a/DCCDecoder.h
+++ b/DCCDecoder.h
@@ -16,13 +16,15 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see .
*/
+#ifdef ARDUINO_ARCH_ESP32
#include
#include "DCCPacket.h"
class DCCDecoder {
public:
- DCCDecoder() {};
- bool parse(DCCPacket &p);
+ static bool parse(DCCPacket &p);
+ static inline void onoff(bool on) {active = on;};
private:
+ static bool active;
};
-
+#endif // ARDUINO_ARCH_ESP32
diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp
index 6bec5fb..a51280f 100644
--- a/DCCEXParser.cpp
+++ b/DCCEXParser.cpp
@@ -3,7 +3,7 @@
* © 2021 Neil McKechnie
* © 2021 Mike S
* © 2021-2024 Herb Morton
- * © 2020-2023 Harald Barth
+ * © 2020-2025 Harald Barth
* © 2020-2021 M Steve Todd
* © 2020-2021 Fred Decker
* © 2020-2021 Chris Harlow
@@ -120,6 +120,7 @@ Once a new OPCODE is decided upon, update this list.
#include "CamParser.h"
#ifdef ARDUINO_ARCH_ESP32
#include "WifiESP32.h"
+#include "DCCDecoder.h"
#endif
// This macro can't be created easily as a portable function because the
@@ -683,6 +684,14 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
case 'C': // CONFIG
#if defined(ARDUINO_ARCH_ESP32)
// currently this only works on ESP32
+ if (p[0] == "SNIFFER"_hk) { //
+ bool on = false;
+ if (params>1 && p[1] == "ON"_hk) {
+ on = true;
+ }
+ DCCDecoder::onoff(on);
+ return;
+ }
#if defined(HAS_ENOUGH_MEMORY)
if (p[0] == "WIFI"_hk) { //
if (params != 5) // the 5 params 0 to 4 are (kinda): WIFI_hk 0x7777 &SSID 0x7777 &PASSWORD