8 years, 2 months ago.

Load / parsing NMEA - GPRMC,GPVTG

Hello, I have a problem with this in my code

void GPS::getline() {
    //char c;
    while (c = _gps.getc() != '$');   
    for (int i=0; i<500; i++) {
        msg[i] = _gps.getc();
        if (msg[i] == 'K') {
            msg[i] = 0;
            return;
        }

thanks to this code:

        getline();
        printf("%s\r\n",msg);

As a result, the console received:

GPGGA,225918.000,5004.4693,N,01954.6789,E,1,8,1.15,238.3,M,42.0,M,,*58 $GPGSA,A,3,17,15,13,19,24,12,28,20,,,,,1.98,1.15,1.62*07 $GPRMC,225918.000,A,5004.4693,N,01954.6789,E,0.02,131.06,251016,,,A*6D $GPVTG,131.06,T,,M,0.02,N,0.04,K,47,12,18,234,

but I would like to display the data on the LCD and I have loaded GPGGA to variables in this way:

if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &satellites, &hdop, &height ) >= 1) {
}

and this works but how can i load for example GPRMC and GPVTG? I tried to do it as above, but it did not work.

1 Answer

8 years, 2 months ago.

There are a lot of ways to solve this but since there is a good thread on this already take a look over there and see if it'll answer your question. https://developer.mbed.org/forum/mbed/topic/500/

Think about scanning just the first parameter and then parsing the remainder as required based on the message. You should think about the checksum validation as well since your method does not compute checksum and does not validate it against what is received. That requires a 2-pass parser which you currently don't have.