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

📄 mapdlg.cpp

📁 控制GSM模块获得当前数据库并进行定位
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	for(int i =0; i<count; i++)
	{
	   m_Array.SetAt(i, m_SendData.GetAt(i));
	}
	m_MSComm.SetOutput(COleVariant(m_Array));
}

CString CMapDlg::GetCommstr()
{
	int k=m_MSComm.GetInBufferCount();     	//接收缓冲区的字符数目 
	char *str,*str1; 
	CString str2; 
	if(k>0) 
	{ 
		VARIANT m_input=m_MSComm.GetInput(); 
		str=(char*)(unsigned char*)m_input.parray->pvData; 
		int i=0; 
		str1=str; 
		while(i<k) 
		{ 
			i++; 
			str1++; 
		} 
		*str1='\0';                               
		str2=(const char*)str;             	//清除字符串中的不必要字符 
	}
	return str2;
}

void CMapDlg::OnCellid() 
{
	// TODO: Add your control notification handler code here
	if(m_OK==1)
	{
		m_List.DeleteAllItems();
		m_row_number=0;
		m_SendData=_T("AT^MONI\r");
		Send_com();
		Sleep(500);
		CString str=GetCommstr();
		char temp[400];
		strcpy(temp,(char*)LPCSTR(str));
		char chann[10];
		for(int i=176;i<=179;i++)
			chann[i-176]=temp[i];
		chann[i-177]='\0';
		char dBm[10];
		for(i=185;i<=187;i++)
			dBm[i-185]=temp[i];
		dBm[i-185]='\0';
		char LAC[10];
		for(i=197;i<=200;i++)
			LAC[i-197]=temp[i];
		LAC[i-197]='\0';
		char cellid[10];
		for(i=202;i<=205;i++)
			cellid[i-202]=temp[i];
		cellid[i-202]='\0';
		str.Format("%d",m_row_number+1);
		m_List.InsertItem(m_row_number,str);
		str.Format("%s",chann);
		m_List.SetItemText(m_row_number,1,str); 
		str.Format("%s",dBm);
		m_List.SetItemText(m_row_number,2,str); 
		str.Format("%s", LAC);
		m_List.SetItemText(m_row_number,3,str);
		str.Format("%s", cellid);
		m_List.SetItemText(m_row_number,4,str);
		GetLocation(str);
		m_List.SetItemText(m_row_number,5,m_jingdu); 
		m_List.SetItemText(m_row_number,6,m_weidu);
		m_List.SetItemText(m_row_number,7,m_location);
		CWebBrowser2 * pBrowse = (CWebBrowser2 *) GetDlgItem(IDC_EXPLORER1);
		m_mode="CELLID";
		if(m_location!="")
		{
			CString strtmp=_T("http://map.baidu.com/#word=");
			strtmp+=m_location;
			COleVariant sLoc(strtmp);
			pBrowse->Navigate2(sLoc, NULL, NULL, NULL, NULL);
			GetDlgItem(IDC_ADDCELL)->EnableWindow(FALSE);
		}
		else
		{
			addcell.m_CELLID=cellid;
			GetDlgItem(IDC_ADDCELL)->EnableWindow(TRUE);
		}
	}
}

void CMapDlg::OnCellinfo() 
{
	// TODO: Add your control notification handler code here
	if(m_OK==1)
	{
		OnCellid();
		m_mode="CELLINFO";
		m_SendData=_T("AT^MONP\r");
		Send_com();
		Sleep(400);
		CString str1=GetCommstr();
		m_SendData=_T("AT^SMONC\r");
		Send_com();
		Sleep(400);
		CString str2=GetCommstr();
		char temp1[500];
		for(int i=0;i<500;i++)
			temp1[i]='\0';
		strcpy(temp1,(char*)LPCSTR(str1));
		char temp2[500];
		strcpy(temp2,(char*)LPCSTR(str2));
		CString dBm[6];
		CString LAC[6];
		CString cellid[6];
		CString chann[6];
		CString str;
		char temp[20];
		for(i=0;i<6;i++)
		{
			if(temp1[47+i*36]!='\0')
			{
				int k=0;
				for(int j=0;j<4;j++)
				{
					if(temp1[46+i*36+j]!=0x20)
					temp[k++]=temp1[46+i*36+j];
				}
				temp[k]='\0';
				chann[i].Format("%s",temp);
				k=0;
				for(j=0;j<4;j++)
				{
					if(temp1[54+i*36]=='-')
						temp[j]=temp1[54+i*36+j];
					else
						temp[j]=temp1[55+i*36+j];
				}
				temp[j]=0;
				dBm[i].Format("%s",temp);
			}
		}
		for(i=30;i<int(strlen(temp2));i++)
		{
			if(temp2[i-2]=='4'&&temp2[i-1]=='6'&&temp2[i]=='0')
			{
				char tmp1[5];
				for(int j=0;j<4;j++)
					tmp1[j]=temp2[i+5+j];
				tmp1[j]='\0';
				char tmp2[5];
				for(j=0;j<4;j++)
					tmp2[j]=temp2[i+10+j];
				tmp2[j]='\0';
				while(temp2[i+j+11]!=',') j++;
				char tmp3[5];
				int k=0;
				j++;
				while(temp2[i+j+11]!=',')
				{
					tmp3[k]=temp2[i+j+11];
					j++;
					k++;
				}
				tmp3[k]='\0';
				CString strtmp;
				strtmp.Format("%s",tmp3);
				for(j=0;j<6;j++)
				{
					if(chann[j]==strtmp)
					{
						LAC[j].Format("%s",tmp1);
						cellid[j].Format("%s",tmp2);
					}
				}
			}
			else continue;
		}
		for(i=0;i<6;i++)
		{		
			if(chann[i]=="\nOK\r"||chann[i]==""||cellid[i]=="0000")
			{
			}
			else
			{
				m_row_number++;
				str.Format("%d",m_row_number+1);
				m_List.InsertItem(m_row_number,str);
				m_List.SetItemText(m_row_number,1,chann[i]); 
				m_List.SetItemText(m_row_number,2,dBm[i]); 
				m_List.SetItemText(m_row_number,3,LAC[i]);
				m_List.SetItemText(m_row_number,4,cellid[i]);
			}
		}
	}
}

