2019-04-30 06:51 AM
Dear Member
I tried to get date from GPRMC, but not getting any response:
code :
sscanf(str,"$GPRMC,%s,%2hhd%2hhd%2hhd,%c,%f,%c,%f,%c,%f,%c,%f,%f,%2hhd%2hhd%2hhd,%f,%c,%c,*%2s\r\n",&GPS.GPRMC.xxRMC,&GPS.GPRMC.UTC_Hour,&GPS.GPRMC.UTC_Min,&GPS.GPRMC.UTC_Sec,&GPS.GPRMC.status,&GPS.GPRMC.Latitude,&GPS.GPRMC.NS_Indicator,&GPS.GPRMC.Longitude,&GPS.GPRMC.EW_Indicator,&GPS.GPRMC.spd,&GPS.GPRMC.cog,&GPS.GPRMC.UTC_Day,&GPS.GPRMC.UTC_Month,&GPS.GPRMC.UTC_Year,&GPS.GPRMC.mv,&GPS.GPRMC.mvEW,&GPS.GPRMC.posMode,&GPS.GPRMC.CheckSum);
Am I missing something here ?
Thanks
2019-04-30 07:31 AM
What does sscanf() actually return?
You're going to need to debug your own code.
Suggest you test on a PC, where you feed it test strings, prove that works.
Make sure the compiler/library you are using supports sscanf() properly.
The use of 32-bit floats for latitude/longitude is not advisable.
I probably would not parse it this way, NMEA can have empty fields and variable formatting.
2019-05-01 04:27 AM
I got :
$GPRMC,112421.00,A,3208.00557,S,11559.30809,E,0.060,,010519,,,A*67
I try to print it
the code :
str=strstr((char*)GPS.rxBuffer,"$GPRMC,");
if(str!=NULL)
{
memset(&GPS.GPRMC,0,sizeof(GPS.GPRMC)); //for the date page 55 u-blox6-GPS-GLONASS----
sscanf(str,"$GPRMC,%2hhd%2hhd%2hhd.%3hd,%c,%f,%c,%f,%c,%f,%f,%2u%2u%2u,%f,%c,%c,*%2s\r\n",
&GPS.GPRMC.UTC_Hour,&GPS.GPRMC.UTC_Min,&GPS.GPRMC.UTC_Sec,&GPS.GPRMC.UTC_MicroSec,
&GPS.GPRMC.status,&GPS.GPRMC.Latitude,&GPS.GPRMC.NS_Indicator,&GPS.GPRMC.Longitude,
&GPS.GPRMC.EW_Indicator,&GPS.GPRMC.spd,&GPS.GPRMC.cog,&GPS.GPRMC.UTC_Day,
&GPS.GPRMC.UTC_Month,&GPS.GPRMC.UTC_Year,&GPS.GPRMC.mv,&GPS.GPRMC.mvEW,
&GPS.GPRMC.posMode,&GPS.GPRMC.CheckSum);
printf(str);printf("\r\n");
printf("======================GPRMC PARSING =================\r\n");
printf("Course over ground value: %lf degree \r\n",GPS.GPRMC.cog);
printf("Date : %2u-%2u-%2u \r\n",GPS.GPRMC.UTC_Day,GPS.GPRMC.UTC_Month,GPS.GPRMC.UTC_Year);
printf("====================== D O N E !=================\r\n");
}
but I got 0-0-0 on date value,
What's missing here ??
Thanks
2019-05-01 04:33 AM
Perhaps, my stack is not enough ?
2019-05-01 04:39 AM
typedef struct
{
uint8_t UTC_Hour;
uint8_t UTC_Min;
uint8_t UTC_Sec;
uint16_t UTC_MicroSec;
char status;
float Latitude;
double LatitudeDecimal;
char NS_Indicator;
float Longitude;
double LongitudeDecimal;
char EW_Indicator;
float spd;
float cog;
int UTC_Day;
int UTC_Month;
int UTC_Year;
float mv;
char mvEW;
char posMode;
char CheckSum[2];
}GPRMC_t;
2019-05-01 07:08 AM
How many fields does sscanf() report successfully parsing?
Does it support the format methods you're using?
2019-05-01 10:35 PM
it works well on this :
if( (HAL_GetTick()-GPS.LastTime>50) && (GPS.rxIndex>0))
{
char *str,*str2;
#if (_GPS_DEBUG==1)
printf("%s",GPS.rxBuffer);
#endif
str=strstr((char*)GPS.rxBuffer,"$GPGGA,");
if(str!=NULL)
{
memset(&GPS.GPGGA,0,sizeof(GPS.GPGGA));
sscanf(str,"$GPGGA,%2hhd%2hhd%2hhd.%3hd,%f,%c,%f,%c,%hhd,%hhd,%f,%f,%c,%hd,%s,*%2s\r\n",&GPS.GPGGA.UTC_Hour,&GPS.GPGGA.UTC_Min,&GPS.GPGGA.UTC_Sec,&GPS.GPGGA.UTC_MicroSec,&GPS.GPGGA.Latitude,&GPS.GPGGA.NS_Indicator,&GPS.GPGGA.Longitude,&GPS.GPGGA.EW_Indicator,&GPS.GPGGA.PositionFixIndicator,&GPS.GPGGA.SatellitesUsed,&GPS.GPGGA.HDOP,&GPS.GPGGA.MSL_Altitude,&GPS.GPGGA.MSL_Units,&GPS.GPGGA.AgeofDiffCorr,GPS.GPGGA.DiffRefStationID,GPS.GPGGA.CheckSum);
.................
memset(&GPS.GPVTG,0,sizeof(GPS.GPVTG));
sscanf(str,"$GPVTG,%f,%c,%f,%c,%f,%c,%f,%c,%f,*%2s\r\n",
&GPS.GPVTG.cogt,&GPS.GPVTG.T,&GPS.GPVTG.cogm,&GPS.GPVTG.M,
&GPS.GPVTG.knots,&GPS.GPVTG.N,&GPS.GPVTG.kph,&GPS.GPVTG.K,
&GPS.GPVTG.posMode,&GPS.GPVTG.CheckSum);
printf(str);printf("\r\n");
printf("======================GPVTG PARSING =================\r\n");
printf("Course over ground value: %f degree \r\n",GPS.GPVTG.cogt);
printf("Speed in km/h : %f km/h \r\n",GPS.GPVTG.kph);
printf("====================== D O N E !=================\r\n");
}
it doesn't work with the bold area.... is it related with ==> if( (HAL_GetTick()-GPS.LastTime>50) && (GPS.rxIndex>0))) ?
or I can not use sscanf with those many fields ??
Thanks
2019-05-01 10:36 PM
I have tried
str=strstr((char*)GPS.rxBuffer,"$GPVTG,");
if(str!=NULL)
{
memset(&GPS.GPVTG,0,sizeof(GPS.GPVTG));
sscanf(str,"$GPVTG,%f,%c,%f,%c,%f,%c,%f,%c,%f,*%2s\r\n",&GPS.GPVTG.cogt,&GPS.GPVTG.T,&GPS.GPVTG.cogm,&GPS.GPVTG.M,&GPS.GPVTG.knots,&GPS.GPVTG.N,&GPS.GPVTG.kph,&GPS.GPVTG.K,&GPS.GPVTG.posMode,&GPS.GPVTG.CheckSum);
//printf(str);
printf("======================GPVTG PARSING =================\r\n");
printf("Course over ground value: %f degree \r\n",GPS.GPVTG.cogt);
printf("Speed in km/h : %f km/h \r\n",GPS.GPVTG.kph);
printf("====================== D O N E !=================\r\n");
}
else
{
printf("GPVTG =0 \r\n");
}
No luck....????
2019-05-02 02:06 AM
Looks like str on the GPVTG is not in scope ?
Captured :
How can I rectify it ?thanks
2019-05-02 09:00 PM
Is this the function for parsing NMEA ?
void ProcessNMEALine(char *s)
thanks