Skip to content

Commit

Permalink
optimize gps parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Dec 13, 2018
1 parent 732b526 commit bbe0cb9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
37 changes: 21 additions & 16 deletions libs/gps/src/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,33 @@ void GPS_Update(uint8_t* data,uint32_t length)
GPS_DEBUG_I("buffer overflow");
if(semCmdSending == NULL)
{
index = Buffer_Query(&gpsNmeaBuffer,"VTG",strlen("VTG"),Buffer_StartPostion(&gpsNmeaBuffer));
if(index >= 0)
while(1)
{
// GPS_DEBUG_I("find $GNVTG");
index = Buffer_Query(&gpsNmeaBuffer,"\r\n",strlen("\r\n"),index);
index = Buffer_Query(&gpsNmeaBuffer,"VTG",strlen("VTG"),Buffer_StartPostion(&gpsNmeaBuffer));
if(index >= 0)
{
// GPS_DEBUG_I("find complete GPS frame");

memset(tmp,0,sizeof(tmp));
uint32_t len = Buffer_Size2(&gpsNmeaBuffer,index)+1;
// GPS_DEBUG_I("frame len:%d",len);
if(!Buffer_Gets(&gpsNmeaBuffer,tmp,len>GPS_NMEA_FRAME_BUFFER_LENGTH?GPS_NMEA_FRAME_BUFFER_LENGTH:len))
// GPS_DEBUG_I("find $GNVTG");
index = Buffer_Query(&gpsNmeaBuffer,"\r\n",strlen("\r\n"),index);
if(index >= 0)
{
GPS_DEBUG_I("get data from buffer fail");
return;
// GPS_DEBUG_I("find complete GPS frame");

memset(tmp,0,sizeof(tmp));
uint32_t len = Buffer_Size2(&gpsNmeaBuffer,index)+1;
// GPS_DEBUG_I("frame len:%d",len);
if(!Buffer_Gets(&gpsNmeaBuffer,tmp,len>GPS_NMEA_FRAME_BUFFER_LENGTH?GPS_NMEA_FRAME_BUFFER_LENGTH:len))
{
GPS_DEBUG_I("get data from buffer fail");
return;
}
GPS_DEBUG_I("parse nmea frame");
if(isSaveLog)
SaveToTFCard((char*)tmp);
GPS_Parse(tmp);
}
GPS_DEBUG_I("parse nmea frame");
if(isSaveLog)
SaveToTFCard((char*)tmp);
GPS_Parse(tmp);
}
else
break;
}
}
else//sending command
Expand Down
4 changes: 3 additions & 1 deletion libs/gps/src/gps_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ bool GPS_Parse(uint8_t* nmeas)
uint8_t* index1 = strstr(nmeas,"$");
if(index1)
{
retFlag = true;
uint8_t* index2 = strstr(index1,"\r\n");
if(index2)
{
retFlag = true;
tmpStore = index2[2];
index2[2] = '\0';
nmeas += index2-index1+2;
retFlag = ParseOneNmea(index1,flag);
index2[2] = tmpStore;
}
else //$GNGGA,084257.000
break;
}
else
break;
Expand Down

0 comments on commit bbe0cb9

Please sign in to comment.