mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-30 03:26:13 +01:00
Turnout recursion test
This commit is contained in:
parent
9d5781a87c
commit
99222bd37f
20
RMFT2.cpp
20
RMFT2.cpp
|
@ -275,6 +275,7 @@ RMFT2::RMFT2(int progCtr) {
|
||||||
forward=true;
|
forward=true;
|
||||||
invert=false;
|
invert=false;
|
||||||
stackDepth=0;
|
stackDepth=0;
|
||||||
|
onTurnoutId=0; // Not handling an ONTHROW/ONCLOSE
|
||||||
|
|
||||||
// chain into ring of RMFTs
|
// chain into ring of RMFTs
|
||||||
if (loopTask==NULL) {
|
if (loopTask==NULL) {
|
||||||
|
@ -685,15 +686,28 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void RMFT2::turnoutEvent(VPIN id, bool closed) {
|
void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) {
|
||||||
|
|
||||||
|
// Check we dont already have a task running this turnout
|
||||||
|
RMFT2 * task=loopTask;
|
||||||
|
while(task) {
|
||||||
|
if (task->onTurnoutId==turnoutId) {
|
||||||
|
DIAG(F("Recursive ONTHROW/ONCLOSE for Turnout %d"),turnoutId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
task=task->next;
|
||||||
|
if (task==loopTask) break;
|
||||||
|
}
|
||||||
|
// Hunt for an ONTHROW/ONCLOSE for this turnout
|
||||||
byte huntFor=closed ? OPCODE_ONCLOSE : OPCODE_ONTHROW ;
|
byte huntFor=closed ? OPCODE_ONCLOSE : OPCODE_ONTHROW ;
|
||||||
// caution hides class progCounter;
|
// caution hides class progCounter;
|
||||||
for (int progCounter=0;; SKIPOP){
|
for (int progCounter=0;; SKIPOP){
|
||||||
byte opcode=GET_OPCODE;
|
byte opcode=GET_OPCODE;
|
||||||
if (opcode==OPCODE_ENDEXRAIL) return;
|
if (opcode==OPCODE_ENDEXRAIL) return;
|
||||||
if (opcode!=huntFor) continue;
|
if (opcode!=huntFor) continue;
|
||||||
if (id!=GET_OPERAND(0)) continue;
|
if (turnoutId!=(int16_t)GET_OPERAND(0)) continue;
|
||||||
new RMFT2(progCounter); // new task starts at this instruction
|
task=new RMFT2(progCounter); // new task starts at this instruction
|
||||||
|
task->onTurnoutId=turnoutId; // flag for recursion detector
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
RMFT2.h
5
RMFT2.h
|
@ -68,7 +68,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
|
||||||
static void readLocoCallback(int16_t cv);
|
static void readLocoCallback(int16_t cv);
|
||||||
static void emitWithrottleRouteList(Print* stream);
|
static void emitWithrottleRouteList(Print* stream);
|
||||||
static void createNewTask(int route, uint16_t cab);
|
static void createNewTask(int route, uint16_t cab);
|
||||||
static void turnoutEvent(VPIN id, bool closed);
|
static void turnoutEvent(int16_t id, bool closed);
|
||||||
private:
|
private:
|
||||||
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
||||||
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
|
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
|
||||||
|
@ -106,10 +106,11 @@ private:
|
||||||
unsigned long delayTime;
|
unsigned long delayTime;
|
||||||
byte taskId;
|
byte taskId;
|
||||||
|
|
||||||
int loco;
|
int16_t loco;
|
||||||
bool forward;
|
bool forward;
|
||||||
bool invert;
|
bool invert;
|
||||||
int speedo;
|
int speedo;
|
||||||
|
int16_t onTurnoutId;
|
||||||
byte stackDepth;
|
byte stackDepth;
|
||||||
int callStack[MAX_STACK_DEPTH];
|
int callStack[MAX_STACK_DEPTH];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user