Skip to content

Commit 49d58ae

Browse files
committed
Make NTPUtils work with an UDP pointer instead of reference
1 parent d436b80 commit 49d58ae

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/utility/time/NTPUtils.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
* PUBLIC MEMBER FUNCTIONS
3434
**************************************************************************************/
3535

36-
unsigned long NTPUtils::getTime(UDP & udp)
36+
unsigned long NTPUtils::getTime(UDP * udp)
3737
{
3838
#ifdef NTP_USE_RANDOM_PORT
39-
udp.begin(NTPUtils::getRandomPort(MIN_NTP_PORT, MAX_NTP_PORT));
39+
udp->begin(NTPUtils::getRandomPort(MIN_NTP_PORT, MAX_NTP_PORT));
4040
#else
41-
udp.begin(NTP_LOCAL_PORT);
41+
udp->begin(NTP_LOCAL_PORT);
4242
#endif
4343

4444
sendNTPpacket(udp);
@@ -48,16 +48,16 @@ unsigned long NTPUtils::getTime(UDP & udp)
4848
do
4949
{
5050
is_timeout = (millis() - start) >= NTP_TIMEOUT_MS;
51-
} while(!is_timeout && !udp.parsePacket());
51+
} while(!is_timeout && !udp->parsePacket());
5252

5353
if(is_timeout) {
54-
udp.stop();
54+
udp->stop();
5555
return 0;
5656
}
5757

5858
uint8_t ntp_packet_buf[NTP_PACKET_SIZE];
59-
udp.read(ntp_packet_buf, NTP_PACKET_SIZE);
60-
udp.stop();
59+
udp->read(ntp_packet_buf, NTP_PACKET_SIZE);
60+
udp->stop();
6161

6262
unsigned long const highWord = word(ntp_packet_buf[40], ntp_packet_buf[41]);
6363
unsigned long const lowWord = word(ntp_packet_buf[42], ntp_packet_buf[43]);
@@ -72,7 +72,7 @@ unsigned long NTPUtils::getTime(UDP & udp)
7272
* PRIVATE MEMBER FUNCTIONS
7373
**************************************************************************************/
7474

75-
void NTPUtils::sendNTPpacket(UDP & udp)
75+
void NTPUtils::sendNTPpacket(UDP * udp)
7676
{
7777
uint8_t ntp_packet_buf[NTP_PACKET_SIZE] = {0};
7878

@@ -85,9 +85,9 @@ void NTPUtils::sendNTPpacket(UDP & udp)
8585
ntp_packet_buf[14] = 49;
8686
ntp_packet_buf[15] = 52;
8787

88-
udp.beginPacket(NTP_TIME_SERVER, NTP_TIME_SERVER_PORT);
89-
udp.write(ntp_packet_buf, NTP_PACKET_SIZE);
90-
udp.endPacket();
88+
udp->beginPacket(NTP_TIME_SERVER, NTP_TIME_SERVER_PORT);
89+
udp->write(ntp_packet_buf, NTP_PACKET_SIZE);
90+
udp->endPacket();
9191
}
9292

9393
int NTPUtils::getRandomPort(int const min_port, int const max_port)

src/utility/time/NTPUtils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class NTPUtils
4141
{
4242
public:
4343

44-
static unsigned long getTime(UDP & udp);
44+
static unsigned long getTime(UDP * udp);
4545
static int getRandomPort(int const min_port, int const max_port);
4646

4747
private:
@@ -56,7 +56,7 @@ class NTPUtils
5656
static unsigned long const NTP_TIMEOUT_MS = 1000;
5757
static constexpr const char * NTP_TIME_SERVER = "time.arduino.cc";
5858

59-
static void sendNTPpacket(UDP & udp);
59+
static void sendNTPpacket(UDP * udp);
6060
};
6161

6262
#endif /* #ifndef HAS_LORA */

0 commit comments

Comments
 (0)