我正在一个使用 GPS 数据的项目中工作。我正在尝试获取所有数据,但我遇到了很多问题。我收到的信息是:
+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>
我决定使用 strsep,因为它适用于 GPS 数据的空白字段。使用 strsep 如果它是肯定的,我可以正确获取数据。在我的情况下,纬度是负数,使用 strsep 我得到一个 0 值。
我为获取所需数据所做的代码是:
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 ++;
}
}
如果您有任何建议,欢迎。