Simple Network Time Protocol Client. This lib feature: Access to SNTP server, and get Epoch (Unix) time.

Files at this revision

API Documentation at this revision

Comitter:
AkinoriHashimoto
Date:
Fri Nov 27 02:10:36 2015 +0000
Parent:
0:2be905de8e28
Commit message:
Add socketClose.

Changed in this revision

SimpleNTP.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleNTP.h Show annotated file Show diff for this revision Revisions of this file
--- a/SimpleNTP.cpp	Wed Nov 25 10:03:10 2015 +0000
+++ b/SimpleNTP.cpp	Fri Nov 27 02:10:36 2015 +0000
@@ -47,5 +47,12 @@
     return timeNTP- 2208988800;//timeEpoch;
 }
 
+SimpleNTP::Result SimpleNTP::close()
+{
+    if(socket.close() == -1)
+        return ERR_SocketClose;
+
+    return SUCCESS;
+}
 
 // EOF
\ No newline at end of file
--- a/SimpleNTP.h	Wed Nov 25 10:03:10 2015 +0000
+++ b/SimpleNTP.h	Fri Nov 27 02:10:36 2015 +0000
@@ -7,7 +7,7 @@
 When cording, I refered to:
 http://www.softech.co.jp/mm_140305_firm.htm
 http://www.venus.dti.ne.jp/~yoshi-o/NTP/NTP-SNTP_Format.html
- 
+
  @code
 #include "mbed.h"
 
@@ -37,6 +37,8 @@
         if(rtc.setRealTime(timeEpoch))
             led[1]= 0;
     }
+    if(sntp.close() == SimpleNTP::SUCCESS)
+        led[2]= 0;
     return;
 }
 int main()
@@ -62,7 +64,8 @@
 public:
     enum Result {
         SUCCESS,
-        ERR_SocketInit, ERR_SetNTPAddr
+        ERR_SocketInit, ERR_SetNTPAddr,
+        ERR_SocketClose
     };
 
     /** Setting for NTP/SNTP server.
@@ -71,16 +74,20 @@
         @return enum.
      */
     Result setNTPServer(string _server, unsigned short _port= 123);
-    
+
     /** Get NetworkTime Converted Epoch.
      *  @return epoch(UNIX) time. NOT 1900/01/01~
      */
     long getNetworkTime();     // mbed is 32bit epoch. NOT "UNSIGNED long".
 
+    /** close the socket
+     */
+    Result close();
+
 private:
     string server;
     unsigned short port;
-    
+
     UDPSocket socket;
     Endpoint serverNTP;