If you find this code useful and appreciate my work, feel free to click the button below to donate and help me continue. Every cent is appreciated! Thank you!
NMEAParser is a library that aims at drastically simplifiying the parsing of NMEA sentences. These can be from a GPS, a gyrocompass or any device that complies with the NMEA 0183 standard.
The reason why I wanted to write this library as there is many like this one, like TinyGPS (and its numerous forks/rewrites)? Because of their adaptability. Have you ever tried to add a custom string to TinyGPS? I did, and it was a real pain in the ass. So I decided to develop my own lib, making it easy to extend. It relies heavily on a custom implementation of sscanf to fit my needs. Technically speaking, sscanf
parses very wells NMEA strings, but has two main drawbacks:
- it's ways to sophisticated for what we need here. And some datas such as latitude or UTC time are recognized as floats.
sscanf
doesn't support empty fields. In NMEA strings, blank fields are common, especially when GPS works indoor. Defaultsscanf
sees empty fields as errors. Mine parses them fine.
Beyond these considerations, NMEAParser is damn fast and has a very low memory footprint. This is what you need when working with Arduinos, ESPs and such.
To assess performance, see unit tests. A part of these is dedicated to performance. Basically, NMEAParser
was used to dispatch and parse great amounts of sentences. Results are very linear, according to the results.
The results are the following:
Number of sentences | Time in seconds |
---|---|
150 | 0.059 |
1 500 | 0.591 |
15 000 | 5.915 |
150k | 59.155 |
Number of sentences | Time in seconds |
---|---|
150 | 0.002 |
1 500 | 0.025 |
15 000 | 0.254 |
150k | 2.530 |
1.5M | 25.288 |
NMEAParser now features native tests, meaning that you can benchmark the library using your own computer, not just a microcontroller. On my i7-6700K, 1.5 millions NMEA strings were parsed in approx. 225ms.
It's quite simple to add your own NMEA sentence:
- declare its structure, with a default
bool isValid
andint16_t fieldValidity
inside it. - declare its type in
STRINGS_TYPES
- create a parsing function based on existing ones
- declare your sentence type in the
dispatch
function. - you're done!
- Add way to compose sentences
- Add calculation tools (distances..)
Icons made by Freepik from www.flaticon.com