Просмотр исходного кода

A lot of code had been added to the developer branch. Because my alternatives continously keeps being rejected by the group I've decided to stop developing this branch. Have fun with it.

>>> Sidenote: This branch is now officially broken due a wrong merge (developer into eeprom-controller-v2). DO NOT MERGE THIS INTO DEVELOPER!

Merge remote-tracking branch 'refs/remotes/origin/developer' into eeprom-controller-v2

# Conflicts:
#	httpstream.h
#	main.c
#	network.c
#	network.h
#	ntp.c
Jordy Sipkema 9 лет назад
Родитель
Сommit
8b9344931a
15 измененных файлов с 317 добавлено и 208 удалено
  1. 3 0
      .gitmodules
  2. 0 15
      .idea/InternetRadio.iml
  3. 1 0
      InternetRadio-webserver
  4. 83 22
      alarm.c
  5. 117 0
      contentparser.c
  6. 10 0
      contentparser.h
  7. 2 3
      displayHandler.c
  8. 2 0
      httpstream.c
  9. 1 0
      httpstream.h
  10. 71 29
      main.c
  11. 10 112
      network.c
  12. 2 5
      network.h
  13. 6 21
      ntp.c
  14. 1 0
      ntp.h
  15. 8 1
      vs10xx.c

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "InternetRadio-webserver"]
+	path = InternetRadio-webserver
+	url = https://github.com/jancoow/InternetRadio-webserver

+ 0 - 15
.idea/InternetRadio.iml

@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="CPP_MODULE" version="4">
-  <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
-    </content>
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="module-library">
-      <library name="Header Search Paths">
-        <CLASSES />
-        <SOURCES />
-      </library>
-    </orderEntry>
-  </component>
-</module>

+ 1 - 0
InternetRadio-webserver

@@ -0,0 +1 @@
+Subproject commit 5d0c9e2db0695ee2d826d7f139d1646496a96577

+ 83 - 22
alarm.c

@@ -8,14 +8,15 @@
 #include "log.h"
 #include "rtc.h"
 #include "alarm.h"
+#include "display.h"
+#include "httpstream.h"
 
 #define n 5
 
 
 struct _snooze
 {
-	struct _tm snoozeStart;
-	struct _tm snoozeEnd;
+	struct _tm snoozeTime;
 };
 
 struct _alarm alarm[n];
