Kaynağa Gözat

Merge branch 'developer' into TwitterFeed

# Conflicts:
#	main.c
MalekSediqi 9 yıl önce
ebeveyn
işleme
f991f0f9ed
5 değiştirilmiş dosya ile 85 ekleme ve 67 silme
  1. 10 23
      contentparser.c
  2. 38 42
      main.c
  3. 7 1
      ntp.c
  4. 4 1
      ntp.h
  5. 26 0
      typedefs.h

+ 10 - 23
contentparser.c

@@ -10,7 +10,7 @@
 #include "displayHandler.h"
 void parseAlarmJson(char* content){
     int r;
-    int i;
+    int i = 2;
     jsmn_parser p;
     jsmntok_t token[150]; /* We expect no more than 128 tokens */
 
@@ -23,65 +23,52 @@ void parseAlarmJson(char* content){
         printf("Aantal tokens found: %d \n", r);
     }
 
-    int start = 1;
     int usedAlarms[maxAlarms()];
     int j;
+    struct _tm time = GetRTCTime();
     for(j = 0; j < maxAlarms(); j++){
         usedAlarms[j] = 0;
     }
-    for(i = 1; i < r; i++)
+    for(i; i < r; i++)
     {
-        struct _tm time = GetRTCTime();
+        int id;
         u_short port;
         char url[24];
         char ip[24];
         char name[16];
-        char st;
+        char st = -1;
         memset(url, 0, 24);
         memset(ip, 0, 24);
-        memset(name, 0, 16);
+        memset(name, 0, 17);
 
-        int id;
-        for (i = i; !((i + start) % 26 == 0); i++) {
+        for (i; (st == -1 && i < r); i+=2) {                                //Zodra ST is gevonden, betekent dit de laatste token van een alarm.
             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++;
+                i+=2;
             }
         }
-        start = 0;
 
         int idx = alarmExist(id);
         if(idx == -1){
@@ -96,7 +83,7 @@ void parseAlarmJson(char* content){
                 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;
+                    j = 10;             //Uit de for loop
                 }
             }
         }else{
@@ -113,7 +100,7 @@ void parseAlarmJson(char* content){
 void parsetimezone(char* content)
 {
     int timezone = atoi(content);
-    printf("%d", timezone);
+    setTimeZone(timezone);
 }
 
 void TwitterParser(char* content)

+ 38 - 42
main.c

@@ -182,10 +182,11 @@ static void SysControlMainBeat(u_char OnOff)
 /*-------------------------------------------------------------------------*/
 /* global variable definitions                                             */
 /*-------------------------------------------------------------------------*/
-int isAlarmSyncing;
-int initialized;
-int running = 0;
-unsigned char VOL = 64;
+bool isAlarmSyncing = false;
+bool initialized = false;
+bool running = false;
+
+u_char VS_volume = 7; //[0-15];
 
 /*-------------------------------------------------------------------------*/
 /* local variable definitions                                              */
@@ -196,43 +197,36 @@ unsigned char VOL = 64;
 /*-------------------------------------------------------------------------*/
 THREAD(StartupInit, arg)
 {
+    NutThreadSetPriority(5);
+
     NetworkInit();
 
-    NtpSync();
+    initialized = true;
 
-    initialized = 1;
     NutThreadExit();
 }
 
-THREAD(NTPSync, arg)
+THREAD(AlarmSync, arg)
 {
-    for(;;)
-    {
-        if(initialized && (hasNetworkConnection() == true))
-        {
-            while(isAlarmSyncing)
-            {
-                NutSleep(2000);
-            }
-            NtpSync();
-        }
-        NutSleep(86400000);
+    NutThreadSetPriority(200);
+
+    while(initialized == false){
+        NutSleep(1000);
     }
-}
 
-THREAD(AlarmSync, arg)
-{
+    NtpSync();
+
     for(;;)
     {
-        if(initialized && (hasNetworkConnection() == true))
+        if((initialized == true) && (hasNetworkConnection() == true))
         {
-            isAlarmSyncing = 1;
-            char url[43];
-            sprintf(url, "%s%s", "/getAlarmen.php?radiomac=", getMacAdress());
+            isAlarmSyncing = true;
+            char url[49];
+            sprintf(url, "/getAlarmen.php?radiomac=%s&tz=%d", getMacAdress(), getTimeZone());
             sprintf(url, "%s%s", "/getTwitter.php", getMacAdress());
             httpGet(url, parseAlarmJson);
             httpGet(url2,TwitterParser);
-            isAlarmSyncing = 0;
+            isAlarmSyncing = false;
         }
         NutSleep(3000);
     }
@@ -304,7 +298,7 @@ int main(void)
 
     NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
     NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
-    NutThreadCreate("BackgroundThread", NTPSync, NULL, 700);
+    //NutThreadCreate("BackgroundThread", NTPSync, NULL, 700);
     /** Quick fix for turning off the display after 10 seconds boot */
 
     RcInit();
@@ -343,38 +337,41 @@ int main(void)
 		//Check if a button is pressed
 		if (checkOffPressed() == 1){
 			X12RtcGetClock(&start);
-			running = 1;
+			running = true;
             LcdBackLight(LCD_BACKLIGHT_ON);
 		}
 
 		//Check if background LED is on, and compare to timer
-		if (running == 1){
+		if (running == true){
 			if (timerStruct(start) >= 10 || running > 1){
-				running = 0;
+				running = false;
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
 		}
 
-        VOL = VOL2;
         if(KbGetKey() == KEY_DOWN)
         {
             NutSleep(150);
-             X12RtcGetClock(&timeCheck);
-            if(VOL > 8){
-                VOL -= 8;
-                VsSetVolume (127-VOL, 127-VOL);
-                displayVolume(VOL/8);
+            X12RtcGetClock(&timeCheck);
+
+            if (VS_volume > 0){
+                --VS_volume;
+                VS_volume = VS_volume % 17;
+                VsSetVolume((127 - (VS_volume * 8)) % 128);
             }
+            displayVolume(VS_volume);
         }
         else if(KbGetKey() == KEY_UP)
         {
             NutSleep(150);
-             X12RtcGetClock(&timeCheck);
-            if(VOL < 128) {
-                VOL += 8;
-                VsSetVolume(128-VOL, 128-VOL);
-                displayVolume(VOL/8);
+            X12RtcGetClock(&timeCheck);
+
+            if (VS_volume < 16){
+                ++VS_volume;
+                VS_volume = VS_volume % 17;
+                VsSetVolume((127 - (VS_volume * 8)) % 128);
             }
+            displayVolume(VS_volume);
         }
         else if(timerStruct(timeCheck) >= 5 && checkAlarms() == 1)
         {
@@ -402,7 +399,6 @@ int main(void)
             displayDate(1);
 		}
 
-        VOL2 = VOL;
         WatchDogRestart();
     }
     return(0);

+ 7 - 1
ntp.c

@@ -104,6 +104,7 @@ void NtpSync(void){
     /* Ophalen van pool.ntp.org */
     isSyncing = true;
     httpGet("/gettimezone.php", parsetimezone);
+    _daylight = 0;
     printf(TIME_ZONE);
     NutDelay(100);
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
@@ -144,5 +145,10 @@ void NtpWriteTimeToEeprom(tm time_struct){
 }
 
 void setTimeZone(int timezone){
-    _timezone = -timezone * 3600;
+    TIME_ZONE = timezone;
+    _timezone = -1*timezone * 3600;
+}
+
+int getTimeZone(){
+    return TIME_ZONE;
 }

+ 4 - 1
ntp.h

@@ -5,7 +5,7 @@
 #ifndef _Ntp_H
 #define _Ntp_H
 
-typedef enum {false, true} bool;
+#include "typedefs.h"
 
 extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
@@ -16,4 +16,7 @@ extern bool NtpTimeIsValid(void);
 void NtpCheckValidTime(void);
 void NtpWriteTimeToEeprom(tm);
 bool NtpCompareTime(tm, tm);
+
+void setTimeZone(int timezone);
+int getTimeZone();
 #endif /* _Ntp_H */

+ 26 - 0
typedefs.h

@@ -12,6 +12,22 @@
  * [PURPOSE]    global typedefs
  * ======================================================================== */
 
+/*
+ *  Copyright 20152016-TI2.3a6, 2016.
+ *
+ *  Project             : 20152016-TI2.3a6-Internet Radio
+ *  Module              : Type definitions
+ *  File name           : Typedefs.h
+ *  Revision            : 1.1
+ *  Creation Date       : 2016/03/04
+ *
+ *  Description         : Global type definitions for the SIR100/120
+ *                        firmware.
+ *
+ *  Changelog       1.1 : Add type definitions for TI2.3a6 software.
+ *                        - Add bool
+ */
+
 
 /*--------------------------------------------------------------------------*/
 /*  Include files                                                           */
@@ -29,6 +45,16 @@
 /*     Make sure that any modification made to this table are reflected by  */
 /*     the LcdErrorStirngs table! (an error is bad but showing the wrong    */
 /*     error is too much....) */
+
+// Additions based on version 1.1
+
+typedef enum {false, true} bool;
+
+
+
+
+
+
 typedef enum _TERRORCODE
 {
     OK = 0,                             /* All ok */