【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了GPSManagerView.cpp提供大家参考,希望对大家有所帮助!
// GPSManagerView.cpp : implementation of the CGPSManagerView class
//
#include "stdafx.h"
#include "GPSManager.h"
#include "GPSManagerDoc.h"
#include "GPSManagerView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 串行端口
char *g_Port[] = {
"COM1",
"COM2",
"COM3",
"COM4"
};
/////////////////////////////////////////////////////////////////////////////
// CGPSManagerView
IMPLEMENT_DYNCREATE(CGPSManagerView, CFormView)
BEGIN_MESSAGE_MAP(CGPSManagerView, CFormView)
//{{AFX_MSG_MAP(CGPSManagerView)
ON_CBN_SELCHANGE(IDC_PORT, OnSelchangePort)
ON_BN_CLICKED(IDC_GETDATA, OnGetdata)
ON_MESSAGE(WM_SHOWGPSDATA, OnShowGPSData)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPSManagerView construction/destruction
CGPSManagerView::CGPSManagerView()
: CFormView(CGPSManagerView::IDD)
{
//{{AFX_DATA_INIT(CGPSManagerView)
m_dAlt = 0.0;
m_bGetData = FALSE;
m_sTime = _T("");
m_sLat = _T("");
m_sLon = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
// 得到通信端口参数
m_nPort = 0;
}
CGPSManagerView::~CGPSManagerView()
{
}
void CGPSManagerView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGPSManagerView)
DDX_Control(pDX, IDC_PORT, m_ctrlPort);
DDX_Text(pDX, IDC_ALT, m_dAlt);
DDX_Check(pDX, IDC_GETDATA, m_bGetData);
DDX_Text(pDX, IDC_TIME, m_sTime);
DDX_Text(pDX, IDC_LAT, m_sLat);
DDX_Text(pDX, IDC_LON, m_sLon);
//}}AFX_DATA_MAP
}
BOOL CGPSManagerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CGPSManagerView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
// 使用保存的端口设置
m_ctrlPort.SetCurSel(m_nPort);
m_clsGPS.m_pView = this;
}
/////////////////////////////////////////////////////////////////////////////
// CGPSManagerView diagnostics
#ifdef _DEBUG
void CGPSManagerView::AssertValid() const
{
CFormView::AssertValid();
}
void CGPSManagerView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CGPSManagerDoc* CGPSManagerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPSManagerDoc)));
return (CGPSManagerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGPSManagerView message handlers
/*************************************************************************
*
* 函数名称:
* OnSelchangePort()
*
* 参数:
* 无
*
* 返回值:
* 无
*
* 说明:
* 更改GPS数据采集端口
*
************************************************************************/
void CGPSManagerView::OnSelchangePort()
{
// 得到设置的端口号
m_nPort = m_ctrlPort.GetCurSel();
}
/*************************************************************************
*
* 函数名称:
* OnGetdata()
*
* 参数:
* 无
*
* 返回值:
* 无
*
* 说明:
* 控制GPS数据的采集与终止
*
************************************************************************/
void CGPSManagerView::OnGetdata()
{
// 更新显示
UpdateData();
if (m_bGetData == TRUE)
{
// 打开串口开始采集数据
if (m_clsGPS.OpenPort(g_Port[m_nPort], CBR_4800) == FALSE)
{
MessageBox("GPS串口未打开,请重新检查后再使用本项功能!", "错误", MB_OK | MB_ICONERROR);
m_bGetData = FALSE;
UpdateData(FALSE);
return;
}
// GPS接收期间禁止更改串口设置
GetDlgItem(IDC_PORT)->EnableWindow(FALSE);
}
else
{
// 关闭串口
if (m_clsGPS.ClosePort() == FALSE)
{
MessageBox("GPS串口未能关闭,请稍后重试!", "错误", MB_OK | MB_ICONERROR);
return;
}
// GPS接收完毕后允许更改串口设置
GetDlgItem(IDC_PORT)->EnableWindow(TRUE);
}
}
/*************************************************************************
*
* 函数名称:
* OnShowGPSData()
*
* 参数:
* 无
*
* 返回值:
* 无
*
* 说明:
* 显示接收到的GPS定位数据
*
************************************************************************/
void CGPSManagerView::OnShowGPSData()
{
// GPS信息显示
m_sLon.Format("%3.6f", m_clsGPS.m_dLon);
m_sLat.Format("%2.6f", m_clsGPS.m_dLat);
m_dAlt = m_clsGPS.m_dAlt;
m_sTime.Format("%04d-%02d-%02d %02d:%02d:%02d",
m_clsGPS.m_lYear,
m_clsGPS.m_lMonth,
m_clsGPS.m_lDay,
m_clsGPS.m_lHour,
m_clsGPS.m_lMinute,
m_clsGPS.m_lSecond);
// 更新显示
UpdateData(FALSE);
}
/*************************************************************************
*
* 函数名称:
* OnClose()
*
* 参数:
* 无
*
* 返回值:
* 无
*
* 说明:
* 程序退出处理
*
************************************************************************/
void CGPSManagerView::OnClose()
{
// 关闭GPS
if (m_bGetData == TRUE)
{
// 关闭串口
if (m_clsGPS.ClosePort() == FALSE)
{
MessageBox("GPS串口未能关闭,请稍后重试!", "错误", MB_OK | MB_ICONERROR);
return;
}
}
CFormView::OnClose();
}
上一篇:
LUNARCAL.PAS
下一篇:
临床前药物安全性评价中毒性病理学新技术的应用