Driver for Sparkfun GP-20U7 GPS module

Dependents:   GP20U7_HelloWorld gpsmpu60500 BaseStation healt_monitor_ECE4180

Revision:
3:5cfc893bfd25
Parent:
2:c17f5ba1c3f0
Child:
4:3aa177df0bcb
--- a/GPS.cpp	Tue Mar 15 21:55:44 2016 +0000
+++ b/GPS.cpp	Wed Mar 16 04:28:03 2016 +0000
@@ -32,17 +32,20 @@
 }
 
 int GPS::sample() {
-    float time;
-    char ns, ew;
-    int lock;
-
+    float time, hori_dilute, alt,geoid;
+    char ns, ew, gu, hu;
+    int lock, num_sat;
+    
     while(1) {        
         getline();
         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
+        //pc1.printf(msg);
+        pc1.printf("\n");
+        wait(5);
+        pc1.printf("display msg\r\n");
         pc1.printf(msg);
         pc1.printf("\n");
-        wait(5);
-        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) { 
+        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f,%c", &time, &latitude, &ns, &longitude, &ew, &lock, &num_sat, &hori_dilute, &alt, &hu, &geoid, &gu/*, &age_diff, &diff_ID*/) >= 1) { 
             if(!lock) {
                 longitude = 0.0;
                 latitude = 0.0;        
@@ -56,9 +59,12 @@
                 degrees = trunc(longitude / 100.0f * 0.01f);
                 minutes = longitude - (degrees * 100.0f);
                 longitude = degrees + minutes / 60.0f;
+                pc1.printf(msg);
                 return 1;
             }
+        
         }
+        return 0;
     }
 }
 
@@ -74,10 +80,76 @@
 }
 
 void GPS::getline() {
+    int i;
+    char a;
+    int n;
     while(1) {
-        char a = _gps.getc();
-        pc1.printf("%c", a);
-    }
+    strcpy(msg, '\0');
+    //pc1.printf("\r\n\n New Message: ");
+//    pc1.printf(msg);
+//    pc1.printf("\r\n\n");    
+    i = 0;
+    a = _gps.getc();
+    msg[i] = a;
+    if (a == '$') {
+        //pc1.printf("%c",a);
+        a = _gps.getc();
+        msg[i] = a;
+        i++;
+        if (a == 'G') {
+            //pc1.printf("%c",a);
+            a = _gps.getc();
+            msg[i] = a;
+            i++;
+            if (a == 'P') {
+                //pc1.printf("%c",a);
+                a = _gps.getc();
+                msg[i] = a;
+                i++;
+                if (a == 'G') {
+                    //pc1.printf("%c",a);
+                    a = _gps.getc();
+                    msg[i] = a;
+                    i++;
+                    if (a == 'G') {
+                        //pc1.printf("%c",a);
+                        a = _gps.getc();
+                        msg[i] = a;
+                        i++;
+                        if (a == 'A') {
+                            //pc1.printf("%c",a);
+                            //a = _gps.getc();
+                            //msg[i] = a;
+                            //pc1.printf(msg);
+                            pc1.printf("\r\n");
+        
+                            for (n = 5; n < 456; n++) {
+                               msg[n] = _gps.getc();
+                               pc1.printf("%c", msg[n]);
+                               if(msg[n] == '\r') {
+                                 msg[n] = '0';
+                                 return;
+                                }
+                            }
+                         }
+                     }
+                 }
+            }
+       }
+       }                          
+//    while(_gps.getc() != '$') {
+//        //char a = _gps.getc();
+//        for(i = 0; i < 256; i++) {
+//            msg[i] = _gps.getc();
+//            pc1.printf("%c", msg[i]);
+//            if(msg[i] == '\r') {
+//             msg[i] = 0;
+//             return;
+//                }
+//                }
+//          
+//         
+//    }
 //    while(_gps.getc() != '$');    // wait for the start of a line
 //    for(int i=0; i<256; i++) {
 //        msg[i] = _gps.getc();
@@ -88,3 +160,4 @@
 //    }
 //    error("Overflowed message limit");
 }
+}