mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Revision:
7:f7c98d836f81
Parent:
3:058292da2cee
--- a/TinyNet/TinySNTP.cpp	Sun Jan 15 13:28:12 2012 +0000
+++ b/TinyNet/TinySNTP.cpp	Thu Mar 15 02:42:39 2012 +0000
@@ -41,15 +41,15 @@
 
 int getSntpResponse (const char *buf, uint32_t *tim) {
     struct SNTPPacket *sntp;
-    uint32_t now;
+//    uint32_t now;
 //    long int delay, offset;
 
     sntp = (struct SNTPPacket *)buf;
     if ((sntp->info & 0x3f) == 0x1c || (sntp->info & 0x3f) == 0x24) {
         // Ver.3or4, Server
 
+/*
         now = htonl(NTP_TIMESTAMP_DELTA + time(NULL));
-/*
         delay = (now - sntp->origTm_s) - (sntp->rxTm_s - sntp->txTm_s);
         offset = ((sntp->rxTm_s - sntp->origTm_s) + (sntp->txTm_s - now));
 
@@ -71,7 +71,7 @@
 }
 
 void isr_sntp (UDPSocketEvent e) {
-    char buf[100];
+    char buf[200];
     Host dsthost;
     int len;
 
@@ -84,7 +84,7 @@
         }
         puts("\r");
 #endif
-        if (len >= sizeof(struct SNTPPacket)) {
+        if (len >= sizeof(struct SNTPPacket) && ! sntptime) {
             getSntpResponse(buf, (uint32_t*)&sntptime);
         }
     }
@@ -120,6 +120,9 @@
     for (i = 0; i < NTP_TIMEOUT / 10; i ++) {
         if (sntptime) {
             *tim = sntptime;
+            Net::poll();
+            wait_ms(10);
+            Net::poll();
             break;
         }
         if (i % 500 == 499) {
@@ -131,6 +134,7 @@
 
 exit:
     sntp->resetOnEvent();
+    sntp->close();
     delete sntp;
 
     return sntptime ? 0 : -1;