📄 gps.c
字号:
#include "gps.h"
#include <stdio.h>
extern unsigned char GpsDataBuffer[1024];
int GpsReadCount;
int GpsDataParse(void);
int GpsDataParse(void)
{
int i,j,temp;
int ContinueTest;
int head[3];
char ch;
GpsReadCount=0;
//if(GpsWriteCount==1024&&GpsReadCount<1024)
do
{
do
{
ch=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
}
while(ch!='$');
GpsReadCount+=2;
head[0]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
head[1]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
head[2]=GpsDataBuffer[GpsReadCount];
if(head[0]=='G' && head[1]=='G' && head[2]=='A')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is beginning with GGA!\n");
GpsReadCount+=1;
i=0;
while(i<8)
{
GgaUTC[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
ContinueTest=GgaUTC[0];
if(ContinueTest==44)
{
//printf("wrong data in reading GGA!\n");
continue;
}
GpsReadCount+=1;
i=0;
while(i<9)
{
GgaLatitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GgaLatitudeA=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<9)
{
GgaLongitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GgaLongitudeA=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
GgaGpsQuality=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
GgaGpsNumber=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<4)
{
GgaHDOP[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<5)
{
GgaAltitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GgaAMeter=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<8)
{
GgaHeight[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GgaHMeter=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
GgaDGPS=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
GgaID=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
}
else if(head[0]=='G' && head[1]=='L' && head[2]=='L')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is correct for GLL!\n");
GpsReadCount+=1;
i=0;
while(i<9)
{
GllLatitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
ContinueTest=GllLatitude[0];
if(ContinueTest==44)
{
//printf("wrong data in reading GLL\n");
continue;
}
GpsReadCount+=1;
GllLatitudeA=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<9)
{
GllLongitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GllLongitudeA=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<8)
{
GllUTC[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
GllDetermin=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
}
else if(head[0]=='G' && head[1]=='S' && head[2]=='A')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is correct for GSA!\n");
GpsReadCount+=1;
GsaAuto=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
ContinueTest=GsaAuto;
if(ContinueTest==44)
{
//printf("wrong data in reading GSA\n");
continue;
}
GpsReadCount+=1;
GsaPosition=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i=0;
while(i<12)
{
GpsReadCount+=1;
j=0;
while(j<2)
{
GsaSate[i][j]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
j++;
}
i++;
}
GpsReadCount+=1;
i=0;
while(i<4)
{
GsaPDOP[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<4)
{
GsaHDOP[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<4)
{
GsaVDOP[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
}
else if(head[0]=='G' && head[1]=='S' && head[2]=='V')
{
//printf("the test is correct for GSV!\n");
GpsReadCount+=2;
GsvNumber=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
ContinueTest=GsvNumber;
if(ContinueTest==44)
{
//printf("wrong data in reading GSV\n");
continue;
}
GpsReadCount+=1;
GsvPacket=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
/* while(i<2)*/
{
GsvSatellites[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
/* i++;*/
}
/* GpsReadCount+=1;*/
i=0;
while(i<4)
{
GpsReadCount+=1;
j=0;
while(j<2)
{
GsvSateNumber[i][j]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
j++;
}
GpsReadCount+=1;
j=0;
while(j<2)
{
GsvSateElevation[i][j]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
j++;
}
GpsReadCount+=1;
j=0;
while(j<3)
{
GsvSateBearing[i][j]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
j++;
}
GpsReadCount+=1;
j=0;
while(j<2)
{
GsvSateSn[i][j]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
j++;
}
i++;
}
}
else if(head[0]=='R' && head[1]=='M' && head[2]=='C')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is correct for RMC!\n");
GpsReadCount+=1;
i=0;
while(i<8)
{
RmcUTC[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
ContinueTest=RmcUTC[0];
if(ContinueTest==44)
{
//printf("wrong data in reading RMC\n");
continue;
}
GpsReadCount+=1;
RmcVaild=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<9)
{
RmcLatitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
RmcNorthSouth=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<9)
{
RmcLongtitude[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
RmcEastWest=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<3)
{
RmcSpeed[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<3)
{
RmcDirection[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<6)
{
RmcData[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<3)
{
RmcMagnetic[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
}
else if(head[0]=='V' && head[1]=='T' && head[2]=='G')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is correct for VTG!\n");
GpsReadCount+=1;
i=0;
while(i<3)
{
VtgDirection[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
ContinueTest=VtgDirection[0];
if(ContinueTest==44)
{
//printf("wrong data in reading VTG\n");
continue;
}
GpsReadCount+=1;
VtgT=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<3)
{
VtgMagnetic[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
VtgM=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<3)
{
VtgKnot[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
VtgN=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
GpsReadCount+=1;
i=0;
while(i<3)
{
VtgKm[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
VtgK=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
}
else if(head[0]=='Z' && head[1]=='D' && head[2]=='A')
{
//for test "GSV" data only!!!!!!!!
continue;
//printf("the test is correct for ZDA!\n");
GpsReadCount+=1;
i=0;
while(i<8)
{
ZdaUTC[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
ContinueTest=ZdaUTC[0];
if(ContinueTest==44)
{
//printf("wrong data in reading ZDA\n");
continue;
}
GpsReadCount+=1;
i=0;
while(i<2)
{
ZdaDay[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<2)
{
ZdaMonth[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<4)
{
ZdaYear[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<2)
{
ZdaHour[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
GpsReadCount+=1;
i=0;
while(i<2)
{
ZdaMinute[i]=GpsDataBuffer[GpsReadCount];
GpsReadCount+=1;
i++;
}
}
}while(GpsReadCount<1024);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -