1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

J command parsing

JA JR JT commands parsed
EXRAIL sets hidden turnout state
HIDDEN description macro
Turnouts hidden flag bit
UNO seems OK, MEGA UNTESTED
This commit is contained in:
Asbelos 2022-04-08 11:41:50 +01:00
parent 4c8b7f8517
commit 5846e0fe23
6 changed files with 86 additions and 10 deletions

View File

@ -37,6 +37,7 @@
#include "CommandDistributor.h"
#include "EEStore.h"
#include "DIAG.h"
#include "EXRAIL2.h"
#include <avr/wdt.h>
////////////////////////////////////////////////////////////////////////////////
@ -74,8 +75,10 @@ const int16_t HASH_KEYWORD_SPEED28 = -17064;
const int16_t HASH_KEYWORD_SPEED128 = 25816;
const int16_t HASH_KEYWORD_SERVO=27709;
const int16_t HASH_KEYWORD_VPIN=-415;
const int16_t HASH_KEYWORD_C=67;
const int16_t HASH_KEYWORD_T=84;
const int16_t HASH_KEYWORD_A='A';
const int16_t HASH_KEYWORD_C='C';
const int16_t HASH_KEYWORD_R='R';
const int16_t HASH_KEYWORD_T='T';
const int16_t HASH_KEYWORD_LCN = 15137;
const int16_t HASH_KEYWORD_HAL = 10853;
const int16_t HASH_KEYWORD_SHOW = -21309;
@ -509,6 +512,57 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
}
break;
case 'J' : // throttle info access
{
if ((params<1) | (params>2)) break; // <J>
int16_t id=(params==2)?p[1]:0;
switch(p[0]) {
case HASH_KEYWORD_A: // <JA> returns automations/routes
StringFormatter::send(stream, F("<jA"));
#ifdef EXRAIL_ACTIVE
if (params==1) sendFlashList(stream,RMFT2::routeIdList);
else StringFormatter::send(stream,F(" %d \"%S\""),
id, RMFT2::getRouteDescription(id));
#endif
StringFormatter::send(stream, F(">\n"));
return;
case HASH_KEYWORD_R: // <JR> returns rosters
StringFormatter::send(stream, F("<jR"));
#ifdef EXRAIL_ACTIVE
if (params==1) sendFlashList(stream,RMFT2::rosterIdList);
else StringFormatter::send(stream,F(" %d \"%S\" \"%S\""),
id, RMFT2::getRosterName(id), RMFT2::getRosterFunctions(id));
#endif
StringFormatter::send(stream, F(">\n"));
return;
case HASH_KEYWORD_T: // <JT> returns turnout list
StringFormatter::send(stream, F("<jT"));
if (params==1) { // <JT>
for ( Turnout * t=Turnout::first(); t; t=t->next()) {
if (t->isHidden()) continue;
StringFormatter::send(stream, F(" %c%d"),
t->isThrown()?'-':' ',t->getId());
}
}
else { // <JT id>
Turnout * t=Turnout::get(id);
if (t && !t->isHidden())
StringFormatter::send(stream, F(" %d \"%S\""),
id,
#ifdef EXRAIL_ACTIVE
RMFT2::getTurnoutDescription(id)
#else
F("")
#endif
);
}
StringFormatter::send(stream, F(">\n"));
return;
default: break;
} // switch(p[1])
break; // case J
}
default: //anything else will diagnose and drop out to <X>
DIAG(F("Opcode=%c params=%d"), opcode, params);
for (int i = 0; i < params; i++)
@ -521,6 +575,14 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
StringFormatter::send(stream, F("<X>\n"));
}
void DCCEXParser::sendFlashList(Print * stream,const int16_t flashList[]) {
for (int16_t i=0;;i+=2) {
int16_t value=GETFLASHW(flashList+i);
if (value==0) return;
StringFormatter::send(stream,F(" %d"),value);
}
}
bool DCCEXParser::parseZ(Print *stream, int16_t params, int16_t p[])
{

View File

@ -70,6 +70,7 @@ struct DCCEXParser
static FILTER_CALLBACK filterRMFTCallback;
static AT_COMMAND_CALLBACK atCommandCallback;
static void funcmap(int16_t cab, byte value, byte fstart, byte fstop);
static void sendFlashList(Print * stream,const int16_t flashList[]);
};

View File

