From 08cfe41cf359bb2964925e0dcf982e829c0f4a7e Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Tue, 24 Aug 2021 22:18:51 +0100 Subject: [PATCH] Revert to original DCC++ Classic Turnout command polarity. Revert to command being 'throw' and being 'close', for turnouts. --- DCCEXParser.cpp | 11 +++-------- Turnouts.cpp | 26 ++++++++++---------------- config.example.h | 11 ----------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index a6a68d8..f44df2f 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -679,22 +679,17 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[]) { bool state = false; switch (p[1]) { - // By default turnout command uses 0=throw, 1=close, - // but legacy DCC++ behaviour is 1=throw, 0=close. + // Turnout messages use 1=throw, 0=close. case 0: - state = Turnout::useClassicTurnoutCommands; - break; - case 1: - state = !Turnout::useClassicTurnoutCommands; - break; case HASH_KEYWORD_C: state = true; break; + case 1: case HASH_KEYWORD_T: state= false; break; default: - return false; + return false; // Invalid parameter } if (!Turnout::setClosed(p[0], state)) return false; diff --git a/Turnouts.cpp b/Turnouts.cpp index 8c022d0..552cd9d 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -42,12 +42,6 @@ * Public static data */ int Turnout::turnoutlistHash = 0; - - #if defined(USE_RCN_213_TURNOUT_COMMANDS) - const bool Turnout::useClassicTurnoutCommands = false; - #else - const bool Turnout::useClassicTurnoutCommands = true; - #endif /* * Protected static functions @@ -75,10 +69,9 @@ } // For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed; - // if consistency with RCN-213 has been selected, it is 0 for thrown and 1 for closed. void Turnout::printState(Print *stream) { StringFormatter::send(stream, F("\n"), - _turnoutData.id, _turnoutData.closed ^ useClassicTurnoutCommands); + _turnoutData.id, !_turnoutData.closed); } // Remove nominated turnout from turnout linked list and delete the object. @@ -207,7 +200,7 @@ return tt; } - // Display, on the specified stream, the current state of the turnout (1 or 0). + // Display, on the specified stream, the current state of the turnout (1=thrown or 0=closed). void Turnout::printState(uint16_t id, Print *stream) { Turnout *tt = get(id); if (!tt) tt->printState(stream); @@ -281,12 +274,11 @@ return tt; } - // For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed; - // if consistency with RCN-213 has been selected, it is 0 for thrown and 1 for closed. + // For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed void ServoTurnout::print(Print *stream) { StringFormatter::send(stream, F("\n"), _turnoutData.id, _servoTurnoutData.vpin, _servoTurnoutData.thrownPosition, _servoTurnoutData.closedPosition, _servoTurnoutData.profile, - _turnoutData.closed ^ useClassicTurnoutCommands); + !_turnoutData.closed); } // ServoTurnout-specific code for throwing or closing a servo turnout. @@ -373,11 +365,11 @@ void DCCTurnout::print(Print *stream) { StringFormatter::send(stream, F("\n"), _turnoutData.id, (((_dccTurnoutData.address-1) >> 2)+1), ((_dccTurnoutData.address-1) & 3), - _turnoutData.closed ^ useClassicTurnoutCommands); + !_turnoutData.closed); // Also report using classic DCC++ syntax for DCC accessory turnouts, since JMRI expects this. StringFormatter::send(stream, F("\n"), _turnoutData.id, (((_dccTurnoutData.address-1) >> 2)+1), ((_dccTurnoutData.address-1) & 3), - _turnoutData.closed ^ useClassicTurnoutCommands); + !_turnoutData.closed); } bool DCCTurnout::setClosedInternal(bool close) { @@ -447,9 +439,10 @@ return tt; } + // Report 1 for thrown, 0 for closed. void VpinTurnout::print(Print *stream) { StringFormatter::send(stream, F("\n"), _turnoutData.id, _vpinTurnoutData.vpin, - _turnoutData.closed ^ useClassicTurnoutCommands); + !_turnoutData.closed); } bool VpinTurnout::setClosedInternal(bool close) { @@ -511,8 +504,9 @@ //void save() override { } //static Turnout *load(struct TurnoutData *turnoutData) { + // Report 1 for thrown, 0 for closed. void LCNTurnout::print(Print *stream) { StringFormatter::send(stream, F("\n"), _turnoutData.id, - _turnoutData.closed ^ useClassicTurnoutCommands); + !_turnoutData.closed); } diff --git a/config.example.h b/config.example.h index 3575cb0..6c5c69a 100644 --- a/config.example.h +++ b/config.example.h @@ -141,15 +141,4 @@ The configuration file for DCC-EX Command Station // don't add it to your config.h. #define DCC_TURNOUTS_RCN_213 -// In addition to the above, there is an option to allow the values in the commands -// sent and received from JMRI to be changed to be consistent with the definition in -// RCN-213. In DCC++ Classic and in previous versions of DCC++EX, a command -// requested a 'throw' and requested a 'close'. -// The macro below, when present, allows this behaviour to be reversed so that a -// requests the turnout to 'close' and requests it to 'throw'. -// This should only be used if the command processor (JMRI) writing to the serial port -// supports it, otherwise turnout operation commands received over the serial port -// will be reversed. -//#define USE_RCN_213_TURNOUT_COMMANDS - /////////////////////////////////////////////////////////////////////////////////////