@@ -27,6 +28,9 @@ int checkAlarms(){
 	int check = 0;
 	for (i = 0; i < n; i++){
 		setState(i);
+		if (alarm[i].time.tm_year == 0){
+			alarm[i].state = 0;
+		}
 		if (alarm[i].state == 1){
 			check = 1;
 		}
@@ -60,26 +64,87 @@ int maxAlarms(){
 	return n;
 }
 
+void setSnooze(int idx){
+	struct _tm ct;
+	X12RtcGetClock(&ct);
+	
+	alarm[idx].state = 2;
+	snooze[idx].snoozeTime = ct;
+	snooze[idx].snoozeTime.tm_min += alarm[idx].snooze;
+	stopStream();
+}
+
+int daysInMonth(int m, int y) {
+    if(m == 2 && isLeapYear(y))
+        return 29 + (int)(m + floor(m/8)) % 2 + 2 % m + 2 * floor(1/m);
+    return 28 + (int)(m + floor(m/8)) % 2 + 2 % m + 2 * floor(1/m);
+}
+
+int daysInYear(int y){
+    if(isLeapYear(y))
+        return 366;
+    return 365;
+}
+
+int isLeapYear(int y){
+    return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
+}
+
+
+void AddSnoozeMinutes(int idx, int minutes){
+	if (snooze[idx].snoozeTime.tm_min + minutes >= 60){ //Checks if minutes is >= 60 else minute
+		snooze[idx].snoozeTime.tm_hour += 1;
+		snooze[idx].snoozeTime.tm_min = ((snooze[idx].snoozeTime.tm_min + minutes) % 60);
+		if (snooze[idx].snoozeTime.tm_hour >= 24){ //Checks if hours is >= 24
+			snooze[idx].snoozeTime.tm_hour = 0;
+			if ((snooze[idx].snoozeTime.tm_mday + 1) <= daysInMonth((snooze[idx].snoozeTime.tm_mon+1), (snooze[idx].snoozeTime.tm_year+1900))){ //Checks if day+1 smaller or even is to the amount of days in the month
+				snooze[idx].snoozeTime.tm_mday += 1;
+			} else { //If the days+1 is bigger than the amount of days in the month, day = 1 & month is + 1
+				snooze[idx].snoozeTime.tm_mday = 1;
+				if (snooze[idx].snoozeTime.tm_mon + 1 > 11){//If month+1 is bigger than 11 (month is 0-11) then month = 0 & year + 1
+					snooze[idx].snoozeTime.tm_mon = 0;
+					snooze[idx].snoozeTime.tm_year += 1;
+				} else {
+					snooze[idx].snoozeTime.tm_mon += 1;
+				}
+			}
+		}
+	} else {
+		snooze[idx].snoozeTime.tm_min += minutes;
+	}
+}
+
 void setState(int idx){
 	struct _tm ct;
 	X12RtcGetClock(&ct);
 	
-	if (compareTime(ct, alarm[idx].time) == 1 && alarm[idx].time.tm_year != 0){
+	if (alarm[idx].state == 0){
+		snooze[idx].snoozeTime = alarm[idx].time;
+		AddSnoozeMinutes(idx,1);
+	}
+	
+	if (compareTime(ct, alarm[idx].time) >= 1 && alarm[idx].time.tm_year != 0 && alarm[idx].state != 2){
 		alarm[idx].state = 1;
-	} else {
+	} else if (alarm[idx].state != 2){
 		alarm[idx].state = 0;
 	}
 	
-	/*if (compareTime(alarm[idx].time,snooze[idx].snoozeStart)){
+	if (compareTime(alarm[idx].time,snooze[idx].snoozeTime) >= 1){
 		alarm[idx].state = 2;
 	}
 	
-	if (alarm[idx].state == 2){
-		if (compareTime(alarm[idx].time, snooze[idx].snoozeEnd)){
-			snooze[idx].snoozeStart.tm_min += alarm[idx].snooze + 1;
-			snooze[idx].snoozeEnd.tm_min += alarm[idx].snooze + 1;
-		}
-	}*/
+	if (alarm[idx].state == 1 && compareTime(ct, snooze[idx].snoozeTime) >= 1){
+		alarm[idx].state = 2;
+		snooze[idx].snoozeTime = ct;
+		AddSnoozeMinutes(idx, alarm[idx].snooze);
+		LcdBackLight(LCD_BACKLIGHT_OFF);
+		stopStream();
+	}
+	
+	if (alarm[idx].state == 2 && compareTime(ct, snooze[idx].snoozeTime) >= 1){
+		alarm[idx].state = 1;
+		AddSnoozeMinutes(idx, 1);
+	}
 }
 
 /*void getAlarm(struct _alarm *am){
@@ -100,11 +165,6 @@ void setAlarm(struct _tm time, char* name, char* ip, u_short port, char* url, in
 	alarm[idx].snooze = snooze;
 	alarm[idx].id = id;
 	alarm[idx].state = 0;
-
-	//snooze[idx].snoozeStart = time;
-	//snooze[idx].snoozeEnd = time;
-	//snooze[idx].snoozeStart += 1;
-	//snooze[idx].snoozeEnd += (snooze +1);
 }
 
 
@@ -119,8 +179,9 @@ void deleteAlarm(int idx){
 }
 
 void handleAlarm(int idx){
-	alarm[idx].time.tm_mday = alarm[idx].time.tm_mday + 1;
 	alarm[idx].state = 0;
+	alarm[idx].time.tm_mday += 1;
+	printf("state is %d \n",alarm[idx].state);
 }
 
 int compareTime(tm t1,tm t2){
@@ -128,19 +189,19 @@ int compareTime(tm t1,tm t2){
         return 1;
 	}
     if (t1.tm_year == t2.tm_year && t1.tm_mon > t2.tm_mon){
-        return 1;
+        return 2;
 	}
     if (t1.tm_year == t2.tm_year && t1.tm_mon == t2.tm_mon && t1.tm_mday > t2.tm_mday){
-        return 1;
+        return 3;
 	}
     if (t1.tm_year == t2.tm_year && t1.tm_mon == t2.tm_mon && t1.tm_mday == t2.tm_mday && t1.tm_hour > t2.tm_hour){
-        return 1;
+        return 4;
 	}
     if (t1.tm_year == t2.tm_year && t1.tm_mon == t2.tm_mon && t1.tm_mday == t2.tm_mday && t1.tm_hour == t2.tm_hour && t1.tm_min > t2.tm_min){
-        return 1;
+        return 5;
 	}
     if (t1.tm_year == t2.tm_year && t1.tm_mon == t2.tm_mon && t1.tm_mday == t2.tm_mday && t1.tm_hour == t2.tm_hour && t1.tm_min == t2.tm_min &&t1.tm_sec > t2.tm_sec){
-        return 1;
+        return 6;
 	}
 
     return 0;

+ 117 - 0
contentparser.c

@@ -0,0 +1,117 @@
+//
+// Created by janco on 25-3-16.
+//
+#include "contentparser.h"
+#include "ntp.h"
+#include "network.h"
+#include "jsmn.h"
+#include "rtc.h"
+#include "alarm.h"
+
+void parseAlarmJson(char* content){
+    int r;
+    int i;
+    jsmn_parser p;
+    jsmntok_t token[150]; /* We expect no more than 128 tokens */
+
+    jsmn_init(&p);
+    r = jsmn_parse(&p, content, strlen(content), token, sizeof(token)/sizeof(token[0]));
+    if (r <= 0) {
+        printf("Failed to parse JSON: %d \n", r);
+        return;
+    }else{
+        printf("Aantal tokens found: %d \n", r);
+    }
+
+    int start = 1;
+    int usedAlarms[maxAlarms()];
+    int j;
+    for(j = 0; j < maxAlarms(); j++){
+        usedAlarms[j] = 0;
+    }
+    for(i = 1; i < r; i++)
+    {
+        struct _tm time = GetRTCTime();
+        u_short port;
+        char url[24];
+        char ip[24];
+        char name[16];
+        char st;
+        memset(url, 0, 24);
+        memset(ip, 0, 24);
+        memset(name, 0, 16);
+
+        int id;
+        for (i = i; !((i + start) % 26 == 0); i++) {
+            if (jsoneq(content, &token[i], "YYYY") == 0) {
+                time.tm_year= getIntegerToken(content, &token[i + 1]) - 1900;
+                i++;
+            }else if (jsoneq(content, &token[i], "MM") == 0) {
+                time.tm_mon=  getIntegerToken(content, &token[i + 1]) - 1;
+                i++;
+            }else if (jsoneq(content, &token[i], "DD") == 0) {
+                time.tm_mday =  getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "hh") == 0) {
+                time.tm_hour = 	getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "mm") == 0) {
+                time.tm_min = getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "ss") == 0) {
+                time.tm_sec = getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "id") == 0) {
+                id = getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "port") == 0) {
+                port = getIntegerToken(content, &token[i + 1]);
+                i++;
+            }else if (jsoneq(content, &token[i], "ip") == 0) {
+                getStringToken(content, &token[i + 1], ip);
+                i++;
+            }else if (jsoneq(content, &token[i], "url") == 0) {
+                getStringToken(content, &token[i + 1], url);
+                i++;
+            }else if (jsoneq(content, &token[i], "name") == 0) {
+                getStringToken(content, &token[i + 1], name);
+                i++;
+            }else if (jsoneq(content, &token[i], "st") == 0) {
+                st = getIntegerToken(content, &token[i + 1]);
+                i++;
+            }
+        }
+        start = 0;
+
+        int idx = alarmExist(id);
+        if(idx == -1){
+            printf("New alarm found!\n");
+            printf("Alarm time is: %02d:%02d:%02d\n", time.tm_hour, time.tm_min, time.tm_sec);
+            printf("Alarm date is: %02d.%02d.%02d\n", time.tm_mday, (time.tm_mon + 1), (time.tm_year + 1900));
+            printf("Alarm stream data is: %s:%d%s\n", ip, port, url);
+            printf("Alarm id and name and st is: %d %s %d\n\n", id, name, st);
+
+            //zoek naar een vrije plaats in de alarm array
+            for(j = 0; j < maxAlarms(); j++){
+                if(usedAlarms[j] == 0){ //Dit is een lege plaats, hier kunnen we ons nieuwe alarm plaatsen
+                    setAlarm(time, name, ip, port, url, st, id, j);
+                    usedAlarms[j] = 1;
+                    j = 10;
+                }
+            }
+        }else{
+            usedAlarms[idx] = 1; //Alarm bestaat al, dus we houden deze plaats vrij voor dat alarm
+        }
+    }
+    for(j = 0; j < maxAlarms(); j++){ //Alle overige plaatsen, die wij niet gezet hebben, verwijderen.
+        if(usedAlarms[j] == 0){
+            deleteAlarm(j);
+        };
+    }
+}
+
+void parsetimezone(char* content)
+{
+    int timezone = atoi(content);
+    printf("%d", timezone);
+}

