Skip to content

Commit

Permalink
EthernetInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbelos committed Sep 23, 2024
1 parent 692f97e commit dc481a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
21 changes: 5 additions & 16 deletions CommandStation-EX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void setup()
CommandDistributor::broadcastPower();
}

/**************** for future reference
void looptimer(unsigned long timeout, const FSH* message)
{
static unsigned long lasttimestamp = 0;
Expand All @@ -156,58 +157,46 @@ void looptimer(unsigned long timeout, const FSH* message)
}
lasttimestamp = now;
}

*********************************************/
void loop()
{
// The main sketch has responsibilities during loop()

// Responsibility 1: Handle DCC background processes
// (loco reminders and power checks)
looptimer(0, F(""));
DCC::loop();
looptimer(5000, F("DCC")); // got warnings up to 3884 during prog track read


// Responsibility 2: handle any incoming commands on USB connection
SerialManager::loop();
looptimer(2000, F("Serial")); // got warnings up to 1900 during start


// Responsibility 3: Optionally handle any incoming WiFi traffic
#ifndef ARDUINO_ARCH_ESP32
#if WIFI_ON
WifiInterface::loop();
looptimer(9000, F("Wifi")); // got warnings up to 8000


#endif //WIFI_ON
#else //ARDUINO_ARCH_ESP32
#ifndef WIFI_TASK_ON_CORE0
WifiESP::loop();
looptimer(1000, F("WifiESP"));

#endif
#endif //ARDUINO_ARCH_ESP32
#if ETHERNET_ON
EthernetInterface::loop();
looptimer(10000, F("Ethernet"));
#endif

RMFT::loop(); // ignored if no automation
looptimer(1000, F("RMFT"));

#if defined(LCN_SERIAL)
LCN::loop();
looptimer(1000, F("LCN"));
#endif

// Display refresh
DisplayInterface::loop();
looptimer(2000, F("Display")); // got warnings around 1150

// Handle/update IO devices.
IODevice::loop();
looptimer(1000, F("IODevice"));

Sensor::checkAll(); // Update and print changes
looptimer(1000, F("Sensor"));

// Report any decrease in memory (will automatically trigger on first call)
static int ramLowWatermark = __INT_MAX__; // replaced on first loop
Expand Down
15 changes: 3 additions & 12 deletions EthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
MDNS mdns(udp);
#endif


extern void looptimer(unsigned long timeout, const FSH* message);

bool EthernetInterface::connected=false;
EthernetServer * EthernetInterface::server= nullptr;
EthernetClient EthernetInterface::clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
Expand Down Expand Up @@ -127,17 +124,15 @@ void EthernetInterface::setup() // STM32 VERSION
void EthernetInterface::loop()
{
if (!connected) return;
looptimer(5000, F("E.loop"));


static bool warnedAboutLink=false;
if (Ethernet.linkStatus() == LinkOFF){
if (warnedAboutLink) return;
DIAG(F("Ethernet link OFF"));
warnedAboutLink=true;
return;
}
looptimer(5000, F("E.loop warn"));


// link status must be ok here
if (warnedAboutLink) {
DIAG(F("Ethernet link RESTORED"));
Expand All @@ -147,8 +142,6 @@ void EthernetInterface::loop()
#ifdef DO_MDNS
// Always do this because we don't want traffic to intefere with being found!
mdns.run();
looptimer(5000, F("E.mdns"));

#endif

//
Expand All @@ -168,8 +161,7 @@ void EthernetInterface::loop()
//DIAG(F("maintained"));
break;
}
looptimer(5000, F("E.maintain"));


// get client from the server
#if defined (STM32_ETHERNET)
// STM32Ethernet doesn't use accept(), just available()
Expand Down Expand Up @@ -224,7 +216,6 @@ void EthernetInterface::loop()
if (Diag::ETHERNET) DIAG(F("Ethernet s=%d, c=%d b=:%e"), socket, count, buffer);
// execute with data going directly back
CommandDistributor::parse(socket,buffer,outboundRing);
//looptimer(5000, F("Ethloop2 parse"));
return; // limit the amount of processing that takes place within 1 loop() cycle.
}

Expand Down
3 changes: 2 additions & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "StringFormatter.h"

#define VERSION "5.2.79"
#define VERSION "5.2.80"
// 5.2.80 - EthernetInterface upgrade
// 5.2.79 - serial manager loop that handles quoted strings
// - WiFiESP32 reconfig
// 5.2.78 - NeoPixel support.
Expand Down

0 comments on commit dc481a2

Please sign in to comment.