https://github.com/hellfirehd/dkw-nmea
Very fast NMEA parser
https://github.com/hellfirehd/dkw-nmea
dotnet-core gps nmea span
Last synced: about 1 month ago
JSON representation
Very fast NMEA parser
- Host: GitHub
- URL: https://github.com/hellfirehd/dkw-nmea
- Owner: hellfirehd
- License: gpl-3.0
- Created: 2018-11-30T07:25:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2026-02-21T23:59:55.000Z (4 months ago)
- Last Synced: 2026-02-22T06:30:13.995Z (4 months ago)
- Topics: dotnet-core, gps, nmea, span
- Language: C#
- Size: 182 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DKW NMEA
[](https://ci.appveyor.com/project/dougkwilson/dkw-nmea/branch/master)
A very fast [NMEA](https://en.wikipedia.org/wiki/NMEA_0183) parser. The speed is achieved by
using `System.Buffers`, `System.IO.Pipelines`, `Span` and related bits and pieces
avoiding as many allocations as possible.
(This is my first foray into Buffers and Pipelines... Be Gentle!)
## Usage
Synchronous:
```csharp
using (var nr = new NmeaReader(File.Open("track2.nmea")))
{
while (true)
{
var message = nr.ReadNext();
if (message == null)
{
break;
}
Console.WriteLine(message);
}
}
```
Asynchronous:
```csharp
using (var nr = new NmeaReader(File.Open("track2.nmea")))
{
while (true)
{
var message = await nr.ReadNextAsync().ConfigureAwait(false);
if (message == null)
{
break;
}
Console.WriteLine(message);
}
}
```
Bloody freaking crazy Asynchronous:
```csharp
var nsr = NmeaStreamReader.Create();
using (var reader = File.Open("track1.nmea"))
{
await nsr.ParseStreamAsync(reader, (s) =>
{
Console.WriteLine(message);
}).ConfigureAwait(false);
}
```
## Filtering
If you are only interested in a specific NMEA sentence then build the `NmeaStreamReader` yourself:
```csharp
var nsr = new NmeaStreamReader().Register(new GGA());
```
Parsers are available for:
* GPGGA
* GPGLL
* GPGSA
* GPGSV
* GPRMC
But don't despair! It's easy to add new sentences.
```csharp
public class GLL : NmeaMessage
{
private static readonly ReadOnlyMemory KEY = Encoding.UTF8.GetBytes("$GPGLL").AsMemory();
protected override ReadOnlyMemory Key => KEY;
public Double Latitude { get; private set; }
public Double Longitude { get; private set; }
public TimeSpan FixTime { get; private set; }
public Char DataActive { get; private set; }
public override String ToString() => $"GPGLL {Latitude} {Longitude} {FixTime} {DataActive}";
public override NmeaMessage Parse(ReadOnlySequence sentence)
{
var lexer = new Lexer(sentence);
if (lexer.NextString() != "GPGLL")
{
throw lexer.Error();
}
return new GLL()
{
Latitude = lexer.NextLatitude(),
Longitude = lexer.NextLongitude(),
FixTime = lexer.NextTimeSpan(),
DataActive = lexer.NextChar(),
Checksum = lexer.NextChecksum()
};
}
}
```