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

📄 gps_famdlg.cpp

📁 EVC下
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			m_brMine = ::CreateSolidBrush(RGB(0,0,0));
			return m_brMine;
		}
	}

	// TODO: Return a different brush if the default is not desired
	return hbr;
}


void CGPS_FAMDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	if(i<7)
	{	
//		if(i != 0)
//		{			
			
			space_time = SetTime[1][i];

			m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
			
			i++;
//		}
//		else
//		{	
//			i++;
//			
//			space_time = SetTime[1][i];
//
//			m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
//						
//		}
	}

	UpdateData(false);
}

void CGPS_FAMDlg::OnSub() 
{
	// TODO: Add your control notification handler code here
	if(0 < i)
	{	
		if(1 < i)
		{
			i--;
		
			space_time = SetTime[1][i-1];

			m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
		}
		
		else
		{
			space_time = SetTime[1][i-1];

			m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
		}
	}

	UpdateData(false);
}

void CGPS_FAMDlg::GetGPSinfo()
{
		
//		CHAR *strInfo;
//		BOOL bReadStat;
//		DWORD   readLen; 
//		CString str_GpsInfo;  //读出的GPS信息(以$GPGGA 开头的)
//		CString hour,minute,second;
//		int stdhour;
// 		int	SateNum;
		
		strInfo = (CHAR*)calloc(2000,sizeof(CHAR));   
		 
		bReadStat=ReadFile(hCom,strInfo,2000,&readLen,NULL);

		if(!bReadStat)
		{
			AfxMessageBox(L"读串口失败");
			m_Bt_Stop.EnableWindow(false);
			m_Bt_Manual_Mode.EnableWindow(true);
			m_Bt_Auto_Mode.EnableWindow(true);
		}
		

		PurgeComm(hCom, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);//清空串口缓冲区

		str_GpsInfo = strInfo;//将CHAR* 转为CString
		
		//str_GpsInfo="rt6hfrthfh,fthfhfgh$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000*1Ffhfghgf,fhfghghf,fhfh";
		
		//str_GpsInfo="rt6hfrthfh,fthfhfgh$GPGGA,092204.999,,,,,,,24.4,19.7,M,,,,0000*1Ffhfghgf,fhfghghf,fhfh";

		//str_GpsInfo="$GPGGA,12125.000,3937.3032,N,11611.6046,E,1,05,2.0,45.9,M,-5.7,M,,0000*77";

		m_text.Format(str_GpsInfo);
		
		int nBegin=0;

		if(str_GpsInfo.Find(L"$GPGGA")!=-1)
		{
			
		nBegin=str_GpsInfo.Find(L"$GPGGA");
		
		}

		str_GpsInfo=str_GpsInfo.Mid(nBegin);

		int nNum =0;

		for(int n =0;n<str_GpsInfo.GetLength();n++)
		{
			if(str_GpsInfo.GetAt(n) == ',')
			{
				nNum++;
			}
		}

		if (nNum < 8)
		{
			nBegin =0;
			str_GpsInfo =",,,,,,,,,,";
		}

		
		int n_point[8];

		int j=0;

		for(int i=0;i<str_GpsInfo.GetLength();i++)
		{
			
			if(str_GpsInfo.GetAt(i)==',')
			{
				n_point[j]=i;
				
				j++;
			}

		if (j==8)

			break;
		}
	
// 		CString s1,s2,s3,s4,s5,s6,s7,s8;

		s1 = str_GpsInfo.Mid(0,n_point[0]);								
		s2 = str_GpsInfo.Mid(n_point[0]+1,n_point[1]-n_point[0] -1); //时间
		s3 = str_GpsInfo.Mid(n_point[1]+1,n_point[2]-n_point[1] -1); //纬度
		s4 = str_GpsInfo.Mid(n_point[2]+1,n_point[3]-n_point[2] -1); //N
		s5 = str_GpsInfo.Mid(n_point[3]+1,n_point[4]-n_point[3] -1); //经度
		s6 = str_GpsInfo.Mid(n_point[4]+1,n_point[5]-n_point[4] -1); //E
		s7 = str_GpsInfo.Mid(n_point[5]+1,n_point[6]-n_point[5] -1); //状态
		s8 = str_GpsInfo.Mid(n_point[6]+1,n_point[7]-n_point[6] -1); //卫星数目

		if(s2.GetLength()==10)
		{
			hour=s2.Left(2); //拆分时间
			minute=s2.Mid(2,2);
			second=s2.Mid(4,2);
			stdhour=CStringToInt(hour)+8;
			
			if(stdhour>24) 
 			stdhour=stdhour-24;
 		}

		SateNum=CStringToInt(s8);

		if(SateNum > 24)
		{
			SateNum = 0;
		}
		
		if(state==1) //自动模式
		{
					
			if((s7=="1"||s7=="2")
				&&SateNum>3
				&&s2.GetLength()==10
				&&s5.GetLength()==10
				&&s3.GetLength()==9
				)
			{

				m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
				m_Info_2=(L"当前状态: 已定位,可以取点...");
				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);

 //				SetTimer(4,1000*30,NULL);

				m_Bt_Auto_Start.EnableWindow(true);
				m_Bt_Auto_Start.ShowWindow(SW_SHOW);

				m_Bt_Add.EnableWindow(true);
 				m_Bt_Sub.EnableWindow(true);
			
				hFileAuto = CreateFile (TEXT("\\ResidentFlash\\Coordinate.txt"), // Pointer to the name of the port
					GENERIC_READ | GENERIC_WRITE,// Access (read-write) mode
					0,            // Share mode
					NULL,         // Pointer to the security attribute
					OPEN_ALWAYS,// How to open the serial port
					0,            // Port attributes
					NULL);        //
				
				KillTimer(1);
			}
			
			else
			{
				m_Info_1=(L"模式: 自动");
				m_Info_2=(L"当前状态: 搜索卫星,请稍候...");
 				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);

				if(minute!=""&&second!=""&&stdhour<24)
				{
					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				}
				else
 					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");

			}
		}

		if(state==2) //手动模式
		{
			if((s7=="1"||s7=="2")
				&&SateNum>3
				&&s2.GetLength()==10
				&&s5.GetLength()==10
				&&s3.GetLength()==9)
			{
				m_Info_1=(L"模式: 手动");
				m_Info_2=(L"当前状态: 已定位,可以取点...");
				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				
				m_Bt_Manual_Start.EnableWindow(true);
				m_Bt_Manual_Start.ShowWindow(SW_SHOW);
				
				hFileManual = CreateFile (TEXT("\\ResidentFlash\\Coordinate.txt"), // Pointer to the name of the port
					GENERIC_READ | GENERIC_WRITE,// Access (read-write) mode
					0,            // Share mode
					NULL,         // Pointer to the security attribute
					OPEN_ALWAYS,// How to open the serial port
					0,            // Port attributes
					NULL);        //
				
				KillTimer(2);
			}
			
			else
			{
				m_Info_1=(L"模式: 手动");
				m_Info_2=(L"当前状态: 搜索卫星,请稍候...");
 				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				
				if(minute!=""&&second!=""&&stdhour<24)
				{
					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				}
				else
					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");
			}
		}

		if(state==3) //自动取点
		{

			if((s7=="1"||s7=="2")
				&&SateNum>2
				&&s5.GetLength()==10
				&&s3.GetLength()==9)
			{
				CString Coord=s5+"E"+s3+"NP\r\n";

				count++;

				int state=CStringToInt(s7);

				CString s9;
				
				switch(state) 
				{
				case 1: s9="非差分定位"; break;
				case 2: s9="差分定位";   break;
				}
				
				CString NorS,EorW;
				CString LatDegree,LonDegree,LatMinute,LonMinute;
				
				if (s4=="N") 
				{
					NorS="北纬";
				}
				else
					NorS="南纬";
				
				if (s6=="E")
				{
					EorW="东经";
				}
				else
					EorW="西经";
				
				LatDegree=s3.Left(2);
				LatMinute=s3.Mid(2,7);
				
				LonDegree=s5.Left(3);
				LonMinute=s5.Mid(3,7);

				m_Info_3.Format(L"%s  %s°%s'",NorS,LatDegree,LatMinute);
				m_Info_4.Format(L"%s %s°%s'",EorW,LonDegree,LonMinute);
				m_PointNum.Format(L"%d",count);
				
				WriteFile(hFileAuto,Coord,Coord.GetLength()*2,&BytesRead,NULL);

				m_Info_1.Format(L"模式: 自动  |  间隔时间: %s",space_time);
				m_Info_2=(L"当前状态: 已定位,正在测量...");

//				m_text.Format(L"%d",SateNum);
						
			}
			
			else
			{
				KillTimer(3);
				
				SetTimer(4,1000,NULL);

				state=5;

//				m_Info_2=(L"当前状态: 正在定位,请稍候...");
//				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
//				
//				if(minute!=""&&second!=""&&stdhour<24)
//				{
//					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
//				}
//				else
//					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");
			}

		}

		if(state==4) //手动取点
		{
	
			if((s7=="1"||s7=="2")&&SateNum>3&&s5.GetLength()==10&&s3.GetLength()==9)
			{
				CString Coord=s5+"E"+s3+"NP\r\n";
				
				count++;
					
				int state=CStringToInt(s7);
				
 				CString NorS,EorW;
				CString LatDegree,LonDegree,LatMinute,LonMinute;
				
				if (s4=="N") 
				{
					NorS="北纬";
				}
				else
					NorS="南纬";

				if (s6=="E")
				{
					EorW="东经";
				}
				else
 					EorW="西经";
				
				LatDegree=s3.Left(2);
				LatMinute=s3.Mid(2,7);

				LonDegree=s5.Left(3);
				LonMinute=s5.Mid(3,7);
			

				m_Info_3.Format(L"%s  %s°%s'",NorS,LatDegree,LatMinute);
				m_Info_4.Format(L"%s %s°%s'",EorW,LonDegree,LonMinute);
				m_PointNum.Format(L"%d",count);
			
				WriteFile(hFileManual,Coord,Coord.GetLength()*2,&BytesRead,NULL);

				m_Info_2=(L"当前状态: 已定位,正在测量...");
					
			}
		
		else
			{	

				SetTimer(4,1000,NULL);

				state=6;

				m_Bt_Manual_Start.EnableWindow(false);
//				m_Bt_Manual_Start.ShowWindow(SW_HIDE);

//				m_Info_2=(L"当前状态: 正在定位,请稍候...");
//				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
// 				
//				if(minute!=""&&second!=""&&stdhour<24)
//				{
//					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
//				}
//				else
// 					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");

			}
		
		}
		
		if(state==5) //自动模式(自动取点丢失卫星时执行)
		{
			if((s7=="1"||s7=="2")
				&&SateNum>3
				&&s2.GetLength()==10
				&&s5.GetLength()==10
				&&s3.GetLength()==9)
			{
//				m_Info_1=(L"模式: 自动");
//				m_Info_2=(L"当前状态: 已定位,可以取点...");
//				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
// 				m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				
				state=3;
				
				KillTimer(4);

				SetTimer(3,1000*t,NULL);
			}
			
			else
			{
				m_Info_1=(L"模式: 自动");
				m_Info_2=(L"当前状态: 搜索卫星,请稍候...");
 				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				
				if(minute!=""&&second!=""&&stdhour<24)
				{
					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				}
				else
					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");
			}
		}

		if(state==6) //手动模式(手动取点丢失卫星时执行)
		{
			if((s7=="1"||s7=="2")
				&&SateNum>3
				&&s2.GetLength()==10
				&&s5.GetLength()==10
				&&s3.GetLength()==9)
			{
				m_Info_1=(L"模式: 手动");
				m_Info_2=(L"当前状态: 已定位,可以取点...");
				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				
				m_Bt_Manual_Start.EnableWindow(true);
				m_Bt_Manual_Start.ShowWindow(SW_SHOW);

				state=4;
				
				KillTimer(4);
			}
			
			else
			{
				m_Info_1=(L"模式: 手动");
				m_Info_2=(L"当前状态: 搜索卫星,请稍候...");
 				m_Info_3.Format(L"使用卫星: %d 颗",SateNum);
				
				if(minute!=""&&second!=""&&stdhour<24)
				{
					m_Info_4.Format(L"系统时间: %d:%s:%s",stdhour,minute,second);
				}
				else
					m_Info_4.Format(L"系统时间: 正在获取,请稍侯...");
			}
		}


	
	UpdateData(false);
		
	free(strInfo);
}

⌨️ 快捷键说明

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