Code Monkey home page Code Monkey logo

dkw-nmea's Introduction

DKW NMEA

Build status

A very fast NMEA parser. The speed is achieved by using System.Buffers, System.IO.Pipelines, Span<T> and related bits and pieces avoiding as many allocations as possible.

(This is my first foray into Buffers and Pipelines... Be Gentle!)

Usage

Synchronous:

using (var nr = new NmeaReader(File.Open("track2.nmea")))
{
  while (true)
  {
    var message = nr.ReadNext();
    if (message == null)
    {
      break;
    }
    Console.WriteLine(message);
  }
}

Asynchronous:

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:

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:

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.

public class GLL : NmeaMessage
{
  private static readonly ReadOnlyMemory<Byte> KEY = Encoding.UTF8.GetBytes("$GPGLL").AsMemory();
  protected override ReadOnlyMemory<Byte> 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<Byte> 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()
    };
  }
}

dkw-nmea's People

Contributors

hellfirehd avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.