File tree 2 files changed +17
-9
lines changed 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1
1
#include " ntp-client/NTPClient.h"
2
2
#include " mbed.h"
3
3
4
- const char * NTPClient::NIST_SERVER_ADDRESS = " 2.pool.ntp.org" ;
5
- const int NTPClient::NIST_SERVER_PORT = 123 ;
6
-
7
4
NTPClient::NTPClient (NetworkInterface *iface) {
8
- this ->iface = iface;
5
+ this ->iface = iface;
6
+
7
+ _nist_server_address = NTP_DEFULT_NIST_SERVER_ADDRESS;
8
+ _nist_server_port = NTP_DEFULT_NIST_SERVER_PORT;
9
+ }
10
+
11
+ void NTPClient::set_server (char * server, int port){
12
+ _nist_server_address = server;
13
+ _nist_server_port = port;
9
14
}
10
15
11
16
time_t NTPClient::get_timestamp (int timeout) {
@@ -14,14 +19,14 @@ time_t NTPClient::get_timestamp(int timeout) {
14
19
int ntp_recv_values[12 ] = {0 };
15
20
16
21
SocketAddress nist;
17
- int ret_gethostbyname = iface->gethostbyname (NIST_SERVER_ADDRESS , &nist);
22
+ int ret_gethostbyname = iface->gethostbyname (_nist_server_address , &nist);
18
23
19
24
if (ret_gethostbyname < 0 ) {
20
25
// Network error on DNS lookup
21
26
return ret_gethostbyname;
22
27
}
23
28
24
- nist.set_port (NIST_SERVER_PORT );
29
+ nist.set_port (_nist_server_port );
25
30
26
31
memset (ntp_send_values, 0x00 , sizeof (ntp_send_values));
27
32
ntp_send_values[0 ] = ' \x1b ' ;
Original file line number Diff line number Diff line change 1
1
#include " mbed.h"
2
2
3
+ #define NTP_DEFULT_NIST_SERVER_ADDRESS " 2.pool.ntp.org"
4
+ #define NTP_DEFULT_NIST_SERVER_PORT 123
5
+
3
6
class NTPClient {
4
7
public:
5
8
NTPClient (NetworkInterface *iface);
9
+ void set_server (char * server, int port);
6
10
time_t get_timestamp (int timeout = 15000 );
7
11
8
- static const char * NIST_SERVER_ADDRESS;
9
- static const int NIST_SERVER_PORT;
10
-
11
12
private:
12
13
NetworkInterface *iface;
13
14
uint32_t ntohl (uint32_t num);
15
+ char * _nist_server_address;
16
+ int _nist_server_port;
14
17
};
You can’t perform that action at this time.
0 commit comments