1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 18:16:13 +01:00

Compare commits

..

No commits in common. "bd44184f574b108d6eee700c635181e43e1b5588" and "198d762a212321ef632f2edf5cb6984c7254622d" have entirely different histories.

3 changed files with 34 additions and 39 deletions

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202312251647Z"
#define GITHUB_SHA "devel-202312131041Z"

View File

@ -74,39 +74,25 @@ class NetworkClient {
public:
NetworkClient(WiFiClient c) {
wifi = c;
inUse = true;
};
bool active(byte clientId) {
if (!inUse)
return false;
if(!wifi.connected()) {
DIAG(F("Remove client %d"), clientId);
CommandDistributor::forget(clientId);
wifi.stop();
inUse = false;
return false;
}
return true;
}
bool ok() {
return (inUse && wifi.connected());
};
bool recycle(WiFiClient c) {
if (wifi == c) {
if (inUse == true)
DIAG(F("WARNING: Duplicate"));
else
DIAG(F("Returning"));
inUse = true;
return true;
}
if (inUse == false) {
wifi = c;
inUse = true;
return true;
}
if (inUse == true) return false;
// return false here until we have
// implemented a LRU timer
// if (LRU too recent) return false;
return false;
wifi = c;
inUse = true;
return true;
};
WiFiClient wifi;
private:
bool inUse;
bool inUse = true;
};
static std::vector<NetworkClient> clients; // a list to hold all clients
@ -296,26 +282,37 @@ void WifiESP::loop() {
// really no good way to check for LISTEN especially in AP mode?
wl_status_t wlStatus;
if (APmode || (wlStatus = WiFi.status()) == WL_CONNECTED) {
// loop over all clients and remove inactive
for (clientId=0; clientId<clients.size(); clientId++){
// check if client is there and alive
if(clients[clientId].inUse && !clients[clientId].wifi.connected()) {
DIAG(F("Remove client %d"), clientId);
CommandDistributor::forget(clientId);
clients[clientId].wifi.stop();
clients[clientId].inUse = false;
//Do NOT clients.erase(clients.begin()+clientId) as
//that would mix up clientIds for later.
}
}
if (server->hasClient()) {
WiFiClient client;
while (client = server->available()) {
for (clientId=0; clientId<clients.size(); clientId++){
if (clients[clientId].recycle(client)) {
DIAG(F("Recycle client %d %s:%d"), clientId, client.remoteIP().toString().c_str(),client.remotePort());
DIAG(F("Recycle client %d %s"), clientId, client.remoteIP().toString().c_str());
break;
}
}
if (clientId>=clients.size()) {
NetworkClient nc(client);
clients.push_back(nc);
DIAG(F("New client %d, %s:%d"), clientId, client.remoteIP().toString().c_str(),client.remotePort());
DIAG(F("New client %d, %s"), clientId, client.remoteIP().toString().c_str());
}
}
}
// loop over all connected clients
// this removes as a side effect inactive clients when checking ::active()
for (clientId=0; clientId<clients.size(); clientId++){
if(clients[clientId].active(clientId)) {
if(clients[clientId].ok()) {
int len;
if ((len = clients[clientId].wifi.available()) > 0) {
// read data from client
@ -353,7 +350,7 @@ void WifiESP::loop() {
}
// buffer filled, end with '\0' so we can use it as C string
buffer[count]='\0';
if((unsigned int)clientId <= clients.size() && clients[clientId].active(clientId)) {
if((unsigned int)clientId <= clients.size() && clients[clientId].ok()) {
if (Diag::CMD || Diag::WITHROTTLE)
DIAG(F("SEND %d:%s"), clientId, buffer);
clients[clientId].wifi.write(buffer,count);
@ -386,9 +383,8 @@ void WifiESP::loop() {
// prio task. On core1 this is not a problem
// as there the wdt is disabled by the
// arduio IDE startup routines.
if (xPortGetCoreID() == 0) {
if (xPortGetCoreID() == 0)
feedTheDog0();
yield();
}
yield();
}
#endif //ESP32

View File

@ -3,8 +3,7 @@
#include "StringFormatter.h"
#define VERSION "5.2.17"
// 5.2.17 - ESP32 simplify network logic
#define VERSION "5.2.16"
// 5.2.16 - Bugfix to allow for devices using the EX-IOExpander protocol to have no analogue or no digital pins
// 5.2.15 - move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions
// - add repeats to function packets that are not reminded in accordance with accessory packets