Introduction to NMEA message format
The NMEA message was originally developped by the National Marine Electronics Association (NMEA). They provided a specification that defines the interface between various pieces of marine electronic equipment. GPS receiver communication is defined within this specification. Most computer programs that provide real time position information understand and expect data to be in NMEA format. This data includes the complete PVT (position, velocity, time) solution computed by the GPS receiver. The idea of NMEA is to send a line of data called a sentence that is totally self contained and independent from other sentences. There are standard sentences for each device category and there is also the ability to define proprietary sentences for use by the individual company. All of the standard sentences have a two letter prefix that defines the device that uses that sentence type. (For gps receivers the prefix is GP.) which is followed by a three letter sequence that defines the sentence contents.
For instance, the most common NMEA message for GPS, is the GPGGA message. It is formatted this way:
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 Where we have:
GGA – Global Positioning System Fix Data
123519 – Fix taken at 12:35:19 UTC
4807.038,N – Latitude 48 deg 07.038′ N
01131.000,E – Longitude 11 deg 31.000′ E
1 – Fix quality: 0 = invalid, 1 = GPS fix (SPS), 2 = DGPS fix, 3 = PPS fix, 4 = Real Time Kinematic, 5 = Float RTK, 6 = estimated (dead reckoning) (2.3 feature), 7 = Manual input mode, 8 = Simulation mode
08 – Number of satellites being tracked
0.9 – Horizontal dilution of position
545.4,M – Altitude, Meters, above mean sea level
46.9,M – Height of geoid (mean sea level) above WGS84 ellipsoid
(empty field) – time in seconds since last DGPS update
(empty field) – DGPS station ID number
*47 – the checksum data, always begins with *
Parsing this data and extracting the relevant information from the strings is fastidious. This is why we developed the NMEA Parser to take this kind of strings as input, and produce UObject that can be manipulated directly in the Unreal Engine blueprints.
For instance, we provide directly this GGA message to the NMEA Parser, and we get in return a UGgaSentence object with convenient properties like Latitude which contains the decimal latitude.
More details about the NMEA format can be found here.
Parsing NMEA messages using the NMEA parser (the simple way)
Parsing NMEA sentences using the NMEA Parser is really easy. We just have to follow these steps:
Contruct an NMEA sentence parser
Call the Parse function with the raw text sentence as a parameter
Get the return value: it is an INmeaSentence
Cast it to GgaSentence
Read the value of any property
This works but it requires us to know what kind of sentence we are expecting. We could use a switch on the sentence ID but it wouldn’t be really convenient. So to overcome this we can use the listeners.
We may also note that if the sentence is not correctly formatted (for instance, a bad number of fields, a wrong ID, etc.), the result will be an empty sentence object, i a sentence object with only default values.
Parsing NMEA messages using the NMEA parser (the best way)
The first step is the same, we start by constructing an NMEA sentence parser. But then, we add a GGA Listener. The function connected to this event (Print String in the given example) will be called every time that the NMEA sentence parser will parse a GGA sentence. The main benefit here is that we know that the parameter passed to the event is of type GGA sentence, so we don’t have to downcast the object.
Eventually we can remove the listener after, to prevent further calls.
Also note that the listener must be added before a call to Parse.