#nmea #embedded-devices #parser #gps

no-std nmea0183

NMEA 0183 parser targetting mostly embedded devices but not limited to

9 unstable releases

new 0.5.0 Dec 2, 2024
0.4.0 Jan 28, 2024
0.3.1 Aug 14, 2023
0.3.0 Aug 11, 2021
0.1.0 Aug 20, 2019

#204 in Embedded development

Download history 3/week @ 2024-09-15 58/week @ 2024-09-22 18/week @ 2024-09-29 14/week @ 2024-10-06 1/week @ 2024-10-13 2/week @ 2024-10-20 5/week @ 2024-10-27 5/week @ 2024-11-03 13/week @ 2024-11-10 8/week @ 2024-11-17 8/week @ 2024-11-24 144/week @ 2024-12-01

173 downloads per month
Used in embedded-sensors

BSD-3-Clause

68KB
1.5K SLoC

Crates.io master

NMEA 0183 parser.

Implemented most used sentences like RMC, VTG, GGA, GLL, GSV, GSA. Parser do not use heap memory and relies only on core.

You should instantiate Parser with new and than use methods like parse_from_byte or parse_from_bytes. If parser accumulates enough data it will return ParseResult on success or &str that describing an error.

You do not need to do any preprocessing such as split data to strings or NMEA sentences.

Optional features

Parser supports Mediatek-related PMTKSPF non-standard sentence. It is disabled by default. Use "mtk" feature if you need it.

If your receiver violates NMEA spec, try disable "strict" feature which enabled by default. For example, without "strict" feature sentence size is set to 120 chars instead of standart NMEA 79 chars.

Examples

If you could read a one byte at a time from the receiver you may use parse_from_byte:

use nmea0183::{Parser, ParseResult};

let nmea = b"$GPGGA,145659.00,5956.695396,N,03022.454999,E,2,07,0.6,9.0,M,18.0,M,,*62\r\n$GPGGA,,,,,,,,,,,,,,*00\r\n";
let mut parser = Parser::new();
for b in &nmea[..] {
    if let Some(result) = parser.parse_from_byte(*b) {
        match result {
            Ok(ParseResult::GGA(Some(gga))) => { }, // Got GGA sentence
            Ok(ParseResult::GGA(None)) => { }, // Got GGA sentence without valid data, receiver ok but has no solution
            Ok(_) => {}, // Some other sentences..
            Err(e) => { } // Got parse error
        }
    }
}

If you read many bytes from receiver at once or want to parse NMEA log from text file you could use Iterator-style:

use nmea0183::{Parser, ParseResult};

let nmea = b"$GPGGA,,,,,,,,,,,,,,*00\r\n$GPRMC,125504.049,A,5542.2389,N,03741.6063,E,0.06,25.82,200906,,,A*56\r\n";
let mut parser = Parser::new();

for result in parser.parse_from_bytes(&nmea[..]) {
    match result {
        Ok(ParseResult::RMC(Some(rmc))) => { }, // Got RMC sentence
        Ok(ParseResult::GGA(None)) => { }, // Got GGA sentence without valid data, receiver ok but has no solution
        Ok(_) => {}, // Some other sentences..
        Err(e) => { } // Got parse error
    }
}

It is possible to ignore some sentences or sources. You can set filter on Parser like so:

use nmea0183::{Parser, ParseResult, Sentence, Source};

let parser_only_gps_gallileo = Parser::new()
    .source_filter(Source::GPS | Source::Gallileo);
let parser_only_rmc_gga_gps = Parser::new()
    .source_only(Source::GPS)
    .sentence_filter(Sentence::RMC | Sentence::GGA);

Panics

Should not panic. If so please report issue on project page.

Errors

Unsupported sentence type. - Got currently not supported sentence.

Checksum error! - Sentence has wrong checksum, possible data corruption.

Source is not supported! - Unknown source, new sattelite system is launched? :)

NMEA format error! - Possible data corruption. Parser drops all accumulated data and starts seek new sentences.

It's possible to got other very rare error messages that relates to protocol errors. Receivers nowadays mostly do not violate NMEA specs.

No runtime deps

Features