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

📄 gpsdoc.cpp

📁 一个gps单点定位的程序
💻 CPP
字号:
// GPSDoc.cpp : implementation of the CGPSDoc class
//

#include "stdafx.h"
#include "GPS.h"

#include "GPSDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGPSDoc

IMPLEMENT_DYNCREATE(CGPSDoc, CDocument)

BEGIN_MESSAGE_MAP(CGPSDoc, CDocument)
	//{{AFX_MSG_MAP(CGPSDoc)
	ON_COMMAND(ID_NAVIGATION, OnNavigation)
	ON_COMMAND(ID_OBSERVE, OnObserve)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSDoc construction/destruction

CGPSDoc::CGPSDoc()
{
	// TODO: add one-time construction code here

}

CGPSDoc::~CGPSDoc()
{
}

BOOL CGPSDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CGPSDoc serialization

void CGPSDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CGPSDoc diagnostics

#ifdef _DEBUG
void CGPSDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CGPSDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGPSDoc commands

void CGPSDoc::OnNavigation() 
{
	// TODO: Add your command handler code here
	
	Open();
	
}

void CGPSDoc::OnObserve() 
{
	// TODO: Add your command handler code here
	Open_Observe();
	
}

void CGPSDoc::Open()
{
	char *szFilter="Text Files(*.txt)|*.txt|All Files(*.*)|*.*|GPS Files(*.dat)|*.dat|";
	CFileDialog fo(true,"*.*",TEXT("gpsdata.txt") ,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
	fo.DoModal();

	CString path=fo.GetPathName();
	if(path=="GPSfile")
		return;

	CString data;
	if(!gpsFile.Open(path,CFile::modeRead))
	{
		AfxMessageBox("Can't open file!");
		return;
	}
	//begin to read
	int PRN;
	int year=0,month=0,day=0;
	int hour=0,minute=0,second=0;
	double a0=0,a1=0,a2=0;
	int a=0,b=0;
    double D[4];
	CNavigationFile temp;

	gpsFile.ReadString(data);
	data.TrimLeft();
	data.TrimRight();
	CString str1;
	while(data!="END OF HEADER")
	{
		gpsFile.ReadString(data);
		data.TrimRight();
		data.TrimLeft();
	}
	m_count=0;
	gpsFile.ReadString (data);
	data.TrimLeft ();
    data.TrimRight ();
	///begint to read zhe zero line
	while(!data.IsEmpty())
	{
		a=data.Find(" ");
		PRN=atoi(data.Mid(0,a));
		temp.SetPRN(PRN);
		year=atoi(data.Mid(a+1,2))+2000;
		a=data.Find(" ",a+1);
		month=atoi(data.Mid(a+1,2));
		a=data.Find(" ",a+1);
		day=atoi(data.Mid(a+1,2));
		a=data.Find(" ",a+1);
		hour =atoi(data.Mid (a+1,2));
		a=data.Find(" ",a+1);
		minute =atoi(data.Mid (a+1,2));
		a=data.Find(" ",a+1);
		second =atoi(data.Mid (a+1,3));
		temp.SetTime(year,month,day,hour,minute,second);
		a=data.Find("."); //秒的小数点
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		a0=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		a1=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		a2=atof(str1);
		
		temp.SetAAA (a0,a1,a2);
		//////read the first line
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		temp.SetFirstLine(D[0],D[1],D[2],D[3]);

			//读取第二行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		
		temp.SetSecondLine(D[0],D[1],D[2],D[3]);  //设置第二行数据
		
		//读取第三行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		
		temp.SetThirdLine(D[0],D[1],D[2],D[3]);  //设置第三行数据
		
		//读取第四行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		
		temp.SetForthLine (D[0],D[1],D[2],D[3]);  //设置第四行数据
		
		//读取第五行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		temp.SetFiveLine(D[0],D[1],D[2],D[3]);  //设置第五行数据
		
		//读取第六行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		
		temp.SetSixLine(D[0],D[1],D[2],D[3]);  //设置第六行数据
		
		//读取第七行数据
		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
		
		a=data.Find(".");
		b=data.Find ("e");
		str1=data.Mid (0,b+5);
		D[0]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[1]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[2]=atof(str1);
		
		a=data.Find(".",a+1);
		str1=data.Mid (a-2,19);
		D[3]=atof(str1);
		
		temp.SetSevenLine(D[0]);
		temp.GetGPSSeconds (year,month,day,hour,minute,second);
		temp.CaculateCOR ();

		m_gpsArray.Add (temp);
		m_count++;
		
		gpsFile.ReadString (data);
		data.TrimLeft ();
	    data.TrimRight ();
		

	}
	gpsFile.Close ();
	/////////////////以下显示所求的卫星坐标
	CString string1=" ";
	CString str;
	str.Format("\t");
	/////
	CString str_1,str_2,str_3,str_4,str_5;
	str_1="卫星号";
	str_2="时间(y-m-d-h-m-s)";
	str_3="坐标(X)";
	str_4="坐标(Y)";
	str_5="坐标(Z)";
	CString m_temp;
	m_temp=str_1+"    "+str_2+"     "+str+str_3+str+"       "+str+str_4+""+str+str+"      "+str_5;
	CString strPRN,strTimeZ;
	CNavigationFile k;
	CString string=" ";
	for(int i=0;i<m_count ;i++)
	{
	k=m_gpsArray.GetAt (i);
	PRN=k.GetPRN ();
	
	strPRN.Format ("%d",PRN);
	if(PRN<10)
	{
		strPRN=strPRN+" ";
	}
	
	//strTime.Format ("",);
	string.Format ("\n  %s      %s        %f      %f     %f    ",strPRN,k.GetUCTTime (),k.GetX(),k.GetY(),k.GetZ());
	
	string1+=string;
	
	}
	string1=m_temp+string1;
	AfxMessageBox(string1);

}

void CGPSDoc::Open_Observe()
{
	int i;

	char *szFilter="Text Files(*.txt)|*txt|All Files(*.*)|*.*|GPS Files(*.dat)|*.dat||";
	CFileDialog fo (true,"*.*",TEXT("gpsdata.txt") ,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
	fo.DoModal();
	
	CString path=fo.GetPathName();

	if(path=="gpsdata")
		return;

	//AfxMessageBox(path);
	CString data;
	
	if( !gpsFile.Open( path, CFile::modeRead ))
	{
		
		AfxMessageBox("文件打开失败!");
		return;
	}
	//读取数据
	int surveyCount;
	int PRNS[20];
	int year=0,month=0,day=0;
	int hour=0,minute=0,second=0;
	double L1[20],L2[20],P2[20],C1[20];
	CString strPRNS;
	CObserveFile temp;

	gpsFile.ReadString (data);
	data.TrimLeft ();
	data.TrimRight ();
    //跳过文件头
	while(data!="END OF HEADER")
	{
		gpsFile.ReadString (data);
		data.TrimLeft ();
	    data.TrimRight ();

	}

	m_surveyCount=0;
    int a=0;

	gpsFile.ReadString (data);
	data.TrimLeft ();
	data.TrimRight ();

	while(!data.IsEmpty ())
	{
		a=data.Find(" ");
		year =atoi(data.Mid (0,a))+2000;
	
		month =atoi(data.Mid (a+1,2));
		a=data.Find(" ",a+1);
		day =atoi(data.Mid (a+1,2));
		a=data.Find(" ",a+1);
		hour =atoi(data.Mid (a+1,2));
		a=data.Find(" ",a+1);
		minute =atoi(data.Mid (a+1,2));

		a=data.Find(" ",a+1);
		second =atoi(data.Mid (a+1,10));

		a=data.Find(" ",a+3);
		surveyCount=atoi(data.Mid (a+3,3));
		
		temp.SetSurveyTime (CTime(year,month,day,hour,minute,second));
		temp.SetSurveyCount (surveyCount);

		strPRNS=data.Right(data.GetLength()-31);
		strPRNS.TrimLeft ();
		strPRNS.TrimRight ();
		
		
		a=0;
		for(i=0;i<surveyCount;i++)
		{
			PRNS[i]=atoi(strPRNS.Mid (a,2));
			a=strPRNS.Find(" ",a+1)+1;
		}
		temp.SetPRNS (PRNS,surveyCount);

		for(i=0;i<surveyCount;i++)
		{
			gpsFile.ReadString(data);
			data=data.Mid (1,data.GetLength ()-2);

			L1[i]=atof(data.Mid (0,15));
			L2[i]=atof(data.Mid (17,15));
			P2[i]=atof(data.Mid (33,15));
			C1[i]=atof(data.Right(15)); 
		}
		temp.SetL1(L1,surveyCount);
		temp.SetL2(L1,surveyCount);
		temp.SetP2(P2,surveyCount);
		temp.SetC1(C1,surveyCount);
		
		m_gpsObserve.Add(temp);
		m_surveyCount++;

		gpsFile.ReadString (data);
		data.TrimLeft ();
		data.TrimRight ();
	}						   
	gpsFile.Close();
	//检查是否有导航文件
	if(m_gpsArray.GetSize ()==0)
	{
		AfxMessageBox("您还没有选择导航文件");
		Open();
	}
	//获得卫星坐标及相应钟差
	CObserveFile station;
	CNavigationFile salite;
	int isFind=0;
	int isAllFind=1;
	int isCan=0;
	for(i=0;i<m_gpsObserve.GetSize();i++)
	{
		station=m_gpsObserve.GetAt (i);
		isAllFind=1;
		for(int j=0;j<station.GetSurveyCount ();j++)
		{
			isFind=0;
			for(int k=0;m_gpsArray.GetSize ();k++)
			{
				salite=m_gpsArray.GetAt (k);
				if (salite.GetPRN()==station.PRNS [j])
				{
					station.Salite [j]=salite;
					isCan=1;
					isFind=1;
					break;
				}
			}
			if(isFind==0)
			{
				//AfxMessageBox("不能在导航文件中找到所有观测卫星!");
				isAllFind=0;
				break;
			}
		}
		if(isAllFind==1)
		{
			station.Salite[j] =salite;
			m_gpsStation=station;
			break;
		}
	
	}//数据完好卫星查找完毕

	if(isCan==1)
	{
		m_gpsStation.CaculateCor();
	    //ShowStationCor();
	}
	else
		AfxMessageBox("数据不足,无法计算!");
	
	
	////
	CString str_2,str_3,str_4,str_5;
	CString str="\t";
	//CObserveFile k;
	
	//str_1="卫星号";
	str_2="坐标(X)";
	str_3="坐标(Y)";
	str_4="坐标(Z)";
	str_5="坐标(T)";
	CString m_temp;
	m_temp="  "+str_2+str+str+str_3+str+"    "+str+str_4+str+"  "+str_5;
	
	CString string;
	string.Format(" \n%f     %f    %f   %f",m_gpsStation.GetX_O(),m_gpsStation.GetY_O(),m_gpsStation.GetZC(),m_gpsStation.GetZC());
    AfxMessageBox(m_temp+string);

}

⌨️ 快捷键说明

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