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

📄 gpssimdlg.cpp

📁 模拟GPS的数据格式
💻 CPP
字号:
// GpsSimDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GpsSim.h"
#include "GpsSimDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGpsSimDlg dialog

CGpsSimDlg::CGpsSimDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGpsSimDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGpsSimDlg)
	m_strGroundDir = _T("359.3");
	m_strGroundSpeed = _T("0.7");
	m_strLAT = _T("2841.2996");
	m_strLONG = _T("12128.4473"); 
	m_strMagAngle = _T("4.4");
	m_strUtcData = _T("270706");
	m_strUtcTime = _T("070235");
	m_nLatHemishere = 0;
	m_nLongHemishere = 0;
	m_nMagAngleDir = 1;	
	m_nPosStatus = 0;
	m_strSerialPort = _T("COM1");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGpsSimDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGpsSimDlg)
	DDX_Text(pDX, IDC_EDIT_GROUND_DIR, m_strGroundDir);
	DDX_Text(pDX, IDC_EDIT_GROUND_SPEED, m_strGroundSpeed);
	DDX_Text(pDX, IDC_EDIT_LAT, m_strLAT);
	DDX_Text(pDX, IDC_EDIT_LONG, m_strLONG);
	DDX_Text(pDX, IDC_EDIT_MAG_ANGLE, m_strMagAngle);
	DDX_Text(pDX, IDC_EDIT_UTC_DATA, m_strUtcData);
	DDX_Text(pDX, IDC_EDIT_UTC_TIME, m_strUtcTime);
	DDX_Radio(pDX, IDC_RADIO_LAT_N, m_nLatHemishere);
	DDX_Radio(pDX, IDC_RADIO_LONG_E, m_nLongHemishere);
	DDX_Radio(pDX, IDC_RADIO_MAG_ANGLE_E, m_nMagAngleDir);
	DDX_Radio(pDX, IDC_RADIO_POS_STATUS_ABLE, m_nPosStatus);
	DDX_CBString(pDX, IDC_COMBO_COMPORT, m_strSerialPort);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGpsSimDlg, CDialog)
	//{{AFX_MSG_MAP(CGpsSimDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_UPDATA, OnBtnUpdata)
	ON_BN_CLICKED(IDC_BTN_START_SEND, OnBtnStartSend)
	ON_BN_CLICKED(IDC_BTN_STOP_SEND, OnBtnStopSend)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsSimDlg message handlers

BOOL CGpsSimDlg::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



	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGpsSimDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGpsSimDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CGpsSimDlg::OnBtnUpdata() 
{
	UpdateData(TRUE);

	CString strGpsData;
	strGpsData.Format("GPRMC,%s,%c,%s,%c,%s,%c,%s,%s,%s,%s,%c\0",
					m_strUtcTime,
					m_nPosStatus==0?'A':'V',
					m_strLAT,
					m_nLatHemishere==0?'N':'S',
					m_strLONG,
					m_nLongHemishere==0?'E':'W',
					m_strGroundSpeed,
					m_strGroundDir,
					m_strUtcData,
					m_strMagAngle,
					m_nMagAngleDir==0?'E':'W');
	
	char szBuffer[256];
	memset(szBuffer,0,sizeof(szBuffer));
	sprintf(szBuffer,"%s\0",strGpsData);
	unsigned char cCheckChar = 0;
	for(int i=0;i<sizeof(szBuffer);i++)
		cCheckChar = cCheckChar^szBuffer[i];
	CString strOutData;
	strOutData.Format("$%s*%2X\r\n",strGpsData,cCheckChar);


	SetDlgItemText(IDC_EDIT_OUTSTR,strOutData);


	
}

void CGpsSimDlg::OnBtnStartSend() 
{
	if(m_SerialPort.IsConnected())
	{
		KillTimer(100);
		m_SerialPort.DisconnectPort();
	}
	GetDlgItemText(IDC_COMBO_COMPORT,m_SerialPort.m_PortConfig.szPortName,sizeof(m_SerialPort.m_PortConfig.szPortName));
	
	if(m_SerialPort.ConnectionPort())
		SetTimer(100,1000,NULL);	
	else
		AfxMessageBox("Connection port error");
}

void CGpsSimDlg::OnBtnStopSend() 
{
	m_SerialPort.DisconnectPort();
	KillTimer(100);
}

void CGpsSimDlg::OnTimer(UINT nIDEvent) 
{
	CString strOutData;
	GetDlgItemText(IDC_EDIT_OUTSTR,strOutData);
	
	if(m_SerialPort.WritePortData(strOutData)==FALSE)
		KillTimer(100);
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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