UCNLNMEA

Форк
0

README.md

UCNLNMEA

NMEA 0183 protocol support library

This repository is a supported version of a library I posted back in 2011 at CodeProject

The library is able to parse and build any NMEA0183-sentences. Common used standard sentences are supported 'from the box'.

If you looking for a tiny and fast C/Arduino code for parsing NMEA0183-sentences, please, refer to UCNL_ALibs library

The parser/builder is made as a static class.
To use it, just:

  • Add UCNLNMEA to your project's references list.
  • Add a propriate using declaration: using UCNLNMEA;

List of supported standard sentences

Sentence IDDescription
AAMWaypoint Arrival Alarm
ALMGPS Almanac Data
APBAutopilot Sentence "B"
APAAutopilot Sentence "A"
ASDAutopilot System Data
BECBearing & Distance to Waypoint, Dead reckoning
BODBearing, Origin to Destination
BWCBearing & Distance to Waypoint, Great Circle
BWRBearing & Distance to Waypoint, Rhumb Line
BWWBearing, Waypoint to Waypoint
DBKDepth Below Keel
DBSDepth Below Surface
DBTDepth Below Transduser
DCNObsolete Decca Position
DPTDepth
DSCDigital Selective Calling Information
DSEExtended DSC
DSIDSC Transponder Initiate
DSRDSC Transponder Response
DTMDatum Reference
FSIFrequency Set Information
GBSGBS Satellite Fault Detection
GGAGlobal Positioning System Fix Data
GLCGeographic Position, Loran-C
GLLGeographic Position, Latitude/Longitude
GRSGPS Range Residuals
GSAGPS DOP and Active Satellites
GSTGPS Pseudorange Noise Statistics
GSVGPS Sattelites in View
GTDGeograpic Location in Time Differences
GXATransit Position
HDGHeading, Deviation & Variation
HDMHeading, Magnetic
HDTHeading, True
HSCHeading Steering Command
LCDLoran-C Signal Data
MSKMSK Receiver Interface (for DGPS Beacon Receivers)
MSSMSK Receiver Signal Status
MTWWater Temperature
MWDWind Direction & Speed
MWVWind Speed & Angle
OLNObsolete Omega Line Numbers
OSDOwn Ship Data
RMARecommend Minimum Specific Loran-C Data
RMBRecommend Minimum Navigation Information
RMCRecommend Minimum Specific GPS/TRANSIT Data
ROOWaypoints in Active Route
ROTRate of Turn
RPMRevolutions
RSARudder Sensor Angle
RSDRADAR System Data
RTERoutes
SFIScanning Frequency Information
STNMultiple Data ID
TLLTarget Latitude & Longitude
TRFObsolete TRANSIT Fix Data
TTMTracked Target Message
VBWDual Ground/Water Speed
VDRSet and Drift
VHWWater Speed and Heading
VLWDistance Traveled through Water
VPWSpeed, Measured Parallel to Wind
VTGTrack Made Good and Ground Speed
VWRRelative Wind Speed & Angle
WCVWaypoint Closure Velocity
WDCDistance to Waypoint, Great Circle
WDRDistance to Waypoint, Rhumb Line
WNCDistance, Waypoint to Waypoint
WPLWaypoint Location
XDRTransducer Measurement
XTECross-Track Error, Measured
XTRCross-Track Error, Dead Reckoning
ZDATime & Date
ZDLTime & Distance to Variable Point
ZFOUTC & Time from Origin Waypoint
ZTGUTC & Time to Destination Waypoint

List of known Talkers

Talker IDDescription
AGAutopilot - General
APAutopilot - Magnetic
CDCommunications - Digital Selective Calling (DSC)
CRCommunications - Receiver / Beacon Receiver
CSCommunications - Sattelite
CTCommunications - Radio-Telephone (MF/HF)
CVCommunications - Radio-Telephone (VHF)
CXCommunications - Scanning Receiver
DFDirection Finder
ECElectronic Chart Display & Information System (ECDIS)
EPEmergency Position Indicating Beacon (EPIRB)
EREngine Room Monitoring Systems
GAGallileo
GBBeiDou
GLGLONASS
GPGlobal Positioning System (GPS)
GNMixed satellite fix
HCHeading - Magnetic Compass
HEHeading - North Seeking Gyro
HNHeading - Non North Seeking Gyro
IIIntegrated instrumentation
INIntegrated Navigation
LCLoran C
PProprietary Code
RARADAR and/or ARPA
SDSounder, Depth
SNElectronic Positioning System, other/general
SSSouder, Scanning
TITurn Rate Indicator
VDVelocity Sensor, Doppler, other/general
DMVelocity Sensor, Speed Log, Water, Magnetic
VWVelocity Sensor, Speed Log, Water, Mechanical
WIWeather Instruments
YXTransduser
ZATimekeeper - Atomic Clock
ZCTimekeeper - Chronometer
ZQTimekeeper - Quartz
ZVRadio Update, WWV or WWVH

Standard sentences examples

Building & parsing of a HDT sentence (Heading from True North)

double shipHeading = 48.123;
string hdt_sentence = NMEAParser.BuildSentence(
   TalkerIdentifiers.GN,    // Talker identifier = GN (GPS + GLONASS)
   SentenceIdentifiers.HDT, // Sentense identifier = HDT (Heading from True North)
   new object[]             // Parameters list
    {
        shipHeading, // Heading value in degrees
        "T"          // T stands for True
    }));

after that, hdt_sentence will has a value "$GNHDT,48.123,T*17\r\n"

To parse new built sentence, one can use following code:

// parseResult can be NMEAStandardSentence or NMEAProprietarySentence
// to use it, you have to check type of the result and make a cast
try parseResult = NMEAParser.Parse(hdt_sentence);

if (parseResult is NMEAStandardSentence) // check if it is a standard sentence
{   
   // sentence parameters are stored in 'paramters' field, which is an object[]
   // accoring to HDT sentence format, the first parameter (index = 0) is a double value for heading
   Console.WriteLine(string.Format("Heading: {0:F03}", (parseResult as NMEAStandardSentence).parameters[0]));
}

double lat = 48.50963056;
double lon = 44.55977778;
double speedKmh = 0.5;

string rmc_sentence = NMEAParser.BuildSentence(
   TalkerIdentifiers.GN,     // Talker identifier = GN (GPS + GLONASS)
   SentenceIdentifiers.RMC,  // Sentence identifier = RMC
   new object[]              // Parameters list
 {
    DateTime.Now,            // UTC time
    "Valid",                 // Time is valid
    lat, "N",                // Position latitude, degrees
    lon, "E",                // Position longitude, degrees
    speedKmh.Value / 0.5144, // Speed
    null,                    // track true  
    DateTime.Now,            // UTC date
    null,                    // magnetic variation
    null,                    // magnetic variation direction
    "D",                     // Positioning system mode indicator, D = differential
});

after that, rmc_sentence will has value $GNRMC,233843.698,A,4830.5778,N,04433.5867,E,0.972006,,270719,,,D*6F\r\n

To parse it, use following code:

// parseResult can be NMEAStandardSentence or NMEAProprietarySentence
// to use it, you have to check type of the result and make a cast
try parseResult = NMEAParser.Parse(rmc_sentence);

if (parseResult is NMEAStandardSentence) // check if it is a standard sentence
{   
   // sentence parameters are stored in 'paramters' field, which is an object[]
   var rmcResult = (parseResult as NMEAStandardSentence);
   Console.WriteLine(string.Format("Lat: {0:F06}, Lon: {1:F06}", 
      rmcResult.parameters[2], // latitude value as double
      rmcResult.parameters[4]  // longitude value as double
      // ... etc
   ));    
}

Proprietary sentence definition, building & parsing example

Dealing with proprietary sentences is pretty the same process as with standard ones, except few diffirencies: First, you should add a description for a sentence. Consider we need an ACK sentence, which should has single integer parameter - error code.

NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.UWV); // Add new entry to proprietary sentences descriptor

// message identifier "0", parameters: integer, double, string and a byte array
// parameters go as a string, where items are separated with commas
// x stands for an integer value
// x.x stands for double 
// c--c stands for string
// h--h stands for a hex string or a byte array (e.g. "ff0123aa4d5a")
NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "0", "x,x.x,c--c,h--h");

Now we can build and parse sentence $PUWV0 as follows:

int int_parameter = 12345;
double double_parameter = 3.1415;
string string_parameter = "this is a string parameter";
byte[] byte_array_parameter = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

var uwv0_sentence = NMEAParser.BuildSentence(
   ManufacturerCodes.UWV, 
   "0", 
   new object[] {
     int_parameter,
     double_parameter,
     string_parameter,
     byte_array_parameter
   });

After the call, uwv0_sentence will has value "$PUWV0,12345,3.1415,this is a string parameter,0x010203040506070809*51\r\n"

Parsing this proprietary sentence is as follows:

var pResult = NMEAParser.Parse(uwv0_sentence);

if (pResult is NMEAProprietarySentence)
{
   var prop_sentence = (pResult as NMEAProprietarySentence);
   
   // here we can check:
   // Manufacturer identifier, by accessing prop_sentence.Manufacturer
   // Sentence identifier, by accessing prop_sentence.SentenceID
   
   // and all the parameters, as with standard sentences:
   int_parameter = (int)prop_sentence.parameters[0];
   double_parameter = (double)prop_sentence.parameters[1];
   string_parameter = (string)prop_sentence.parameters[2];
   byte_array_parameter = (byte[])prop_sentence.parameters[3];   
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.