From 5846e0fe2384f159927fcfc691ddd3839188ca4a Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 8 Apr 2022 11:41:50 +0100 Subject: [PATCH] J command parsing JA JR JT commands parsed EXRAIL sets hidden turnout state HIDDEN description macro Turnouts hidden flag bit UNO seems OK, MEGA UNTESTED --- DCCEXParser.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++-- DCCEXParser.h | 1 + EXRAIL2.cpp | 10 +++++--- EXRAIL2.h | 3 ++- EXRAILMacros.h | 4 +++ Turnouts.h | 12 ++++++--- 6 files changed, 86 insertions(+), 10 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 11a2796..bc2e759 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -37,6 +37,7 @@ #include "CommandDistributor.h" #include "EEStore.h" #include "DIAG.h" +#include "EXRAIL2.h" #include //////////////////////////////////////////////////////////////////////////////// @@ -74,8 +75,10 @@ const int16_t HASH_KEYWORD_SPEED28 = -17064; const int16_t HASH_KEYWORD_SPEED128 = 25816; const int16_t HASH_KEYWORD_SERVO=27709; const int16_t HASH_KEYWORD_VPIN=-415; -const int16_t HASH_KEYWORD_C=67; -const int16_t HASH_KEYWORD_T=84; +const int16_t HASH_KEYWORD_A='A'; +const int16_t HASH_KEYWORD_C='C'; +const int16_t HASH_KEYWORD_R='R'; +const int16_t HASH_KEYWORD_T='T'; const int16_t HASH_KEYWORD_LCN = 15137; const int16_t HASH_KEYWORD_HAL = 10853; const int16_t HASH_KEYWORD_SHOW = -21309; @@ -509,6 +512,57 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) } break; + case 'J' : // throttle info access + { + if ((params<1) | (params>2)) break; // + int16_t id=(params==2)?p[1]:0; + switch(p[0]) { + case HASH_KEYWORD_A: // returns automations/routes + StringFormatter::send(stream, F("\n")); + return; + case HASH_KEYWORD_R: // returns rosters + StringFormatter::send(stream, F("\n")); + return; + case HASH_KEYWORD_T: // returns turnout list + StringFormatter::send(stream, F(" + for ( Turnout * t=Turnout::first(); t; t=t->next()) { + if (t->isHidden()) continue; + StringFormatter::send(stream, F(" %c%d"), + t->isThrown()?'-':' ',t->getId()); + } + } + else { // + Turnout * t=Turnout::get(id); + if (t && !t->isHidden()) + StringFormatter::send(stream, F(" %d \"%S\""), + id, +#ifdef EXRAIL_ACTIVE + RMFT2::getTurnoutDescription(id) +#else + F("") +#endif + ); + } + StringFormatter::send(stream, F(">\n")); + return; + default: break; + } // switch(p[1]) + break; // case J + } + default: //anything else will diagnose and drop out to DIAG(F("Opcode=%c params=%d"), opcode, params); for (int i = 0; i < params; i++) @@ -521,6 +575,14 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) StringFormatter::send(stream, F("\n")); } +void DCCEXParser::sendFlashList(Print * stream,const int16_t flashList[]) { + for (int16_t i=0;;i+=2) { + int16_t value=GETFLASHW(flashList+i); + if (value==0) return; + StringFormatter::send(stream,F(" %d"),value); + } +} + bool DCCEXParser::parseZ(Print *stream, int16_t params, int16_t p[]) { diff --git a/DCCEXParser.h b/DCCEXParser.h index 5761eb0..227e3f0 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -70,6 +70,7 @@ struct DCCEXParser static FILTER_CALLBACK filterRMFTCallback; static AT_COMMAND_CALLBACK atCommandCallback; static void funcmap(int16_t cab, byte value, byte fstart, byte fstop); + static void sendFlashList(Print * stream,const int16_t flashList[]); }; diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 1a4f536..583bbd9 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -196,7 +196,7 @@ int16_t LookList::find(int16_t value) { VPIN id=operand; int addr=GET_OPERAND(1); byte subAddr=GET_OPERAND(2); - DCCTurnout::create(id,addr,subAddr); + setTurnoutHiddenState(DCCTurnout::create(id,addr,subAddr)); break; } @@ -206,14 +206,14 @@ int16_t LookList::find(int16_t value) { int activeAngle=GET_OPERAND(2); int inactiveAngle=GET_OPERAND(3); int profile=GET_OPERAND(4); - ServoTurnout::create(id,pin,activeAngle,inactiveAngle,profile); + setTurnoutHiddenState(ServoTurnout::create(id,pin,activeAngle,inactiveAngle,profile)); break; } case OPCODE_PINTURNOUT: { VPIN id=operand; VPIN pin=GET_OPERAND(1); - VpinTurnout::create(id,pin); + setTurnoutHiddenState(VpinTurnout::create(id,pin)); break; } @@ -257,6 +257,10 @@ int16_t LookList::find(int16_t value) { new RMFT2(0); // add the startup route } +void RMFT2::setTurnoutHiddenState(Turnout * t) { + t->setHidden(GETFLASH(getTurnoutDescription(t->getId()))==0x01); +} + // This filter intercepts <> commands to do the following: // - Implement RMFT specific commands/diagnostics // - Reject/modify JMRI commands that would interfere with RMFT processing diff --git a/EXRAIL2.h b/EXRAIL2.h index 97e0d98..2d3807b 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -22,6 +22,7 @@ #define EXRAIL2_H #include "FSH.h" #include "IODevice.h" +#include "Turnouts.h" // The following are the operation codes (or instructions) for a kind of virtual machine. // Each instruction is normally 3 bytes long with an operation code followed by a parameter. @@ -110,7 +111,7 @@ private: static bool getFlag(VPIN id,byte mask); static int16_t progtrackLocoId; static void doSignal(VPIN id,bool red, bool amber, bool green); - + static void setTurnoutHiddenState(Turnout * t); static RMFT2 * loopTask; static RMFT2 * pausingTask; void delayMe(long millisecs); diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 60fd557..07405fe 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -49,7 +49,11 @@ // CAUTION: The macros below are multiple passed over myAutomation.h + +// helper macro for turnout descriptions, creates NULL for missing description #define O_DESC(id, desc) case id: return ("" desc)[0]?F("" desc):NULL; +// helper macro for turnout description as HIDDEN +#define HIDDEN "\0x01" // Pass 1 Implements aliases #include "EXRAIL2MacroReset.h" diff --git a/Turnouts.h b/Turnouts.h index e394c85..3d1f0bc 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -3,7 +3,7 @@ * © 2021 M Steve Todd * © 2021 Fred Decker * © 2020-2021 Harald Barth - * © 2020-2021 Chris Harlow + * © 2020-2022 Chris Harlow * © 2013-2016 Gregg E. Berman * All rights reserved. * @@ -61,7 +61,8 @@ protected: struct { bool closed : 1; bool _rfu: 2; - uint8_t turnoutType : 5; + bool hidden: 1; + uint8_t turnoutType : 4; }; uint8_t flags; }; @@ -83,6 +84,7 @@ protected: _turnoutData.id = id; _turnoutData.turnoutType = turnoutType; _turnoutData.closed = closed; + _turnoutData.hidden=false; add(this); } @@ -104,11 +106,11 @@ protected: * Static functions */ - static Turnout *get(uint16_t id); static void add(Turnout *tt); public: + static Turnout *get(uint16_t id); /* * Static data */ @@ -120,6 +122,8 @@ public: */ inline bool isClosed() { return _turnoutData.closed; }; inline bool isThrown() { return !_turnoutData.closed; } + inline bool isHidden() { return _turnoutData.hidden; } + inline void setHidden(bool h) { _turnoutData.hidden=h; } inline bool isType(uint8_t type) { return _turnoutData.turnoutType == type; } inline uint16_t getId() { return _turnoutData.id; } inline Turnout *next() { return _nextTurnout; } @@ -169,7 +173,7 @@ public: #endif static void printAll(Print *stream) { for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) - StringFormatter::send(stream, F("\n"),tt->getId(), tt->isThrown()); + if (!tt->isHidden()) StringFormatter::send(stream, F("\n"),tt->getId(), tt->isThrown()); }