From 4e1fad48325608888da61a2e30f9068366f0139e Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 21 Nov 2023 15:37:08 +0100 Subject: [PATCH] Trackmanager consolidate getModeName --- CommandDistributor.cpp | 4 +-- CommandDistributor.h | 2 +- EXRAILMacros.h | 16 +++++------ TrackManager.cpp | 63 ++++++++++++++++++++---------------------- TrackManager.h | 2 +- 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index fa70e0c..1f11e28 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -275,8 +275,8 @@ void CommandDistributor::broadcastRaw(clientType type, char * msg) { broadcastReply(type, F("%s"),msg); } -void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr) { - broadcastReply(COMMAND_TYPE, format, trackLetter, dcAddr); +void CommandDistributor::broadcastTrackState(const FSH* format, byte trackLetter, const FSH *modename, int16_t dcAddr) { + broadcastReply(COMMAND_TYPE, format, trackLetter, modename, dcAddr); } void CommandDistributor::broadcastRouteState(uint16_t routeId, byte state ) { diff --git a/CommandDistributor.h b/CommandDistributor.h index 359c0fe..e4dff5d 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -55,7 +55,7 @@ public : static int16_t retClockTime(); static void broadcastPower(); static void broadcastRaw(clientType type,char * msg); - static void broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr); + static void broadcastTrackState(const FSH* format,byte trackLetter, const FSH* modename, int16_t dcAddr); template static void broadcastReply(clientType type, Targs... msg); static void forget(byte clientId); static void broadcastRouteState(uint16_t routeId,byte state); diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 6024290..8edbd2b 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -121,14 +121,14 @@ const byte RMFT2::compileFeatures = 0 #include "EXRAIL2MacroReset.h" #undef ROUTE #define ROUTE(id, description) id, -const int16_t HIGHFLASH RMFT2::routeIdList[]= { +const int16_t HIGHFLASH const RMFT2::routeIdList[]= { #include "myAutomation.h" INT16_MAX}; // Pass 2a create throttle automation list #include "EXRAIL2MacroReset.h" #undef AUTOMATION #define AUTOMATION(id, description) id, -const int16_t HIGHFLASH RMFT2::automationIdList[]= { +const int16_t HIGHFLASH const RMFT2::automationIdList[]= { #include "myAutomation.h" INT16_MAX}; @@ -150,7 +150,7 @@ const FSH * RMFT2::getRouteDescription(int16_t id) { const int StringMacroTracker1=__COUNTER__; #define THRUNGE(msg,mode) \ case (__COUNTER__ - StringMacroTracker1) : {\ - static const char HIGHFLASH thrunge[]=msg;\ + static const char HIGHFLASH const thrunge[]=msg;\ strfar=(uint32_t)GETFARPTR(thrunge);\ tmode=mode;\ break;\ @@ -186,7 +186,7 @@ case (__COUNTER__ - StringMacroTracker1) : {\ #undef LCD #define LCD(id,msg) \ case (__COUNTER__ - StringMacroTracker1) : {\ - static const char HIGHFLASH thrunge[]=msg;\ + static const char HIGHFLASH const thrunge[]=msg;\ strfar=(uint32_t)GETFARPTR(thrunge);\ tmode=thrunge_lcd; \ lcdid=id;\ @@ -195,7 +195,7 @@ case (__COUNTER__ - StringMacroTracker1) : {\ #undef SCREEN #define SCREEN(display,id,msg) \ case (__COUNTER__ - StringMacroTracker1) : {\ - static const char HIGHFLASH thrunge[]=msg;\ + static const char HIGHFLASH const thrunge[]=msg;\ strfar=(uint32_t)GETFARPTR(thrunge);\ tmode=(thrunger)(thrunge_lcd+display); \ lcdid=id;\ @@ -274,7 +274,7 @@ const byte RMFT2::rosterNameCount=0 #include "EXRAIL2MacroReset.h" #undef ROSTER #define ROSTER(cabid,name,funcmap...) cabid, -const int16_t HIGHFLASH RMFT2::rosterIdList[]={ +const int16_t HIGHFLASH const RMFT2::rosterIdList[]={ #include "myAutomation.h" INT16_MAX}; @@ -314,7 +314,7 @@ const FSH * RMFT2::getRosterFunctions(int16_t id) { #undef VIRTUAL_SIGNAL #define VIRTUAL_SIGNAL(id) id,0,0,0, -const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { +const HIGHFLASH int16_t const RMFT2::SignalDefinitions[] = { #include "myAutomation.h" 0,0,0,0 }; @@ -503,7 +503,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; // Build RouteCode const int StringMacroTracker2=__COUNTER__; -const HIGHFLASH byte RMFT2::RouteCode[] = { +const HIGHFLASH byte const RMFT2::RouteCode[] = { #include "myAutomation.h" OPCODE_ENDTASK,0,0,OPCODE_ENDEXRAIL,0,0 }; diff --git a/TrackManager.cpp b/TrackManager.cpp index 58a5c30..a7998f4 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -397,46 +397,58 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[]) return false; } -// null stream means send to commandDistributor for broadcast -void TrackManager::streamTrackState(Print* stream, byte t) { - if (track[t]==NULL) return; - auto format=F("<= %d XXX>\n"); - TRACK_MODE tm = track[t]->getMode(); +const FSH* TrackManager::getModeName(TRACK_MODE tm) { + const FSH *modename=F("---"); + if (tm & TRACK_MODE_MAIN) { if(tm & TRACK_MODE_AUTOINV) - format=F("<= %c MAIN A>\n"); + modename=F("MAIN A"); else if (tm & TRACK_MODE_INV) - format=F("<= %c MAIN I>\n"); + modename=F("MAIN I>\n"); else - format=F("<= %c MAIN>\n"); + modename=F("MAIN"); } #ifndef DISABLE_PROG else if (tm & TRACK_MODE_PROG) - format=F("<= %c PROG>\n"); + modename=F("PROG"); #endif else if (tm & TRACK_MODE_NONE) - format=F("<= %c NONE>\n"); + modename=F("NONE"); else if(tm & TRACK_MODE_EXT) - format=F("<= %c EXT>\n"); + modename=F("EXT"); else if(tm & TRACK_MODE_BOOST) { if(tm & TRACK_MODE_AUTOINV) - format=F("<= %c B A>\n"); + modename=F("B A"); else if (tm & TRACK_MODE_INV) - format=F("<= %c B I>\n"); + modename=F("B I"); else - format=F("<= %c B>\n"); + modename=F("B"); } else if (tm & TRACK_MODE_DC) { if (tm & TRACK_MODE_INV) - format=F("<= %c DCX %d>\n"); + modename=F("DCX"); else - format=F("<= %c DC %d>\n"); + modename=F("DC"); } + return modename; +} +// null stream means send to commandDistributor for broadcast +void TrackManager::streamTrackState(Print* stream, byte t) { + const FSH *format; + + if (track[t]==NULL) return; + TRACK_MODE tm = track[t]->getMode(); + if (tm & TRACK_MODE_DC) + format=F("<= %c %S %d>\n"); + else + format=F("<= %c %S>\n"); + + const FSH *modename=getModeName(tm); if (stream) { // null stream means send to commandDistributor for broadcast - StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]); + StringFormatter::send(stream,format,'A'+t, modename, trackDCAddr[t]); } else { - CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]); + CommandDistributor::broadcastTrackState(format,'A'+t, modename, trackDCAddr[t]); CommandDistributor::broadcastPower(); } @@ -641,18 +653,3 @@ int16_t TrackManager::returnDCAddr(byte t) { return (trackDCAddr[t]); } -const char* TrackManager::getModeName(byte Mode) { - - //DIAG(F("PowerMode %d"), Mode); - -switch (Mode) - { - case 1: return "NONE"; - case 2: return "MAIN"; - case 4: return "PROG"; - case 8: return "DC"; - case 16: return "DCX"; - case 32: return "EXT"; - default: return "----"; - } -} diff --git a/TrackManager.h b/TrackManager.h index 8092f0a..f2a357d 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -91,7 +91,7 @@ class TrackManager { static bool isProg(byte t); static byte returnMode(byte t); static int16_t returnDCAddr(byte t); - static const char* getModeName(byte Mode); + static const FSH* getModeName(TRACK_MODE Mode); static int16_t joinRelay; static bool progTrackSyncMain; // true when prog track is a siding switched to main