Skip to content

Commit a50c4b5

Browse files
authored
Merge pull request #404 from sparkfun/NTP_Updates
NTP updates
2 parents 6bd8ec8 + 5d42efb commit a50c4b5

File tree

10 files changed

+290
-393
lines changed

10 files changed

+290
-393
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ void beginFS()
778778
}
779779

780780
// Check if configureViaEthernet.txt exists
781-
// Used to indicate if SparkFun_WebServer_ESP32_W5500 needs _exclusive_ access to SPI and interrupts
782781
bool checkConfigureViaEthernet()
783782
{
784783
if (online.fs == false)
@@ -796,7 +795,6 @@ bool checkConfigureViaEthernet()
796795
}
797796

798797
// Force configure-via-ethernet mode by creating configureViaEthernet.txt in LittleFS
799-
// Used to indicate if SparkFun_WebServer_ESP32_W5500 needs _exclusive_ access to SPI and interrupts
800798
bool forceConfigureViaEthernet()
801799
{
802800
if (online.fs == false)
@@ -836,8 +834,6 @@ void beginInterrupts()
836834
{
837835
DMW_if systemPrintf("pin_Ethernet_Interrupt: %d\r\n", pin_Ethernet_Interrupt);
838836
pinMode(pin_Ethernet_Interrupt, INPUT); // Prepare the interrupt pin
839-
// TODO: figure out how to handle NTP mode and timestamp the arrival of UDP NTP requests
840-
// attachInterrupt(pin_Ethernet_Interrupt, ethernetISR, FALLING); // Attach the interrupt
841837
}
842838
#endif // COMPILE_ETHERNET
843839
}

Firmware/RTK_Everywhere/Display.ino

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void displayUpdate()
261261
paintLogging(&iconPropertyList);
262262
displaySivVsOpenShort(&iconPropertyList);
263263
displayBatteryVsEthernet(&iconPropertyList);
264+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
264265
setRadioIcons(&iconPropertyList);
265266
break;
266267
case (STATE_ROVER_NO_FIX):
@@ -269,6 +270,7 @@ void displayUpdate()
269270
paintLogging(&iconPropertyList);
270271
displaySivVsOpenShort(&iconPropertyList);
271272
displayBatteryVsEthernet(&iconPropertyList);
273+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
272274
setRadioIcons(&iconPropertyList);
273275
break;
274276
case (STATE_ROVER_FIX):
@@ -277,6 +279,7 @@ void displayUpdate()
277279
paintLogging(&iconPropertyList);
278280
displaySivVsOpenShort(&iconPropertyList);
279281
displayBatteryVsEthernet(&iconPropertyList);
282+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
280283
setRadioIcons(&iconPropertyList);
281284
break;
282285
case (STATE_ROVER_RTK_FLOAT):
@@ -285,6 +288,7 @@ void displayUpdate()
285288
paintLogging(&iconPropertyList);
286289
displaySivVsOpenShort(&iconPropertyList);
287290
displayBatteryVsEthernet(&iconPropertyList);
291+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
288292
setRadioIcons(&iconPropertyList);
289293
break;
290294
case (STATE_ROVER_RTK_FIX):
@@ -293,6 +297,7 @@ void displayUpdate()
293297
paintLogging(&iconPropertyList);
294298
displaySivVsOpenShort(&iconPropertyList);
295299
displayBatteryVsEthernet(&iconPropertyList);
300+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
296301
setRadioIcons(&iconPropertyList);
297302
break;
298303

