📄 gps.c
字号:
{
OS_ENTER_CRITICAL();
for(i = 0; i < GPS_CMDNUM; i ++)
{
if(GPSDataQ[i].State == 2) //是否找到完整的一帧数据
break;
}
OS_EXIT_CRITICAL();
if(i >= GPS_CMDNUM)
{
return; //没有找到接收完整的字符串
}
temptr = GPSDataQ[i].Data;
if(strncmp(temptr,GGA_DATA_L,strlen(GGA_DATA_L)) == 0) //判断是否是GGA消息
{
if(CheckSum(temptr) == 1)
{
temptr = strchr(temptr,',')+1;
//UTC
length = strchr(temptr,',') - temptr;
if(length >= 8) //正常情况下时间的长度
{
strncpy(GPS_DATA.UTC_Time,temptr,2); //hour
strncpy(GPS_DATA.UTC_Time+3,temptr+2,2); //minute
strncpy(GPS_DATA.UTC_Time+6,temptr+4,2); //second
strncpy(GPS_DATA.UTC_Time+9,temptr+7,2); //ms
}
temptr += length+1;
//在GPRS任务中使用经度和纬度的数据进行短信息的实验,
//涉及到资源同步,因此这里关中断
OS_ENTER_CRITICAL();
//Latitude
length = strchr(temptr,',') - temptr;
if(length >= 9) //正常情况下纬度的长度
{
strncpy(GPS_DATA.Latitude,temptr,2);
strcpy(GPS_DATA.Latitude+2,"d");
strncpy(GPS_DATA.Latitude+3,temptr+2,length-2);
GPS_DATA.Latitude[length+1] = '\0';
}
else
{
GPS_DATA.Latitude[0] = '\0';
}
temptr += length+1;
//南纬和北纬的指示
length = strchr(temptr,',') - temptr;
if(length == 1) //正常情况下纬度的长度
{
length = strlen(GPS_DATA.Latitude);
strncat(GPS_DATA.Latitude,temptr-1,2);
GPS_DATA.Latitude[length+2] = '\0';
length = 1;
}
temptr += length+1;
//Longtitude 经度
length = strchr(temptr,',') - temptr;
if(length >= 10)
{
strncpy(GPS_DATA.Longtitude,temptr,3);
strcpy(GPS_DATA.Longtitude+3,"d");
strncpy(GPS_DATA.Longtitude+4,temptr+3,length-3);
GPS_DATA.Longtitude[length+1] = '\0';
}
else
{
GPS_DATA.Longtitude[0] = '\0';
}
temptr += length+1;//dddmm.mmmm,
//东经和西经的指示
length = strchr(temptr,',') - temptr;
if(length == 1) //正常情况下纬度的长度
{
length = strlen(GPS_DATA.Longtitude);
strncat(GPS_DATA.Longtitude,temptr-1,2);
GPS_DATA.Longtitude[length+2] = '\0';
length = 1;
}
temptr += length+1;
OS_EXIT_CRITICAL();
//Fix Indicator
length = strchr(temptr,',') - temptr;
if(length == 1)
{
GPS_DATA.Status = (char)(StrTOUINT(temptr,1) << 4); //参看Status的定义
}
temptr += length + 1;//1,
//Satellites Used
length = strchr(temptr,',') - temptr;
if(length > 0)
{
GPS_DATA.SatelliteUsed[0] = '\0';
strncat(GPS_DATA.SatelliteUsed,temptr,length);
}
temptr += length + 1;//07,
//HDOP
length = strchr(temptr,',') - temptr;
if(length > 0)
{
GPS_DATA.HDOP[0] = '\0';
strncat(GPS_DATA.HDOP,temptr,length);//1.0,
}
temptr += length+1;
//Altitude
length = strchr(temptr,',') - temptr;
if(length > 0)
{
strncpy(GPS_DATA.Altitude,temptr,length);
GPS_DATA.Altitude[length] = '\0';
temptr += length+1;
strncat(GPS_DATA.Altitude,temptr,1);
}
}
}
else if(strncmp(temptr,GLL_DATA_L,strlen(GLL_DATA_L)) == 0) //判断是否是GLL消息
{
//该字符串不处理
}
else if(strncmp(temptr,GSA_DATA_L,strlen(GSA_DATA_L)) == 0) //判断是否是GSA数据
{
if(CheckSum(temptr) == 1)
{
temptr = strchr(temptr,',') + 1;//$GPGSA,A,
temptr = strchr(temptr,',') + 1;
//MODE
length = strchr(temptr,',') - temptr;
if(length == 1)
{
temp8 = (char)(StrTOUINT(temptr,1));
GPS_DATA.Status = (GPS_DATA.Status & 0XF0) + temp8;
}
temptr += length + 1;
//Satellite
for(j = 0; j < MAXSATELLITE; j++)
{
length = strchr(temptr,',') - temptr;
if(length > 0)
{
GPS_DATA.Satellite[j].ID = (char)atoi(temptr);
}
temptr += length + 1;//07,//,,
}
//PDOP
length = strchr(temptr,',') - temptr;
if(length > 0)
{
GPS_DATA.PDOP[0] = '\0';
strncat(GPS_DATA.PDOP,temptr,length);
}
temptr += length + 1;//1.0,
//HDOP
length = strchr(temptr,',') - temptr;//1.0,
if(length > 0)
{
GPS_DATA.HDOP[0] = '\0';
strncat(GPS_DATA.HDOP,temptr,length);
}
temptr += length + 1;//1.0,
//VDOP
length = strchr(temptr,'*') - temptr;//1.0,
if(length > 0)
{
GPS_DATA.VDOP[0] = '\0';
strncat(GPS_DATA.VDOP,temptr,length);
}
}
}
else if(strncmp(temptr,GSV_DATA_L,strlen(GSV_DATA_L)) == 0) //判断是否是GSV数据
{
if(CheckSum(temptr) == 1)
{
temptr = strchr(temptr,',') + 1;
temptr = strchr(temptr,',') + 1;//$GPGSV,2,
temp8 = (char)atoi(temptr)-1;
for(j = 0; j < 4; j++)
{
GPS_DATA.Satellite[temp8 * MAXMSG + j].SNR = 0;
}
temptr = strchr(temptr,',') + 1;//1,
//Stl Use
err = (char)atoi(temptr);
err = MAXSATELLITE - (temp8 * MAXMSG) ;
err = ( err > MAXMSG ) ? MAXMSG : err; //计算出剩余的还在视野中的卫星数目
temptr = strchr(temptr,',') + 1;//07,
//Satellite message
for(j = 0; j < err; j++)
{
//ID
GPS_DATA.Satellite[temp8 * 4 + j].ID = (char)atoi(temptr);
temptr = temptr + 3;//07,
//Elevation
GPS_DATA.Satellite[temp8 * 4 + j].AZnEL = (unsigned short int)(atoi(temptr));
temptr = temptr + 3;//79,
//Azimuth
temp16 = 100*(unsigned short int)(atoi(temptr));
GPS_DATA.Satellite[temp8 * 4 + j].AZnEL += temp16;
temptr = temptr + 4;//035,
//SNR
GPS_DATA.Satellite[temp8 * 4 + j].SNR = (char)( atoi(temptr));
temptr = temptr + 3;//42,
}
}
}
else if(strncmp(temptr,RMC_DATA_L,strlen(RMC_DATA_L)) == 0) //判断是否是RMC数据
{
if(CheckSum(temptr) == 1)
{
temptr = strchr(temptr,',') + 1;
temptr = strchr(temptr,',') + 1;//$GPRMC,HHMMSS.SSS,
//data flag
length = strchr(temptr,',') - temptr;
if(length > 0)
{
GPS_DATA.UTC_Time[12] = temptr[0];
}
temptr += length + 1;//A,
temptr = strchr(temptr,',') + 1;//DDMM.MMMM,
temptr = strchr(temptr,',') + 1;//N,
temptr = strchr(temptr,',') + 1;//DDDMM.MMMM,
temptr = strchr(temptr,',') + 1;//W,
temptr = strchr(temptr,',') + 1;//0.13,
temptr = strchr(temptr,',') + 1;//306.62,
length = strchr(temptr,',') - temptr;
if(length == 6)
{
strncpy(GPS_DATA.UTC_Date,temptr+4,2);
strncpy(GPS_DATA.UTC_Date+3,temptr+2,2);
strncpy(GPS_DATA.UTC_Date+6,temptr,2);
}
}
}
else if(strncmp(temptr,VTG_DATA_L,strlen(VTG_DATA_L)) == 0)
{
if(CheckSum(temptr) == 1)
{
temptr = strchr(temptr,',') + 1;//$GPVTG,
length = strchr(temptr,',') - temptr;
if(length > 0)
{
strncpy(GPS_DATA.Heading, temptr, length);
GPS_DATA.Heading[length] = '\0';
strcat(GPS_DATA.Heading," deg");
}
else
{
strcpy(GPS_DATA.Heading,"0.000 deg");
}
temptr += length+1;
temptr = strchr(temptr,',') + 1;//T,
temptr = strchr(temptr,',') + 1;//,
temptr = strchr(temptr,',') + 1;//M,
temptr = strchr(temptr,',') + 1;//0.13,
temptr = strchr(temptr,',') + 1;//N,
length = strchr(temptr,',') - temptr;
if(length > 0)
{
strncpy(GPS_DATA.Speed, temptr, length);
GPS_DATA.Speed[length] = '\0';
strcat(GPS_DATA.Speed," kph");
}
}
}
OS_ENTER_CRITICAL();
GPSDataQ[i].State = 0; //清空字符串标志位
OS_EXIT_CRITICAL();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -