mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
WiThrott;e FIXES
This commit is contained in:
parent
a2636b1296
commit
4aceff8b7c
2
DCC.cpp
2
DCC.cpp
@ -390,7 +390,7 @@ int DCC::lookupSpeedTable(int locoId) {
|
|||||||
}
|
}
|
||||||
if (reg==firstEmpty){
|
if (reg==firstEmpty){
|
||||||
speedTable[reg].loco = locoId;
|
speedTable[reg].loco = locoId;
|
||||||
speedTable[reg].speedCode=0;
|
speedTable[reg].speedCode=128; // default direction forward
|
||||||
speedTable[reg].groupFlags=0;
|
speedTable[reg].groupFlags=0;
|
||||||
speedTable[reg].functions=0;
|
speedTable[reg].functions=0;
|
||||||
}
|
}
|
||||||
|
@ -51,27 +51,22 @@
|
|||||||
|
|
||||||
WiThrottle * WiThrottle::firstThrottle=NULL;
|
WiThrottle * WiThrottle::firstThrottle=NULL;
|
||||||
|
|
||||||
WiThrottle* WiThrottle::getThrottle(Print & stream, int wifiClient) {
|
WiThrottle* WiThrottle::getThrottle( int wifiClient) {
|
||||||
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
|
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
|
||||||
if (wt->clientid==wifiClient) return wt;
|
if (wt->clientid==wifiClient) return wt;
|
||||||
return new WiThrottle(stream, 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(Print & stream, 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);
|
||||||
nextThrottle=firstThrottle;
|
nextThrottle=firstThrottle;
|
||||||
firstThrottle= this;
|
firstThrottle= this;
|
||||||
clientid=wificlientid;
|
clientid=wificlientid;
|
||||||
for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0';
|
heartBeatEnable=false; // until client turns it on
|
||||||
StringFormatter::send(stream,F("VN2.0\nHTDCC++EX\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\\PTL"), DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
|
firstCall=true;
|
||||||
|
for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0';
|
||||||
for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){
|
|
||||||
StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE));
|
|
||||||
}
|
|
||||||
StringFormatter::send(stream,F("\n*10\n"));
|
|
||||||
heartBeatEnable=false; // until client turns it on
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WiThrottle::~WiThrottle() {
|
WiThrottle::~WiThrottle() {
|
||||||
@ -87,10 +82,33 @@ WiThrottle::~WiThrottle() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiThrottle::parse(Print & stream, byte * cmd) {
|
void WiThrottle::parse(Print & stream, byte * cmdx) {
|
||||||
|
|
||||||
|
// we have to take a copy of the cmd buffer as the reply will get built into the cmdx
|
||||||
|
byte local[50];
|
||||||
|
for (byte i=0;i<sizeof(local);i++) {
|
||||||
|
local[i]=cmdx[i];
|
||||||
|
if (!cmdx[i]) break;
|
||||||
|
}
|
||||||
|
local[49]='\0'; // prevent runaway parser
|
||||||
|
|
||||||
|
byte * cmd=local;
|
||||||
|
|
||||||
heartBeat=millis();
|
heartBeat=millis();
|
||||||
DIAG(F("\nWiThrottle(%d) [%e]"),clientid, cmd);
|
DIAG(F("\nWiThrottle(%d) [%e]"),clientid, cmd);
|
||||||
|
|
||||||
|
if (firstCall) {
|
||||||
|
firstCall=false;
|
||||||
|
StringFormatter::send(stream,F("VN2.0\nHTDCC++EX\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\\PTL"),
|
||||||
|
DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
|
||||||
|
|
||||||
|
for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){
|
||||||
|
StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE));
|
||||||
|
}
|
||||||
|
StringFormatter::send(stream,F("\n*10\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (cmd[0]) {
|
||||||
switch (cmd[0]) {
|
switch (cmd[0]) {
|
||||||
case '*': // heartbeat control
|
case '*': // heartbeat control
|
||||||
if (cmd[1]=='+') heartBeatEnable=true;
|
if (cmd[1]=='+') heartBeatEnable=true;
|
||||||
@ -120,6 +138,10 @@ void WiThrottle::parse(Print & stream, byte * cmd) {
|
|||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// skip over cmd until 0 or past \r or \n
|
||||||
|
while(*cmd !='\0' && *cmd != '\r' && *cmd !='\n') cmd++;
|
||||||
|
if (*cmd!='\0') cmd++; // skip \r or \n
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int WiThrottle::getInt(byte * cmd) {
|
int WiThrottle::getInt(byte * cmd) {
|
||||||
int i=0;
|
int i=0;
|
||||||
@ -196,12 +218,12 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
|
|||||||
case 'q':
|
case 'q':
|
||||||
if (aval[1]=='V') { //qV
|
if (aval[1]=='V') { //qV
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
StringFormatter::send(stream,F("M%cAL%d<;>V%d"), throttleChar, myLocos[loco].cab, DCC::getThrottleSpeed(myLocos[loco].cab));
|
StringFormatter::send(stream,F("M%cAL%d<;>V%d\n"), throttleChar, myLocos[loco].cab, DCC::getThrottleSpeed(myLocos[loco].cab));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (aval[1]=='R') { // qR
|
else if (aval[1]=='R') { // qR
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
StringFormatter::send(stream,F("M%cAL%d<;>R%d"), throttleChar, myLocos[loco].cab, DCC::getThrottleDirection(myLocos[loco].cab));
|
StringFormatter::send(stream,F("M%cAL%d<;>R%d\n"), throttleChar, myLocos[loco].cab, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -29,10 +29,10 @@ class WiThrottle {
|
|||||||
public:
|
public:
|
||||||
static void loop();
|
static void loop();
|
||||||
void parse(Print & stream, byte * cmd);
|
void parse(Print & stream, byte * cmd);
|
||||||
static WiThrottle* getThrottle(Print & stream, int wifiClient);
|
static WiThrottle* getThrottle( int wifiClient);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WiThrottle(Print & stream, int wifiClientId);
|
WiThrottle( int wifiClientId);
|
||||||
~WiThrottle();
|
~WiThrottle();
|
||||||
|
|
||||||
static const int MAX_MY_LOCO=10;
|
static const int MAX_MY_LOCO=10;
|
||||||
@ -46,6 +46,7 @@ class WiThrottle {
|
|||||||
|
|
||||||
MYLOCO myLocos[MAX_MY_LOCO];
|
MYLOCO myLocos[MAX_MY_LOCO];
|
||||||
bool heartBeatEnable;
|
bool heartBeatEnable;
|
||||||
|
bool firstCall;
|
||||||
unsigned long heartBeat;
|
unsigned long heartBeat;
|
||||||
|
|
||||||
void multithrottle(Print & stream, byte * cmd);
|
void multithrottle(Print & stream, byte * cmd);
|
||||||
|
@ -172,12 +172,12 @@ void WifiInterface::loop(Stream & wifiStream) {
|
|||||||
}
|
}
|
||||||
else if (buffer[0]=='<') parser.parse(streamer,buffer, true); // tell JMRI parser that callbacks are diallowed because we dont want to handle the async
|
else if (buffer[0]=='<') parser.parse(streamer,buffer, true); // tell JMRI parser that callbacks are diallowed because we dont want to handle the async
|
||||||
|
|
||||||
else WiThrottle::getThrottle(streamer, connectionId)->parse(streamer, buffer);
|
else WiThrottle::getThrottle(connectionId)->parse(streamer, buffer);
|
||||||
|
|
||||||
|
|
||||||
if (streamer.available()) { // there is a reply to send
|
if (streamer.available()) { // there is a reply to send
|
||||||
streamer.write('\0');
|
streamer.write('\0');
|
||||||
DIAG(F("WiFiInterface Responding client (%d) l(%d) %e\n"),connectionId,streamer.available()-1,buffer);
|
DIAG(F("\nWiFiInterface reply c(%d) l(%d) [%e]\n"),connectionId,streamer.available()-1,buffer);
|
||||||
|
|
||||||
StringFormatter::send(wifiStream,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available()-1);
|
StringFormatter::send(wifiStream,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available()-1);
|
||||||
if (checkForOK(wifiStream,1000,PROMPT_SEARCH,true)) wifiStream.print((char *) buffer);
|
if (checkForOK(wifiStream,1000,PROMPT_SEARCH,true)) wifiStream.print((char *) buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user