From 9a8a254d92e81cb9030dce2ff7055160ea042246 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Fri, 3 Jan 2020 21:42:24 +0100 Subject: [PATCH] common: Restart NMEA message parsing when a '$' character is seen. 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/gps.rs b/src/common/gps.rs index b9fcbc3..b053917 100644 --- a/src/common/gps.rs +++ b/src/common/gps.rs @@ -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'*' { -- 2.30.2