mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
- Added esp8266 revceive buffer clear when a link drop is detected
- Added timestamps for CIPSEND and +IPD tracing
This commit is contained in:
parent
2a16e7d710
commit
ac550e81c8
|
@ -70,7 +70,7 @@ void WifiInboundHandler::loop1()
|
||||||
|
|
||||||
//If there is data in the ring
|
//If there is data in the ring
|
||||||
if (clientPendingCIPSEND >= 0 ) {
|
if (clientPendingCIPSEND >= 0 ) {
|
||||||
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_PENDING"));
|
if (Diag::WIFI) { ts.cipSendStart = millis(); DIAG( F("cipSendStatus = CIP_SEND_PENDING")); }
|
||||||
//Get the length of the reply to send
|
//Get the length of the reply to send
|
||||||
currentReplySize = outboundRing->count();
|
currentReplySize = outboundRing->count();
|
||||||
//Set the pending CIPSEND flag
|
//Set the pending CIPSEND flag
|
||||||
|
@ -82,7 +82,7 @@ void WifiInboundHandler::loop1()
|
||||||
if (cipSendStatus == CIP_SEND_PENDING) {
|
if (cipSendStatus == CIP_SEND_PENDING) {
|
||||||
if (Diag::WIFI) DIAG( F("WiFi: [[CIPSEND=%d,%d]]"), clientPendingCIPSEND, currentReplySize);
|
if (Diag::WIFI) DIAG( F("WiFi: [[CIPSEND=%d,%d]]"), clientPendingCIPSEND, currentReplySize);
|
||||||
StringFormatter::send(wifiStream, F("AT+CIPSEND=%d,%d\r\n"), clientPendingCIPSEND, currentReplySize);
|
StringFormatter::send(wifiStream, F("AT+CIPSEND=%d,%d\r\n"), clientPendingCIPSEND, currentReplySize);
|
||||||
if (Diag::WIFI) DIAG( F("pendingCipsend = CIP_SEND_SENT"));
|
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_SENT [%lms]"),millis()-ts.cipSendStart);
|
||||||
cipSendStatus = CIP_SEND_SENT;
|
cipSendStatus = CIP_SEND_SENT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,7 @@ int WifiInboundHandler::antoi(char* str, int len) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This loop processes the inbound bytes from an ES AT command processor
|
// This loop processes the inbound bytes from an ES AT command processor
|
||||||
WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
|
|
||||||
|
@ -136,7 +137,7 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
//The execption is the +IPD message. Only the data up to the ':' character (end of length)
|
//The execption is the +IPD message. Only the data up to the ':' character (end of length)
|
||||||
//is put in this buffer. The actual +IPD data is written directly into the inbound buffer
|
//is put in this buffer. The actual +IPD data is written directly into the inbound buffer
|
||||||
while (!exitLoop)
|
while (!exitLoop)
|
||||||
{
|
{
|
||||||
//We exit this loop either if there is no data available, or we have a complete message to process
|
//We exit this loop either if there is no data available, or we have a complete message to process
|
||||||
while (wifiStream->available() && messageToProcess == RECV_MSG_NONE)
|
while (wifiStream->available() && messageToProcess == RECV_MSG_NONE)
|
||||||
{
|
{
|
||||||
|
@ -167,6 +168,9 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
|
|
||||||
//IPD message
|
//IPD message
|
||||||
else if ((stringStartPos = strstr(recBuffer, "+IPD,")) != NULL && (stringEndPos = strstr(recBuffer, ":")) != NULL) {
|
else if ((stringStartPos = strstr(recBuffer, "+IPD,")) != NULL && (stringEndPos = strstr(recBuffer, ":")) != NULL) {
|
||||||
|
|
||||||
|
if (Diag::WIFI) { ts.ipdStart = millis(); DIAG( F("+IPD Message START")); }
|
||||||
|
|
||||||
//Advance the start string to the beginning of the length
|
//Advance the start string to the beginning of the length
|
||||||
stringStartPos += strlen("+IPD,");
|
stringStartPos += strlen("+IPD,");
|
||||||
|
|
||||||
|
@ -210,16 +214,16 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
if (strstr(recBuffer, "SEND FAIL") != NULL) {
|
if (strstr(recBuffer, "SEND FAIL") != NULL) {
|
||||||
if (Diag::WIFI) DIAG(F("[SEND FAIL - detected"));
|
if (Diag::WIFI) DIAG(F("[SEND FAIL - detected"));
|
||||||
if (cipSendStatus == CIP_SEND_DATA_SENT) {
|
if (cipSendStatus == CIP_SEND_DATA_SENT) {
|
||||||
if (Diag::WIFI) DIAG( F("pendingCipsend = CIP_SEND_NONE"));
|
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_NONE [%lms]"),millis()-ts.cipSendStart);
|
||||||
cipSendStatus = CIP_SEND_NONE;
|
cipSendStatus = CIP_SEND_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for a SEND OK message
|
//Check for a SEND OK message
|
||||||
else if (strstr(recBuffer, "SEND OK") != NULL) {
|
else if (strstr(recBuffer, "SEND OK") != NULL) {
|
||||||
if (Diag::WIFI) DIAG(F("[SEND OK - detected"));
|
if (Diag::WIFI) DIAG(F("[SEND OK - detected [%lms]"),millis()-ts.cipSendStart);
|
||||||
if (cipSendStatus == CIP_SEND_DATA_SENT) {
|
if (cipSendStatus == CIP_SEND_DATA_SENT) {
|
||||||
if (Diag::WIFI) DIAG( F("pendingCipsend = CIP_SEND_NONE"));
|
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_NONE [%lms]"),millis()-ts.cipSendStart);
|
||||||
cipSendStatus = CIP_SEND_NONE;
|
cipSendStatus = CIP_SEND_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,12 +242,16 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
if (clientPendingCIPSEND >= 0) {
|
if (clientPendingCIPSEND >= 0) {
|
||||||
if (Diag::WIFI) DIAG(F("['link is not valid' detected - purging CIPSEND]"));
|
if (Diag::WIFI) DIAG(F("['link is not valid' detected - purging CIPSEND]"));
|
||||||
purgeCurrentCIPSEND();
|
purgeCurrentCIPSEND();
|
||||||
|
//Clear out all data from esp8266 receive buffer
|
||||||
|
while (wifiStream->available()) {
|
||||||
|
wifiStream->read();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RECV_MSG_SND_DATA:
|
case RECV_MSG_SND_DATA:
|
||||||
if (Diag::WIFI) DIAG(F("[XMIT %d]"), currentReplySize);
|
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_DATA_SENT [XMIT START %d] [%lms]"),currentReplySize, millis()-ts.cipSendStart);
|
||||||
for (i = 0; i < currentReplySize; i++)
|
for (i = 0; i < currentReplySize; i++)
|
||||||
{
|
{
|
||||||
//Read data from the outboundRing and write to to Wifi
|
//Read data from the outboundRing and write to to Wifi
|
||||||
|
@ -254,7 +262,7 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
|
|
||||||
//Set CIPSEND flag to -1
|
//Set CIPSEND flag to -1
|
||||||
clientPendingCIPSEND = -1;
|
clientPendingCIPSEND = -1;
|
||||||
if (Diag::WIFI) DIAG( F("pendingCipsend = CIP_SEND_DATA_SENT"));
|
if (Diag::WIFI) DIAG( F("cipSendStatus = CIP_SEND_DATA_SENT [XMIT END] [%lms]"),millis()-ts.cipSendStart);
|
||||||
cipSendStatus = CIP_SEND_DATA_SENT;
|
cipSendStatus = CIP_SEND_DATA_SENT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -262,7 +270,7 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
|
|
||||||
//Mark the location with the client ID
|
//Mark the location with the client ID
|
||||||
if (dataRemaining == dataLength) {
|
if (dataRemaining == dataLength) {
|
||||||
if (Diag::WIFI) DIAG(F("Wifi inbound data(%d:%d):"), runningClientId, dataLength);
|
if (Diag::WIFI) DIAG(F("Wifi inbound data(%d:%d) [%lms]:"), runningClientId, dataLength, millis()-ts.ipdStart);
|
||||||
inboundRing->mark(runningClientId);
|
inboundRing->mark(runningClientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +304,7 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||||
|
|
||||||
// Commit inbound ring data
|
// Commit inbound ring data
|
||||||
if (dataRemaining == 0) {
|
if (dataRemaining == 0) {
|
||||||
if (Diag::WIFI) DIAG(F("COMMIT"));
|
if (Diag::WIFI) DIAG(F("COMMIT [%lms]:"),millis()-ts.ipdStart);
|
||||||
if(inboundRing->commit() == false) {
|
if(inboundRing->commit() == false) {
|
||||||
outboundRing->flush();
|
outboundRing->flush();
|
||||||
inboundRing->flush();
|
inboundRing->flush();
|
||||||
|
@ -352,7 +360,7 @@ void WifiInboundHandler::purgeCurrentCIPSEND() {
|
||||||
wifiStream->write(c);
|
wifiStream->write(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Clear CIP send status
|
||||||
cipSendStatus = CIP_SEND_NONE;
|
cipSendStatus = CIP_SEND_NONE;
|
||||||
clientPendingCIPSEND = -1;
|
clientPendingCIPSEND = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,11 @@ class WifiInboundHandler {
|
||||||
CIP_SEND_DATA_SENT
|
CIP_SEND_DATA_SENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct _timeStamps {
|
||||||
|
long cipSendStart;
|
||||||
|
long ipdStart;
|
||||||
|
} timeStamps_t;
|
||||||
|
|
||||||
WifiInboundHandler(Stream * ESStream);
|
WifiInboundHandler(Stream * ESStream);
|
||||||
void loop1();
|
void loop1();
|
||||||
INBOUND_STATE loop2();
|
INBOUND_STATE loop2();
|
||||||
|
@ -82,5 +87,6 @@ class WifiInboundHandler {
|
||||||
char recBuffer[INBOUND_CMD_BUFFER] = {'\0'};
|
char recBuffer[INBOUND_CMD_BUFFER] = {'\0'};
|
||||||
int recBufferPos = 0;
|
int recBufferPos = 0;
|
||||||
int recBufferWatermark = 0;
|
int recBufferWatermark = 0;
|
||||||
|
timeStamps_t ts = {0};
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user