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

📄 gps_xiaoxidlg.cpp

📁 该程序主要功能是获取gps数据,并且提供解析功能,运行ppc2003下,开发导航系统,或者定位系统的同仁们,可以参考一下.
💻 CPP
字号:
// gps_xiaoxiDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gps_xiaoxi.h"
#include "gps_xiaoxiDlg.h"
#include "GpsComm.h"
#define WM_NEW_DATA_ARRIVE WM_USER+1
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGps_xiaoxiDlg dialog

CGps_xiaoxiDlg::CGps_xiaoxiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGps_xiaoxiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGps_xiaoxiDlg)
	m_StrReceived = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGps_xiaoxiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGps_xiaoxiDlg)
	DDX_Control(pDX, IDC_EDIT1, m_CtrlReceived);
	DDX_Text(pDX, IDC_EDIT1, m_StrReceived);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGps_xiaoxiDlg, CDialog)
	//{{AFX_MSG_MAP(CGps_xiaoxiDlg)
	ON_MESSAGE(WM_NEW_DATA_ARRIVE,OnDataArrivedMsg)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGps_xiaoxiDlg message handlers

BOOL CGps_xiaoxiDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
		int PortNo,BaudRate,DataBits,StopBits,Parity;
//	CString PortID,PortIDs[9];
//	int BaudRates[8];
	PortID="COM6:";
	BaudRates=57600;
	PortNo=1;
	BaudRate=3;
	DataBits=8;
	StopBits=ONESTOPBIT;
	Parity=NOPARITY;
	m_pSerial=new CPSerialPort();
if(	m_pSerial->OpenPort(PortID,BaudRates,DataBits,StopBits,Parity,OnDataArrive,(DWORD)this))
{
    m_pSerial->Activate();
}
	return TRUE;  // return TRUE  unless you set the focus to a control
}


void CGps_xiaoxiDlg::OnDataArrive(char *data,int length,DWORD userdata)
{
	CGps_xiaoxiDlg *pWnd=(CGps_xiaoxiDlg *)userdata;
	::SendMessage(pWnd->m_hWnd,WM_NEW_DATA_ARRIVE,(WPARAM)data,LPARAM(length));
}
void CGps_xiaoxiDlg::OnDataArrivedMsg(WPARAM wParam,LPARAM lParam)
{
	//处理收到的数据
	int length=(int)lParam;
	char *data=(char*)wParam;
//	CString THex(_T(""));
    int RecvIndex = 200;
//	int i;

	if(length!=0)
	{           
		
	    	char		RecvBuf[200];
		        memcpy(	RecvBuf,data,200);
				   
				int	CommType = CGpsComm::CheckCommand(RecvBuf,&RecvIndex);
			if ( CommType) //数据包已经完整
			{

				// 2003-06-30 modified
				// 处理3种数据包, 原来仅仅处理GGA和RMC,现在增加GSA
				CGPSInfo	GPSData;
				if (CommType == CONST_GGA)
				{
					CGpsComm::ProcessGGA((BYTE*)RecvBuf,GPSData);
				}
				 if (CommType == CONST_RMC)
				 {
					CGpsComm::ProcessRMC((BYTE*)RecvBuf,GPSData);
				 }
			    if (CommType == CONST_GSA)
				{
					CGpsComm::ProcessGSA((BYTE*)RecvBuf,GPSData);
				
				}
				
				//arr[1]=CGps_xiaoxiDlg::DoubleToStr(parse.weidu);

                m_CtrlReceived.SetWindowText(DoubleToStr(GPSData.Lat));
				 
                // double i GPSData.Lat
				//	THex.Format(_T("%2X "),data[i]);
			}
			
			
	}
	
}

void CGps_xiaoxiDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	m_pSerial->Deactivate();
}
CString CGps_xiaoxiDlg::DoubleToStr(double num)
{
	char str[30];
	sprintf(str,"%.5f",num);
	return str;
}

⌨️ 快捷键说明

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