Using NMEAP with an 8-bit ATmega
I’ve been using the NMEAP library by David Howard for parsing GPS sentences for a project with an ATmega 1280. It’s a wonderful library, but it runs into problems decoding UTC timestamps on 8-bit architectures like the 1280. I found a fix and thought I would share.
In the function:
int nmeap_gpgga(nmeap_context_t *context,nmeap_sentence_t *sentence)
gga->time = atoi(context->token);
sscanf(context->token, "%"SCNu32, &gga->time);
What’s basically happening is that the AVR implementation of atoi will overflow UTC times past 6:55:36 on 8-bit architectures. (Since I was working on this during an all-nighter, the fact that my code stopped working at 7 AM was quite annoying.) You have to use sscanf to specify a 32-bit result — even though gga->time is already defined as a long, the definition of long varies based on the architecture. The best way to be sure is to look at AVRinttypes.h and use something like int32_t in your own code. Hope this helps.