فهرست منبع

Merge pull request #38 from jancoow/httpgetFix

several bug fixes
Janco Kock 9 سال پیش
والد
کامیت
cfafe5aac4
5فایلهای تغییر یافته به همراه22 افزوده شده و 6 حذف شده
  1. 1 0
      alarm.c
  2. 2 0
      httpstream.c
  3. 2 2
      main.c
  4. 10 3
      network.c
  5. 7 1
      vs10xx.c

+ 1 - 0
alarm.c

@@ -138,6 +138,7 @@ void setState(int idx){
 		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){

+ 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(){

+ 2 - 2
main.c

@@ -271,7 +271,7 @@ int checkOffPressed(){
 int main(void)
 {
 	initialized = 0;
-    int VOL2;
+    int VOL2 = 127;
     struct _tm timeCheck;
 	struct _tm start;
 	int idx = 0;
@@ -361,7 +361,7 @@ int main(void)
              X12RtcGetClock(&timeCheck);
             if(VOL > 8){
                 VOL -= 8;
-                VsSetVolume (128-VOL, 128-VOL);
+                VsSetVolume (127-VOL, 127-VOL);
                 displayVolume(VOL/8);
             }
         }

+ 10 - 3
network.c

@@ -50,6 +50,7 @@ char* getMacAdress(){
 }
 
 char* httpGet(char address[]){
+    u_long rx_to = 3000;
     isReceiving = true;
     printf("\n\n #-- HTTP get -- #\n");
 
@@ -64,6 +65,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");
@@ -137,12 +140,13 @@ void parseAlarmJson(char* content){
         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) % 24 == 0); i++) {
+        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++;
@@ -176,6 +180,9 @@ void parseAlarmJson(char* content){
             }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;
@@ -186,12 +193,12 @@ void parseAlarmJson(char* content){
             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);
+            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, 5, id, j);
+                    setAlarm(time, name, ip, port, url, st, id, j);
                     usedAlarms[j] = 1;
                     j = 10;
                 }

+ 7 - 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,12 @@ 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;
+    }
 
     ief = VsPlayerInterrupts(0);