下面是GPS相关数据格式的解析程序:
unsigned char
GPS_GPGGA(char *str, GPS_INFO *GPS)
{
unsigned char ch, status;
char *buf = str;
ch = buf[4];
status = buf[GetComma(2, buf)];
if (ch == 'G')
{
if (status != ',')
{
GPS->height_sea = (float)Get_Double_Number(&buf[GetComma(9, buf)]);
GPS->height_ground = (float)Get_Double_Number(&buf[GetComma(11, buf)]);
return 1;
}
}
return 0;
}
unsigned char
GPS_GPRMC(char *str, GPS_INFO *GPS)
{
unsigned char ch, status, ucTemp;
char *buf = str;
double LatitudeTemp, LongitudeTemp;
ch = buf[5];
status = buf[GetComma(2, buf)];
if(ch == 'C')
{
if(status == 'A')
{
GPS -> NS = buf[GetComma(4, buf)];
GPS -> EW = buf[GetComma(6, buf)];
GPS->latitude = Get_Double_Number(&buf[GetComma(3, buf)]);
GPS->longitude = Get_Double_Number(&buf[GetComma(5, buf)]);
GPS->latitude_Degree = (unsigned char)(GPS->latitude / 100);
LatitudeTemp = GPS->latitude - GPS->latitude_Degree * 100;
GPS->latitude_Cent = (unsigned char)LatitudeTemp;
GPS->latitude_Second = (unsigned char)((LatitudeTemp - GPS->latitude_Cent) * 60);
GPS->longitude_Degree = (unsigned char)(GPS->longitude / 100);
LongitudeTemp = GPS->longitude - GPS->longitude_Degree * 100;
GPS->longitude_Cent = (unsigned char)LongitudeTemp;
GPS->longitude_Second = (unsigned char)((LongitudeTemp - GPS->longitude_Cent) * 60);
GPS->speed = (float)Get_Double_Number(&buf[GetComma(7, buf)]) * 1.85;
GPS->direction = (float)Get_Double_Number(&buf[GetComma(8, buf)]);
ucTemp = GetComma(1, buf);
GPS->D.hour = (buf[ucTemp + 0] - '0') * 10 + (buf[ucTemp + 1] - '0');
GPS->D.minute = (buf[ucTemp + 2] - '0') * 10 + (buf[ucTemp + 3] - '0');
GPS->D.second = (buf[ucTemp + 4] - '0') * 10 + (buf[ucTemp + 5] - '0');
ucTemp = GetComma(9, buf);
GPS->D.day = (buf[ucTemp + 0] - '0') * 10 + (buf[ucTemp + 1] - '0');
GPS->D.month = (buf[ucTemp + 2] - '0') * 10 + (buf[ucTemp + 3] - '0');
GPS->D.year = (buf[ucTemp + 4] - '0') * 10 + (buf[ucTemp + 5] - '0') + 2000;
UTC2BTC(&GPS->D);
return 1;
}
}
return 0;
}