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

Revision:
2:e7f24389167b
Parent:
1:214714f54773
Child:
3:ebd79e3acf14
--- a/SerialGPS.cpp	Mon Feb 15 20:32:48 2021 +0100
+++ b/SerialGPS.cpp	Tue Feb 16 16:48:14 2021 +0100
@@ -22,15 +22,12 @@
  */
  
 #include "SerialGPS.h"
-#include <cstdio>
 
 SerialGPS::SerialGPS(PinName tx, PinName rx, int baud) 
     : 
-    _gps_p(new UnbufferedSerial(tx, rx)),
+    _gps_p(new BufferedSerial(tx, rx, baud)),
     _gps(*_gps_p)
 {
-    printf("SerialGPS");
-    _gps.baud(baud);
     longitude   = 0.0;
     latitude    = 0.0;        
 }
@@ -101,19 +98,26 @@
 void SerialGPS::getline() 
 {
     char ch;
+    int idx = 0;
 
-    while(_gps.read(&ch, 1) != '$')
+    while(1)
     {
-        for(int i = 0; i < 256; i++) 
+        _gps.read(&ch, 1);
+        if(ch != '$')
         {
-            msg[i] = _gps.read(&ch, 1);
-            if(msg[i] == '\r') 
+            while(idx++ < 256)
             {
-                msg[i] = 0;
-                return;
+                if(ch == '\r')
+                {
+                    msg[idx] = 0;
+                    return;
+                }
+
+                msg[idx] = ch;
             }
         }
     }
-
-    error("Overflowed message limit");
+    fprintf(stderr, "\r\nGPS: Overflowed message limit\r\n");
+    return;
+    //error("Overflowed message limit");
 }
\ No newline at end of file