From: Tilman Sauerbeck Date: Fri, 3 Jan 2020 20:42:24 +0000 (+0100) Subject: common: Restart NMEA message parsing when a '$' character is seen. X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=9a8a254d92e81cb9030dce2ff7055160ea042246;p=gps-watch.git 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. --- 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'*' {