Prototyping the Adaptable Emergency System on an C027 board.

Dependencies:   C027_Support mbed

Fork of c027_prototyping by Philémon Favrod

Revision:
7:eeef6f9fa1db
Parent:
4:f1708f6ec905
Child:
13:3c1f0b8c1d21
--- a/gps_locate.cpp	Tue Sep 30 16:06:35 2014 +0000
+++ b/gps_locate.cpp	Tue Sep 30 17:57:38 2014 +0000
@@ -12,35 +12,43 @@
 }
 
 int gps_locate(struct gps_data_t* gps_data)
-{/*
+{
     // Power on gps
     GPSI2C gps;
 
+    bool coord_ok = false, altitude_ok = false, speed_ok = false;
+
     int ret = 0;
     char buf[512] = {0};
+    while(!coord_ok || !altitude_ok || !speed_ok) {
+        while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) {
+            int len = LENGTH(ret);
+            if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) {
+                if (!strncmp("$GPGLL", buf, 6)) {
+                    double la = 0, lo = 0;
+                    char ch;
+                    if (gps.getNmeaAngle(1,buf,len,la) &&
+                            gps.getNmeaAngle(3,buf,len,lo) &&
+                            gps.getNmeaItem(6,buf,len,ch) && ch == 'A') {
+                        gps_data->lo = lo;
+                        gps_data->la = la;
+                        coord_ok = true;
+                    }
+                } else if (!strncmp("$GPGGA", buf, 6)) {
+                    double a = 0;
+                    if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m]
+                        gps_data->altitude = a;
+                    altitude_ok = true;
+                } else if (!strncmp("$GPVTG", buf, 6)) {
+                    double s = 0;
+                    if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h]
+                        gps_data->speed = s;
+                    speed_ok = true;
+                }
 
-    while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) {
-        int len = LENGTH(ret);
-        if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) {
-            if (!strncmp("$GPGLL", buf, 6)) {
-                double la = 0, lo = 0;
-                char ch;
-                if (gps.getNmeaAngle(1,buf,len,la) &&
-                        gps.getNmeaAngle(3,buf,len,lo) &&
-                        gps.getNmeaItem(6,buf,len,ch) && ch == 'A') {
-                    printf("GPS Location: %.5f %.5f\r\n", la, lo);
-                    printf(link, "I am here!\n"
-                            "https://maps.google.com/?q=%.5f,%.5f", la, lo);     
-                }
-            } else if (!strncmp("$GPGGA", buf, 6)) {
-                double a = 0;
-                if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m]
-                    printf("GPS Altitude: %.1f\r\n", a);
-            } else if (!strncmp("$GPVTG", buf, 6)) {
-                double s = 0;
-                if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h]
-                    printf("GPS Speed: %.1f\r\n", s);
             }
         }
-    }*/ return 0;
+    }
+
+    return 0;
 }
\ No newline at end of file