1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-06-29 10:35:24 +02:00

DCCPacket: Print to USB_SERIAL in HEX

This commit is contained in:
Harald Barth 2025-06-28 21:55:30 +02:00
parent e6c6f78bb6
commit 6a361872e2
3 changed files with 11 additions and 7 deletions

View File

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

View File

@ -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;
}

View File

@ -20,6 +20,7 @@
#ifndef DCCPacket_h
#define DCCPacket_h
#include <strings.h>
#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;};