1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

Debugging Nucleo Ethernet

This commit is contained in:
pmantoine 2024-04-26 18:14:14 +08:00
parent d9183cfdba
commit 6cd94d9ed2

View File

@ -241,6 +241,8 @@ void EthernetInterface::loop2() {
if (Diag::ETHERNET) DIAG(F("No outboundRing")); if (Diag::ETHERNET) DIAG(F("No outboundRing"));
return; return;
} }
// Make sure mDNS continues to work!
mdns.run();
// get client from the server // get client from the server
#if defined (STM32_ETHERNET) #if defined (STM32_ETHERNET)
// STM32Ethernet doesn't use accept(), just available() // STM32Ethernet doesn't use accept(), just available()
@ -252,24 +254,24 @@ void EthernetInterface::loop2() {
if (client) if (client)
{ {
byte socket; byte socket;
bool sockfound = false; bool sockfound = false;
for (socket = 0; socket < MAX_SOCK_NUM; socket++) { for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
if (clients[socket] && (clients[socket] == client)) { if (clients[socket] && (clients[socket] == client)) {
sockfound = true; sockfound = true;
if (Diag::ETHERNET) DIAG(F("Ethernet: Old client socket %d"),socket); if (Diag::ETHERNET) DIAG(F("Ethernet: Old client socket %d"),socket);
break; break;
} }
} }
if (!sockfound) { // new client if (!sockfound) { // new client
for (socket = 0; socket < MAX_SOCK_NUM; socket++) { for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
if (!clients[socket]) { if (!clients[socket]) {
// On accept() the EthernetServer doesn't track the client anymore // On accept() the EthernetServer doesn't track the client anymore
// so we store it in our client array // so we store it in our client array
clients[socket] = client; clients[socket] = client;
if (Diag::ETHERNET) DIAG(F("Ethernet: New client socket %d"),socket); if (Diag::ETHERNET) DIAG(F("Ethernet: New client socket %d"),socket);
break; break;
} }
} }
} }
if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW")); if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW"));
} }
@ -278,34 +280,33 @@ void EthernetInterface::loop2() {
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
{ {
if (clients[socket]) { if (clients[socket]) {
if (!clients[socket].connected()) { // stop any clients which disconnect if (!clients[socket].connected()) { // stop any clients which disconnect
CommandDistributor::forget(socket); CommandDistributor::forget(socket);
clients[socket].stop(); clients[socket].stop();
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR)
clients[socket]=NULL; clients[socket]=NULL;
#else #else
clients[socket]=(EthernetClient)nullptr; clients[socket]=(EthernetClient)nullptr;
#endif #endif
//if (Diag::ETHERNET) //if (Diag::ETHERNET)
DIAG(F("Ethernet: disconnect %d "), socket); DIAG(F("Ethernet: disconnect %d "), socket);
return; // Trick: So that we do not continue in this loop with client that is NULL return; // Trick: So that we do not continue in this loop with client that is NULL
} }
int available=clients[socket].available(); int available=clients[socket].available();
if (available > 0) { if (available > 0) {
if (Diag::ETHERNET) DIAG(F("Ethernet: available socket=%d,avail=%d"), socket, available); if (Diag::ETHERNET) DIAG(F("Ethernet: available socket=%d,avail=%d"), socket, available);
// read bytes from a client // read bytes from a client
int count = clients[socket].read(buffer, MAX_ETH_BUFFER); int count = clients[socket].read(buffer, MAX_ETH_BUFFER);
buffer[count] = '\0'; // terminate the string properly buffer[count] = '\0'; // terminate the string properly
if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer); if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer);
// execute with data going directly back // execute with data going directly back
CommandDistributor::parse(socket,buffer,outboundRing); CommandDistributor::parse(socket,buffer,outboundRing);
return; // limit the amount of processing that takes place within 1 loop() cycle. return; // limit the amount of processing that takes place within 1 loop() cycle.
} }
} }
} }
mdns.run();
WiThrottle::loop(outboundRing); WiThrottle::loop(outboundRing);