1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 05:31:24 +01:00

task Id and KILL

Also fixes a long standing flags bug  no idea where that line went!
This commit is contained in:
Asbelos 2021-08-15 23:15:02 +01:00
parent 3a6e41ac49
commit 7227a0696e
2 changed files with 38 additions and 11 deletions

View File

@ -35,6 +35,7 @@ const int16_t HASH_KEYWORD_LATCH=1618;
const int16_t HASH_KEYWORD_UNLATCH=1353; const int16_t HASH_KEYWORD_UNLATCH=1353;
const int16_t HASH_KEYWORD_PAUSE=-4142; const int16_t HASH_KEYWORD_PAUSE=-4142;
const int16_t HASH_KEYWORD_RESUME=27609; const int16_t HASH_KEYWORD_RESUME=27609;
const int16_t HASH_KEYWORD_KILL=5218;
// One instance of RMFT clas is used for each "thread" in the automation. // One instance of RMFT clas is used for each "thread" in the automation.
// Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation. // Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation.
@ -138,8 +139,8 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
StringFormatter::send(stream, F("<* EXRAIL STATUS")); StringFormatter::send(stream, F("<* EXRAIL STATUS"));
RMFT2 * task=loopTask; RMFT2 * task=loopTask;
while(task) { while(task) {
StringFormatter::send(stream,F("\nPC=%d,DT=%l,LOCO=%d%c,SPEED=%d%c"), StringFormatter::send(stream,F("\nID=%d,PC=%d,LOCO=%d%c,SPEED=%d%c"),
task->progCounter,task->delayTime,task->loco, (int)(task->taskId),task->progCounter,task->loco,
task->invert?'I':' ', task->invert?'I':' ',
task->speedo, task->speedo,
task->forward?'F':'R' task->forward?'F':'R'
@ -150,7 +151,7 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
// Now stream the flags // Now stream the flags
for (int id=0;id<MAX_FLAGS; id++) { for (int id=0;id<MAX_FLAGS; id++) {
byte flag=flags[id]; byte flag=flags[id];
if (flag) { if (flag & ~TASK_FLAG) { // not interested in TASK_FLAG only. Already shown above
StringFormatter::send(stream,F("\nflags[%d} "),id); StringFormatter::send(stream,F("\nflags[%d} "),id);
if (flag & SECTION_FLAG) StringFormatter::send(stream,F(" RESERVED")); if (flag & SECTION_FLAG) StringFormatter::send(stream,F(" RESERVED"));
if (flag & LATCH_FLAG) StringFormatter::send(stream,F(" LATCHED")); if (flag & LATCH_FLAG) StringFormatter::send(stream,F(" LATCHED"));
@ -201,6 +202,20 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
if (paramCount!=2 || p[1]<0 || p[1]>=MAX_FLAGS) return false; if (paramCount!=2 || p[1]<0 || p[1]>=MAX_FLAGS) return false;
switch (p[0]) { switch (p[0]) {
case HASH_KEYWORD_KILL: // Kill taskid
{
RMFT2 * task=loopTask;
while(task) {
if (task->taskId==p[1]) {
delete task;
return true;
}
task=task->next;
if (task==loopTask) break;
}
}
return false;
case HASH_KEYWORD_RESERVE: // force reserve a section case HASH_KEYWORD_RESERVE: // force reserve a section
setFlag(p[1],SECTION_FLAG); setFlag(p[1],SECTION_FLAG);
return true; return true;
@ -234,6 +249,16 @@ void RMFT2::emitWithrottleRouteList(Print* stream) {
RMFT2::RMFT2(int progCtr) { RMFT2::RMFT2(int progCtr) {
progCounter=progCtr; progCounter=progCtr;
// get an unused task id from the flags table
taskId=255; // in case of overflow
for (int f=0;f<MAX_FLAGS;f++) {
if (!getFlag(f,TASK_FLAG)) {
taskId=f;
setFlag(f, TASK_FLAG);
break;
}
}
delayTime=0; delayTime=0;
loco=0; loco=0;
speedo=0; speedo=0;
@ -254,6 +279,7 @@ RMFT2::RMFT2(int progCtr) {
RMFT2::~RMFT2() { RMFT2::~RMFT2() {
setFlag(taskId,0,TASK_FLAG); // we are no longer using this id
if (next==this) loopTask=NULL; if (next==this) loopTask=NULL;
else for (RMFT2* ring=next;;ring=ring->next) if (ring->next == this) { else for (RMFT2* ring=next;;ring=ring->next) if (ring->next == this) {
ring->next=next; ring->next=next;
@ -609,9 +635,10 @@ void RMFT2::setFlag(VPIN id,byte onMask, byte offMask) {
byte f=flags[id]; byte f=flags[id];
f &= ~offMask; f &= ~offMask;
f |= onMask; f |= onMask;
flags[id]=f;
} }
byte RMFT2::getFlag(VPIN id,byte mask) { bool RMFT2::getFlag(VPIN id,byte mask) {
if (FLAGOVERFLOW(id)) return 0; // Outside range limit if (FLAGOVERFLOW(id)) return 0; // Outside range limit
return flags[id]&mask; return flags[id]&mask;
} }

10
RMFT2.h
View File

@ -51,6 +51,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
// Flag bits for status of hardware and TPL // Flag bits for status of hardware and TPL
static const byte SECTION_FLAG = 0x01; static const byte SECTION_FLAG = 0x01;
static const byte LATCH_FLAG = 0x02; static const byte LATCH_FLAG = 0x02;
static const byte TASK_FLAG = 0x04;
static const byte MAX_STACK_DEPTH=4; static const byte MAX_STACK_DEPTH=4;
@ -73,7 +74,7 @@ private:
static bool parseSlash(Print * stream, byte & paramCount, int p[]) ; static bool parseSlash(Print * stream, byte & paramCount, int p[]) ;
static void streamFlags(Print* stream); static void streamFlags(Print* stream);
static void setFlag(VPIN id,byte onMask, byte OffMask=0); static void setFlag(VPIN id,byte onMask, byte OffMask=0);
static byte getFlag(VPIN id,byte mask); static bool getFlag(VPIN id,byte mask);
static int locateRouteStart(int16_t _route); static int locateRouteStart(int16_t _route);
static int progtrackLocoId; static int progtrackLocoId;
static void doSignal(VPIN id,bool red, bool amber, bool green); static void doSignal(VPIN id,bool red, bool amber, bool green);
@ -85,9 +86,6 @@ private:
bool readSensor(int16_t sensorId); bool readSensor(int16_t sensorId);
bool skipIfBlock(); bool skipIfBlock();
bool readLoco(); bool readLoco();
void showManual();
void showProg(bool progOn);
bool doManual();
void loop2(); void loop2();
void kill(const FSH * reason=NULL,int operand=0); void kill(const FSH * reason=NULL,int operand=0);
void printMessage(uint16_t id); // Built by RMFTMacros.h void printMessage(uint16_t id); // Built by RMFTMacros.h
@ -98,12 +96,14 @@ private:
static const FLASH char RouteDescription[]; static const FLASH char RouteDescription[];
static byte flags[MAX_FLAGS]; static byte flags[MAX_FLAGS];
// Local variables - exist for each instance/task // Local variables - exist for each instance/task
RMFT2 *next; // loop chain RMFT2 *next; // loop chain
int progCounter; // Byte offset of next route opcode in ROUTES table int progCounter; // Byte offset of next route opcode in ROUTES table
unsigned long delayStart; // Used by opcodes that must be recalled before completing unsigned long delayStart; // Used by opcodes that must be recalled before completing
unsigned long waitAfter; // Used by OPCODE_AFTER unsigned long waitAfter; // Used by OPCODE_AFTER
unsigned long delayTime; unsigned long delayTime;
byte taskId;
int loco; int loco;
bool forward; bool forward;
bool invert; bool invert;