mikalhart / TinyGPSPlus

A new, customizable Arduino NMEA parsing library
http://arduiniana.org
1.05k stars 486 forks source link

Custom objects: more convenient parsing of sentence name (was: Update TinyGPS++.cpp) #71

Open 88markus88 opened 4 years ago

88markus88 commented 4 years ago

Hi Mikal,

I am using your "TinyGPS++" library to create a generic NMEA info display for use on a boat. Thank you for your great work, the library works very well!

Nevertheless I 'd ask you for a modification in the handling of custom NMEA sentences. :-)

Background: In the present version V1.0.2 the parser looks at the complete first term in a NMEA sentence - even though the actual identification of the NMEA sentence is only done in the last three characters of the first term, the first two characters are a manufacturer code.

Example: These two NMEA sentences "VHW" contain the same information, but differ in the first two characters ("II" vs. "VW"), (and the checksum):

$IIVHW,,,307.,M,08.08,N,14.97,K10 $VWVHW,,,307.,M,08.08,N,14.97,K11

To parse the data using TinyGPS++ two separate definitions are needed:

TinyGPSCustom nmeaLogSpeedKmh(gps, "GPVHW", 7); // Log Speed in km/h TinyGPSCustom nmeaLogSpeedKmh(gps, "IIVHW", 7); // Log Speed in km/h

This makes it almost impossible to write a generic code, that works regardless of the manufacturer ID in the first two characters.

My request: The parser in TinyGPS++ can easily be modified to look only at the relevant sentence identifiers (VHW in the example above) and use this definition: TinyGPSCustom nmeaLogSpeedKmh(gps, "VHW", 7); // Log Speed in km/h

With that change, the "VHV" data set can be extracted from NMEA sentences by any manufacturer without changing the software.

The only modification required is in line 223 of "tinygps.cpp", replacing "!strstr" for "strcmp", see - code change