Prototyping the Adaptable Emergency System on an C027 board.

Dependencies:   C027_Support mbed

Fork of c027_prototyping by Philémon Favrod

Files at this revision

API Documentation at this revision

Comitter:
aroulin
Date:
Tue Sep 30 17:57:38 2014 +0000
Parent:
4:f1708f6ec905
Child:
8:a45beb0e6145
Commit message:
GPS Encapsulation

Changed in this revision

gps_locate.cpp Show annotated file Show diff for this revision Revisions of this file
gps_locate.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/gps_locate.h	Tue Sep 30 16:06:35 2014 +0000
+++ b/gps_locate.h	Tue Sep 30 17:57:38 2014 +0000
@@ -6,7 +6,7 @@
     double lo;
     double altitude;
     double speed;
-} gps_data_t; 
+}; 
 
 int gps_on(void);
 
--- a/main.cpp	Tue Sep 30 16:06:35 2014 +0000
+++ b/main.cpp	Tue Sep 30 17:57:38 2014 +0000
@@ -1,8 +1,11 @@
 #include "mbed.h"
-#include "sms_lib.h"
+#include "gps_locate.h"
 
 int main() {
-    printf("Hello");
-    init_sms_features();
+    printf("Hello here is the position: ");
+    struct gps_data_t gps_data;
+    gps_locate(&gps_data);
+    printf("https://maps.google.com/?q=%.5f,%.5f\n", gps_data.la, gps_data.lo);
+    printf("End");
     return 0;
 }