1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00
This commit is contained in:
Asbelos 2023-11-09 19:27:52 +00:00
parent 44351b83ae
commit 26cf28dff7
5 changed files with 34 additions and 9 deletions

View File

@ -273,7 +273,7 @@ void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter,
broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr); broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr);
} }
void CommandDistributor::broadcastRouteState(uint16_t routeId, RouteState state ) { void CommandDistributor::broadcastRouteState(uint16_t routeId, byte state ) {
broadcastReply(COMMAND_TYPE, F("<jB %d %d>\n"),routeId,state); broadcastReply(COMMAND_TYPE, F("<jB %d %d>\n"),routeId,state);
} }

View File

@ -37,7 +37,6 @@
class CommandDistributor { class CommandDistributor {
public: public:
enum clientType: byte {NONE_TYPE,COMMAND_TYPE,WITHROTTLE_TYPE}; enum clientType: byte {NONE_TYPE,COMMAND_TYPE,WITHROTTLE_TYPE};
enum RouteState: byte {STATE_ACTIVE,STATE_INACTIVE,STATE_HIDDEN};
private: private:
static void broadcastToClients(clientType type); static void broadcastToClients(clientType type);
static StringBuffer * broadcastBufferWriter; static StringBuffer * broadcastBufferWriter;
@ -59,7 +58,7 @@ public :
static void broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr); static void broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr);
template<typename... Targs> static void broadcastReply(clientType type, Targs... msg); template<typename... Targs> static void broadcastReply(clientType type, Targs... msg);
static void forget(byte clientId); static void forget(byte clientId);
static void broadcastRouteState(uint16_t routeId,RouteState state); static void broadcastRouteState(uint16_t routeId,byte state);
static void broadcastRouteCaption(uint16_t routeId,const FSH * caption); static void broadcastRouteCaption(uint16_t routeId,const FSH * caption);

View File

@ -100,6 +100,7 @@ LookList * RMFT2::onClockLookup=NULL;
LookList * RMFT2::onRotateLookup=NULL; LookList * RMFT2::onRotateLookup=NULL;
#endif #endif
LookList * RMFT2::onOverloadLookup=NULL; LookList * RMFT2::onOverloadLookup=NULL;
byte * RMFT2::routeStateArray=nullptr;
#define GET_OPCODE GETHIGHFLASH(RMFT2::RouteCode,progCounter) #define GET_OPCODE GETHIGHFLASH(RMFT2::RouteCode,progCounter)
#define SKIPOP progCounter+=3 #define SKIPOP progCounter+=3
@ -139,6 +140,15 @@ int16_t LookList::find(int16_t value) {
} }
return -1; return -1;
} }
int16_t LookList::findPosition(int16_t value) {
for (int16_t i=0;i<m_size;i++) {
if (m_lookupArray[i]==value) return i;
}
return -1;
}
int16_t LookList::size() {
return m_size;
}
LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) { LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
int progCounter; int progCounter;
@ -172,6 +182,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
// create lookups // create lookups
sequenceLookup=LookListLoader(OPCODE_ROUTE, OPCODE_AUTOMATION,OPCODE_SEQUENCE); sequenceLookup=LookListLoader(OPCODE_ROUTE, OPCODE_AUTOMATION,OPCODE_SEQUENCE);
routeStateArray=(byte *)calloc(sequenceLookup->size(),sizeof(byte));
onThrowLookup=LookListLoader(OPCODE_ONTHROW); onThrowLookup=LookListLoader(OPCODE_ONTHROW);
onCloseLookup=LookListLoader(OPCODE_ONCLOSE); onCloseLookup=LookListLoader(OPCODE_ONCLOSE);
onActivateLookup=LookListLoader(OPCODE_ONACTIVATE); onActivateLookup=LookListLoader(OPCODE_ONACTIVATE);
@ -1131,13 +1142,13 @@ void RMFT2::loop2() {
printMessage(operand); printMessage(operand);
break; break;
case OPCODE_ROUTE_HIDDEN: case OPCODE_ROUTE_HIDDEN:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_HIDDEN); manageRoute(operand,2);
break; break;
case OPCODE_ROUTE_ACTIVE: case OPCODE_ROUTE_ACTIVE:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_ACTIVE); manageRoute(operand,0);
break; break;
case OPCODE_ROUTE_INACTIVE: case OPCODE_ROUTE_INACTIVE:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_INACTIVE); manageRoute(operand,1);
break; break;
case OPCODE_ROUTE: case OPCODE_ROUTE:
@ -1462,3 +1473,14 @@ void RMFT2::thrungeString(uint32_t strfar, thrunger mode, byte id) {
break; break;
} }
} }
void RMFT2::manageRoute(uint16_t id, byte state) {
CommandDistributor::broadcastRouteState(id,state);
// Route state must be maintained for when new throttles connect.
// locate route id in the Routes lookup
int16_t position=sequenceLookup->findPosition(id);
if (position<0) return;
// set state beside it
routeStateArray[position]=state;
}

View File

@ -121,7 +121,9 @@ class LookList {
public: public:
LookList(int16_t size); LookList(int16_t size);
void add(int16_t lookup, int16_t result); void add(int16_t lookup, int16_t result);
int16_t find(int16_t value); int16_t find(int16_t value); // finds result value
int16_t findPosition(int16_t value); // finds index
int16_t size();
private: private:
int16_t m_size; int16_t m_size;
int16_t m_loaded; int16_t m_loaded;
@ -217,6 +219,8 @@ private:
static const int countLCCLookup; static const int countLCCLookup;
static int onLCCLookup[]; static int onLCCLookup[];
static const byte compileFeatures; static const byte compileFeatures;
static void manageRoute(uint16_t id, byte state);
static byte * routeStateArray;
// Local variables - exist for each instance/task // Local variables - exist for each instance/task
RMFT2 *next; // loop chain RMFT2 *next; // loop chain

View File

@ -126,8 +126,8 @@
#undef ROTATE #undef ROTATE
#undef ROTATE_DCC #undef ROTATE_DCC
#undef ROUTE #undef ROUTE
#undef ROUTE_ACTVE #undef ROUTE_ACTIVE
#undef ROUTE_INACTVE #undef ROUTE_INACTIVE
#undef ROUTE_HIDDEN #undef ROUTE_HIDDEN
#undef ROUTE_CAPTION #undef ROUTE_CAPTION
#undef SENDLOCO #undef SENDLOCO