@ -196,7 +196,7 @@ int16_t LookList::find(int16_t value) {
VPIN id=operand;
int addr=GET_OPERAND(1);
byte subAddr=GET_OPERAND(2);
DCCTurnout::create(id,addr,subAddr);
setTurnoutHiddenState(DCCTurnout::create(id,addr,subAddr));
break;
}
@ -206,14 +206,14 @@ int16_t LookList::find(int16_t value) {
int activeAngle=GET_OPERAND(2);
int inactiveAngle=GET_OPERAND(3);
int profile=GET_OPERAND(4);
ServoTurnout::create(id,pin,activeAngle,inactiveAngle,profile);
setTurnoutHiddenState(ServoTurnout::create(id,pin,activeAngle,inactiveAngle,profile));
break;
}
case OPCODE_PINTURNOUT: {
VPIN id=operand;
VPIN pin=GET_OPERAND(1);
VpinTurnout::create(id,pin);
setTurnoutHiddenState(VpinTurnout::create(id,pin));
break;
}
@ -257,6 +257,10 @@ int16_t LookList::find(int16_t value) {
new RMFT2(0); // add the startup route
}
void RMFT2::setTurnoutHiddenState(Turnout * t) {
t->setHidden(GETFLASH(getTurnoutDescription(t->getId()))==0x01);
}
// This filter intercepts <> commands to do the following:
// - Implement RMFT specific commands/diagnostics
// - Reject/modify JMRI commands that would interfere with RMFT processing

View File

@ -22,6 +22,7 @@
#define EXRAIL2_H
#include "FSH.h"
#include "IODevice.h"
#include "Turnouts.h"
// The following are the operation codes (or instructions) for a kind of virtual machine.
// Each instruction is normally 3 bytes long with an operation code followed by a parameter.
@ -110,7 +111,7 @@ private:
static bool getFlag(VPIN id,byte mask);
static int16_t progtrackLocoId;
static void doSignal(VPIN id,bool red, bool amber, bool green);
static void setTurnoutHiddenState(Turnout * t);
static RMFT2 * loopTask;
static RMFT2 * pausingTask;
void delayMe(long millisecs);

View File

@ -49,7 +49,11 @@
// CAUTION: The macros below are multiple passed over myAutomation.h
// helper macro for turnout descriptions, creates NULL for missing description
#define O_DESC(id, desc) case id: return ("" desc)[0]?F("" desc):NULL;
// helper macro for turnout description as HIDDEN
#define HIDDEN "\0x01"
// Pass 1 Implements aliases
#include "EXRAIL2MacroReset.h"

View File

@ -3,7 +3,7 @@
* © 2021 M Steve Todd
* © 2021 Fred Decker
* © 2020-2021 Harald Barth
* © 2020-2021 Chris Harlow
* © 2020-2022 Chris Harlow
* © 2013-2016 Gregg E. Berman
* All rights reserved.
*
@ -61,7 +61,8 @@ protected:
struct {
bool closed : 1;
bool _rfu: 2;
uint8_t turnoutType : 5;
bool hidden: 1;
uint8_t turnoutType : 4;
};
uint8_t flags;
};
@ -83,6 +84,7 @@ protected:
_turnoutData.id = id;
_turnoutData.turnoutType = turnoutType;
_turnoutData.closed = closed;
_turnoutData.hidden=false;
add(this);
}
@ -104,11 +106,11 @@ protected:
* Static functions
*/
static Turnout *get(uint16_t id);
static void add(Turnout *tt);
public:
static Turnout *get(uint16_t id);
/*
* Static data
*/
@ -120,6 +122,8 @@ public:
*/
inline bool isClosed() { return _turnoutData.closed; };
inline bool isThrown() { return !_turnoutData.closed; }
inline bool isHidden() { return _turnoutData.hidden; }
inline void setHidden(bool h) { _turnoutData.hidden=h; }
inline bool isType(uint8_t type) { return _turnoutData.turnoutType == type; }
inline uint16_t getId() { return _turnoutData.id; }
inline Turnout *next() { return _nextTurnout; }
@ -169,7 +173,7 @@ public:
#endif
static void printAll(Print *stream) {
for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout)
StringFormatter::send(stream, F("<H %d %d>\n"),tt->getId(), tt->isThrown());
if (!tt->isHidden()) StringFormatter::send(stream, F("<H %d %d>\n"),tt->getId(), tt->isThrown());
}