1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Route state management (part 1)

This commit is contained in:
Asbelos 2023-11-07 16:27:26 +00:00
parent 24e0f189e1
commit 4e08177b7b
6 changed files with 41 additions and 1 deletions

View File

@ -272,3 +272,11 @@ void CommandDistributor::broadcastRaw(clientType type, char * msg) {
void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr) { void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr) {
broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr); broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr);
} }
void CommandDistributor::broadcastRouteState(uint16_t routeId, RouteState state ) {
broadcastReply(COMMAND_TYPE, F("<jB %d %d>\n"),routeId,state);
}
void CommandDistributor::broadcastRouteCaption(uint16_t routeId, const FSH* caption ) {
broadcastReply(COMMAND_TYPE, F("<jB %d \"%S\">\n"),routeId,caption);
}

View File

@ -37,6 +37,7 @@
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;
@ -58,6 +59,9 @@ 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 broadcastRouteCaption(uint16_t routeId,const FSH * caption);
}; };

View File

@ -1130,7 +1130,16 @@ void RMFT2::loop2() {
case OPCODE_PRINT: case OPCODE_PRINT:
printMessage(operand); printMessage(operand);
break; break;
case OPCODE_ROUTE_HIDDEN:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_HIDDEN);
break;
case OPCODE_ROUTE_ACTIVE:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_ACTIVE);
break;
case OPCODE_ROUTE_INACTIVE:
CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_INACTIVE);
break;
case OPCODE_ROUTE: case OPCODE_ROUTE:
case OPCODE_AUTOMATION: case OPCODE_AUTOMATION:
case OPCODE_SEQUENCE: case OPCODE_SEQUENCE:

View File

@ -68,6 +68,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT, OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT,
OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC, OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC,
OPCODE_ONOVERLOAD, OPCODE_ONOVERLOAD,
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
// OPcodes below this point are skip-nesting IF operations // OPcodes below this point are skip-nesting IF operations
// placed here so that they may be skipped as a group // placed here so that they may be skipped as a group

View File

@ -126,6 +126,10 @@
#undef ROTATE #undef ROTATE
#undef ROTATE_DCC #undef ROTATE_DCC
#undef ROUTE #undef ROUTE
#undef ROUTE_ACTVE
#undef ROUTE_INACTVE
#undef ROUTE_HIDDEN
#undef ROUTE_CAPTION
#undef SENDLOCO #undef SENDLOCO
#undef SEQUENCE #undef SEQUENCE
#undef SERIAL #undef SERIAL
@ -267,6 +271,10 @@
#define ROTATE_DCC(turntable_id,position) #define ROTATE_DCC(turntable_id,position)
#define ROSTER(cab,name,funcmap...) #define ROSTER(cab,name,funcmap...)
#define ROUTE(id,description) #define ROUTE(id,description)
#define ROUTE_ACTIVE(id)
#define ROUTE_INACTIVE(id)
#define ROUTE_HIDDEN(id)
#define ROUTE_CAPTION(id,caption)
#define SENDLOCO(cab,route) #define SENDLOCO(cab,route)
#define SEQUENCE(id) #define SEQUENCE(id)
#define SERIAL(msg) #define SERIAL(msg)

View File

@ -153,6 +153,12 @@ const int StringMacroTracker1=__COUNTER__;
#define PRINT(msg) THRUNGE(msg,thrunge_print) #define PRINT(msg) THRUNGE(msg,thrunge_print)
#undef LCN #undef LCN
#define LCN(msg) THRUNGE(msg,thrunge_lcn) #define LCN(msg) THRUNGE(msg,thrunge_lcn)
#undef ROUTE_CAPTION
#define ROUTE_CAPTION(id,caption) \
case (__COUNTER__ - StringMacroTracker1) : {\
CommandDistributor::broadcastRouteCaption(id,F(caption));\
return;\
}
#undef SERIAL #undef SERIAL
#define SERIAL(msg) THRUNGE(msg,thrunge_serial) #define SERIAL(msg) THRUNGE(msg,thrunge_serial)
#undef SERIAL1 #undef SERIAL1
@ -440,6 +446,10 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define ROTATE_DCC(id,position) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(0), #define ROTATE_DCC(id,position) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(0),
#endif #endif
#define ROUTE(id, description) OPCODE_ROUTE, V(id), #define ROUTE(id, description) OPCODE_ROUTE, V(id),
#define ROUTE_ACTIVE(id) OPCODE_ROUTE_ACTIVE,V(id),
#define ROUTE_INACTIVE(id) OPCODE_ROUTE_INACTIVE,V(id),
#define ROUTE_HIDDEN(id) OPCODE_ROUTE_HIDDEN,V(id),
#define ROUTE_CAPTION(id,caption) PRINT(caption)
#define SENDLOCO(cab,route) OPCODE_SENDLOCO,V(cab),OPCODE_PAD,V(route), #define SENDLOCO(cab,route) OPCODE_SENDLOCO,V(cab),OPCODE_PAD,V(route),
#define SEQUENCE(id) OPCODE_SEQUENCE, V(id), #define SEQUENCE(id) OPCODE_SEQUENCE, V(id),
#define SERIAL(msg) PRINT(msg) #define SERIAL(msg) PRINT(msg)