common: Restart NMEA message parsing when a '$' character is seen.
authorTilman Sauerbeck <tilman@code-monkey.de>
Fri, 3 Jan 2020 20:42:24 +0000 (21:42 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Mon, 6 Jan 2020 09:45:34 +0000 (10:45 +0100)
The GPS module sometimes sends incomplete NMEA messages such as this:
  $GP$GGA...*
This changeset makes it so we'd only parse the second, complete message
in that example.

src/common/gps.rs

index b9fcbc3f23d9a732676082fbc3cccac4d2535310..b0539173272bbe5b5a0fc833deb8eb8b4899f278 100644 (file)
@@ -209,13 +209,17 @@ impl Gps {
         let hexdigits = b"0123456789abcdef";
 
         while let Some(received) = try_read() {
+            if received == b'$' {
+                self.state = ParseState::InPacket;
+                self.offset = 0;
+                self.checksum = 0x00;
+
+                continue;
+            }
+
             match self.state {
                 ParseState::Start => {
-                    if received == b'$' {
-                        self.state = ParseState::InPacket;
-                        self.offset = 0;
-                        self.checksum = 0x00;
-                    }
+                    // Empty.
                 },
                 ParseState::InPacket => {
                     if received == b'*' {