void CMapDlg::GetLocation(CString str)
{
	m_jingdu=_T("");
	m_weidu=_T("");
	m_location=_T("");
	fstream file;
	char location[100];
	char weidu[20];
	char jingdu[20];
	int sucess=0;
	file.open("基站数据.txt", ios::in|ios::nocreate);
	if(!file)
	{
	}
	else
	{	
		char temp[300];
		char tmp[5];
		CString strtmp;
		while(!file.eof())
		{
			file.getline(temp,300);
			for(int i=0;i<4;i++)
				tmp[i]=temp[i];
			tmp[i]='\0';
			strtmp.Format("%s",tmp);
			if(strtmp==str)
			{
				for(int j=10;j<int(strlen(temp));j++)
				{
					if(temp[j]!=0x9)
					{
						location[j-10]=temp[j];
					}
					else
						break;
				}
				location[j-10]='\0';
				while(temp[j]==0x9) j++;
				for(int k=0;k<9;k++)
				{
					if(temp[j]!=0x9&&temp[j]!='\0')
					{
						jingdu[k]=temp[j];
						j++;
					}
					else
						break;
				}
				jingdu[k]='\0';
				while(temp[j]==0x9) j++;
				for(k=0;k<9;k++)
				{
					if(temp[j]!=0x9&&temp[j]!='\0')
					{
						weidu[k]=temp[j];
						j++;
					}
					else
						break;
				}
				weidu[k]='\0';
				sucess=1;
			}
		}
		if(sucess==1)
		{
			m_jingdu.Format("%s",jingdu);
			m_weidu.Format("%s",weidu);
			m_location.Format("%s",location);
		}
	}
}

void CMapDlg::OnAddcell() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	if(addcell.DoModal()==IDOK)
	{
		CString cellid=addcell.m_CELLID;
		CString location=addcell.m_Location;
		CString jingdu=addcell.m_jingdu;
		CString weidu=addcell.m_weidu;
		CString fangwei=addcell.m_fangwei;
		fstream file;
		if(location==""||jingdu==""||weidu==""||fangwei=="")
		{
			AfxMessageBox("请填完整基站信息!");
			return;
		}
		int length=fangwei.GetLength();
		if(length!=4)
		{
			AfxMessageBox("请填完整4个字符的方位信息!");
			return;
		}
		file.open("基站数据.txt", ios::out|ios::ate);
		if(!file)
		{
		}
		else
		{	
			file<<cellid<<'\t'<<fangwei<<'\t'<<location<<'\t'<<jingdu<<'\t'<<weidu<<'\n';
			file.close();
		}
		OnCellid();
	}
}

void CMapDlg::OnOpencom() 
{
	// TODO: Add your control notification handler code here

	UpdateData(true);
	CString comm;
	int com_index=m_Comm.GetCurSel();
	if(com_index!=-1)
	{
		m_Comm.GetLBText(com_index,comm);
		char temp[7];
		temp[5]='\0';
		temp[6]='\0';
		temp[4]='\0';
		strncpy(temp,(LPCTSTR)comm,sizeof(temp));  

		char tmp[4];
		tmp[0]=temp[3];
		tmp[1]=temp[4];
		tmp[2]=temp[5];
		tmp[4]=temp[6];

		int comnum=atoi(tmp);

		m_MSComm.SetCommPort(comnum); //选择COM1
		m_MSComm.SetInBufferSize(1024); //接收缓冲区
		m_MSComm.SetOutBufferSize(1024);//发送缓冲区
		m_MSComm.SetInputLen(0);//设置当前接收区数据长度为0,表示全部读取
		m_MSComm.SetInputMode(1);//以二进制方式读写数据
		m_MSComm.SetRThreshold(500);//接收缓冲区有1个及1个以上字符时,将引发接收数据的OnComm事件
		m_MSComm.SetSettings("9600,n,8,1");//波特率9600无检验位,8个数据位,1个停止位
		int flag=m_MSComm.GetPortOpen();
		if(!flag)//如果串口没有打开则打开
		{
			m_MSComm.SetPortOpen(TRUE);//打开串口
			m_OK=1;
		}
		else
		{
			m_MSComm.SetOutBufferCount(0);
			AfxMessageBox("Open The Serial Port Failure!");
			m_OK=0;
		}
		InitalTC35i();
	}
}

void CMapDlg::OnManu() 
{
	// TODO: Add your control notification handler code here
	KillTimer(1);
	m_time="";
}

void CMapDlg::OnAuto() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_autorefresh<5||m_autorefresh>10000)
		m_autorefresh=5;
	m_time="auto";
	SetTimer(1,m_autorefresh*1000,NULL);
}

void CMapDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_mode=="CELLID")
		OnCellid();
	else if(m_mode=="CELLINFO")
		OnCellinfo();
	CDialog::OnTimer(nIDEvent);
}

void CMapDlg::OnChangeAutorefresh() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	if(m_time=="auto")
	{
		OnManu();
		OnAuto();
	}

}

⌨️ 快捷键说明

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