Experimental Stuff
Home Function Descriptions Downloads Other Functions GeoCalcİ Experimental Stuff

 

                       

This page is dedicated to presenting some of the things that I am playing around with or have found useful. 

NOTE: Downloads of the source code for items discussed on this page are not yet available. I should find time to post them after the Christmas holidays.

NMEA Parser:

I needed a good parser for the NMEA sentences from my GPS receiver. I wanted one that was both quick and expandable so I created NMEAParser which comes in both flavors, .PAS and .BAS. NMEAParser currently contains routines for parsing the sentences that come from my old Garmin 45 but as you will see, you can easily modify or add functions to handle any NMEA sentence, even those from other than GPSRs or any instrument that speaks NMEA.

NMEAParser, as distributed, contains routines for tokenizing the following NMEA sentences:

GPBOD,  GPGGA, GPGLL, GPGSA, GPGSV, GPRMB, GPRMC, GPRTE, GPVTG, and GPWPL

which are the one supported by my Garmin 45.

As is common in my software, there is a data structure defined for each sentence, for example:

Visual Basic

Delphi

Public Type GGAStruct
  SentenceType As String * 6 '$GPGGA
  Time As Double
  Latitude As Double
  NorS As String * 1
  Longitude As Double
  EorW As String * 1
  FixQuality As Integer
  NumSats As Integer
  HDP As Double
  Altitude As Double
  AltUnits As String * 1
  GeoidHgt As Double
  GeoUnits As String * 1
  DGPSTime As Double
  DGPSStation As Integer
  CheckSum As Byte
End Type
GGAStruct = record
  SentenceType: string; //$GPGGA
  Time: Double;
  Latitude: Double;
  NorS: string;
  Longitude: Double;
  EorW: string;
  FixQuality: Integer;
  NumSats: Integer;
  HDP: Double;
  Altitude: Double;
 AltUnits: string;
  GeoidHgt: Double;
  GeoUnits: string;
  DGPSTime: Double;
  DGPSStation: Integer;
  CheckSum: integer;
end;

$GPGGA,123519,4807.038,N,01131.324,E,1,08,0.9,545.4,M,46.9,M, , *42

The parser will take the NMEA string and strip out all of the values and place them in a structure like these and return the structure to the caller. You have the data from the sentence ready for use in your program. The structures have two fields in common. The first is the Sentence type ($GPGGA) and the check sum. Using the structures and the example sentence above you should be able to work out how the sentence is constructed. The sentence is always a text string. The fields are always comma delimited save for the check sum field at the end (*42) which is delimited by the *. The actual check sum is a hexadecimal number (in this case 42). There is a null (empty) field in the example which is shown by the two commas with no interposed value. In order to parse out the values tokens from this string these conditions have to be addressed.

The heart of NMEAParser is my StrTokenizer (Tokenizer in my VB software). This function allows you to specify both the comma and the asterisk as field delimiters. After the tokenizer is done its thing on a sentence, each token is examined and the proper conversion is made and the resultant value is placed in the data structure. If you examine the code that parses the $GPGGA sentence you can see how this is done.

There is a prototype data structure that you can use to describe any NMEA sentence. This structure has the name YYYStruct. There is a prototype parse function as well called ParseYYYSentence. Use this to get started coding up a new parsing function. Just follow the methods in the standard functions using cut and paste (for the most part) to roll your own function(s). 

There are a couple of helper functions in the file.

GetNMEAType:

 The first of these is GetNMEAType. This function takes a raw NMEA sentence and returns an integer associated with the sentence type (i.e. $GPGGA = 1). The numeric return type is a constant and you should define one for each of your sentences and place the appropriate sentence type check in GetNMEAType. Just follow what I have done and you should be OK.

ParseNMEAToSList:

This function can be used to return the component parts of a tokenized NMEA sentence as individual strings. In the Delphi file the strings are returned in a TStringList. I have yet to implement this in the VB file.

LatLongToDouble:

This function converts a NMEA latitude or longitude string to a double.

TimeToDouble:

This function converts a NMEA time string to a double.

ConvToDouble:

Converts a NMEA numeric value to a double.

ConvToInt:

Converts a NMEA numeric value to an integer.


 Top

 

This page was last updated on 12/11/2003