Slightly modified version of the SerialGPS library (https://os.mbed.com/teams/components/code/SerialGPS/) to support the BufferedSerial class

Revision:
1:214714f54773
Parent:
0:1a8299deb917
Child:
2:e7f24389167b
diff -r 1a8299deb917 -r 214714f54773 SerialGPS.cpp
--- a/SerialGPS.cpp	Fri Feb 12 12:39:46 2021 +0100
+++ b/SerialGPS.cpp	Mon Feb 15 20:32:48 2021 +0100
@@ -22,18 +22,26 @@
  */
  
 #include "SerialGPS.h"
+#include <cstdio>
 
-SerialGPS::SerialGPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
-    _gps.set_baud(Baud);    
+SerialGPS::SerialGPS(PinName tx, PinName rx, int baud) 
+    : 
+    _gps_p(new UnbufferedSerial(tx, rx)),
+    _gps(*_gps_p)
+{
+    printf("SerialGPS");
+    _gps.baud(baud);
     longitude   = 0.0;
     latitude    = 0.0;        
 }
 
-int SerialGPS::sample() {
+int SerialGPS::sample() 
+{
     char ns, ew, unit;
     int lock;
 
-    while(1) {        
+    while(1)
+    {
         getline();
 
         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
@@ -92,15 +100,18 @@
 
 void SerialGPS::getline() 
 {
-    while(_gps.getc() != '$');    // wait for the start of a line
+    char ch;
 
-    for(int i = 0; i < 256; i++) 
+    while(_gps.read(&ch, 1) != '$')
     {
-        msg[i] = _gps.getc();
-        if(msg[i] == '\r') 
+        for(int i = 0; i < 256; i++) 
         {
-            msg[i] = 0;
-            return;
+            msg[i] = _gps.read(&ch, 1);
+            if(msg[i] == '\r') 
+            {
+                msg[i] = 0;
+                return;
+            }
         }
     }