+ 10 - 0
contentparser.h

@@ -0,0 +1,10 @@
+//
+// Created by janco on 25-3-16.
+//
+#ifndef CONTENTPARSER_H
+#define CONTENTPARSER_H
+
+void parseAlarmJson(char* content);
+void parsetimezone(char* content);
+
+#endif //CONTENTPARSER_H

+ 2 - 3
displayHandler.c

@@ -26,7 +26,7 @@ void displayTime(int line_number){
     X12RtcGetClock(&time);
 
     char str[16];
-    if (NtpTimeIsValid()){
+    if (1){
         sprintf(str, "    %02d:%02d:%02d    ", time.tm_hour, time.tm_min, time.tm_sec);
     }else {
         sprintf(str, "    ??:??:??    ");
@@ -43,7 +43,7 @@ void displayDate(int line_number) {
 
     char str[16];
 
-    if (NtpTimeIsValid()) {
+    if (1) {
         sprintf(str, "   %02d-%02d-%04d      ", time->tm_mday, time->tm_mon + MONTH_OFFSET, time->tm_year + YEAR_OFFSET);
     } else {
         sprintf(str, "   ??-??-????      ");
@@ -85,7 +85,6 @@ void displayAlarm(int line_number, int line_numberTwo, int idx)
 	if (j != 16){
 		startidx = (8-(j/2));
 	}
-	printf("startidx: %d, %d",startidx, j);
 	j = 0;
 	for(i = 0; i < 16; i++){
 		if (i >= startidx){

+ 2 - 0
httpstream.c

@@ -52,6 +52,7 @@ void playStream(char *ipaddr, u_short port, char *radiourl){
     if(isStreaming != true){
         isStreaming = true;
         ConnectStation(sock, inet_addr(ipaddr), port, radiourl, &metaint);
+        VsPlayerKick();
         NutThreadCreate("Stream", Stream, NULL, 1024);
     }
 }
@@ -60,6 +61,7 @@ void stopStream(){
     isStreaming = false;
     fclose(stream);
     NutTcpCloseSocket(sock);
+    VsPlayerStop();
 }
 
 bool HttpIsStreaming(){

+ 1 - 0
httpstream.h

@@ -5,6 +5,7 @@
 #ifndef _Httpstream_H
 #define _Httpstream_H
 
+#include "ntp.h"
 #include "typedefs.h"
 
 extern bool HttpIsStreaming(void);

+ 71 - 29
main.c

@@ -48,6 +48,7 @@
 #include "alarm.h"
 #include "ntp.h"
 #include "httpstream.h"
+#include "contentparser.h"
 
 /*-------------------------------------------------------------------------*/
 /* local routines (prototyping)                                            */
@@ -221,12 +222,16 @@ THREAD(AlarmSync, arg)
 
     for(;;)
     {
-        isAlarmSyncing = 1;
-        char* content = httpGet("/getAlarmen.php?radioid=DE370");
-        parseAlarmJson(content);
-        free(content);
-        isAlarmSyncing = 0;
-
+        if(initialized && (hasNetworkConnection() == true))
+        {
+            isAlarmSyncing = 1;
+            char url[43];
+            sprintf(url, "%s%s", "/getAlarmen.php?radiomac=", getMacAdress());
+            char* content = httpGet(url);
+            parseAlarmJson(content);
+            free(content);
+            isAlarmSyncing = 0;
+        }
         NutSleep(3000);
     }
 
@@ -243,8 +248,18 @@ int timer(time_t start){
     return diff;
 }
 
+long timerStruct(struct _tm s){
+	struct _tm ct;
+	X12RtcGetClock(&ct);
+	
+	long stime = (s.tm_hour * 3600) + (s.tm_min * 60) + s.tm_sec;
+	long ctime = (ct.tm_hour * 3600) + (ct.tm_min * 60) + ct.tm_sec;
+	
+	return ctime - stime;
+}
+
 int checkOffPressed(){
-    if (KbGetKey() == KEY_POWER){
+    if (KbGetKey() != KEY_UNDEFINED){
         LcdBackLight(LCD_BACKLIGHT_ON);
         return 1;
     } else {
@@ -257,12 +272,11 @@ int checkOffPressed(){
 int main(void)
 {
 	initialized = 0;
-    int VOL2;
-    time_t start;
+    int VOL2 = 127;
+    struct _tm timeCheck;
+	struct _tm start;
 	int idx = 0;
 
-	int running;
-
     WatchDogDisable();
 
     NutDelay(100);
@@ -285,7 +299,7 @@ int main(void)
 
     VsPlayerInit();
 
-    LcdBackLight(LCD_BACKLIGHT_ON);
+ 
     NtpInit();
 
     RcInit();
@@ -302,25 +316,49 @@ int main(void)
 	/* Enable global interrupts */
 	sei();
 
+    /*struct _tm tm;
+	tm = GetRTCTime();
+	tm.tm_sec += 10;
+    setAlarm(tm,"    test1234      ", "0.0.0.0","", 8001,1,0,0);
+	tm.tm_sec +=20;
+	setAlarm(tm,"    test5678      ", "0.0.0.0","", 8001,1,0,1);*/
+
+/*    if(hasNetworkConnection() == true){
+        playStream("145.58.53.152", 80, "/3fm-bb-mp3");
+    }*/
     start = time(0) - 10;
+    unsigned char VOL = 64;
 
-    running = 1;
+	
+	LcdBackLight(LCD_BACKLIGHT_OFF);
+	X12RtcGetClock(&timeCheck);
+	X12RtcGetClock(&start);
 
     NutThreadCreate("Startup", StartupInit, NULL, 1024);
     NutThreadCreate("Alarm", AlarmSync, NULL, 2500);
 
     for (;;)
     {
+		//printf("running = %d, time = %d\n", running, timerStruct(start));
+		
+		if (timerStruct(start) < 0){
+			X12RtcGetClock(&start);
+		}
+		
+		if (timerStruct(timeCheck) < 0){
+			X12RtcGetClock(&timeCheck);
+		}
+		
 		//Check if a button is pressed
 		if (checkOffPressed() == 1){
-			start = time(0);
+			X12RtcGetClock(&start);
 			running = 1;
-            LcdBacklightKnipperen(startLCD);
+            LcdBackLight(LCD_BACKLIGHT_ON);
 		}
 
 		//Check if background LED is on, and compare to timer
 		if (running == 1){
-			if (timer(start) >= 10){
+			if (timerStruct(start) >= 10 || running > 1){
 				running = 0;
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
@@ -330,38 +368,42 @@ int main(void)
         {
             NutSleep(150);
             start = time(0);
-            if (VS_volume >= 1){
-                VS_volume = (--VS_volume) % 17;
-                VsSetVolume (128-(VS_volume*8), 128-(VS_volume*8));
-                displayVolume(VS_volume);
+            if(VOL > 8){
+                VOL -= 8;
+                VsSetVolume (128-VOL, 128-VOL);
+                displayVolume(VOL/8);
             }
         }
         else if(KbGetKey() == KEY_UP)
         {
             NutSleep(150);
             start = time(0);
-            if (VS_volume <= 15){
-                VS_volume = (++VS_volume) % 17;
-                VsSetVolume (128-(VS_volume*8), 128-(VS_volume*8));
-                displayVolume(VS_volume);
+            if(VOL < 128) {
+                VOL += 8;
+                VsSetVolume(128-VOL, 128-VOL);
+                displayVolume(VOL/8);
             }
         }
-        else if(timer(start) >= 5 && checkAlarms() == 1)
+        else if(timerStruct(timeCheck) >= 5 && checkAlarms() == 1)
         {
-			for (idx = 0; idx < 2; idx++){
+			for (idx = 0; idx < 5; idx++){
 				if (getState(idx) == 1){
 					displayAlarm(0,1,idx);
 					if (KbGetKey() == KEY_ESC){
-						NutDelay(50);
+						//NutDelay(50);
 						handleAlarm(idx);
-						NutDelay(50);
+						//NutDelay(50);
+						LcdBackLight(LCD_BACKLIGHT_OFF);
+                        stopStream();
+					} else if (KbGetKey() == KEY_01 || KbGetKey() == KEY_02 || KbGetKey() == KEY_03 || KbGetKey() == KEY_04 || KbGetKey() == KEY_05 || KbGetKey() == KEY_ALT){
+						setSnooze(idx);
 						LcdBackLight(LCD_BACKLIGHT_OFF);
                         stopStream();
 					}
 				}
 			}
 		}
-		else if (timer(start) >= 5){
+		else if (timerStruct(timeCheck) >= 5){
             displayTime(0);
             displayDate(1);
 		}

+ 10 - 112
network.c

@@ -22,6 +22,7 @@
 #include <pro/sntp.h>
 
 #include "alarm.h"
+#include "contentparser.h"
 #include "jsmn.h"
 #include "ntp.h"
 #include "network.h"
@@ -49,7 +50,8 @@ char* getMacAdress(){
     ether_ntoa(confnet.cdn_mac);
 }
 
-char* httpGet(char address[]){
+void httpGet(char address[], void (*parser)(char*)){
+    u_long rx_to = 3000;
     isReceiving = true;
     printf("\n\n #-- HTTP get -- #\n");
 
@@ -64,6 +66,8 @@ char* httpGet(char address[]){
         printf("Can't calloc memory\n");
     }else if (NutTcpConnect(sock, inet_addr("62.195.226.247"), 80)) {
         printf("Can't connect to server\n");
+    }else if (NutTcpSetSockOpt(sock, SO_RCVTIMEO, &rx_to, sizeof(rx_to))){
+
     }else{
         FILE *stream;
         stream = _fdopen((int) sock, "r+b");
@@ -93,118 +97,12 @@ char* httpGet(char address[]){
     NutTcpCloseSocket(sock);
 
     content[t] = '\0';
-    //printf("\nContent size: %d, Content: %s \n", t, content);
-    isReceiving = false;
-    return content;
-}
-
-int getTimeZone()
-{
-    char* content = httpGet("/gettimezone.php");
-    int timezone = atoi(content);
+    printf("\nContent size: %d, Content: %s \n", t, content);
+    parser(content);
     free(content);
-    printf("%d", timezone);
-    return timezone;
-}
-
-void parseAlarmJson(char* content){
-    int r;
-    int i;
-    jsmn_parser p;
-    jsmntok_t token[150]; /* We expect no more than 128 tokens */
-
-    jsmn_init(&p);
-    r = jsmn_parse(&p, content, strlen(content), token, sizeof(token)/sizeof(token[0]));
-    if (r <= 0) {
-        printf("Failed to parse JSON: %d \n", r);
-        return;
-    }else{
-        printf("Aantal tokens found: %d \n\n", r);
-    }
-
-
 
-    int start = 1;
-    int usedAlarms[maxAlarms()];
-    int j;
-    for(j = 0; j < maxAlarms(); j++){
-        usedAlarms[j] = 0;
-    }
-    for(i = 1; i < r; i++)
-    {
-        struct _tm time = GetRTCTime();
-        u_short port;
-        char url[24];
-        char ip[24];
-        char name[16];
-		memset(url, 0, 24);
-		memset(ip, 0, 24);
-		memset(name, 0, 16);
-        
-		int id;
-        for (i = i; !((i + start) % 24 == 0); i++) {
-            if (jsoneq(content, &token[i], "YYYY") == 0) {
-                time.tm_year= getIntegerToken(content, &token[i + 1]) - 1900;
-                i++;
-            }else if (jsoneq(content, &token[i], "MM") == 0) {
-                time.tm_mon=  getIntegerToken(content, &token[i + 1]) - 1;
-                i++;
-            }else if (jsoneq(content, &token[i], "DD") == 0) {
-                time.tm_mday =  getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "hh") == 0) {
-                time.tm_hour = 	getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "mm") == 0) {
-                time.tm_min = getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "ss") == 0) {
-                time.tm_sec = getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "id") == 0) {
-                id = getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "port") == 0) {
-                port = getIntegerToken(content, &token[i + 1]);
-                i++;
-            }else if (jsoneq(content, &token[i], "ip") == 0) {
-                getStringToken(content, &token[i + 1], ip);
-                i++;
-            }else if (jsoneq(content, &token[i], "url") == 0) {
-                getStringToken(content, &token[i + 1], url);
-                i++;
-            }else if (jsoneq(content, &token[i], "name") == 0) {
-                getStringToken(content, &token[i + 1], name);
-                i++;
-            }
-        }
-        start = 0;
-
-        int idx = alarmExist(id);
-        if(idx == -1){
-            printf("New alarm found!\n");
-            printf("Alarm time is: %02d:%02d:%02d\n", time.tm_hour, time.tm_min, time.tm_sec);
-            printf("Alarm date is: %02d.%02d.%02d\n", time.tm_mday, (time.tm_mon + 1), (time.tm_year + 1900));
-            printf("Alarm stream data is: %s:%d%s\n", ip, port, url);
-            printf("Alarm id and name is: %d %s\n\n", id, name);
-
-            //zoek naar een vrije plaats in de alarm array
-            for(j = 0; j < maxAlarms(); j++){
-                if(usedAlarms[j] == 0){ //Dit is een lege plaats, hier kunnen we ons nieuwe alarm plaatsen
-                    setAlarm(time, name, ip, port, url, 5, id, j);
-                    usedAlarms[j] = 1;
-                    j = 10;
-                }
-            }
-        }else{
-            usedAlarms[idx] = 1; //Alarm bestaat al, dus we houden deze plaats vrij voor dat alarm
-        }
-    }
-    for(j = 0; j < maxAlarms(); j++){ //Alle overige plaatsen, die wij niet gezet hebben, verwijderen.
-        if(usedAlarms[j] == 0){
-            deleteAlarm(j);
-        };
-    }
+    isReceiving = false;
+    return content;
 }
 
 bool NetworkIsReceiving(void){
@@ -213,4 +111,4 @@ bool NetworkIsReceiving(void){
 
 bool hasNetworkConnection(void){
     return hasNetwork;
-}
+}

+ 2 - 5
network.h

@@ -7,12 +7,9 @@
 
 #include "typedefs.h"
 
-bool hasNetworkConnection(void);
-bool NetworkIsReceiving(void);
 extern void NetworkInit(void);
-char* httpGet(char address[]);
+extern void httpGet(char address[], void (*parser)(char*));
 char* getMacAdress();
-void parseAlarmJson(char* content);
-int getTimeZone(void);
+
 
 #endif /* _Network_H */

+ 6 - 21
ntp.c

@@ -31,7 +31,6 @@
 #include "eeprom.h"
 #include "log.h"
 #include "ntp.h"
-#include "typedefs.h"
 
 #define LOG_MODULE  LOG_NTP_MODULE
 
@@ -81,23 +80,6 @@ void NtpCheckValidTime(void){
 
 //Tests if t1 is after t2.
 bool NtpCompareTime(tm t1, tm t2){
-    char debug[120];
-    sprintf(&debug, "Comparing two times\nt1=%04d-%02d-%02d+%02d:%02d:%02d\nt2=%04d-%02d-%02d+%02d:%02d:%02d \n",
-            t1.tm_year+1900,
-            t1.tm_mon+1,
-            t1.tm_mday,
-            t1.tm_hour,
-            t1.tm_min,
-            t1.tm_sec,
-
-            t2.tm_year+1900,
-            t2.tm_mon+1,
-            t2.tm_mday,
-            t2.tm_hour,
-            t2.tm_min,
-            t2.tm_sec
-    );
-    puts(debug);
 
     if (t1.tm_year > t2.tm_year){
         return true;
@@ -128,9 +110,8 @@ bool NtpTimeIsValid(void){
 void NtpSync(void){
     /* Ophalen van pool.ntp.org */
     isSyncing = true;
-    //_timezone = -getTimeZone() * 3600;
-    puts("NtpSync(): Timezone fetched. ");
-
+    httpGet("/gettimezone.php", parsetimezone);
+    printf(TIME_ZONE);
     NutDelay(100);
     puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     uint32_t timeserver = inet_addr("213.154.229.24");
@@ -164,3 +145,7 @@ void NtpWriteTimeToEeprom(tm time_struct){
     cache.last_sync = time_struct;
     EepromSetCache(&cache);
 }
+
+//unsigned long TmStructToEpoch(tm tm_struct){
+//
+//}

+ 1 - 0
ntp.h

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

+ 8 - 1
vs10xx.c

@@ -513,7 +513,7 @@ int VsPlayerKick(void)
 //        LogMsg_P(LOG_DEBUG,PSTR("Kick: CLOCKF = [0x%02X]"),VsRegRead(VS_CLOCKF_REG));
 //        LogMsg_P(LOG_DEBUG,PSTR("Kick: CLOCKF = [0x%02X]"),VsRegRead(VS_CLOCKF_REG));
 
-        VsLoadProgramCode();
+       // VsLoadProgramCode();
         vs_status = VS_STATUS_RUNNING;
         VsPlayerFeed(NULL);
         VsPlayerInterrupts(1);
@@ -787,6 +787,13 @@ u_short VsMemoryTest(void)
 int VsSetVolume(u_char left, u_char right)
 {
     u_char ief;
+    if(left < 0){
+        left = 0;
+    }
+    if(right < 0){
+        right = 0;
+    }
+    printf("%d %d", left, right);
 
     ief = VsPlayerInterrupts(0);