cancel
Showing results for 
Search instead for 
Did you mean: 

GPRMC date ?

antonius
Senior

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

15 REPLIES 15

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior

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

antonius
Senior

Perhaps, my stack is not enough ?

antonius
Senior
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;

How many fields does sscanf() report successfully parsing?

Does it support the format methods you're using?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

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....????

Looks like str on the GPVTG is not in scope ?

Captured :

0690X000008BAcZQAW.jpg

0690X000008BAcoQAG.jpg

How can I rectify it ?thanks

Is this the function for parsing NMEA ?

void ProcessNMEALine(char *s)

thanks