1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 16:16:13 +01:00

Z21 error fix for turnout feedback

This commit is contained in:
Harald Barth 2024-04-01 11:10:54 +02:00
parent b6a15aa5c3
commit e075df7164
2 changed files with 32 additions and 25 deletions

View File

@ -417,40 +417,46 @@ void Z21Throttle::notifyLocoInfo(byte inMSB, byte inLSB) {
notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_LOCO_INFO, Z21Throttle::replyBuffer, 9, false); notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_LOCO_INFO, Z21Throttle::replyBuffer, 9, false);
} }
// This variant is called from the broadcast function when turnouts change
// from the "inside" where we know the turnout state
void Z21Throttle::notifyTurnoutInfo(uint16_t addr, bool isClosed) { void Z21Throttle::notifyTurnoutInfo(uint16_t addr, bool isClosed) {
char c; notifyTurnoutInfo((byte)((addr-1) >> 8), (byte)((addr-1) & 0xFF), isClosed);
Z21Throttle::replyBuffer[0] = (byte)(addr >> 8); }
Z21Throttle::replyBuffer[1] = (byte)(addr & 0xFF);
if (isClosed) { // This variant is called from the Xnet protocol when the client queries
Z21Throttle::replyBuffer[2] = B00000010; // the state of a turnout (which may or may not exist)
c = 'c'; void Z21Throttle::notifyTurnoutInfo(byte inMSB, byte inLSB) {
} else { uint16_t addr = (inMSB << 8) + inLSB + 1;
Z21Throttle::replyBuffer[2] = B00000001; Turnout *tt = Turnout::get(addr);
c = 't'; if (tt) {
notifyTurnoutInfo(inMSB, inLSB, tt->isClosed());
return;
} }
// if the tt does not exist we fall through with replyBuffer set to invalid
Z21Throttle::replyBuffer[0] = inMSB; // turnout address msb
Z21Throttle::replyBuffer[1] = inLSB; // turnout address lsb
Z21Throttle::replyBuffer[2] = B00000011; // 000000ZZ ZZ: 00=not-switched 01=pos1 10=pos2 11=invalid
if (Diag::Z21THROTTLE) if (Diag::Z21THROTTLE)
DIAG(F("Z21 Throttle %d : Turnoutinfo %d %c"), clientid, addr, c); DIAG(F("Z21 Throttle %d : Turnoutinfo %d (invalid)"), clientid, addr);
notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_TURNOUT_INFO, Z21Throttle::replyBuffer, 3, false); notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_TURNOUT_INFO, Z21Throttle::replyBuffer, 3, false);
} }
void Z21Throttle::notifyTurnoutInfo(byte inMSB, byte inLSB) { // This variant is called when we know that turnout exists and it's state.
Z21Throttle::replyBuffer[0] = inMSB; // turnout address msb void Z21Throttle::notifyTurnoutInfo(byte inMSB, byte inLSB, bool isClosed) {
Z21Throttle::replyBuffer[1] = inLSB; // turnout address lsb Z21Throttle::replyBuffer[0] = inMSB;
Z21Throttle::replyBuffer[2] = B00000011; // 000000ZZ ZZ : 00 not switched 01 pos1 10 pos2 11 invalid Z21Throttle::replyBuffer[1] = inLSB;
char c = '?'; char c;
uint16_t addr = (inMSB << 8) + inLSB + 1; if (isClosed) {
Turnout *tt = Turnout::get(addr); Z21Throttle::replyBuffer[2] = B00000010; // 000000ZZ ZZ: 00=not-switched 01=pos1 10=pos2 11=invalid
if (tt) { // if the tt does not exist we fall through with replyBuffer set to invalid
if (tt->isClosed()) {
Z21Throttle::replyBuffer[2] = B00000010;
c = 'c'; c = 'c';
} else { } else {
Z21Throttle::replyBuffer[2] = B00000001; Z21Throttle::replyBuffer[2] = B00000001;
c = 't'; c = 't';
} }
} if (Diag::Z21THROTTLE) {
if (Diag::Z21THROTTLE) uint16_t addr = (inMSB << 8) + inLSB + 1;
DIAG(F("Z21 Throttle %d : Turnoutinfo %d %c"), clientid, addr, c); DIAG(F("Z21 Throttle %d : Turnoutinfo %d %c"), clientid, addr, c);
}
notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_TURNOUT_INFO, Z21Throttle::replyBuffer, 3, false); notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_TURNOUT_INFO, Z21Throttle::replyBuffer, 3, false);
} }

View File

@ -125,6 +125,7 @@ class Z21Throttle {
void notifyLocoInfo(byte inMSB, byte inLSB); void notifyLocoInfo(byte inMSB, byte inLSB);
void notifyTurnoutInfo(uint16_t addr, bool isClosed); void notifyTurnoutInfo(uint16_t addr, bool isClosed);
void notifyTurnoutInfo(byte inMSB, byte inLSB); void notifyTurnoutInfo(byte inMSB, byte inLSB);
void notifyTurnoutInfo(byte inMSB, byte inLSB, bool isClosed);
void notifySensor(uint16_t addr); void notifySensor(uint16_t addr);
void notifySensor(uint16_t addr, bool state); void notifySensor(uint16_t addr, bool state);
void notifyLocoMode(byte inMSB, byte inLSB); void notifyLocoMode(byte inMSB, byte inLSB);