📄 gps_receive.c.bak
字号:
{
i += 6;
for (j = i; j < ((UART0DATA *)GPSTemp)->Rec_Lenght; j++)//读取卫星的总数目00~12
{
if (nFindComma == 3)
{
if (((UART0DATA *)GPSTemp)->RecBuff[j] != ',')
{
szState[nIndex] = ((UART0DATA *)GPSTemp)->RecBuff[j];
nIndex++;
}
}
if (((UART0DATA *)GPSTemp)->RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 3)
{
i = j + 1;
GPSData.cState = atoi(szState);
break;
}
}
}
}
OS_EXIT_CRITICAL();
//OSTimeDly(2);
}
}
/***************************************************************************************************************
* GetGPSInfo
*
* Description: 读取GPS信息
*
* Arguments : pBuf :从串口收到的GPS原始数据
* nLength:pBuf的数据长度
* gpsData:从pBuf中取出GPS信息
* Returns : 为true时才保存数据
*
* Note : GPS的每帧数据以'$'开始,以'\r\n'结尾。中间以','分隔每字段。需要处理的帧数据有:
* 分别以"$GPRMC", "$GPGGA","$GPGSV"开始的数据帧。只需将经度、纬度、卫星个数、速度等字段取出即可。
***************************************************************************************************************/
/*uint8 GetGPSInfo(UART0DATA * gpsData)
//uint8 GetGPSInfo(char *pBuf,int nLength,GPSDATA *gpsData)
{
char szLat[11] = {0}; // 纬度寄存器
char szLon[11] = {0}; // 经度寄存器
char szTime[6] = {0}; // 时间寄存器
char szSpeed[15]={0}; // 速率寄存器
char szState[32]={0}; // 卫星个数寄存器
char szHeight[32]={0};// 读取海平面高度
double dCurLat = 0.0;
double dCurLot = 0.0;
uint32 i,j,nIndex = 0,nFindComma = 0;
OS_ENTER_CRITICAL();
if ((*gpsData).RecBuff == NULL)
return 0;
//$GPRMC,174921,A,2216.386,N,11331.650,E,000.0,360.0,311205,001.9,W*6D
if (((*gpsData).RecBuff[i] == '$' ) & ((*gpsData).RecBuff[i+1] == 'G') & ((*gpsData).RecBuff[i+2] == 'P' )&
((*gpsData).RecBuff[i+3] == 'R') & ((*gpsData).RecBuff[i+4] == 'M') & ((*gpsData).RecBuff[i+5] == 'C'))
{
i += 6;
nIndex = 0;
for (j = i; j < (*gpsData).Rec_Lenght; j++) //读取纬度
{
if (nFindComma == 1)
{
if ((*gpsData).RecBuff[j] != ',')
{
szTime[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 1)
{
if ((Time_Adjust == 1) | (Time_Count == 720))
{
struct time sTime;
char k = 0;
char Time[2] = {0};
Time_Adjust = 0x00;
Time_Count = 0x00;
Time[0] = szTime[0];
Time[1] = szTime[1];
k = atoi(Time) + 8; // 字符串转换为整型
if (k > 0x18)
sTime.wHour = k - 0x18;
else
sTime.wHour = k;
Time[0] = szTime[2];
Time[1] = szTime[3];
sTime.wMinute = atoi(Time);
Time[0] = szTime[4];
Time[1] = szTime[5];
sTime.wSecond = atoi(Time);
settime(&sTime);
}
Time_Count++;
i = j + 1;
break;
}
}
}
nIndex = 0;
for (j = i; j < (*gpsData).Rec_Lenght; j++) //读取纬度
{
if (nFindComma == 3)
{
if ((*gpsData).RecBuff[j] != ',')
{
szLat[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 3)
{
int nLatInt = atoi(szLat) / 100;
GPSData.dLat = (atof(szLat) - nLatInt * 100) / 60.0 + nLatInt;
i = j + 1;
break;
}
}
}
nIndex = 0;
for (j = i; j < (*gpsData).Rec_Lenght; j++)//读取经度
{
if (nFindComma == 5)
{
if ((*gpsData).RecBuff[j] != ',')
{
szLon[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 5)
{
int nLonInt = atoi(szLon) / 100;
GPSData.dLot = (atof(szLon) - nLonInt * 100) / 60.0 + nLonInt;
i = j + 1;
break;
}
}
}
nIndex = 0;
for (j = i; j < (*gpsData).Rec_Lenght; j++) // 读取速度
{
if (nFindComma == 7)
{
if ((*gpsData).RecBuff[j] != ',')
{
szSpeed[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 7)
{
i = j + 1;
GPSData.iSpeed = atof(szSpeed) * 1.852;
break;
}
}
}
}
//$GPGGA,174921,2216.386,N,11331.650,E,1,03,5.4,-33.6,M,-3.3,M,,*46
else if (((*gpsData).RecBuff[i] =='$') & ((*gpsData).RecBuff[i+1]=='G') & ((*gpsData).RecBuff[i+2]=='P') &
((*gpsData).RecBuff[i+3]=='G') & ((*gpsData).RecBuff[i+4]=='G') & ((*gpsData).RecBuff[i+5]=='A'))
{
i += 6;
nIndex = 0;
for (j = i; j < (*gpsData).Rec_Lenght;j++) //读取纬度
{
if (nFindComma == 2)
{
if ((*gpsData).RecBuff[j] != ',')
{
szLat[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 2)
{
int nLatInt = atoi(szLat) / 100;
i = j+1;
dCurLat = (atof(szLat) - nLatInt * 100) / 60.0+nLatInt;
break;
}
}
}
nIndex=0;
for (j = i; j < (*gpsData).Rec_Lenght; j++)//读取经度
{
if (nFindComma == 4)
{
if ((*gpsData).RecBuff[j] != ',')
{
szLon[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 4)
{
int nLonInt = atoi(szLon) / 100;
i = j+1;
dCurLot = (atof(szLon) - nLonInt * 100) / 60.0 + nLonInt;
break;
}
}
}
for (j = i; j < (*gpsData).Rec_Lenght; j++)// GPS状态批示0-未定位 1-无差分定位信息 2-带差分定位信息
{
if (nFindComma == 6)
{
if ((*gpsData).RecBuff[j] != ',')
{
uint8 GPS_State;
GPS_State = (*gpsData).RecBuff[j];
if ((GPS_State == '1')||(GPS_State == '2'))
{
// IO0DIR = GPS_Detect;
IO0CLR = GPS_Detect;
//IO0SET = GPS_Detect;
GPSData.OSSemGPS_State =0X01;
}
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 6)
{
i = j+1;
break;
}
}
}
}
//$GPGSV,3,1,10,01,08,285,49,05,44,088,00,06,00,160,00,09,23,037,00*79
//$GPGSV,3,2,10,14,34,315,52,15,40,211,31,18,67,103,00,21,23,184,31*7C
//$GPGSV,3,3,10,22,62,342,53,30,45,134,00,,,,,,,,*7B
else if((*gpsData).RecBuff[i] =='$' && (*gpsData).RecBuff[i+1]=='G' && (*gpsData).RecBuff[i+2]=='P' &&
(*gpsData).RecBuff[i+3]=='G' && (*gpsData).RecBuff[i+4]=='S' && (*gpsData).RecBuff[i+5]=='V')
{
i += 6;
for (j = i; j < (*gpsData).Rec_Lenght; j++)//读取卫星的总数目00~12
{
if (nFindComma == 3)
{
if ((*gpsData).RecBuff[j] != ',')
{
szState[nIndex] = (*gpsData).RecBuff[j];
nIndex++;
}
}
if ((*gpsData).RecBuff[j] == ',')
{
nFindComma++;
if (nFindComma > 3)
{
i = j + 1;
GPSData.cState = atoi(szState);
break;
}
}
}
}
//检测经纬度有没有变化
if (((GPSData.dLat - dCurLat > 0.000001) |( GPSData.dLat - dCurLat < -0.000001))
|((GPSData.dLot - dCurLot > 0.000001) | (GPSData.dLot - dCurLot < -0.000001)))
{
GPSData.dLat = dCurLat;
GPSData.dLot = dCurLot;
OS_EXIT_CRITICAL();
return 1;
}
OS_EXIT_CRITICAL();
return 0;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -