2019-04-30 6: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-05-02 9:33 PM
$GPGGA,043139.00,3208.00593,S,11559.31050,E,1,11,0.80,33.1,M,-30.6,M,,*54
$GPGSA,A,3,11,23,31,08,32,18,22,01,03,14,17,,1.27,0.80,0.98*0D
$GPGSV,4,1,15,01,83,198,34,03,54,216,31,08,14,351,29,09,09,312,*71
$GPGSV,4,2,15,11,66,329,35,14,24,137,29,17,19,230,29,18,67,042,26*76
$GPGSV,4,3,15,19,04,214,14,22,63,174,16,23,43,309,33,31,33,102,32*78
$GPGSV,4,4,15,32,09,136,28,42,41,046,,50,41,046,*48
$GPGLL,3208.00593,S,11559.31050,E,043139.00,A,A*70
$GPRMC,043140.00,A,3208.00595,S,11559.31048,E,0.046,,030519,,,A*64
$GPVTG,,T,,M,0.046,N,0.086,K,A*2F
$GPGGA,043140.00,3208.00595,S,11559.31048,E,1,11,0.80,33.1,M,-30.6,M,,*55
$GPGSA,A,3,11,23,31,08,32,18,22,
looks like strstr can not parse the line after \r\n ....GPVTG is on the bottom...do you reckon ? thanks
2019-05-02 10:28 PM
I never used clib str functions for parsing such long strings.
Instead, I did the following:
- check for proper sentence type ($GPRMC) string, and proper termination (\r\n).
- count comma characters, until you reach the parameter(s) you need.
- extract (up to the next comma) and convert (e.g. sscanf()).
You also need to evaluate the fix state field, i.e. if a proper position fix occured.
2019-05-03 12:00 AM
the complete code, it works on GPGGA, but doesn't work with GPVTG ....I have no clue ??? anyone ?
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,"$GPVTG,");
printf(str);printf("\r\n");
if(str!=NULL)
{
memset(&GPS.GPVTG,0,sizeof(GPS.GPVTG));
sscanf(str,"$GPVTG,%f,%c,%f,%c,%f,%c,%f,%c,*%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.CheckSum);
//$GPVTG,,T,,M,0.069,N,0.128,K,A*27 = 9 field ,spd = field7
//printf(str);printf("\r\n");
printf("======================GPVTG PARSING =================\r\n");
printf("Speed knots : %f N \r\n",GPS.GPVTG.knots);
printf("Speed in km/h : %f km/h \r\n",GPS.GPVTG.kph);
printf("====================== D O N E !=================\r\n");
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
}
str=strstr((char*)GPS.rxBuffer,"$GPGGA,");
//str2=str;
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);
//printf(str);printf("\r\n");
if(GPS.GPGGA.NS_Indicator==0)
GPS.GPGGA.NS_Indicator='-';
if(GPS.GPGGA.EW_Indicator==0)
GPS.GPGGA.EW_Indicator='-';
if(GPS.GPGGA.Geoid_Units==0)
GPS.GPGGA.Geoid_Units='-';
if(GPS.GPGGA.MSL_Units==0)
GPS.GPGGA.MSL_Units='-';
GPS.GPGGA.LatitudeDecimal=convertDegMinToDecDeg(GPS.GPGGA.Latitude);
GPS.GPGGA.LongitudeDecimal=convertDegMinToDecDeg(GPS.GPGGA.Longitude);
perth_hour = GPS.GPGGA.UTC_Hour + 8;
printf("======================B E G I N =================\r\n");
printf("NEO 6M GPS MODULE INIT....\r\n");
printf("UTC TIME %u ",GPS.GPGGA.UTC_Hour);
printf(": %u :",GPS.GPGGA.UTC_Min);
printf(" %u \r\n",GPS.GPGGA.UTC_Sec);
printf("Perth TIME %u ",perth_hour);
printf(": %u :",GPS.GPGGA.UTC_Min);
printf(" %u \r\n",GPS.GPGGA.UTC_Sec);
printf("Altitude: %lf m\r\n",GPS.GPGGA.MSL_Altitude);
printf("Latitude is %lf \r\n",GPS.GPGGA.LatitudeDecimal);
printf("North South Indicator, (S)South (N)North is %c",GPS.GPGGA.NS_Indicator);
printf("\r\n");
printf("Longitude is %lf ",GPS.GPGGA.LongitudeDecimal);
printf("\r\n");
printf("West East Indicator, (W)West (E)East is %c \r\n",GPS.GPGGA.EW_Indicator);
printf("Satellites Used : %d \r\n",GPS.GPGGA.SatellitesUsed);
printf("===================================================\r\n");
//test_card();
}
2019-05-03 12:02 AM
I got from printf on line 10
$GPVTG,,T,,M,0.074,N,0.138,K,A*2A
$GPGGA,070050.00,3208.00548,S,11559.30824,E,1,10,0.82,36.0,M,-30.6,M,,*51
$GPGSA,A,3,23,26,06,09,22,01,03,16,19,07,,,1.52,0.82,1.28*05
$GPGSV,5,1,17,01,21,009,23,02,01,214,,03,52,084,37,04,40,264,31*7B
$GPGSV,5,2,17,06,33,233,35,07,40,341,25,09,54,244,28,11,04,005,*79
$GPGSV,5,3,17,16,15,089,12,17,06,297,,19,09,273,27,22,32,066,32*76
$GPGSV,5,4,17,23,60,164,35,26,12,117,21,30,09,332,19,42,41,046,*7E
$GPGSV,5,5,17,50,41,046,*4D
$GPGLL,3208.00548,S,11559.30824,E,070050.00,A,A*72
$GPRMC,070051.00,A,3208.00541,S,11559.30818,E,0.146,,030519,,,A*61
$GPVTG,,T,,M,0.146,N,0.271,K,A*24
$GPGGA,070051.00,3208.00541,S,11559.30818,E,1,10,0.82,36.1,M,-30.6,M,,
2019-05-03 12:45 AM
This what I got from function ProcessNMEALine((char*)GPS.rxBuffer)
DecodeNMEA
$GPRMC,074341.00,A,3208.00668,S,11559.30844,E,0.029,,030519,,,A*6E
$GPVTG,,T,,M,0.029,N,0.055,K,A*28
$GPGGA,074341.00,3208.00668,S,11559.30844,E,1,10,0.79,32.5,M,-30.6,M,,*54
$GPGSA,A,3,23,02,26,06,09,22,03,16,07,30,,,1.46,0.79,1.23*07
$GPGSV,4,1,15,01,03,012,,02,14,225,25,03,38,061,31,04,50,239,31*7A
$GPGSV,4,2,15,06,41,255,36,07,62,333,32,09,60,209,42,16,20,108,28*7A
$GPGSV,4,3,15,19,00,290,,22,17,053,20,23,49,137,35,26,09,134,20*7D
$GPGSV,4,4,15,30,27,326,37,42,41,046,,50,41,046,*4B
$GPGLL,3208.00668,S,11559.30844,E,074341.00,A,A*72
$GPRMC,074342.00,A,3208.00667,S,11559.30843,E,0.057,,030519,,,A*6C
$GPVTG,,T,,M,0.057,N,0.106,K,A*26
$GPGGA,074342.00,3208.00667,S,11559.30843,E,1,10,0.79,32.6,M,-30.6,M,,*5C
$GPGSA,A,3,23,02,26,06,09,22,03,16,07
Fields 13
#00 : $GPRMC
#01 : 074341.00
#02 : A
#03 : 3208.00668
#04 : S
#05 : 11559.30844
#06 : E
#07 : 0.029
#08 :
#09 : 030519
#10 :
#11 :
#12 : A
2019-05-03 1:03 AM
Hi,
scanf works for fixed length and format messages.
Depending on sentence validity or fix validity or state (A or V , 2D,3D,etc) the sentences may change length by omitting fields and change signs.
Also for different versions of NMEA output the decimal part of Latitude and Longitude can vary from 2 to 5 digits.
An option is to feed raw data to a State Machine and by byte per byte process to extract Talker, Command, Data fields, Checksum or other proprietary data. Using an atoi function can convert arithmetical fields to numbers.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.