@@ -78,8 +78,6 @@ const RtkMode_t ntpServerMode = RTK_MODE_NTP;
78
78
79
79
static NetworkUDP *ntpServer; // This will be instantiated when we know the NTP port
80
80
static uint8_t ntpServerState;
81
- static volatile uint8_t
82
- ntpSockIndex; // The W5500 socket index for NTP - so we can enable and read the correct interrupt
83
81
static uint32_t lastLoggedNTPRequest;
84
82
85
83
// ----------------------------------------
@@ -474,7 +472,7 @@ struct NTPpacket
474
472
475
473
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
476
474
// NTP process one request
477
- // recTv contains the timeval the NTP packet was received - from the W5500 interrupt
475
+ // recTv contains the timeval the NTP packet was received
478
476
// syncTv contains the timeval when the RTC was last sync'd
479
477
// ntpDiag will contain useful diagnostics
480
478
bool ntpProcessOneRequest (bool process, const timeval *recTv, const timeval *syncTv, char *ntpDiag = nullptr ,
@@ -486,19 +484,24 @@ bool ntpProcessOneRequest(bool process, const timeval *recTv, const timeval *syn
486
484
if (ntpDiag != nullptr )
487
485
*ntpDiag = 0 ; // Clear any existing diagnostics
488
486
489
- int packetDataSize = ntpServer-> parsePacket ();
487
+ gettimeofday ((timeval *)ðernetNtpTv, nullptr ); // Record the possible time of the NTP request
490
488
491
- IPAddress remoteIP = ntpServer->remoteIP ();
492
- uint16_t remotePort = ntpServer->remotePort ();
489
+ int packetDataSize = 0 ;
493
490
494
- if (ntpDiag != nullptr ) // Add the packet size and remote IP/Port to the diagnostics
495
- {
496
- snprintf (ntpDiag, ntpDiagSize, " NTP request from: Remote IP: %d.%d.%d.%d Remote Port: %d\r\n " , remoteIP[0 ],
497
- remoteIP[1 ], remoteIP[2 ], remoteIP[3 ], remotePort);
498
- }
491
+ if (ntpServer->available () > 0 )
492
+ packetDataSize = ntpServer->parsePacket ();
499
493
500
- if (packetDataSize && (packetDataSize >= NTPpacket::NTPpacketSize) )
494
+ if (packetDataSize >= NTPpacket::NTPpacketSize)
501
495
{
496
+ IPAddress remoteIP = ntpServer->remoteIP ();
497
+ uint16_t remotePort = ntpServer->remotePort ();
498
+
499
+ if (ntpDiag != nullptr ) // Add the packet size and remote IP/Port to the diagnostics
500
+ {
501
+ snprintf (ntpDiag, ntpDiagSize, " NTP request from: Remote IP: %d.%d.%d.%d Remote Port: %d\r\n " , remoteIP[0 ],
502
+ remoteIP[1 ], remoteIP[2 ], remoteIP[3 ], remotePort);
503
+ }
504
+
502
505
// Read the NTP packet
503
506
NTPpacket packet;
504
507
@@ -774,7 +777,6 @@ void ntpServerStop()
774
777
// Release the NTP server memory
775
778
if (ntpServer)
776
779
{
777
- w5500DisableSocketInterrupt (ntpSockIndex); // Disable the receive interrupt
778
780
ntpServer->stop ();
779
781
delete ntpServer;
780
782
ntpServer = nullptr ;
@@ -850,12 +852,7 @@ void ntpServerUpdate()
850
852
ntpServerStop ();
851
853
else
852
854
{
853
- // Start the NTP server
854
- // TODO
855
- // ntpServer->begin(settings.ethernetNtpPort);
856
- // ntpSockIndex = ntpServer->getSockIndex(); // Get the socket index
857
- // w5500ClearSocketInterrupts(); // Clear all interrupts
858
- // w5500EnableSocketInterrupt(ntpSockIndex); // Enable the RECV interrupt for the desired socket index
855
+ ntpServer->begin (settings.ethernetNtpPort ); // Start the NTP server
859
856
online.ethernetNTPServer = true ;
860
857
if (!inMainMenu)
861
858
reportHeapNow (settings.debugNtp );
@@ -872,9 +869,6 @@ void ntpServerUpdate()
872
869
873
870
else
874
871
{
875
- if (w5500CheckSocketInterrupt (ntpSockIndex))
876
- w5500ClearSocketInterrupt (ntpSockIndex); // Clear the socket interrupt here
877
-
878
872
// Check for new NTP requests - if the time has been sync'd
879
873
bool processed = ntpProcessOneRequest (systemState == STATE_NTPSERVER_SYNC, (const timeval *)ðernetNtpTv,
880
874
(const timeval *)&gnssSyncTv, ntpDiag, sizeof (ntpDiag));
0 commit comments