From 97f9fb48136da2b51678c2f2ac5693f825c483b2 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 13 Jun 2024 13:01:33 +0100 Subject: [PATCH] Squashed commit of the following: commit a2b3ee8b5d52c2eefa461ace8f95c7f782a58efc Merge: fc1217b 3d6c935 Author: Asbelos Date: Thu Jun 13 11:58:00 2024 +0100 Merge branch 'devel' into devel_merg commit fc1217b8fa27a83174a4cf3bb82666f075103637 Author: Asbelos Date: Thu Jun 13 11:57:12 2024 +0100 Update EXRAIL2Parser.cpp commit b89508671ccf5701c6f2cf1dd4f6a6d106a558c0 Author: Asbelos Date: Wed Jun 12 16:25:17 2024 +0100 Separate polling cycle commit 9f1257bc6ce8e36b507f8e7362d26fd3a1656028 Merge: a2fb585 5f65fd5 Author: Asbelos Date: Wed Jun 12 10:57:09 2024 +0100 Merge branch 'devel' into devel_merg commit a2fb58584f489c24ace18f089da954d70b15bdac Author: Asbelos Date: Fri May 31 19:49:39 2024 +0100 ACON/ACOF 32 bit + 1=OFF commit fca4ea052ef28425f3749a9c5696710326cf3bf8 Author: Asbelos Date: Fri May 31 12:09:38 2024 +0100 Rename to ACON/ACOF terminology commit 0d07aa6271813b38dbcc74dd00d86a9c0dc6f060 Author: Asbelos Date: Thu May 30 19:59:29 2024 +0100 MERG macris in exrail --- EXRAIL2.cpp | 10 ++++++ EXRAIL2.h | 2 ++ EXRAIL2MacroReset.h | 8 +++++ EXRAIL2Parser.cpp | 84 ++++++++++++++++++++++++++++++++------------- EXRAILMacros.h | 18 +++++++++- 5 files changed, 98 insertions(+), 24 deletions(-) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 088b79b..b2f29e2 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -1000,6 +1000,14 @@ void RMFT2::loop2() { if ((compileFeatures & FEATURE_LCC) && LCCSerial) StringFormatter::send(LCCSerial,F(""),(uint16_t)operand); break; + + case OPCODE_ACON: // MERG adapter + case OPCODE_ACOF: + if ((compileFeatures & FEATURE_LCC) && LCCSerial) + StringFormatter::send(LCCSerial,F(""), + opcode==OPCODE_ACON?'0':'1', + (uint16_t)operand,getOperand(progCounter,1)); + break; case OPCODE_LCCX: // long form LCC if ((compileFeatures & FEATURE_LCC) && LCCSerial) @@ -1088,6 +1096,8 @@ void RMFT2::loop2() { case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime case OPCODE_ONCLOSE: // Turnout event catchers ignored here case OPCODE_ONLCC: // LCC event catchers ignored here + case OPCODE_ONACON: // MERG event catchers ignored here + case OPCODE_ONACOF: // MERG event catchers ignored here case OPCODE_ONTHROW: case OPCODE_ONACTIVATE: // Activate event catchers ignored here case OPCODE_ONDEACTIVATE: diff --git a/EXRAIL2.h b/EXRAIL2.h index 8750e41..9271bba 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -69,6 +69,8 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT, OPCODE_TTADDPOSITION,OPCODE_DCCTURNTABLE,OPCODE_EXTTTURNTABLE, OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT, OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC, + OPCODE_ACON, OPCODE_ACOF, + OPCODE_ONACON, OPCODE_ONACOF, OPCODE_ONOVERLOAD, OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN, OPCODE_ROUTE_DISABLED, diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index c799ddf..8927fbe 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -99,6 +99,10 @@ #undef LCCX #undef LCN #undef MOVETT +#undef ACON +#undef ACOF +#undef ONACON +#undef ONACOF #undef MESSAGE #undef ONACTIVATE #undef ONACTIVATEL @@ -265,6 +269,10 @@ #define LCN(msg) #define MESSAGE(msg) #define MOVETT(id,steps,activity) +#define ACON(eventid) +#define ACOF(eventid) +#define ONACON(eventid) +#define ONACOF(eventid) #define ONACTIVATE(addr,subaddr) #define ONACTIVATEL(linear) #define ONAMBER(signal_id) diff --git a/EXRAIL2Parser.cpp b/EXRAIL2Parser.cpp index 4023633..8c498ab 100644 --- a/EXRAIL2Parser.cpp +++ b/EXRAIL2Parser.cpp @@ -61,47 +61,85 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16 case 'L': // This entire code block is compiled out if LLC macros not used if (!(compileFeatures & FEATURE_LCC)) return; - + static int lccProgCounter=0; + static int lccEventIndex=0; + if (paramCount==0) { // LCC adapter introducing self LCCSerial=stream; // now we know where to send events we raise + opcode=0; // flag command as intercepted - // loop through all possible sent events - for (int progCounter=0;; SKIPOP) { - byte opcode=GET_OPCODE; - if (opcode==OPCODE_ENDEXRAIL) break; - if (opcode==OPCODE_LCC) StringFormatter::send(stream,F("\n"),getOperand(progCounter,0)); - if (opcode==OPCODE_LCCX) { // long form LCC - StringFormatter::send(stream,F("\n"), + // loop through all possible sent/waited events + for (int progCounter=lccProgCounter;; SKIPOP) { + byte exrailOpcode=GET_OPCODE; + switch (exrailOpcode) { + case OPCODE_ENDEXRAIL: + stream->print(F("\n")); // ready to roll + lccProgCounter=0; // allow a second pass + lccEventIndex=0; + return; + + case OPCODE_LCC: + StringFormatter::send(stream,F("\n"),getOperand(progCounter,0)); + SKIPOP; + lccProgCounter=progCounter; + return; + + case OPCODE_LCCX: // long form LCC + StringFormatter::send(stream,F("\n"), getOperand(progCounter,1), getOperand(progCounter,2), getOperand(progCounter,3), getOperand(progCounter,0) - ); - }} + ); + SKIPOP;SKIPOP;SKIPOP;SKIPOP; + lccProgCounter=progCounter; + return; + + case OPCODE_ACON: // CBUS ACON + case OPCODE_ACOF: // CBUS ACOF + StringFormatter::send(stream,F("\n"), + exrailOpcode==OPCODE_ACOF?'1':'0', + getOperand(progCounter,0),getOperand(progCounter,1)); + SKIPOP;SKIPOP; + lccProgCounter=progCounter; + return; // we stream the hex events we wish to listen to // and at the same time build the event index looku. - - int eventIndex=0; - for (int progCounter=0;; SKIPOP) { - byte opcode=GET_OPCODE; - if (opcode==OPCODE_ENDEXRAIL) break; - if (opcode==OPCODE_ONLCC) { - onLCCLookup[eventIndex]=progCounter; // TODO skip... + case OPCODE_ONLCC: StringFormatter::send(stream,F("\n"), - eventIndex, + lccEventIndex, getOperand(progCounter,1), getOperand(progCounter,2), getOperand(progCounter,3), getOperand(progCounter,0) ); - eventIndex++; - } + SKIPOP;SKIPOP;SKIPOP;SKIPOP; + // start on handler at next + onLCCLookup[lccEventIndex]=progCounter; + lccEventIndex++; + lccProgCounter=progCounter; + return; + + case OPCODE_ONACON: + case OPCODE_ONACOF: + StringFormatter::send(stream,F("\n"), + lccEventIndex, + exrailOpcode==OPCODE_ONACOF?'1':'0', + getOperand(progCounter,0),getOperand(progCounter,1) + ); + SKIPOP;SKIPOP; + // start on handler at next + onLCCLookup[lccEventIndex]=progCounter; + lccEventIndex++; + lccProgCounter=progCounter; + return; + + default: + break; + } } - StringFormatter::send(stream,F("\n")); // Ready to rumble - opcode=0; - break; } if (paramCount==1) { // LCC event arrived from adapter int16_t eventid=p[0]; diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 827c1d2..e4d72a1 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -189,6 +189,14 @@ bool exrailHalSetup() { #define LCCX(senderid,eventid) | FEATURE_LCC #undef ONLCC #define ONLCC(senderid,eventid) | FEATURE_LCC +#undef ACON +#define ACON(eventid) | FEATURE_LCC +#undef ACOF +#define ACOF(eventid) | FEATURE_LCC +#undef ONACON +#define ONACON(eventid) | FEATURE_LCC +#undef ONACOF +#define ONACOF(eventid) | FEATURE_LCC #undef ROUTE_ACTIVE #define ROUTE_ACTIVE(id) | FEATURE_ROUTESTATE #undef ROUTE_INACTIVE @@ -429,10 +437,14 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { #include "myAutomation.h" 0,0,0,0 }; -// Pass 9 ONLCC counter and lookup array +// Pass 9 ONLCC/ ONMERG counter and lookup array #include "EXRAIL2MacroReset.h" #undef ONLCC #define ONLCC(sender,event) +1 +#undef ONACON +#define ONACON(event) +1 +#undef ONACOF +#define ONACOF(event) +1 const int RMFT2::countLCCLookup=0 #include "myAutomation.h" @@ -529,6 +541,10 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\ OPCODE_PAD,V((((uint64_t)sender)>>16)&0xFFFF),\ OPCODE_PAD,V((((uint64_t)sender)>>0)&0xFFFF), +#define ACON(eventid) OPCODE_ACON,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF), +#define ACOF(eventid) OPCODE_ACOF,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF), +#define ONACON(eventid) OPCODE_ONACON,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF), +#define ONACOF(eventid) OPCODE_ONACOF,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF), #define LCD(id,msg) PRINT(msg) #define SCREEN(display,id,msg) PRINT(msg) #define STEALTH(code...) PRINT(dummy)