Skip to content

expilu/nmea-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nmea-server

A NMEA TCP server and sentences generator in C#

Important: Note that this is a hobbyist implementation of a NMEA server that lacks many of the features or sentences that a complete NMEA implementation could have. It includes some basic sentences to track location, heading, wind, speed, depth, etc,.. This was done mainly to support this other project: SailawayToNMEA

How to use

  1. Download NMEAServerLib.dll and add it to your project references.

  2. Initialize the server with InstrumentsData and a TCP port. Then start it.

InstrumentsData instrumentsData = new InstrumentsData(); 
NmeaServer nmeaServer = new NMEAServer(ref instrumentsData, 10110);
nmeaServer.Start();

At this point you can connect to the server with any hardware or software (qtVlm, OpenCPN,...) that supports NMEA through TCP.

Note that instrumentsData is passed by ref, you only need to modify its properties when instruments changes occur.

  1. Set the properties of your instrumentsData. None of them is mandatory. The server will just send the sentences for which it has enough information. Currently the supported sentences are: GLL, VHW, HDT, MWV, DPT, DBT, VTG and RMC.
// Latitude and Longitude should be in +-180 degrees with decimals
instrumentsData.Lat = 28.134529;
instrumentsData.Lon = -15.435154;
instrumentsData.Heading = 47;
instrumentsData.WaterSpeed = 3.5; // in knots
instrumentsData.CourseOverGround = 48;
instrumentsData.SpeedOverGround = 3.4; // in knots
instrumentsData.TrueWindAngle = 260; // in 360 degrees relative to the heading
instrumentsData.TrueWindSpeed = 3.2; // in knots
instrumentsData.ApparentWindAngle = 260; // in 360 degrees relative to the heading
instrumentsData.ApparentWindSpeed = 3.2; // in knots
instrumentsData.Depth = 15.4; // in meters
instrumentsData.TransducerDepth = 1.2; // in meters
  1. To send NMEA sentences do
nmeaServer.SendData();

You can also initialize the server with a send rate. The server will then send the current instrumentsData at the specified rate (in milliseconds). You can still also call SendData() any moment you like.

InstrumentsData instrumentsData = new InstrumentsData(); 
NmeaServer nmeaServer = new NMEAServer(ref instrumentsData, 10110, 10000); // send data every 10 seconds
nmeaServer.Start();
  1. Remember to stop the server when it is not needed anymore
nmeaServer.Stop();

The NmeaServer has some events you can use: OnServerStarted, OnServerStop, OnNMEASent, OnClientConnected and OnServerError.