I am working with a GPS and working to parse the NMEA data myself. I am aware of libraries such as TinyGPS but I prefer to learn and do it myself. I am 95% done in being able to grab all the information I need and what I have works great. I need pieces of data from 3 separate lines in order to store the data I want and here is an example of what I get.
$GPRMC,044159.000,A,3903.1262,N,07729.0495,W,0.00,40.30,061212,,,A*4D
$GPGGA,044200.000,3903.1262,N,07729.0497,W,1,08,1.0,83.7,M,-33.4,M,,0000*5F
$GPGSA,A,3,30,31,32,16,20,23,29,14,,,,,2.1,1.0,1.8*33
In the $GPRMC and $GPGGA data I can easily grab any piece of data that I want such as latitude and longitude using strtok() using the comma as a delimiter. This part is working perfectly.
Where I struggle is grabbing the data from the $GPGSA line since many of the comma delimited fields have no data and the data I want is at the end. In the example data I need to be able to grab the 2.1, 1.0 and 1.8 at the end. fixType (in the code below) works reliably since it is in a fixed position within the data, but PDOP is the 2.1 and it has a variable number of blank spaces before it. I cant seem to keep a fixed number here because the number of blank data can be different from one second to the next. For example $GPGSA could have 8 blank fields instead of 4 and could easily look like this instead $GPGSA,A,3,30,31,32,16,,,,,,,,,2.1,1.0,1.8*33. How should I handle data like this?
Here is a sample of how I break the data apart and store it as separate variables.
void GPGSA(){
valPosition = strtok(GPGSAC, delimiters);
i = 0;
while(valPosition != NULL && i < 18){
i++;
valPosition = strtok(NULL, delimiters);
if (i ==2){
fixType = atoi(valPosition);
Serial.print(F("fixType = "));
Serial.println(fixType);
}
if (i ==15){
PDOP = atof(valPosition);
Serial.print(F("PDOP = "));
Serial.println(PDOP);
}
}
}