Sfoglia il codice sorgente

Merge pull request #4 from jancoow/network_realiseren

NTP is now updating the RTC properly.
Jordy Sipkema 9 anni fa
parent
commit
e0ee29b28b
3 ha cambiato i file con 22 aggiunte e 14 eliminazioni
  1. 9 4
      main.c
  2. 1 1
      network.h
  3. 12 9
      ntp.c

+ 9 - 4
main.c

@@ -48,6 +48,9 @@
 #include "rtc.h"
 #include "ntp.h"
 
+#define MONTH_OFFSET 1
+#define YEAR_OFFSET 1900
+
 
 /*-------------------------------------------------------------------------*/
 /* global variable definitions                                             */
@@ -197,7 +200,7 @@ void displayDate(){
 	struct _tm gmt;
 	gmt = GetRTCTime();
 	char str[13];
-	sprintf(str, "   %02d-%02d-%04d", gmt.tm_mday, gmt.tm_mon, gmt.tm_year+1900);
+	sprintf(str, "   %02d-%02d-%04d", gmt.tm_mday, gmt.tm_mon+MONTH_OFFSET, gmt.tm_year+YEAR_OFFSET);
 	LcdArrayLineOne(str,13);
 }
 
@@ -267,17 +270,19 @@ int main(void)
     Uart0DriverInit();
     Uart0DriverStart();
 	LogInit();
-	
 
     CardInit();
 
+    X12Init();
+
     NetworkInit();
 
-    //NtpInit();
+    NtpInit();
+
 	/*
 	 * Kroeske: sources in rtc.c en rtc.h
 	 */
-    X12Init();
+
 	gmt = GetRTCTime();
 	LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
 	

+ 1 - 1
network.h

@@ -7,4 +7,4 @@
 
 extern void NetworkInit(void);
 
-#endif /* _Network_H */
+#endif /* _Network_H */

+ 12 - 9
ntp.c

@@ -19,13 +19,15 @@
 
 #include "ntp.h"
 
+#define TIME_ZONE 0
+
 time_t ntp_time = 0;
 tm *ntp_datetime;
 uint32_t timeserver = 0;
 
 void NtpInit() {
     /* Timezone van nederland (gmt 1) */
-    _timezone = -2 * 60 * 60;
+    _timezone = -TIME_ZONE * 3600;
     GetTime();
 }
 
@@ -49,15 +51,16 @@ void GetTime(){
     printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
     printf("NTP date is: %02d.%02d.%02d\n\n", ntp_datetime->tm_mday, (ntp_datetime->tm_mon + 1), (ntp_datetime->tm_year + 1900));
 
-    NutRtcSetTime(ntp_datetime);
-
-
-    // This isn't working...
-    tm *test;
+    X12RtcSetClock(ntp_datetime);
 
-    X12RtcGetClock(test);
 
-    printf("RTC time is: %02d:%02d:%02d\n", test->tm_hour, test->tm_min, test->tm_sec);
-    printf("RTC date is: %02d.%02d.%02d\n\n", test->tm_mday, (test->tm_mon + 1), (test->tm_year + 1900));
+    NutDelay(100);
+//
+//    // This isn't working...
+//    struct _tm* test;
+//    X12RtcGetClock(test);
+//
+//    printf("RTC time is: %02d:%02d:%02d\n", test->tm_hour, test->tm_min, test->tm_sec);
+//    printf("RTC date is: %02d.%02d.%02d\n\n", test->tm_mday, (test->tm_mon + 1), (test->tm_year + 1900));
 }