mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
make sending loop ringbuffer to ESP32 Wifi more simple
This commit is contained in:
parent
76c5608181
commit
ecda69ba32
|
@ -270,25 +270,6 @@ void WifiESP::loop() {
|
|||
// something to write out?
|
||||
clientId=outboundRing->read();
|
||||
if (clientId >= 0) {
|
||||
if ((unsigned int)clientId > clients.size()) {
|
||||
// something is wrong with the ringbuffer position
|
||||
// or client has disconnected
|
||||
outboundRing->info();
|
||||
if ((unsigned int)clientId < 8) {
|
||||
// try to recover by reading out to nowhere
|
||||
int count=outboundRing->count();
|
||||
for(int i=0;i<count;i++) {
|
||||
int c = outboundRing->read();
|
||||
if (c < 0) {
|
||||
DIAG(F("Ringread fail in discarding data for client %d at pos %d"),clientId, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
outboundRing->info();
|
||||
} else {
|
||||
DIAG(F("No clientId where expected: Ring beyond rescue"));
|
||||
}
|
||||
} else {
|
||||
// We have data to send in outboundRing
|
||||
// and we have a valid clientId.
|
||||
// First read it out to buffer
|
||||
|
@ -296,19 +277,22 @@ void WifiESP::loop() {
|
|||
// we can not leave it in the ring for ever
|
||||
int count=outboundRing->count();
|
||||
{
|
||||
char buffer[count+1];
|
||||
char buffer[count+1]; // one extra for '\0'
|
||||
for(int i=0;i<count;i++) {
|
||||
int c = outboundRing->read();
|
||||
if (c >= 0)
|
||||
if (c >= 0) // Panic check, should never be false
|
||||
buffer[i] = (char)c;
|
||||
else {
|
||||
DIAG(F("Ringread fail at %d"),i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
buffer[count]=0;
|
||||
if(clients[clientId].ok())
|
||||
// buffer filled, end with '\0' so we can use it as C string
|
||||
buffer[count]='\0';
|
||||
if((unsigned int)clientId <= clients.size() && clients[clientId].ok()) {
|
||||
clients[clientId].wifi.write(buffer,count);
|
||||
} else {
|
||||
DIAG(F("Unsent(%d): %s"), clientId, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user