mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
drop any acquired locos on Q(uit), reduce heartbeat to 2s
also some indentation fixes note that 2s heartbeat works best with next version of ED.
This commit is contained in:
parent
5256c1d021
commit
68255dcadd
|
@ -48,7 +48,7 @@
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
|
|
||||||
#define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco<MAX_MY_LOCO;loco++) \
|
#define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco<MAX_MY_LOCO;loco++) \
|
||||||
if (myLocos[loco].throttle==THROTTLECHAR && (CAB<0 || myLocos[loco].cab==CAB))
|
if ((myLocos[loco].throttle==THROTTLECHAR || '*'==THROTTLECHAR) && (CAB<0 || myLocos[loco].cab==CAB))
|
||||||
|
|
||||||
WiThrottle * WiThrottle::firstThrottle=NULL;
|
WiThrottle * WiThrottle::firstThrottle=NULL;
|
||||||
bool WiThrottle::annotateLeftRight=false;
|
bool WiThrottle::annotateLeftRight=false;
|
||||||
|
@ -59,7 +59,7 @@ WiThrottle* WiThrottle::getThrottle( int wifiClient) {
|
||||||
return new WiThrottle( wifiClient);
|
return new WiThrottle( wifiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// One instance of WiTHrottle per connected client, so we know what the locos are
|
// One instance of WiThrottle per connected client, so we know what the locos are
|
||||||
|
|
||||||
WiThrottle::WiThrottle( int wificlientid) {
|
WiThrottle::WiThrottle( int wificlientid) {
|
||||||
DIAG(F("\nCreating new WiThrottle for client %d\n"),wificlientid);
|
DIAG(F("\nCreating new WiThrottle for client %d\n"),wificlientid);
|
||||||
|
@ -164,7 +164,15 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Q': //
|
case 'Q': //
|
||||||
DIAG(F("WiThrottle Quit\n"));
|
LOOPLOCOS('*', -1) { //stop and drop all locos still assigned to this WiThrottle
|
||||||
|
if (myLocos[loco].throttle!='\0') {
|
||||||
|
DCC::setThrottle(myLocos[loco].cab,0,1);
|
||||||
|
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
||||||
|
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
||||||
|
myLocos[loco].throttle='\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DIAG(F("WiThrottle(%d) Quit\n"), clientid);
|
||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,10 +236,10 @@ void WiThrottle::multithrottle(Print & stream, byte * cmd){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '-': // remove loco
|
case '-': // stop and remove loco(s)
|
||||||
LOOPLOCOS(throttleChar, locoid) {
|
LOOPLOCOS(throttleChar, locoid) {
|
||||||
myLocos[loco].throttle='\0';
|
myLocos[loco].throttle='\0';
|
||||||
DCC::setThrottle(myLocos[loco].cab,0,1);
|
DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
||||||
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
||||||
}
|
}
|
||||||
|
@ -293,14 +301,14 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
|
||||||
//Emergency Stop (speed code 1)
|
//Emergency Stop (speed code 1)
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab));
|
DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'I': // Idle, set speed to 0
|
case 'I': // Idle, set speed to 0
|
||||||
case 'Q': // Quit, set speed to 0
|
case 'Q': // Quit, set speed to 0
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab));
|
DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,12 +321,13 @@ void WiThrottle::loop() {
|
||||||
void WiThrottle::checkHeartbeat() {
|
void WiThrottle::checkHeartbeat() {
|
||||||
// if 2 heartbeats missed... STOP and forget all locos for this client
|
// if 2 heartbeats missed... STOP and forget all locos for this client
|
||||||
if(heartBeatEnable && (millis()-heartBeat > HEARTBEAT_TIMEOUT*2000)) {
|
if(heartBeatEnable && (millis()-heartBeat > HEARTBEAT_TIMEOUT*2000)) {
|
||||||
DIAG(F("WiThrottle hearbeat missed client=%d"),clientid);
|
DIAG(F("WiThrottle(%d) hearbeat missed, dropping connection"),clientid);
|
||||||
for (int loco=0;loco<MAX_MY_LOCO;loco++) {
|
LOOPLOCOS('*', -1) { //stop and drop all locos still assigned to this WiThrottle
|
||||||
if (myLocos[loco].throttle!='\0') {
|
if (myLocos[loco].throttle!='\0') {
|
||||||
DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); //eStop
|
DIAG(F(" dropping cab %c"),clientid, myLocos[loco].cab);
|
||||||
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); //eStop
|
||||||
}
|
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete this;
|
delete this;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,7 +36,7 @@ class WiThrottle {
|
||||||
~WiThrottle();
|
~WiThrottle();
|
||||||
|
|
||||||
static const int MAX_MY_LOCO=10; //maximum number of locos assigned to a single client
|
static const int MAX_MY_LOCO=10; //maximum number of locos assigned to a single client
|
||||||
static const int HEARTBEAT_TIMEOUT=3;// heartbeat at 3secs to provide messaging transport
|
static const int HEARTBEAT_TIMEOUT=2;// heartbeat at 2secs to provide messaging transport
|
||||||
static WiThrottle* firstThrottle;
|
static WiThrottle* firstThrottle;
|
||||||
static int getInt(byte * cmd);
|
static int getInt(byte * cmd);
|
||||||
static int getLocoId(byte * cmd);
|
static int getLocoId(byte * cmd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user