From c5045e4cacc7cefd7366e1b5846c337c7d1b635d Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 19 Jun 2020 09:19:41 +0100 Subject: [PATCH] Implement <1 MAIN> etc. --- DCCEXParser.cpp | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 96bb80a..58d755e 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -11,6 +11,9 @@ const char VERSION[] PROGMEM ="99.666"; +const int HASH_KEYWORD_PROG=-29718; +const int HASH_KEYWORD_MAIN=11339; + int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; @@ -84,6 +87,12 @@ void DCCEXParser::loop(Stream & stream) { runningValue=10*runningValue+(hot-'0'); break; } + if (hot>='A' && hot<='Z') { + // Since JMRI got modified to send keywords in some rare cases, we need this + // Super Kluge to turn keywords into a hash value that can be recognised later + runningValue = ((runningValue << 5) + runningValue) ^ hot; + break; + } result[parameterCount] = runningValue * (signNegative ?-1:1); parameterCount++; state=1; @@ -164,18 +173,32 @@ void DCCEXParser::parse(Print & stream, const char *com) { DCC::readCV(p[0],callback_R); return; - case '1': // POWERON <1> - DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON); - DCCWaveform::progTrack.setPowerMode(POWERMODE::ON); - StringFormatter::send(stream,F("")); - return; - - case '0': // POWEROFF <0> - DCCWaveform::mainTrack.setPowerMode(POWERMODE::OFF); - DCCWaveform::progTrack.setPowerMode(POWERMODE::OFF); - StringFormatter::send(stream,F("")); - return; - + case '1': // POWERON <1 [MAIN|PROG]> + case '0': // POWEROFF <0 [MAIN | PROG] > + if (params>1) break; + { + POWERMODE mode= opcode=='1'?POWERMODE::ON:POWERMODE::OFF; + if (params==0) { + DCCWaveform::mainTrack.setPowerMode(mode); + DCCWaveform::progTrack.setPowerMode(mode); + StringFormatter::send(stream,F(""),opcode); + return; + } + if (p[0]==HASH_KEYWORD_MAIN) { + DCCWaveform::mainTrack.setPowerMode(mode); + StringFormatter::send(stream,F(""),opcode); + return; + } + if (p[0]==HASH_KEYWORD_PROG) { + DCCWaveform::progTrack.setPowerMode(mode); + StringFormatter::send(stream,F(""),opcode); + return; + } + DIAG(F("keyword hash=%d\n"),p[0]); + break; + } + return; + case 'c': // READ CURRENT StringFormatter::send(stream,F(""), DCCWaveform::mainTrack.getLastCurrent()); return;