Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Branch:
MbedBMAGThrRev
Revision:
38:a1615de4ee64
Parent:
37:fdd60dde174a
Child:
39:0aeb019323bf
--- a/main.cpp	Wed Sep 27 06:57:20 2017 +0000
+++ b/main.cpp	Thu Sep 28 09:13:10 2017 +0000
@@ -14,6 +14,10 @@
 
 //Global GPS variables
 Timer t;
+bool ppsTick = false;
+char tmpHour[5];
+char tmpMinute[5];
+char tmpSecond[5];
 char time_buffer[32];
 bool RTC_set = false;
 bool GPS_Data_Rdy = false;
@@ -161,8 +165,8 @@
 
 //timer reset // clock update
 void resetTimer(void){
-    t.reset();
-    clk.pps_Tick();    
+    clockobj.pps_Tick();
+    t.reset();   
 }
 
 int main(void){
@@ -182,7 +186,7 @@
     wd.init(5.0);
     
     //PPS
-    InterruptIn PPS(p12);
+    InterruptIn PPS(p12);  
     PPS.rise(&resetTimer);
       
     //Led outputs
@@ -308,6 +312,9 @@
     //gps available ticker
     Ticker gpsAvailableTicker;
     gpsAvailableTicker.attach(gpsAvailCheck, 10.0);
+    
+    //clock freqency info
+    dbg.printf("SystemCoreClock = %d Hz\r\n", SystemCoreClock);
       
     snprintf(PreassureArr, 10, "%s", "NaN");
     snprintf(TemperatureArr, 10, "%s", "NaN");
@@ -493,19 +500,11 @@
             //reset last read ms val
             memset(timer_ms,'\0',5);
             tmpTime = t.read_ms();
-            snprintf (timer_ms, 5, "%d",tmpTime);
-            
-            //dbg.printf("Timer: %d\r\n", tmpTime);
-            //dbg.printf("ms timer val = %s\r\n", timer_ms);            
-            
-                        
+            snprintf (timer_ms, 5, "%d",tmpTime);    
+                         
             if(RTC_set){
-                //t_of_day = time(NULL);
-                //char buffer[15];
-                //strftime(buffer, 15, "%T", localtime(&t_of_day));
-                //dbg.printf("Time: %s\r\n", buffer);
                 
-                string tmpTime = clk.getTime();
+                string tmpTime = clockobj.getTime();
                 
                                 
                 //HH
@@ -623,22 +622,8 @@
                 
 
                 if(!lastErrStatus && firstErrsWritten) {
-                    //clock resync
-                    char tmpHour[5];
-                    char tmpMinute[5];
-                    char tmpSecond[5];
-                    
-                    memset(tmpHour, '/0', 5);
-                    memset(tmpMinute, '/0', 5);
-                    memset(tmpSecond, '/0', 5);
-                    
-                    snprintf(tmpHour, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(0, 2));
-                    snprintf(tmpMinute, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(3, 2));
-                    snprintf(tmpSecond, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(6, 2));
-                    int hours = atoi(tmpHour);
-                    int minutes = atoi(tmpMinute);
-                    int seconds = atoi(tmpSecond);  
-                    clk.setTime(seconds, minutes, hours);  
+                    //force clock resync
+                    RTC_set = false;  
                     
                     //error end string
                     spsGen.UpdateCurrentErrString("ERRE", IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, magParser.getMagTimeStr(), magParser.getMagNTStr(), magParser.getMagSq(), &dbg);
@@ -750,14 +735,9 @@
             GPS_Data_Valid = false;
             GPS_Data_Rdy = false;
             
-            if(GGA_Fix_Present && !RTC_set && (strlen(gpsNMEA.currentDATEFromGPRMC.c_str()) > 5)){
+            if(GGA_Fix_Present && !RTC_set){
                     setMbedTime(gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, &dbg);
-                    RTC_set = true;
-                    
-                    char tmpHour[5];
-                    char tmpMinute[5];
-                    char tmpSecond[5];
-                    
+                                 
                     memset(tmpHour, '/0', 5);
                     memset(tmpMinute, '/0', 5);
                     memset(tmpSecond, '/0', 5);
@@ -768,9 +748,13 @@
                     
                     int hours = atoi(tmpHour);
                     int minutes = atoi(tmpMinute);
-                    int seconds = atoi(tmpSecond);  
+                    int seconds = atoi(tmpSecond);                 
+                    clockobj.setTime(seconds, minutes, hours);
                     
-                    clk.setTime(seconds, minutes, hours);                          
+                    dbg.printf("Clock resync done!\r\n"); 
+                    dbg.printf("Clock set to %s\r\n", clockobj.getTime());    
+                    
+                    RTC_set = true;                          
             }
                 
         }