【原创】小学生也能做的GPS信息解码流程
来源:互联网 发布:淘宝开学季时间 编辑:程序博客网 时间:2024/04/29 23:51
GPS解码其实超简单,一般GPS模块只要上电了就会不停的发包,你随便接下来几个包看看就明白了
参见nmea协议,大部分人有用的包就是一个$GPRMC开头的字符串
把里面UTC时间加8换成东八区时间,再把里面经纬度速度啊高度啊什么的龟龟都memcpy了就完成了!
详见下面代码,小学生也能做的出来
void Gps_info_out()
{
while((Receivedata_temp.Find(0x0d)!=-1)&&(Receivedata_temp.Find(0x0a)!=-1))
{
BOOL up_jw=1;//是否刷新经纬度
BOOL up_date=1;//是否刷新日期
int startLF=Receivedata_temp.Find(0x0a);
int endCR=Receivedata_temp.Find(0x0d);
if(startLF>endCR)
endCR=Receivedata_temp.Find(0x0d,startLF);
CString msg= Receivedata_temp.Mid(startLF+1,endCR-startLF-1);
Receivedata_temp.Delete(0,endCR+1);
if(msg.Left(6).Compare(_T("$GPRMC"))!=0)//判断报头
{
continue;
}
msg.Delete(0,msg.Find(',')+1);
wchar_t * pTime=msg.GetBuffer(msg.GetLength()+1);
int hour,min,sec;
wchar_t hour_t[3];
wchar_t min_t[3];
wchar_t sec_t[3];
wchar_t year_t[3];
wchar_t mon_t[3];
wchar_t day_t[3];
wchar_t t2[10];
memset(temp,0,9);
memcpy(hour_t,pTime,4);
memcpy(min_t,pTime+2,4);
memcpy(sec_t,pTime+4,4);
hour=_wtoi(hour_t);
min=_wtoi(min_t);
sec=_wtoi(sec_t);
msg.ReleaseBuffer();
msg.Delete(0,msg.Find(',')+1);
if(msg.GetAt(0)!='A')//判断是否是有效数据 A为有效
{
continue;
}
msg.Delete(0,msg.Find(',')+1);
CString longitude=msg.Left(2);
// longitude+="`";
CString longitudeD=msg.Mid(2,6);
double longitudeD1;
_AtlSimpleFloatParse(longitude,longitudeD1);
double longitudeD2;
_AtlSimpleFloatParse(longitudeD,longitudeD2);
longitudeD2=longitudeD2/60;
longitudeD1+=longitudeD2;
longitudeD2=longitudeD1*3600000;
long longitudeDl=(long)longitudeD2;
memcpy(GPS_lg,(char *) &longitudeDl,4);
ChangeHL(GPS_lg,4);
// longitude+=".";
msg.Delete(0,msg.Find(',')+1);
// if(msg.GetAt(0)=='N')
// longitude.Insert(0,_T("N"));
// if(msg.GetAt(0)=='S')
// longitude.Insert(0,_T("S"));
msg.Delete(0,msg.Find(',')+1);
CString latitude=msg.Left(3);
CString latitudeD=msg.Mid(3,6);
double latitudeD1;
_AtlSimpleFloatParse(latitude,latitudeD1);
double latitudeD2;
_AtlSimpleFloatParse(latitudeD,latitudeD2);
latitudeD2=latitudeD2/60;
latitudeD1+=latitudeD2;
latitudeD2=latitudeD1*3600000;
long latitudeDl=(long)latitudeD2;
memcpy(GPS_la,(char *) &latitudeDl,4);
ChangeHL(GPS_la,4);
// latitude+=".";
msg.Delete(0,msg.Find(',')+1);
// if(msg.GetAt(0)=='E')
// latitude.Insert(0,_T("E"));
// if(msg.GetAt(0)=='W')
// latitude.Insert(0,_T("W"));
msg.Delete(0,msg.Find(',')+1);
CString StrSpeed = msg.Mid(0,msg.Find(','));
double dSpeed = _tcstod(StrSpeed, NULL)*1.852;
int fSpeed=(int)dSpeed;
memcpy(GPS_spd,(char *) &fSpeed,1);
msg.Delete(0,msg.Find(',')+1);
CString StrDirection = msg.Mid(0,msg.Find(','));
double dDirection = _tcstod(StrDirection, NULL);
memcpy(GPS_dir,(char *) &dDirection,1);
msg.Delete(0,msg.Find(',')+1);
wchar_t * pDate=msg.GetBuffer(msg.GetLength()+1);
int day,mon,year;
memset(temp,0,9);
memcpy(year_t,pDate,4);
memcpy(mon_t,pDate+2,4);
memcpy(day_t,pDate+4,4);
day=_wtoi(year_t);
mon=_wtoi(mon_t);
year=_wtoi(day_t);
if((year>40)&&(year<97))//判断日期是否正常
continue;
year+=2000;
hour+=8;
if (hour>23)
{
day++;
if((mon==1||mon==3||mon==5||mon==7||mon==8||mon==10)&&day>31)
{
mon++;
day=1;
}
else if(mon==12&&day>31)
{
year++;
mon=1;
day=1;
}
else if(mon==2)
{
if(year==2012||year==2016||year==2020||year==2024||year==2028)
{
if (day>29)
{
mon++;
day=1;
}
}
else
{
if(day>28)
{
mon++;
day=1;
}
}
}
else if(day>30&&(mon==4||mon==6||mon==9||mon==11))
{
mon++;
day=1;
}
}
hour=hour%24;
memcpy(GPS_UTC,(char *) &year,2);
char tt;
tt=GPS_UTC[0];
GPS_UTC[0]=GPS_UTC[1];
GPS_UTC[1]=tt;
memcpy((GPS_UTC+2),(char *) &mon,1);
memcpy((GPS_UTC+3),(char *) &day,1);
memcpy((GPS_UTC+4),(char *) &hour,1);
memcpy((GPS_UTC+5),(char *) &min,1);
memcpy((GPS_UTC+6),(char *) &sec,1);
//latitude 是东经 E113'55.619
m_pos.Format(_T("%s,%s"),longitude,latitude);
GPS_STATE=1;
msg.ReleaseBuffer();
}
}
- 【原创】小学生也能做的GPS信息解码流程
- 【原创】“小学生也能”系列之二,控制GPS以及高低为互换操作
- android的GPS信息
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- 解码流程的理解
- FFMpeg的解码流程
- H264的解码流程:
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- FFMpeg的解码流程
- 解码流程的理解
- old《APUE 2e》学习笔记 第七章 进程环境
- 清空数据日志
- 【转】JAVA笔试题汇总(31-60)
- Javascript获取当前时间和日期的方法
- Top 15 free SQL Injection Scanners
- 【原创】小学生也能做的GPS信息解码流程
- 【转】JAVA笔试题汇总(61-90)
- Flash游戏开发技术分析(上)
- 【转】JAVA笔试题汇总(91-122)
- Disk2vhd – utility to creates Virtual Hard Disk
- Web知识积累
- 各大IT公司薪水行
- Cygwin的简介以及使用方法
- 测试