diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index ba00b25..61b23ec 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -168,7 +168,7 @@ void loop() DCCPacket p = dccSniffer->fetchPacket(); if (p.len() != 0) { if (DCCDecoder::parse(p)) { - p.print(Serial); + p.print(); } } } diff --git a/DCCDecoder.cpp b/DCCDecoder.cpp index 1304367..6e7d858 100644 --- a/DCCDecoder.cpp +++ b/DCCDecoder.cpp @@ -42,7 +42,8 @@ bool DCCDecoder::parse(DCCPacket &p) { for (byte n = 0; n < p.len(); n++) checksum ^= d[n]; if (checksum) { // Result should be zero, if not it's an error! - DIAG(F("Checksum error")); + DIAG(F("Checksum error:")); + p.print(); return false; } diff --git a/DCCPacket.h b/DCCPacket.h index e754142..8258378 100644 --- a/DCCPacket.h +++ b/DCCPacket.h @@ -20,6 +20,7 @@ #ifndef DCCPacket_h #define DCCPacket_h #include +#include "defines.h" class DCCPacket { public: @@ -63,13 +64,15 @@ public: return true; return (bcmp(_data, right._data, _len) == 0); }; - void print(HardwareSerial &s) { - s.print("<* DCCPACKET "); + void print() { + static const char hexchars[]="0123456789ABCDEF"; + USB_SERIAL.print(F("<* DCCPACKET ")); for (byte n = 0; n< _len; n++) { - s.print(_data[n], HEX); - s.print(" "); + USB_SERIAL.print(hexchars[_data[n]>>4]); + 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 *data() {return _data;};