2 #include "EthernetInterface.h"
6 const char *HTTP_SERVER_NAME
= "utcnist.colorado.edu";
7 const int HTTP_SERVER_PORT
= 37;
8 const float YEARS_TO_PASS
= 114.0;
13 MBED_HOSTTEST_TIMEOUT(20);
14 MBED_HOSTTEST_SELECT(default_auto
);
15 MBED_HOSTTEST_DESCRIPTION(NIST Internet Time Service
);
16 MBED_HOSTTEST_START("NET_2");
19 EthernetInterface eth
;
20 eth
.init(); //Use DHCP
22 printf("UDP client IP Address is %s\n", eth
.getIPAddress());
28 nist
.set_address(HTTP_SERVER_NAME
, HTTP_SERVER_PORT
);
30 char out_buffer
[] = "plop"; // Does not matter
31 sock
.sendTo(nist
, out_buffer
, sizeof(out_buffer
));
34 char in_buffer_tab
[4];
35 unsigned int in_buffer_uint
;
38 const int n
= sock
.receiveFrom(nist
, in_buffer_tab
, sizeof(in_buffer_tab
));
41 const unsigned int timeRes
= ntohl(in_buffer_uint
);
42 const float years
= timeRes
/ 60.0 / 60.0 / 24.0 / 365.0;
43 const float days
= timeRes
/ 24.0 / 60.0 / 60.0;
44 printf("UDP: Received %d bytes from server %s on port %d\r\n", n
, nist
.get_address(), nist
.get_port());
45 printf("UDP: %u seconds since 01/01/1900 00:00 GMT ... %s\r\n", timeRes
, timeRes
> 0 ? "[OK]" : "[FAIL]");
46 printf("UDP: %.2f days since 01/01/1900 00:00 GMT ... %s\r\n", days
, timeRes
> 0 ? "[OK]" : "[FAIL]");
47 printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years
, timeRes
> YEARS_TO_PASS
? "[OK]" : "[FAIL]");
49 if (years
< YEARS_TO_PASS
) {
55 MBED_HOSTTEST_RESULT(result
);