mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
task Id and KILL
Also fixes a long standing flags bug no idea where that line went!
This commit is contained in:
parent
3a6e41ac49
commit
7227a0696e
35
RMFT2.cpp
35
RMFT2.cpp
@ -35,6 +35,7 @@ const int16_t HASH_KEYWORD_LATCH=1618;
|
||||
const int16_t HASH_KEYWORD_UNLATCH=1353;
|
||||
const int16_t HASH_KEYWORD_PAUSE=-4142;
|
||||
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.
|
||||
// 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"));
|
||||
RMFT2 * task=loopTask;
|
||||
while(task) {
|
||||
StringFormatter::send(stream,F("\nPC=%d,DT=%l,LOCO=%d%c,SPEED=%d%c"),
|
||||
task->progCounter,task->delayTime,task->loco,
|
||||
StringFormatter::send(stream,F("\nID=%d,PC=%d,LOCO=%d%c,SPEED=%d%c"),
|
||||
(int)(task->taskId),task->progCounter,task->loco,
|
||||
task->invert?'I':' ',
|
||||
task->speedo,
|
||||
task->forward?'F':'R'
|
||||
@ -150,7 +151,7 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
// Now stream the flags
|
||||
for (int id=0;id<MAX_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);
|
||||
if (flag & SECTION_FLAG) StringFormatter::send(stream,F(" RESERVED"));
|
||||
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;
|
||||
|
||||
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
|
||||
setFlag(p[1],SECTION_FLAG);
|
||||
return true;
|
||||
@ -234,6 +249,16 @@ void RMFT2::emitWithrottleRouteList(Print* stream) {
|
||||
|
||||
RMFT2::RMFT2(int 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;
|
||||
loco=0;
|
||||
speedo=0;
|
||||
@ -254,6 +279,7 @@ RMFT2::RMFT2(int progCtr) {
|
||||
|
||||
|
||||
RMFT2::~RMFT2() {
|
||||
setFlag(taskId,0,TASK_FLAG); // we are no longer using this id
|
||||
if (next==this) loopTask=NULL;
|
||||
else for (RMFT2* ring=next;;ring=ring->next) if (ring->next == this) {
|
||||
ring->next=next;
|
||||
@ -609,9 +635,10 @@ void RMFT2::setFlag(VPIN id,byte onMask, byte offMask) {
|
||||
byte f=flags[id];
|
||||
f &= ~offMask;
|
||||
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
|
||||
return flags[id]&mask;
|
||||
}
|
||||
|
8
RMFT2.h
8
RMFT2.h
@ -51,6 +51,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
|
||||
// Flag bits for status of hardware and TPL
|
||||
static const byte SECTION_FLAG = 0x01;
|
||||
static const byte LATCH_FLAG = 0x02;
|
||||
static const byte TASK_FLAG = 0x04;
|
||||
|
||||
static const byte MAX_STACK_DEPTH=4;
|
||||
|
||||
@ -73,7 +74,7 @@ private:
|
||||
static bool parseSlash(Print * stream, byte & paramCount, int p[]) ;
|
||||
static void streamFlags(Print* stream);
|
||||
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 progtrackLocoId;
|
||||
static void doSignal(VPIN id,bool red, bool amber, bool green);
|
||||
@ -85,9 +86,6 @@ private:
|
||||
bool readSensor(int16_t sensorId);
|
||||
bool skipIfBlock();
|
||||
bool readLoco();
|
||||
void showManual();
|
||||
void showProg(bool progOn);
|
||||
bool doManual();
|
||||
void loop2();
|
||||
void kill(const FSH * reason=NULL,int operand=0);
|
||||
void printMessage(uint16_t id); // Built by RMFTMacros.h
|
||||
@ -104,6 +102,8 @@ private:
|
||||
unsigned long delayStart; // Used by opcodes that must be recalled before completing
|
||||
unsigned long waitAfter; // Used by OPCODE_AFTER
|
||||
unsigned long delayTime;
|
||||
byte taskId;
|
||||
|
||||
int loco;
|
||||
bool forward;
|
||||
bool invert;
|
||||
|
Loading…
Reference in New Issue
Block a user