@@ -309,27 +314,32 @@ void displayUpdate()
309314
paintLogging(&iconPropertyList);
310315
displaySivVsOpenShort(&iconPropertyList);
311316
displayBatteryVsEthernet(&iconPropertyList);
317+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
312318
setRadioIcons(&iconPropertyList);
313319
break;
314320
case (STATE_BASE_TEMP_SURVEY_STARTED):
315321
paintLogging(&iconPropertyList);
316322
displayBatteryVsEthernet(&iconPropertyList); // Top right
323+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
317324
setRadioIcons(&iconPropertyList);
318325
paintBaseTempSurveyStarted(&iconPropertyList);
319326
break;
320327
case (STATE_BASE_TEMP_TRANSMITTING):
321328
paintLogging(&iconPropertyList);
322329
displayBatteryVsEthernet(&iconPropertyList); // Top right
330+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
323331
setRadioIcons(&iconPropertyList);
324332
paintRTCM(&iconPropertyList);
325333
break;
326334
case (STATE_BASE_FIXED_NOT_STARTED):
327335
displayBatteryVsEthernet(&iconPropertyList); // Top right
336+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
328337
setRadioIcons(&iconPropertyList);
329338
break;
330339
case (STATE_BASE_FIXED_TRANSMITTING):
331340
paintLogging(&iconPropertyList);
332341
displayBatteryVsEthernet(&iconPropertyList); // Top right
342+
displayFullIPAddress(&iconPropertyList); // Bottom left - 128x64 only
333343
setRadioIcons(&iconPropertyList);
334344
paintRTCM(&iconPropertyList);
335345
break;
@@ -1767,36 +1777,66 @@ void paintConnectingToNtripCaster()
17671777
printTextwithKerning("Connecting", textX, textY, textKerning);
17681778
}
17691779

1770-
// Scroll through IP address. Wipe with spaces both ends.
1780+
// Shuttle through IP address
17711781
void paintIPAddress()
17721782
{
1773-
char ipAddress[32];
1774-
snprintf(ipAddress, sizeof(ipAddress), " %d.%d.%d.%d ",
1783+
char ipAddress[16];
1784+
snprintf(ipAddress, sizeof(ipAddress), "%s",
17751785
#ifdef COMPILE_ETHERNET
1776-
ETH.localIP()[0], ETH.localIP()[1], ETH.localIP()[2], ETH.localIP()[3]);
1786+
ETH.localIP().toString());
17771787
#else // COMPILE_ETHERNET
1778-
0, 0, 0, 0);
1788+
"0.0.0.0");
17791789
#endif // COMPILE_ETHERNET
17801790

1781-
static uint8_t ipAddressPosition = 0;
1791+
oled->setFont(QW_FONT_5X7); // Set font to smallest
1792+
oled->setCursor(0, 3);
17821793

1783-
// Check if IP address is all single digits and can be printed without scrolling
1784-
if (strlen(ipAddress) <= 21)
1785-
ipAddressPosition = 7;
1794+
// If we can print the full IP address without shuttling
1795+
if (strlen(ipAddress) <= 7)
1796+
{
1797+
oled->print(ipAddress);
1798+
}
1799+
else
1800+
{
1801+
// Print as many characters as we can. Shuttle back and forth to display all.
1802+
static int startPos = 0;
1803+
char printThis[7 + 1];
1804+
int extras = strlen(ipAddress) - 7;
1805+
int shuttle[(2 * extras) + 2]; // Wait for a double state at each end
1806+
shuttle[0] = 0;
1807+
int x;
1808+
for (x = 0; x <= extras; x++)
1809+
shuttle[x + 1] = x;
1810+
shuttle[extras + 2] = extras;
1811+
x += 2;
1812+
for (int y = extras - 1; y > 0; y--)
1813+
shuttle[x++] = y;
1814+
if (startPos >= (2 * extras) + 2)
1815+
startPos = 0;
1816+
snprintf(printThis, sizeof(printThis), &ipAddress[shuttle[startPos]]);
1817+
startPos++;
1818+
oled->print(printThis);
1819+
}
1820+
}
1821+
1822+
void displayFullIPAddress(std::vector<iconPropertyBlinking> *iconList) // Bottom left - 128x64 only
1823+
{
1824+
if (present.display_type == DISPLAY_128x64)
1825+
{
1826+
char myAddress[16];
17861827

1787-
// Print seven characters of IP address
1788-
char printThis[9];
1789-
snprintf(printThis, sizeof(printThis), "%c%c%c%c%c%c%c", ipAddress[ipAddressPosition + 0],
1790-
ipAddress[ipAddressPosition + 1], ipAddress[ipAddressPosition + 2], ipAddress[ipAddressPosition + 3],
1791-
ipAddress[ipAddressPosition + 4], ipAddress[ipAddressPosition + 5], ipAddress[ipAddressPosition + 6]);
1828+
uint8_t networkType = networkGetType();
1829+
IPAddress ipAddress = networkGetIpAddress(networkType);
17921830

1793-
oled->setFont(QW_FONT_5X7); // Set font to smallest
1794-
oled->setCursor(0, 3);
1795-
oled->print(printThis);
1831+
if (ipAddress != IPAddress((uint32_t)0))
1832+
{
1833+
snprintf(myAddress, sizeof(myAddress), "%s", ipAddress.toString());
17961834

1797-
ipAddressPosition++; // Increment the print position
1798-
if (ipAddress[ipAddressPosition + 7] == 0) // Wrap
1799-
ipAddressPosition = 0;
1835+
oled->setFont(QW_FONT_5X7); // Set font to smallest
1836+
oled->setCursor(0, 55);
1837+
oled->print(ipAddress);
1838+
}
1839+
}
18001840
}
18011841

