Forráskód Böngészése

Fixed ntp sync problem

Aareschluchtje 9 éve
szülő
commit
ec3605623e
6 módosított fájl, 34 hozzáadás és 13 törlés
  1. 1 1
      alarm.h
  2. 8 2
      contentparser.c
  3. 1 1
      displayHandler.h
  4. 16 7
      main.c
  5. 7 1
      ntp.c
  6. 1 1
      ntp.h

+ 1 - 1
alarm.h

@@ -25,7 +25,7 @@ int compareTime(tm t1, tm t2);
 void setState(int idx);
 void setState(int idx);
 int getState(int idx);
 int getState(int idx);
 struct _alarm* getAlarm(int idx);
 struct _alarm* getAlarm(int idx);
-char getRunningAlarmID();
+char getRunningAlarmID(void);
 int maxAlarms(void);
 int maxAlarms(void);
 int isLeapYear(int y);
 int isLeapYear(int y);
 void setSnooze(int idx);
 void setSnooze(int idx);

+ 8 - 2
contentparser.c

@@ -12,7 +12,7 @@
 #include "vs10xx.h"
 #include "vs10xx.h"
 #include "twitch.h"
 #include "twitch.h"
 #include "Twitter.h"
 #include "Twitter.h"
-int streamid;
+#include <string.h>
 
 
 void parseAlarmJson(char* content){
 void parseAlarmJson(char* content){
     int r;
     int r;
@@ -187,7 +187,13 @@ void parseCommandQue(char* content){
 void parsetimezone(char* content)
 void parsetimezone(char* content)
 {
 {
     int timezone = atoi(content); //parsing string to int (only works when everything is int)
     int timezone = atoi(content); //parsing string to int (only works when everything is int)
-    setTimeZone(timezone);
+    if(strlen(content) == 0)
+    {
+        setTimeZone(50);
+    }
+    else {
+        setTimeZone(timezone);
+    }
 }
 }
 
 
 void parseTwitch(char* content) {
 void parseTwitch(char* content) {

+ 1 - 1
displayHandler.h

@@ -20,7 +20,7 @@ void refreshScreen(void);
 
 
 void displayDateTime(void);
 void displayDateTime(void);
 void displayAlarm(char idx);
 void displayAlarm(char idx);
-void displayVolume();
+void displayVolume(void);
 void displayTwitter(char text[]);
 void displayTwitter(char text[]);
 void displayTwitch(char name[], char title[], char game[]);
 void displayTwitch(char name[], char title[], char game[]);
 
 

+ 16 - 7
main.c

@@ -215,10 +215,14 @@ THREAD(AlarmSync, arg)
     while(initialized == false){
     while(initialized == false){
         NutSleep(1000);
         NutSleep(1000);
     }
     }
-
-    NtpSync();
-    int dayCounter;
-    dayCounter = 0;
+    int dayCounter = 0;
+    int counter = 0;
+    while(!NtpSync() && counter < 10)
+    {
+        NutSleep(1000);
+        counter++;
+    }
+    counter = 0;
     for(;;)
     for(;;)
     {
     {
         if((initialized == true) && (hasNetworkConnection() == true))
         if((initialized == true) && (hasNetworkConnection() == true))
@@ -240,10 +244,15 @@ THREAD(AlarmSync, arg)
             sprintf(url, "%s%s", "/getCommands.php?radiomac=", getMacAdress());
             sprintf(url, "%s%s", "/getCommands.php?radiomac=", getMacAdress());
             httpGet(url, parseCommandQue);
             httpGet(url, parseCommandQue);
         }
         }
-        if(dayCounter > 28800 && (hasNetworkConnection() == true))
+        while(dayCounter > 28800 && (hasNetworkConnection() == true))
         {
         {
-            NtpSync();
-            dayCounter = 0;
+            while(!NtpSync() && counter < 10)
+            {
+                NutSleep(1000);
+                counter++;
+            }
+            dayCounter = 28800;
+            counter = 0;
         }
         }
         dayCounter++;
         dayCounter++;
         NutSleep(3000);
         NutSleep(3000);

+ 7 - 1
ntp.c

@@ -82,12 +82,17 @@ bool NtpTimeIsValid(void){
     return validTime;
     return validTime;
 }
 }
 
 
-void NtpSync(void){
+int NtpSync(void){
     /* Ophalen van pool.ntp.org */
     /* Ophalen van pool.ntp.org */
     isSyncing = true;
     isSyncing = true;
+    setTimeZone(50);
     httpGet("/gettimezone.php", parsetimezone);
     httpGet("/gettimezone.php", parsetimezone);
     _daylight = 0;
     _daylight = 0;
     printf("Timezone is: %d", TIME_ZONE);
     printf("Timezone is: %d", TIME_ZONE);
+    if(TIME_ZONE == 50)
+    {
+        return 0;
+    }
     NutDelay(100);
     NutDelay(100);
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     timeserver = inet_addr("213.154.229.24");
     timeserver = inet_addr("213.154.229.24");
@@ -112,6 +117,7 @@ void NtpSync(void){
 
 
     isSyncing = false;
     isSyncing = false;
     validTime = true;
     validTime = true;
+    return 1;
 }
 }
 
 
 void NtpWriteTimeToEeprom(tm time_struct){
 void NtpWriteTimeToEeprom(tm time_struct){

+ 1 - 1
ntp.h

@@ -10,7 +10,7 @@
 
 
 extern bool NtpIsSyncing(void);
 extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
 extern void NtpInit(void);
-extern void NtpSync(void);
+extern int NtpSync(void);
 extern void setTimeZone(int timezone);
 extern void setTimeZone(int timezone);
 extern bool NtpTimeIsValid(void);
 extern bool NtpTimeIsValid(void);