rustedbytes-nmea
Rust no_std library for parsing NMEA messages from a GNSS receiver.
Features
no_stdcompatible - can be used in embedded systems- Stateless parser - no internal buffers or state retention
- Multi-byte parsing - parse multiple bytes at once with bytes consumed tracking
- Local time registration - optionally record local reception time for each message
- Multiconstellation support - tracks which GNSS constellation provided each message
- GPS (GP), GLONASS (GL), Galileo (GA), BeiDou (GB/BD), Multi-GNSS (GN), QZSS (QZ)
- Supports common NMEA message types:
- GGA (Global Positioning System Fix Data)
- RMC (Recommended Minimum Navigation Information)
- GSA (GPS DOP and active satellites)
- GSV (GPS Satellites in view)
- GLL (Geographic Position - Latitude/Longitude)
- VTG (Track Made Good and Ground Speed)
- GNS (GNSS Fix Data)
- Handles spurious characters between messages
- Structured parameter extraction for each message type
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Example
use ;
Streaming Example
use ;
Multiconstellation Support
The library automatically tracks which GNSS constellation provided each message through the talker_id field:
use ;
Supported Constellations
| Talker ID | Constellation | Description |
|---|---|---|
GP |
GPS | Global Positioning System (USA) |
GL |
GLONASS | Russian satellite navigation |
GA |
Galileo | European satellite navigation |
GB |
BeiDou | Chinese satellite navigation (GBxxxx format) |
BD |
BeiDou | Chinese satellite navigation (BDxxxx format) |
GN |
Multi-GNSS | Combined data from multiple systems |
QZ |
QZSS | Japanese Quasi-Zenith Satellite System |
API
NmeaParser
The main parser structure. The parser is now stateless - it maintains no internal buffers or message storage.
Methods
new()- Create a new parser instanceparse_bytes(data: &[u8]) -> Result<(Option<NmeaMessage>, usize), (ParseError, usize)>- Parse bytes and return:Ok((Some(message), bytes_consumed))- Successfully parsed a complete, valid messageOk((None, bytes_consumed))- Partial message (need more data) or consumed spurious charactersErr((ParseError::InvalidMessage, bytes_consumed))- Complete message but missing mandatory fieldsErr((ParseError::InvalidChecksum, bytes_consumed))- Checksum verification failed
ParseError
Error types returned when parsing fails:
InvalidMessage- Message is syntactically complete but missing mandatory fields or invalidInvalidChecksum- Checksum verification failed (not yet fully implemented)
NmeaMessage
Enum representing a parsed NMEA message with associated data.
Variants
GGA(GgaData)- Global Positioning System Fix DataRMC(RmcData)- Recommended Minimum Navigation InformationGSA(GsaData)- GPS DOP and active satellitesGSV(GsvData)- GPS Satellites in viewGLL(GllData)- Geographic Position - Latitude/LongitudeVTG(VtgData)- Track Made Good and Ground SpeedGNS(GnsData)- GNSS Fix Data
Methods
message_type() -> MessageType- Get the message type identifiertalker_id() -> TalkerId- Get the talker ID (constellation identifier)as_gga() -> Option<&GgaData>- Extract GGA message parametersas_rmc() -> Option<&RmcData>- Extract RMC message parametersas_gsa() -> Option<&GsaData>- Extract GSA message parametersas_gsv() -> Option<&GsvData>- Extract GSV message parametersas_gll() -> Option<&GllData>- Extract GLL message parametersas_vtg() -> Option<&VtgData>- Extract VTG message parametersas_gns() -> Option<&GnsData>- Extract GNS message parameters
MessageType
Enumeration of NMEA message type identifiers:
GGA- Global Positioning System Fix DataRMC- Recommended Minimum Navigation InformationGSA- GPS DOP and active satellitesGSV- GPS Satellites in viewGLL- Geographic Position - Latitude/LongitudeVTG- Track Made Good and Ground SpeedGNS- GNSS Fix DataUnknown- Unrecognized message type
Parameter Structures
The library provides typed parameter structures for each NMEA message type, allowing structured access to message-specific fields.
GgaData
Global Positioning System Fix Data parameters:
time()- Mandatory - UTC time (hhmmss format) - accessed via methodlatitude- Mandatory - Latitude valuelat_direction- Mandatory - N or Slongitude- Mandatory - Longitude valuelon_direction- Mandatory - E or Wfix_quality- Mandatory - Fix quality (0=invalid, 1=GPS fix, 2=DGPS fix, etc.)num_satellites- Optional - Number of satellites in usehdop- Optional - Horizontal Dilution of Precisionaltitude- Optional - Altitude above mean sea levelaltitude_units- Optional - Units of altitude (M for meters)geoid_separation- Optional - Height of geoid above WGS84 ellipsoidgeoid_units- Optional - Units of geoid separationage_of_diff- Optional - Age of differential GPS datadiff_station_id()- Optional - Differential reference station ID - accessed via method
Note: If any mandatory field is missing or cannot be parsed, the parser returns None.
RmcData
Recommended Minimum Navigation Information parameters:
time()- Mandatory - UTC time (hhmmss format) - accessed via methodstatus- Mandatory - Status (A=active/valid, V=void/invalid)latitude- Mandatory - Latitude valuelat_direction- Mandatory - N or Slongitude- Mandatory - Longitude valuelon_direction- Mandatory - E or Wspeed_knots- Mandatory - Speed over ground in knotstrack_angle- Mandatory - Track angle in degreesdate()- Mandatory - Date (ddmmyy format) - accessed via methodmagnetic_variation- Optional - Magnetic variationmag_var_direction- Optional - E or W
Note: If any mandatory field is missing or cannot be parsed, the parser returns None.
GsaData
GPS DOP and active satellites parameters:
mode- Mandatory - Mode (M=manual, A=automatic)fix_type- Mandatory - Fix type (1=no fix, 2=2D, 3=3D)satellite_ids- Optional - Array of up to 12 satellite PRN numberspdop- Optional - Position Dilution of Precisionhdop- Optional - Horizontal Dilution of Precisionvdop- Optional - Vertical Dilution of Precision
Note: If any mandatory field is missing or cannot be parsed, as_gsa() returns None.
GsvData
GPS Satellites in view parameters:
num_messages- Mandatory - Total number of GSV messagesmessage_num- Mandatory - Current message numbersatellites_in_view- Mandatory - Total number of satellites in viewsatellite_info- Optional - Array of up to 4 satellite information structures
Each SatelliteInfo contains:
prn- Optional - Satellite PRN numberelevation- Optional - Elevation in degrees (0-90)azimuth- Optional - Azimuth in degrees (0-359)snr- Optional - Signal-to-Noise Ratio in dB
Note: If any mandatory field is missing or cannot be parsed, as_gsv() returns None.
GllData
Geographic Position parameters:
latitude- Mandatory - Latitude valuelat_direction- Mandatory - N or Slongitude- Mandatory - Longitude valuelon_direction- Mandatory - E or Wtime()- Mandatory - UTC time (hhmmss format) - accessed via methodstatus- Mandatory - Status (A=active/valid, V=void/invalid)
Note: If any mandatory field is missing or cannot be parsed, the parser returns None.
VtgData
Track Made Good and Ground Speed parameters (all fields are optional):
track_true- Optional - True track angletrack_true_indicator- Optional - T (true)track_magnetic- Optional - Magnetic track angletrack_magnetic_indicator- Optional - M (magnetic)speed_knots- Optional - Speed in knotsspeed_knots_indicator- Optional - N (knots)speed_kph- Optional - Speed in kilometers per hourspeed_kph_indicator- Optional - K (km/h)
Note: VTG messages can be parsed even with all fields empty, as all fields are optional.
GnsData
GNSS Fix Data parameters:
time()- Mandatory - UTC time (hhmmss format) - accessed via methodlatitude- Mandatory - Latitude valuelat_direction- Mandatory - N or Slongitude- Mandatory - Longitude valuelon_direction- Mandatory - E or Wmode_indicator()- Mandatory - Position fix mode for each GNSS system - accessed via methodnum_satellites- Mandatory - Number of satellites in usehdop- Optional - Horizontal Dilution of Precisionaltitude- Optional - Altitude above mean sea levelgeoid_separation- Optional - Height of geoid above WGS84 ellipsoidage_of_diff- Optional - Age of differential GPS datadiff_station_id()- Optional - Differential reference station ID - accessed via methodnav_status- Optional - Navigation status indicator
Note: If any mandatory field is missing or cannot be parsed, the parser returns None.
NMEA 0183 Compliance
For detailed information about the library's compliance with the NMEA 0183 standard, including supported and unsupported message types and fields, see the NMEA 0183 Compliance Matrix.
Testing
Run the test suite:
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
cargo test) - Code is properly formatted (
cargo fmt) - No clippy warnings (
cargo clippy)
For maintainers: See RELEASE.md for instructions on creating a new release.
License
MIT License - see LICENSE file for details.