1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-02-18 15:06:03 +01:00

Make Z21 diag selectable from DCCEXParser

This commit is contained in:
Harald Barth 2024-04-01 22:12:05 +02:00
parent 7ebbe8bed2
commit d21aef533b
4 changed files with 40 additions and 10 deletions

View File

@ -1117,6 +1117,21 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
return true;
#ifdef HAS_ENOUGH_MEMORY
#ifdef Z21_PROTOCOL
case "Z21THROTTLE"_hk: // <D Z21THROTTLE ON/OFF>
case "Z21THR"_hk: // <D Z21THR ON/OFF>
Diag::Z21THROTTLE = onOff;
return true;
case "Z21THROTTLEVERBOSE"_hk: // <D Z21THROTTLEVERBOSE ON/OFF>
case "Z21THRV"_hk: // <D Z21THV ON/OFF>
Diag::Z21THROTTLEVERBOSE = onOff;
return true;
case "Z21THROTTLEDATA"_hk: // <D Z21THROTTLEDATA ON/OFF>
case "Z21THRD"_hk: // <D Z21THD ON/OFF>
Diag::Z21THROTTLEDATA = onOff;
return true;
#endif // Z21_PROTOCOL
case "WIFI"_hk: // <D WIFI ON/OFF>
Diag::WIFI = onOff;
return true;

View File

@ -25,9 +25,9 @@ bool Diag::ACK=false;
bool Diag::CMD=false;
bool Diag::WIFI=false;
bool Diag::WITHROTTLE=false;
bool Diag::Z21THROTTLE=true;
bool Diag::Z21THROTTLEVERBOSE=true;
bool Diag::Z21THROTTLEDATA=true;
bool Diag::Z21THROTTLE=false;
bool Diag::Z21THROTTLEVERBOSE=false;
bool Diag::Z21THROTTLEDATA=false;
bool Diag::ETHERNET=false;
bool Diag::LCN=false;

View File

@ -123,7 +123,6 @@
return true;
}
#define DIAG_IO
// Static setClosed function is invoked from close(), throw() etc. to perform the
// common parts of the turnout operation. Code which is specific to a turnout
// type should be placed in the virtual function setClosedInternal(bool) which is

View File

@ -707,27 +707,43 @@ bool Z21Throttle::parse(byte *networkPacket, int len) {
int lengthData = GETINT16(p);
l -= lengthData;
if (p == networkPacket && lengthData != len) {
diagPacket(networkPacket, len);
}
// This is not an error, just several X bus packets in one UDP packet
if (Diag::Z21THROTTLEDATA) // only care if diag is on
if (p == networkPacket && lengthData != len) {
diagPacket(networkPacket, len);
}
// This is a client error, report always
if (l < 0) {
DIAG(F("ERROR: Xbus data exceeds UDP packet size: l < 0 pos=%d, l=%d"), p-networkPacket, l);
diagPacket(p, len);
return false;
}
// This is kinda client error but not harmful
// Report if diag and we are done with parsing this UDP packet
if (l > 0 && lengthData < 4) {
DIAG(F("WARNING: Xbus data does not fill UDP packet size: l > 0 pos=%d, l=%d, lengthData=%d"),
p-networkPacket, l, lengthData);
diagPacket(p, len);
// The client did send a too long UDP packet which was not filled with X bus packet(s)
// The Z21 App does this sometimes
if (Diag::Z21THROTTLEDATA) {
DIAG(F("WARNING: Xbus data does not fill UDP packet size: l > 0 pos=%d, l=%d, lengthData=%d"),
p-networkPacket, l, lengthData);
diagPacket(p, len);
}
return true;
}
// length of the data = total length - length of length (!) - length of header
// Error, this should not happen
lengthData -= 4;
if (lengthData < 0) {
DIAG(F("ERROR: lengthData < 0 SHOULD NOT GET HERE"));
diagPacket(networkPacket, len);
return false;
}
// All checks done, start looking at packet content
p += 2;
Header = GETINT16(p);
p += 2;