Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Revision:
4:c70ef089a3fd
Parent:
3:38eabaa92552
Child:
5:11782a2008c2
--- a/main.cpp	Thu Feb 23 14:54:35 2017 +0000
+++ b/main.cpp	Thu Mar 02 14:04:56 2017 +0000
@@ -1,5 +1,6 @@
 #include "main.h"
 
+
 //Global GPS variables
 bool GPS_Data_Rdy = false;
 bool GPS_Data_Valid = false;
@@ -16,6 +17,8 @@
 
 int main(void){
     
+    string currentFilename, nextFilename; 
+    
     //Initializing string buffer for GPS data
     string GPS_String_Buff;
     GPS_String_Buff.resize(128);
@@ -37,9 +40,12 @@
     }
     
     //Opening a file on usb disk
-    FILE * fp = fopen("/usb/test1.txt", "w");
+    FILE * fp = fopen("/usb/test1.sps", "w");
     fclose(fp);
-    fp = fopen("/usb/test1.txt", "a");
+    wait_ms(100);
+    
+    fp = fopen("/usb/test1.sps", "a");
+    wait_ms(100);
     
     //Start comms with the GPS, Enabling GPRMC and  GPGGA
     gps.printf("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");
@@ -84,45 +90,47 @@
             GPS_String_Buff.resize(128);
             
             
-            //parse current date 
-            gpsNMEA.ParseCurrentDateFromGPRMC(&dbg);
+            //If gps fix is present, parse gps data
+            if(GGA_Fix_Present){   
+                //parse current date 
+                gpsNMEA.ParseCurrentDateFromGPRMC(&dbg);
+            
+                //parse current time
+                gpsNMEA.ParseCurrentUTCFromGPRMC(&dbg);
             
-            //parse current time
-            gpsNMEA.ParseCurrentUTCFromGPRMC(&dbg);
+                //parse gps coordinates
+                gpsNMEA.ParseCurrentLatitudeFromGPRMC(&dbg);
+                gpsNMEA.ParseCurrentLongitudeFromGPRMC(&dbg);
+                
+                
+                //write current data received data to file if gga fix is present.
+                if (fp != NULL) {
+                    //dbg.printf("Writing to usb flash disk\r\n");
+                    writecount += 1;
+                    fprintf(fp, gpsNMEA.currentGGAString.c_str());
+                    fprintf(fp, "\r\n");
+                    fprintf(fp, gpsNMEA.currentGPRMCString.c_str());
+                    fprintf(fp, "\r\n");
+                }
             
-            //parse gps coordinates
-            gpsNMEA.ParseCurrentLatitudeFromGPRMC(&dbg);
-            gpsNMEA.ParseCurrentLongitudeFromGPRMC(&dbg);
+                if(fp == NULL){
+                    //Reopening a file on usb disk
+                    FILE * fp = fopen("/usb/test1.txt", "a");        
+                }
             
+                //Close file and reopen
+                if(writecount > 10){
+                    //dbg.printf("Closing file and reopening.\r\n");
+                    fclose(fp);
+                    writecount = 0;
+                    fp = fopen("/usb/test1.txt", "a");    
+                }
+            }
+
             //clearing flags
             GPS_Data_Valid = false;
             GPS_Data_Rdy = false; 
             
-            
-                            
-            //write current data received data to file if gga fix is present.
-            if (fp != NULL) {
-                //dbg.printf("Writing to usb flash disk\r\n");
-                writecount += 1;
-                fprintf(fp, gpsNMEA.currentGGAString.c_str());
-                fprintf(fp, "\r\n");
-                fprintf(fp, gpsNMEA.currentGPRMCString.c_str());
-                fprintf(fp, "\r\n");
-            }
-            
-            if(fp == NULL){
-                //Reopening a file on usb disk
-                FILE * fp = fopen("/usb/test1.txt", "a");        
-            }
-            
-            //Close file and reopen
-            if(writecount > 10){
-                //dbg.printf("Closing file and reopening.\r\n");
-                fclose(fp);
-                writecount = 0;
-                fp = fopen("/usb/test1.txt", "a");    
-            }
-            
        }
         
         
@@ -136,7 +144,7 @@
             }
                 
             //Reopening a file on usb disk
-            fp = fopen("/usb/test1.txt", "a");
+            fp = fopen("/usb/test1.sps", "a");
                      
         }