18021842
void paintMACAddress4digit(uint8_t xPos, uint8_t yPos)
@@ -2081,7 +2121,7 @@ void displayWiFiConfig()
20812121

20822122
// Convert to string
20832123
char myIP[20] = {'\0'};
2084-
snprintf(myIP, sizeof(myIP), "%d.%d.%d.%d", myIpAddress[0], myIpAddress[1], myIpAddress[2], myIpAddress[3]);
2124+
snprintf(myIP, sizeof(myIP), "%s", myIpAddress.toString());
20852125

20862126
char myIPFront[displayMaxCharacters + 1]; // 1 for null terminator
20872127
char myIPBack[displayMaxCharacters + 1]; // 1 for null terminator
@@ -3008,7 +3048,7 @@ void displayConfigViaEthernet()
30083048

30093049
char ipAddress[16];
30103050
IPAddress localIP = ETH.localIP();
3011-
snprintf(ipAddress, sizeof(ipAddress), "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
3051+
snprintf(ipAddress, sizeof(ipAddress), "%s", localIP.toString());
30123052

30133053
int displayWidthChars = ((present.display_type == DISPLAY_128x64) ? 21 : 10);
30143054

Firmware/RTK_Everywhere/Ethernet.ino

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,6 @@ bool ethernetIsNeeded()
208208
return needed;
209209
}
210210

211-
// Ethernet (W5500) ISR
212-
// Triggered by the falling edge of the W5500 interrupt signal - indicates the arrival of a packet
213-
// Record the time the packet arrived
214-
void ethernetISR()
215-
{
216-
// Don't check or clear the interrupt here -
217-
// it may clash with a GNSS SPI transaction and cause a wdt timeout.
218-
// Do it in updateEthernet
219-
gettimeofday((timeval *)&ethernetNtpTv, nullptr); // Record the time of the NTP interrupt
220-
}
221-
222211
// Restart the Ethernet controller
223212
void ethernetRestart()
224213
{
@@ -393,7 +382,7 @@ void onEthernetEvent(arduino_event_id_t event, arduino_event_info_t info)
393382
// Web server routines
394383
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
395384

396-
// Start Ethernet WebServer ESP32 W5500 - needs exclusive access to WiFi, SPI and Interrupts
385+
// Start Ethernet for the web server
397386
void ethernetWebServerStartESP32W5500()
398387
{
399388
Network.onEvent(onEthernetEvent);
@@ -405,10 +394,10 @@ void ethernetWebServerStartESP32W5500()
405394
ETH.config(settings.ethernetIP, settings.ethernetGateway, settings.ethernetSubnet, settings.ethernetDNS);
406395
}
407396

408-
// Stop the Ethernet web server
397+
// Stop Ethernet for the web server
409398
void ethernetWebServerStopESP32W5500()
410399
{
411-
ETH.end(); // This is _really_ important. It undoes the low-level changes to SPI and interrupts
400+
ETH.end();
412401
}
413402

414403
#endif // COMPILE_ETHERNET

0 commit comments

Comments
 (0)