Browse Source

Merge pull request #13 from jancoow/NTP_syncing

Ntp syncing
Janco Kock 9 years ago
parent
commit
47c3a0fd4f
4 changed files with 22 additions and 3 deletions
  1. 2 2
      main.c
  2. 15 0
      network.c
  3. 1 0
      network.h
  4. 4 1
      ntp.c

+ 2 - 2
main.c

@@ -195,9 +195,9 @@ THREAD(StartupInit, arg)
 
     char* content = httpGet("/getAlarmen.php?radioid=DE370");
     parseAlarmJson(content);
+    free(content);
     isAlarmSyncing = 0;
 
-    free(content);
     NutThreadExit();
 }
 
@@ -247,7 +247,7 @@ int main(void)
     LcdBackLight(LCD_BACKLIGHT_ON);
     NtpInit();
 
-    NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
+    NutThreadCreate("BackgroundThread", StartupInit, NULL, 1500);
 
     /** Quick fix for turning off the display after 10 seconds boot */
     start = time(0);

+ 15 - 0
network.c

@@ -6,6 +6,7 @@
 #include <sys/timer.h>
 #include <sys/confnet.h>
 #include <sys/socket.h>
+#include <netinet/tcp.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -26,6 +27,9 @@
 #include "alarm.h"
 
 bool isReceiving;
+u_short mss = 1460;
+u_long rx_to = 3000;
+u_short tcpbufsiz = 1500;
 
 void NetworkInit() {
     /* Register de internet controller. */
@@ -51,6 +55,8 @@ char* httpGet(char address[]){
     int len = sizeof(http);
 
     char buffer[300];
+    memset(buffer, 0, 300);
+
     if (NutTcpConnect(sock, inet_addr("62.195.226.247"), 80)) {
         printf("Can't connect to server\n");
     }else{
@@ -94,6 +100,15 @@ char* httpGet(char address[]){
     return content;
 }
 
+int getTimeZone()
+{
+    char* content = httpGet("/gettimezone.php");
+    int timezone = atoi(content);
+    free(content);
+    printf("%d", timezone);
+    return timezone;
+}
+
 void parseAlarmJson(char* content){
     int r;
     int i;

+ 1 - 0
network.h

@@ -9,5 +9,6 @@
 extern void NetworkInit(void);
 char* httpGet(char address[]);
 void parseAlarmJson(char* content);
+int getTimeZone();
 
 #endif /* _Network_H */

+ 4 - 1
ntp.c

@@ -21,7 +21,7 @@
 #include "log.h"
 #include "ntp.h"
 
-#define TIME_ZONE 1
+int TIME_ZONE = 1;
 #define LOG_MODULE  LOG_NTP_MODULE
 
 typedef struct _Eeprom_tm {
@@ -119,6 +119,9 @@ bool NtpTimeIsValid(void){
 void NtpSync(void){
     /* Ophalen van pool.ntp.org */
     isSyncing = true;
+    _timezone = -getTimeZone() * 3600;
+    printf(TIME_ZONE);
+    NutDelay(100);
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     timeserver = inet_addr("213.154.229.24");