mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Turnout states according to RCN-123 where Thrown is 0 and Closed is 1. Additional protection against invalid chars in protocol
This commit is contained in:
parent
88949358b4
commit
4f0c80a503
|
@ -140,7 +140,7 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
}
|
}
|
||||||
else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
|
else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
|
||||||
int id=getInt(cmd+4);
|
int id=getInt(cmd+4);
|
||||||
bool newstate=false;
|
byte newstate=2; // newstate can be 0,1 or 2. 2 is "invalid".
|
||||||
Turnout * tt=Turnout::get(id);
|
Turnout * tt=Turnout::get(id);
|
||||||
if (!tt) {
|
if (!tt) {
|
||||||
// If turnout does not exist, create it
|
// If turnout does not exist, create it
|
||||||
|
@ -150,12 +150,16 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
StringFormatter::send(stream, F("HmTurnout %d created\n"),id);
|
StringFormatter::send(stream, F("HmTurnout %d created\n"),id);
|
||||||
}
|
}
|
||||||
switch (cmd[3]) {
|
switch (cmd[3]) {
|
||||||
case 'T': newstate=true; break;
|
// T and C according to RCN-213 where 0 is Stop, Red, Thrown, Diverging.
|
||||||
case 'C': newstate=false; break;
|
case 'T': newstate=0; break;
|
||||||
case '2': newstate=!Turnout::isActive(id);
|
case 'C': newstate=1; break;
|
||||||
|
case '2': newstate=!Turnout::isActive(id); break;
|
||||||
|
default : /* newstate still invalid */ break;
|
||||||
}
|
}
|
||||||
Turnout::activate(id,newstate);
|
if (newstate != 2) {
|
||||||
StringFormatter::send(stream, F("PTA%c%d\n"),newstate?'4':'2',id );
|
Turnout::activate(id,newstate);
|
||||||
|
StringFormatter::send(stream, F("PTA%c%d\n"),newstate?'4':'2',id );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'N': // Heartbeat (2), only send if connection completed by 'HU' message
|
case 'N': // Heartbeat (2), only send if connection completed by 'HU' message
|
||||||
|
|
Loading…
Reference in New Issue
Block a user