I'm working in a project that use GPS data. I'm trying to get all the data but I've had a lot of problems. The secuence that I recieve is:
+CGNSINF: <GNSS run status>,<Fix status >,<UTC date &
Time>,<Latitude>,<Longitude>,<MSLAltitude>,<SpeedOverGround>,
<CourseOverGround>,<FixMode>,<Reserved1>,<HDOP>,<PDOP>,<VDOP>,<Reserved2>,
<GNSSSatellites in View>,<GPS Satellites Used>,
<GLONASS SatellitesUsed>,<Reserved3>,<C/N0 max>,<HPA>,<VPA>
I have decided to use strsep because it works with the empty fields of the GPS data. With strsep I can get the data correctly if it's positive. In my case the latitude is negative and with strsep I get a 0 value.
The code that I've done to get the data that I need is:
char *string = aux_str_gps;
char *token;
int counter = 0;
float gps_date;
float latitude;
float longitude;
float altitude;
float speed;
float COG; //course over ground in degrees
float HDOP;
int GNSS_sat_used; //numer of GNSS satellites used
while ((token = strsep(&string, ",")) != NULL){
switch (counter){
case 2:
sscanf(token, "%f", &gps_date);
write_gps_date(gps_date);
counter ++;
break;
case 3:
sscanf(token, "%f", &latitude);
write_gps_lat(latitude);
counter ++;
break;
case 4:
sscanf(token, "%f", &longitude);
write_gps_long(longitude);
counter ++;
break;
case 5:
sscanf(token, "%f", &altitude);
write_gps_alt(altitude);
counter ++;
break;
case 6:
sscanf(token, "%f", &speed);
write_gps_speed(speed);
counter ++;
break;
case 7:
sscanf(token, "%f", &COG);
write_gps_COG(COG);
counter ++;
break;
case 10:
sscanf(token, "%f", &HDOP);
write_gps_HDOP(HDOP);
counter ++;
break;
case 15:
sscanf(token, "%d", &GNSS_sat_used);
write_gps_GNSS_used(GNSS_sat_used);
counter ++;
break;
default:
counter ++;
}
}
If you got any suggest is welcomed.