1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-07-08 14:48:55 +02:00

Add Diag::SNIFFER so config verbosity of sniffer output

This commit is contained in:
Harald Barth 2025-07-07 20:37:57 +02:00
parent 113a01de43
commit a6c86bc294
6 changed files with 19 additions and 8 deletions

View File

@ -166,7 +166,8 @@ void loop()
DCCPacket p = dccSniffer->fetchPacket(); DCCPacket p = dccSniffer->fetchPacket();
if (p.len() != 0) { if (p.len() != 0) {
if (DCCDecoder::parse(p)) { if (DCCDecoder::parse(p)) {
p.print(Serial); if (Diag::SNIFFER)
p.print();
} }
} }
} }

View File

@ -42,7 +42,10 @@ bool DCCDecoder::parse(DCCPacket &p) {
for (byte n = 0; n < p.len(); n++) for (byte n = 0; n < p.len(); n++)
checksum ^= d[n]; checksum ^= d[n];
if (checksum) { // Result should be zero, if not it's an error! if (checksum) { // Result should be zero, if not it's an error!
DIAG(F("Checksum error")); if (Diag::SNIFFER) {
DIAG(F("Checksum error"));
p.print();
}
return false; return false;
} }

View File

@ -1243,6 +1243,9 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
case "LCN"_hk: // <D LCN ON/OFF> case "LCN"_hk: // <D LCN ON/OFF>
Diag::LCN = onOff; Diag::LCN = onOff;
return true; return true;
case "SNIFFER"_hk: // <D SNIFFER ON/OFF>
Diag::SNIFFER = onOff;
return true;
#endif #endif
#ifndef DISABLE_EEPROM #ifndef DISABLE_EEPROM
case "EEPROM"_hk: // <D EEPROM NumEntries> case "EEPROM"_hk: // <D EEPROM NumEntries>

View File

@ -20,6 +20,7 @@
#ifndef DCCPacket_h #ifndef DCCPacket_h
#define DCCPacket_h #define DCCPacket_h
#include <strings.h> #include <strings.h>
#include "defines.h"
class DCCPacket { class DCCPacket {
public: public:
@ -63,13 +64,15 @@ public:
return true; return true;
return (bcmp(_data, right._data, _len) == 0); return (bcmp(_data, right._data, _len) == 0);
}; };
void print(HardwareSerial &s) { void print() {
s.print("<* DCCPACKET "); static const char hexchars[]="0123456789ABCDEF";
USB_SERIAL.print(F("<* DCCPACKET "));
for (byte n = 0; n< _len; n++) { for (byte n = 0; n< _len; n++) {
s.print(_data[n], HEX); USB_SERIAL.print(hexchars[_data[n]>>4]);
s.print(" "); USB_SERIAL.print(hexchars[_data[n] & 0x0f]);
USB_SERIAL.print(' ');
} }
s.print("*>\n"); USB_SERIAL.print(F("*>\n"));
}; };
inline byte len() {return _len;}; inline byte len() {return _len;};
inline byte *data() {return _data;}; inline byte *data() {return _data;};

View File

@ -27,6 +27,7 @@ bool Diag::WIFI=false;
bool Diag::WITHROTTLE=false; bool Diag::WITHROTTLE=false;
bool Diag::ETHERNET=false; bool Diag::ETHERNET=false;
bool Diag::LCN=false; bool Diag::LCN=false;
bool Diag::SNIFFER=false;
void StringFormatter::diag( const FSH* input...) { void StringFormatter::diag( const FSH* input...) {

View File

@ -30,7 +30,7 @@ class Diag {
static bool WITHROTTLE; static bool WITHROTTLE;
static bool ETHERNET; static bool ETHERNET;
static bool LCN; static bool LCN;
static bool SNIFFER;
}; };
class StringFormatter class StringFormatter