Improved, thread compatible. Adds new features

Dependents:   GroveGPS-Example

Fork of GroveGPS by Michael Ray

Revision:
4:4615d6e99bb4
Parent:
3:cc5c9faa1cc6
--- a/GroveGPS.cpp	Sun Apr 22 00:06:53 2018 +0000
+++ b/GroveGPS.cpp	Thu May 31 17:21:40 2018 +0000
@@ -20,15 +20,45 @@
 
 #include "GroveGPS.h"
 
-Serial gps_serial(PE_8, PE_7, 9600);
+Serial gps_serial(D1, D0, 9600);
+
+
+
+//Thread gpsThread;
+GroveGPS gps;
+    
+Semaphore parse;
+Thread parsethread(osPriorityBelowNormal);
 
 
-Thread gpsThread;
-GroveGPS gps;
+    static void parseLine() {
+        while(1) {
+            parse.wait();
+            if (gps._last_line.find("GPGGA") != std::string::npos) {
+                gps.parseGGA();
+            }
+            if (gps._last_line.find("GPZDA") != std::string::npos) {
+                gps.parseZDA();
+            }
+            if (gps._last_line.find("GPVTG") != std::string::npos) {
+                gps.parseVTG();
+            }
+            gps._last_line = "";
+        }
+    }
 
 
+    void readCharacter(char newCharacter) {
+        if (newCharacter == '\n') {
+            parse.release();
+        } else {
+            gps._last_line += newCharacter;
+        }
+    }
+        
+
 void service_serial(void) {
-    gps.readCharacter(gps_serial.getc());
+    readCharacter(gps_serial.getc());
     }
  
 
@@ -44,7 +74,7 @@
     
 void nema_send( void ) {
     
-    char nema_mode[] = "$PMTK314,5,5,5,5,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0*";
+    char nema_mode[] = "$PMTK314,0,0,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*";
     char nema_cmd[64];
    int x = 0;
     sprintf( nema_cmd, "%s%x\r\n", nema_mode, calc_cs(nema_mode));
@@ -54,11 +84,13 @@
     }
 
 int GPS_init() {
-
+    gps._last_line = "";
    gps_serial.attach( &service_serial, Serial::RxIrq );
    gps.gps_gga.new_flag = 0;
    gps.gps_zda.new_flag = 0;
    gps.gps_vtg.new_flag = 0;
    nema_send();
-    return 0;
+   printf("\r\nGPS Init\r\n");
+   parsethread.start(parseLine);
+   return 0;
 }
\ No newline at end of file