From b89508671ccf5701c6f2cf1dd4f6a6d106a558c0 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Wed, 12 Jun 2024 16:25:17 +0100 Subject: [PATCH] Separate polling cycle --- EXRAIL2Parser.cpp | 91 +++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/EXRAIL2Parser.cpp b/EXRAIL2Parser.cpp index f174bf8f..29a9bcd8 100644 --- a/EXRAIL2Parser.cpp +++ b/EXRAIL2Parser.cpp @@ -61,61 +61,82 @@ 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/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; - // 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"), + case OPCODE_LCCX: // long form LCC + StringFormatter::send(stream,F("\n"), getOperand(progCounter,1), getOperand(progCounter,2), getOperand(progCounter,3), getOperand(progCounter,0) - ); - } - if (opcode==OPCODE_ACON) StringFormatter::send(stream,F("\n"), - getOperand(progCounter,0),getOperand(progCounter,1)); - if (opcode==OPCODE_ACOF) StringFormatter::send(stream,F("\n"), - getOperand(progCounter,0),getOperand(progCounter,1)); - } + ); + SKIPOP;SKIPOP;SKIPOP;SKIPOP; + lccProgCounter=progCounter; + return; + + case OPCODE_ACON: // CBUS ACON + case OPCODE_ACOF: // CBUS ACON + 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: + onLCCLookup[lccEventIndex]=progCounter; StringFormatter::send(stream,F("\n"), - eventIndex, + lccEventIndex, getOperand(progCounter,1), getOperand(progCounter,2), getOperand(progCounter,3), getOperand(progCounter,0) ); - eventIndex++; - } - if (opcode==OPCODE_ONACON || opcode==OPCODE_ONACOF) { - onLCCLookup[eventIndex]=progCounter; // TODO skip... + lccEventIndex++; + SKIPOP;SKIPOP;SKIPOP;SKIPOP; + lccProgCounter=progCounter; + return; + + case OPCODE_ONACON: + case OPCODE_ONACOF: + onLCCLookup[lccEventIndex]=progCounter; StringFormatter::send(stream,F("\n"), - eventIndex, - opcode==OPCODE_ONACON?'0':'1', + lccEventIndex, + exrailOpcode==OPCODE_ONACOF?'1':'0', getOperand(progCounter,0),getOperand(progCounter,1) - ); - eventIndex++; - } + ); + lccEventIndex++; + SKIPOP;SKIPOP; + 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];