⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpspointdlg.cpp

📁 GPS定位报警程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		GpsDataCount[4]++;
	}else{
		//卫星数不足的GPS数据计数
		GpsDataCount[3]++;
		//图标显示
		SetShowIcon(IDI_GPS_ERROR);
	}
}
//处理经纬度数据
void CGpsPointDlg::DoLateLong(double dLate, double dLong,long lTime,long lJiao,double dV)
{
	//m_BreakMeter;//1秒允许的突变米数
	//m_BreakTime; //允许突变的秒数
	//m_ErrorMrter;//定位一个点的误差范围(米)
	//当前的时间
	if(lTime==0){//时时采集
		lTime=CCommFun::GetSyslongTime();
	}
	long   lTmp1;
	double dTmp;
	//检查一秒之间的突变
	if(lTime0==0){
		//第一个点开始的时间
		lTime1=lTime;
		//定点
		DoPoint(dLate,dLong,lTime,lJiao,dV);
		dLate0=dLate;
		dLong0=dLong;
		lTime0=lTime;
		//正规GPS数据
		GpsDataCount[6]++;
	}else{
		//检查突变,一米允许m_BreakMeter
		//取得秒数
		lTmp1=(lTime-lTime0);
		if(lTmp1<m_BreakTime+1){//允许突变的秒数
			//判断距离
			dTmp=CGps::GetDis(dLate0,dLong0,dLate,dLong);
			if(dTmp<=(lTmp1*m_BreakMeter)){//没有突变
				//定点
				DoPoint(dLate,dLong,lTime,lJiao,dV);
				dLate0=dLate;
				dLong0=dLong;
				lTime0=lTime;
				//正规GPS数据
				GpsDataCount[6]++;
				//图标显示
				SetShowIcon(IDI_GPS_OK);
			}else{ //突变舍弃
				//偏移GPS数据
				GpsDataCount[5]++;
				//图标显示
				SetShowIcon(IDI_GPS_ERROR);
			}
		}else{//超出允许突变的秒数,认为正确
			//定点
			DoPoint(dLate,dLong,lTime,lJiao,dV);
			dLate0=dLate;
			dLong0=dLong;
			lTime0=lTime;
			//正规GPS数据
			GpsDataCount[6]++;
			//图标显示
			SetShowIcon(IDI_GPS_OK);
		}
	}
	//显示统计信息
	//GpsDataCount[0] GPS数据
	//GpsDataCount[1] 验证失败GPS数据
	//GpsDataCount[2] 正确的GPS数据
	//GpsDataCount[3] 卫星数不足的GPS数据
	//GpsDataCount[4] 卫星数足够的GPS数据
	//GpsDataCount[5] 偏移GPS数据
	//GpsDataCount[6] 正规GPS数据
	CString strTmp;
	strTmp.Format("A%d -Y%d +Y%d -W%d +W%d -P%d +P%d",GpsDataCount[0],GpsDataCount[1],GpsDataCount[2],GpsDataCount[3],GpsDataCount[4],GpsDataCount[5],GpsDataCount[6]);
	this->SetWindowText(strTmp);
}
//定位点操作
void CGpsPointDlg::DoPoint(double dLate, double dLong, long lTime, long lJiao,double dV)
{
	CString strTmp;
	CString strTmp2;
	double dDis;
	long Ljiao;
	long LTmp;
	BOOL   bRlt=FALSE;
	
	m_SP.SetWindowText("...");
	//显示角度和速度
	strTmp.Format(" 角度 %d 速度 %s",lJiao,ftoa(dV));
	m_Msg.SetWindowText(strTmp);
	//显示
	if(m_bDraw){
		pDraw->NewLateLong(dLate,dLong,lJiao,dV);
	}
	for(int i=1;i<=iPoint;i++){
		bRlt=FALSE;
		//先判断方向
		if(m_Fangxiang){//+-m_Jiao
			if((Point[i].lJiao>=(lJiao-m_Jiao)) && (Point[i].lJiao<=(lJiao+m_Jiao))){
				//方向正确
			}else{
				//方向错误
				continue;
			}
		}
		if(m_Point){//定点算法
			dDis=CGps::GetDis(Point[i].dLate,Point[i].dLong,dLate,dLong);
			if(dDis<=m_ErrorMrter){//定位点是否在区域内
				bRlt=TRUE;
			}
		}
		//穿线判断
		if(!bRlt && m_CutRound){//如果在设定的时间间隔,穿过圆就是定位成功
			if((lTime-lTime0)<=m_CutTime){//在时间间隔内
				bRlt=CGps::LineCutRound(dLate0,dLong0,dLate,dLong,Point[i].dLate,Point[i].dLong,m_ErrorMrter,m_CutCount);
			}
		}
		if(bRlt){
			m_SP.SetWindowText(Point[i].sDM);
			//整理发送代码
			strTmp="";
			if(m_Code){
				strTmp+=Point[i].sDM;
			}
			if(m_Dis){
				dDis=CGps::GetDis(dLate,dLong,Point[i].dLate,Point[i].dLong,&Ljiao);
				LTmp=abs(Ljiao-Point[i].lJiao);
				dDis=dDis*cos(LTmp*PAI/180);
				strTmp2.Format("%10.2f",fabs(dDis));
				strTmp2.TrimLeft();
				strTmp2.TrimRight();
				if(dDis<0){
					strTmp2="F" + strTmp2;
				}
				if(strTmp.Compare("")==0)
					strTmp+=strTmp2;
				else
					strTmp+="-" + strTmp2;
			}
			if(m_Error){
				strTmp2.Format("%d",m_ErrorMrter);
				if(strTmp.Compare("")==0)
					strTmp+=strTmp2;
				else
					strTmp+="-" + strTmp2;
			}
			//发送给使用程序
			HWND hwnd=::FindWindow(NULL,m_strAppTitle);
			if(hwnd){//发送字符串
				//::PostMessage(hwnd,WM_GPS,atoi(Point[i].sDM),0);
				COPYDATASTRUCT cds;
				cds.cbData = strTmp.GetLength();
				cds.lpData = (void*)strTmp.GetBuffer(strTmp.GetLength());
				::SendMessage(hwnd,WM_COPYDATA,(WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cds);
			}
			//播放数字编码语音
			if(m_bSound){
				if(iSoundNum!=i){
					m_SoundLock.Lock();
					iSoundNum=i;
					m_SoundLock.Unlock();
					hthread=AfxBeginThread(SoundThread,&iSoundNum);
				}
			}
		}
	}
	//传输给设置点窗口
	if(m_bSetPoint){
		cp->NewLateLong(dLate,dLong,lJiao,dV);
	}
	if(m_bSavePoint){//记录轨迹
		SavePoint(dLate,dLong,lTime,lJiao,dV);
	}
	//记录在列表框
	//纬度
	strTmp=ftoa(dLate);
	strTmp+="                    ";
	strTmp=strTmp.Left(20);
	//经度
	strTmp+=ftoa(dLong);
	strTmp+="                    ";
	strTmp=strTmp.Left(40);
	//角度
	strTmp+=ftoa(lJiao);
	strTmp+="                    ";
	strTmp=strTmp.Left(46);
	//速度
	strTmp+=ftoa(dV);
	strTmp+="                    ";
	strTmp=strTmp.Left(52);
	//间隔秒数
	strTmp2.Format("%d",(lTime-lTime1));
	strTmp+=strTmp2;

	m_ListPoint.InsertString(0,strTmp);
}
//设置
void CGpsPointDlg::OnButtonSetup() 
{
	//设置参数
	CSysSetup setup;
	setup.DoModal();
}
//定点
void CGpsPointDlg::OnButtonPoint() 
{
	m_bSetPoint=TRUE;
	cp=new CSetPoint();
	cp->DoModal();
	delete cp;
	m_bSetPoint=FALSE;
}
//加载点
void CGpsPointDlg::LoadPoint()
{
	CString strTmp1;
	CString strTmp2;
	CString strTmp3;
	iPoint=CCommFun::Getini("定位点设置","定位点数目",0,strFile1);
	for(int i=1;i<=iPoint;i++){
		if(i>100){
			return;
		}
		strTmp1.Format("定点%d",i);
		strTmp2.Format("T1");
		strTmp3=CCommFun::Getini(strTmp1,strTmp2,"0",strFile1);
		Point[i].sDM=strTmp3;
		strTmp2.Format("T2");
		strTmp3=CCommFun::Getini(strTmp1,strTmp2,"0",strFile1);
		Point[i].dLate=atof(strTmp3);
		strTmp2.Format("T3");
		strTmp3=CCommFun::Getini(strTmp1,strTmp2,"0",strFile1);
		Point[i].dLong=atof(strTmp3);
		strTmp2.Format("T4");
		strTmp3=CCommFun::Getini(strTmp1,strTmp2,"0",strFile1);
		Point[i].lJiao=atol(strTmp3);
	}
}
//记录轨迹
void CGpsPointDlg::SavePoint(double dLate, double dLong, long lTime,long lJiao,double dV)
{
	int iCount;
	CString strFile;
	CString strTmp;
	iCount=CCommFun::Getini(CCommFun::GetSysDateString(),"数量",0,strFile2);
	strFile.Format("%s-%d.ini",CCommFun::GetSysDateString(),iCount);
	strFile="log\\" + strFile;
	strFile=CCommFun::GetAppPath(strFile);

	iCount=CCommFun::Getini("记录","数量",0,strFile)+1;
	strTmp.Format("%d",iCount);
	CCommFun::Writeini("记录","数量",strTmp,strFile);
	CCommFun::Writeini(strTmp,"dLate",ftoa(dLate),strFile);
	CCommFun::Writeini(strTmp,"dLong",ftoa(dLong),strFile);
	CCommFun::Writeini(strTmp,"lTime",ftoa(lTime),strFile);
	CCommFun::Writeini(strTmp,"lJiao",ftoa(lJiao),strFile);
	CCommFun::Writeini(strTmp,"dV",ftoa(dV),strFile);
}
//保存统计
void CGpsPointDlg::SavePointStat(CString strStat)
{
	int iCount;
	CString strFile;
	CString strTmp;
	iCount=CCommFun::Getini(CCommFun::GetSysDateString(),"数量",0,strFile2);
	strFile.Format("%s-%d.ini",CCommFun::GetSysDateString(),iCount);
	strFile="log\\" + strFile;
	strFile=CCommFun::GetAppPath(strFile);

	CCommFun::Writeini("记录","统计",strStat,strFile);
}
//double to CString
CString CGpsPointDlg::ftoa(double dData)
{
	COleVariant vt;
	CString strTmp;

	vt.vt=VT_R8;
	vt.dblVal=dData;
	vt.ChangeType(VT_BSTR);
	strTmp=vt.bstrVal;
	
	return strTmp;
}

BOOL CGpsPointDlg::PreTranslateMessage(MSG* pMsg) 
{
	//避免回车键退出
	if(pMsg->message == WM_KEYDOWN){ 
		switch(pMsg->wParam){
		case VK_RETURN://截获回车 
			return TRUE;
		case VK_ESCAPE://截获ESC 
			return TRUE;
		break;
		}
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

void CGpsPointDlg::OnButtonDraw() 
{
	//画图
	m_bDraw=TRUE;
	pDraw=new CDraw;
	if(m_ReadFile.GetCheck()){
		pDraw->m_iTimer=m_iTimer;
	}
	pDraw->DoModal();
	delete pDraw;
	m_bDraw=FALSE;
}
//定时读取GPS记录文件,模拟采集
void CGpsPointDlg::OnTimer(UINT nIDEvent) 
{
	//定时采集文件 lastLL iCount
	static int iTime=1;//间隔周期
	long     lTime;
	CString  strTmp;
	LateLong dLL;//当前的
	
	switch(nIDEvent){
	case 1:
		strTmp.Format("%d",iCount);
		if(iCount==1){
			lastLL.dLate=atof(CCommFun::Getini(strTmp,"dLate","0",strGpsFile));
			lastLL.dLong=atof(CCommFun::Getini(strTmp,"dLong","0",strGpsFile));
			lastLL.lTime=atol(CCommFun::Getini(strTmp,"lTime","0",strGpsFile));
			lastLL.lJiao=atol(CCommFun::Getini(strTmp,"lJiao","0",strGpsFile));
			lastLL.dV=atof(CCommFun::Getini(strTmp,"dV","0",strGpsFile));
			iCount++;
			iTime=1;
		}else{
			lTime=atol(CCommFun::Getini(strTmp,"lTime","0",strGpsFile));
			if((lTime-lastLL.lTime)>iTime){
				iTime++;
			}else{//间隔到了
				lastLL.dLate=atof(CCommFun::Getini(strTmp,"dLate","0",strGpsFile));
				lastLL.dLong=atof(CCommFun::Getini(strTmp,"dLong","0",strGpsFile));
				lastLL.lTime=atol(CCommFun::Getini(strTmp,"lTime","0",strGpsFile));
				lastLL.lJiao=atol(CCommFun::Getini(strTmp,"lJiao","0",strGpsFile));
				lastLL.dV=atof(CCommFun::Getini(strTmp,"dV","0",strGpsFile));
				iCount++;
				iTime=1;
			}
		}
		if((iTime==1) && (lastLL.lTime!=0)){//正确
			DoLateLong(lastLL.dLate,lastLL.dLong,lastLL.lTime,lastLL.lJiao,lastLL.dV);
		}
		if((iTime==1) && (lastLL.lTime==0)){//结束了
			this->KillTimer(1);
			OnButtonStartEnd();
		}
		break;
	case 2:
		SetShowIcon(IDI_GPS_NONE);
		break;
	}
	CDialog::OnTimer(nIDEvent);
}

void CGpsPointDlg::OnSelchangeComboTime() 
{	//保存读取时间周期选择
	m_iTimer=(m_Time.GetCurSel()+1)*100;
	CCommFun::Writeini("GPS设置","读取文件定时器周期",m_iTimer,strFile);
}
//是否保存
void CGpsPointDlg::OnCheckLog() 
{
	m_bSavePoint=m_BtnSave.GetCheck();	
	CCommFun::Writeini("GPS设置","记录轨迹",m_bSavePoint,strFile);
}
//报语音
void CGpsPointDlg::OnCheckSound() 
{
	m_bSound=m_BtnSound.GetCheck();	
	CCommFun::Writeini("GPS设置","报语音",m_bSound,strFile);
}
void CGpsPointDlg::OnDestroy() 
{
	this->KillTimer(1);
	this->KillTimer(2);
	//关闭语音线程
	if(hthread){
		if(!(hthread->m_bAutoDelete)){
			TerminateThread(hthread->m_hThread,0);
			CloseHandle(hthread->m_hThread);
			delete hthread;
			hthread=NULL;
		}
	}
	CDialog::OnDestroy();
}
//设置图标,并且定时监控是否采集不到数据
void CGpsPointDlg::SetShowIcon(UINT ISouece)
{
	this->KillTimer(2);
	m_Icon.SetIcon(theApp.LoadIcon(ISouece));
	if(ISouece!=IDI_GPS_NONE)
		this->SetTimer(2,60000,NULL);
}
//测试
void CGpsPointDlg::OnButtonTest() 
{
	DoGPSData("$GPGGA,184036,2456.4748,N,11828.4758,E,1,07,1.6,15.1,M,9.0,M,,*40","$GPVTG,355,T,358,M,001.2,N,0002.2,K*70");

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -