Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Revision:
2:39c4a85dc2a4
Parent:
0:b3313c5ffca3
Child:
3:38eabaa92552
--- a/NMEA/NMEA.cpp	Fri Feb 17 09:33:57 2017 +0000
+++ b/NMEA/NMEA.cpp	Thu Feb 23 13:01:35 2017 +0000
@@ -71,7 +71,7 @@
     
 //Store function to move GGA to currentGGAString, 
 //or GPRMC to currentGPRMCString
-void NMEA::StoreString(string cstStr, Serial * debg){
+void NMEA::StoreString(string cstStr/*, Serial * debg*/){
     static std::string gga = "$GPGGA";
     static std::string rmc = "$GPRMC";
     
@@ -101,23 +101,104 @@
 
 
 //Parser / formatter function to get current UTC timestamp from GPRMC
-void NMEA::ParseCurrentUTCFromGPRMC(){
+void NMEA::ParseCurrentUTCFromGPRMC(Serial * dbg){
  
-     //rewrite    
+     //getting utc from GPRMC string, assign to tmpStr
+     getXFromNMEAString(1,currentGPRMCString, dbg);
+     
+     currentUTCFromGPRMC = "";
+     currentUTCFromGPRMC.resize(20);
+     
+     //if time format == 10 characters
+     if(strlen(tmpStr.c_str()) == 10){
+         
+        //HH
+        currentUTCFromGPRMC[0] = tmpStr[0];
+        currentUTCFromGPRMC[1] = tmpStr[1];
+        currentUTCFromGPRMC[2] = ':';
+     
+        //MM
+        currentUTCFromGPRMC[3] = tmpStr[2];
+        currentUTCFromGPRMC[4] = tmpStr[3];
+        currentUTCFromGPRMC[5] = ':';
+     
+        //SS
+        currentUTCFromGPRMC[6] = tmpStr[4];
+        currentUTCFromGPRMC[7] = tmpStr[5];
+        currentUTCFromGPRMC[8] = '.';     
+     
+        //FFF
+        currentUTCFromGPRMC[9] = tmpStr[7];
+        currentUTCFromGPRMC[10] = tmpStr[8];
+        currentUTCFromGPRMC[11] = tmpStr[9];   
+     }
+     
+     //if time format == 6 characters
+     if(strlen(tmpStr.c_str()) == 6){
+         
+        //HH
+        currentUTCFromGPRMC[0] = tmpStr[0];
+        currentUTCFromGPRMC[1] = tmpStr[1];
+        currentUTCFromGPRMC[2] = ':';
+     
+        //MM
+        currentUTCFromGPRMC[3] = tmpStr[2];
+        currentUTCFromGPRMC[4] = tmpStr[3];
+        currentUTCFromGPRMC[5] = ':';
+     
+        //SS
+        currentUTCFromGPRMC[6] = tmpStr[4];
+        currentUTCFromGPRMC[7] = tmpStr[5];
+        currentUTCFromGPRMC[8] = '.';     
+     
+        //FFF
+        currentUTCFromGPRMC[9] = '0';
+        currentUTCFromGPRMC[10] = '0';
+        currentUTCFromGPRMC[11] = '0';  
+     }    
 
 };
 
 //Parser getting current Date from GPRMC
-void NMEA::ParseCurrentDateFromGPRMC(){
+void NMEA::ParseCurrentDateFromGPRMC(Serial * dbg){
+    
+    //Getting date from GPRMC string, assigning to tmpStr 
+    getXFromNMEAString(9,currentGPRMCString, dbg);
 
-    //rewrite
-        
+    currentDATEFromGPRMC = "";
+    currentDATEFromGPRMC.resize(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];       
+    }
+    
+
+    dbg->printf("currentDATEFromGPRMC: ");
+    dbg->printf(currentDATEFromGPRMC.c_str());
+    dbg->printf("\r\n");
+ 
 };
 
 //Verification of gps fix, returns gps fix value character in ascii
-bool  NMEA::GGAFixVerification(Serial * debg){
+bool  NMEA::GGAFixVerification(/*Serial * debg*/){
     //accessing the string after the sixth comma, which is the gga fix column
-    debg->printf("Commencing GGA fix verification\r\n");
+    //debg->printf("Commencing GGA fix verification\r\n");
     
     char commaCount = 0;
     char index = 0;
@@ -131,12 +212,12 @@
         //if gga fix is 1 or 2, gga fix is sufficient, return true
         if(commaCount == 6){   
             if(currentGGAString[index+1] == '1'){
-                debg->printf("Valid GGA fix present(1)!\r\n"); 
+                //debg->printf("Valid GGA fix present(1)!\r\n"); 
                 return true;    
             }
             
             if(currentGGAString[index+1] == '2'){
-                debg->printf("Valid GGA fix present(2)!\r\n"); 
+                //debg->printf("Valid GGA fix present(2)!\r\n"); 
                 return true;    
             }
             
@@ -147,6 +228,37 @@
         
     }
     
-    debg->printf("Invalid GGA fix!\r\n");           
+    //debg->printf("Invalid GGA fix!\r\n");           
     return false;
+};
+
+void NMEA::getXFromNMEAString(int desiredCommaCount, string stringToParse, Serial * dbg){
+    
+    //clearing tmpStr
+    tmpStr = "";
+    tmpStr.resize(10);
+    
+    
+    int commaCnt = 0;
+    int index = 0;
+    int idx = 0;    
+    
+    while(commaCnt < (desiredCommaCount+1)){
+        
+        if(stringToParse[index] == ','){
+            commaCnt += 1;
+        }
+        
+        if((commaCnt == desiredCommaCount) && (stringToParse[index] != ',')){
+            tmpStr[idx] = stringToParse[index];
+            idx += 1;
+        }
+        
+        index += 1;    
+    }
+    
+    dbg->printf("tmpStr: ");
+    dbg->printf(tmpStr.c_str());
+    dbg->printf("\r\n");  
+    
 };
\ No newline at end of file