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:
parent
e6c6f78bb6
commit
6a361872e2
@ -168,7 +168,7 @@ 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);
|
p.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ 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"));
|
DIAG(F("Checksum error:"));
|
||||||
|
p.print();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
DCCPacket.h
13
DCCPacket.h
@ -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;};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user