Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Revision:
56:df9052e3808c
Parent:
21:325cb82f1838
--- a/NMEA/NMEA.cpp	Tue Aug 15 13:41:07 2017 +0000
+++ b/NMEA/NMEA.cpp	Thu Jun 20 07:13:18 2019 +0000
@@ -193,32 +193,31 @@
     will be stored in the format:
     YYYY/MM/DD
 */
+int strtoint(string Str, int index) {
+   char value[3];    
+   value[0]=Str[index];
+   value[1]=Str[index+1];
+   return atoi(value);
+}    
+
 void NMEA::ParseCurrentDateFromGPRMC(){
     
     //Getting date from GPRMC string, assigning to tmpStr 
     getXFromNMEAString(9,currentGPRMCString);
-
+  
     currentDATEFromGPRMC = "";
     currentDATEFromGPRMC.resize(20);  
-    
+    char tmpdate[20];
     //if date string is the expected length
     if(strlen(tmpStr.c_str()) == 6){
-            
-        //Year
-        currentDATEFromGPRMC[0] = '2';
-        currentDATEFromGPRMC[1] = '0';
-        currentDATEFromGPRMC[2] = tmpStr[4];
-        currentDATEFromGPRMC[3] = tmpStr[5];
-        currentDATEFromGPRMC[4] = '/';
-    
-        //Month
-        currentDATEFromGPRMC[5] = tmpStr[2];
-        currentDATEFromGPRMC[6] = tmpStr[3];
-        currentDATEFromGPRMC[7] = '/';
-    
-        //Date
-        currentDATEFromGPRMC[8] = tmpStr[0];
-        currentDATEFromGPRMC[9] = tmpStr[1];       
+        int y=strtoint(tmpStr,4);
+        int m=strtoint(tmpStr,2);
+        int d=strtoint(tmpStr,0);
+        struct tm t = { .tm_year=y, .tm_mon=m-1, .tm_mday=d };
+        t.tm_mday += 1024*7; //rollover compentation
+        mktime(&t);
+        strftime (tmpdate,20,"%G/%m/%e",&t);
+        for (int i=0; i<20; i++) currentDATEFromGPRMC[i]=tmpdate[i];
     } 
 };