📄 embest_gpsdlg.cpp
字号:
// Embest_GPSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Embest_GPS.h"
#include "Embest_GPSDlg.h"
#include "CSerial.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/****************************************/
DWORD m_nBaud; //波特率
UINT m_nCom; //串口号
BYTE m_cParity; //校验
BYTE m_nDatabits; //数据位
BYTE m_nStopbits; //停止位
CSerial m_Port; //CSerial类对象
BOOL m_bOpenPort;
/////////////////////////////////////////////////////////////////////////////
// CEmbest_GPSDlg dialog
CEmbest_GPSDlg::CEmbest_GPSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEmbest_GPSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEmbest_GPSDlg)
m_Time = _T("");
m_North = _T("");
m_East = _T("");
m_Date = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEmbest_GPSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEmbest_GPSDlg)
DDX_Control(pDX, IDC_STATIC_NORSOU, m_NorSou);
DDX_Control(pDX, IDC_STATIC_EASWES, m_EasWes);
DDX_Control(pDX, IDC_BUTTON_OPEN, m_ctrlOpenPort);
DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlPortStatus);
DDX_Text(pDX, IDC_EDIT_TIME, m_Time);
DDX_Text(pDX, IDC_EDIT_NORTH, m_North);
DDX_Text(pDX, IDC_EDIT_EAST, m_East);
DDX_Text(pDX, IDC_EDIT_DATE, m_Date);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEmbest_GPSDlg, CDialog)
//{{AFX_MSG_MAP(CEmbest_GPSDlg)
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_STATIC_STATUS, OnStaticStatus)
ON_BN_CLICKED(IDC_STATIC_NORSOU, OnStaticNorsou)
ON_EN_CHANGE(IDC_EDIT_DATE, OnChangeEditDate)
ON_BN_CLICKED(IDC_STATIC_EASWES, OnStaticEaswes)
ON_EN_CHANGE(IDC_EDIT_TIME, OnChangeEditTime)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEmbest_GPSDlg message handlers
BOOL CEmbest_GPSDlg::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
m_nBaud = 4800; //波特率
m_nCom = 1; //串口号
m_cParity = 0; //校验
m_nDatabits = 8; //数据位
m_nStopbits = 0; //停止位
m_bOpenPort = TRUE;
return TRUE; // return TRUE unless you set the focus to a control
}
//类中回调函数的定义
void CEmbest_GPSDlg::response(BYTE* point,int bufLen)
{
int i,err = 0,nDotNum = 0;
int dog1 = 0; //看门狗,避免输入信号错误,没有'*'结尾的情况
int dog2 = 0; //看门狗,避免输入信号错误,没有','结尾的情况
int dog3 = 0; //看门狗,避免输入信号错误,没有'$'开头的情况
char *buf = NULL; //储存','到','之间的数据
buf = new char[16];
while(*(point) != '$')
{
point++;
dog3++;
if(dog3 == 100)
goto Wrong;
}
if((*(point) == '$')&&(*(point+2) == 'P')&&(*(point+4) == 'M')&&(*(point+5) == 'C'))
{
while((*(point+1) != '*') && (*(point+2) != '*') && (*(point+3) != '*'))
{
i = 0;
dog1++;
dog2 = 0;
while(*(++point) != ',')
{
dog2++;
buf[i++] = *point;
if(dog2 == 16)
goto Wrong;
}
buf[i] = '\0';
nDotNum++;
switch(nDotNum)
{
case 2:
UpdateData(TRUE);// Greenwich time,063741.998: 6:37:41.998(UT)
m_Time.Format(_T("%d%d : %d%d : %d%d"),int(buf[0])-48,int(buf[1])-48,int(buf[2])-48,int(buf[3])-48,int(buf[4])-48,int(buf[5])-48);
UpdateData(FALSE);
break;
case 3: // Valid(A)/InValid(V)
if(buf[0] == 'V')
{
UpdateData(TRUE);
m_ctrlPortStatus.SetWindowText(_T("InValid Message!"));
UpdateData(FALSE);
err =1;
}
else
{
UpdateData(TRUE);
m_ctrlPortStatus.SetWindowText(_T("Valid Message!"));
UpdateData(FALSE);
err =0;
}
break;
case 4: // 2234.2551,N: North Latitude:22.342551
if(!err)
{
UpdateData(TRUE);
m_North.Format(_T("%d%d.%d%d%d%d"),(int(buf[0])-48),(int(buf[1])-48),(int(buf[2])-48),(int(buf[3])-48),(int(buf[5])-48),(int(buf[6])-48));
UpdateData(FALSE);
}
break;
case 5: // 2234.2551,N: North Latitude:22.342551
if(buf[0] == 'N')
{
UpdateData(TRUE);
m_NorSou.SetWindowText(_T("North Latitude:"));
UpdateData(FALSE);
}
else
{
UpdateData(TRUE);
m_NorSou.SetWindowText(_T("South Latitude:"));
UpdateData(FALSE);
}
break;
case 6: // 11408.0338,E: East Longtitude:114.080338
if(!err)
{
UpdateData(TRUE);
m_East.Format(_T("%d%d%d.%d%d%d%d"),(int(buf[0])-48),(int(buf[1])-48),(int(buf[2])-48),(int(buf[3])-48),(int(buf[4])-48),(int(buf[6])-48),(int(buf[7])-48));
UpdateData(FALSE);
}
break;
case 7: // 2234.2551,N: North Latitude:22.342551
if(buf[0] == 'E')
{
UpdateData(TRUE);
m_EasWes.SetWindowText(_T("East Longtitude:"));
UpdateData(FALSE);
}
else
{
UpdateData(TRUE);
m_EasWes.SetWindowText(_T("West Longtitude:"));
UpdateData(FALSE);
}
break;
case 10: // 150805: 2005-8-15
UpdateData(TRUE);
m_Date.Format(_T("20%d%d - %d%d - %d%d"),int(buf[4])-48,int(buf[5])-48,int(buf[2])-48,int(buf[3])-48,int(buf[0])-48,int(buf[1])-48);
UpdateData(FALSE);
default:
break;
}
if(dog1 == 20)
goto Wrong;
}
}
Wrong:
delete[]buf;
}
void CEmbest_GPSDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
CString strStatus;
m_bOpenPort=(!m_bOpenPort);
if(m_bOpenPort) //关闭串口
{
m_ctrlOpenPort.SetWindowText(_T("OPEN"));
UpdateData();
m_ctrlPortStatus.SetWindowText(_T("GPS Closed"));
UpdateData(FALSE);
KillTimer(m_nTimer);
m_Port.ClosePort();//关闭串口
}
else //打开串口
{
m_ctrlOpenPort.SetWindowText(_T("CLOSE"));
UpdateData();
UpdateData(FALSE);
m_nTimer=SetTimer(1,2000,NULL);
if (m_Port.OpenPort(this, m_nCom, m_nBaud,m_cParity,m_nDatabits,m_nStopbits))
{
UpdateData();
m_ctrlPortStatus.SetWindowText(_T("GPS Opened"));
UpdateData(FALSE);
}
else
{
UpdateData();
m_ctrlPortStatus.SetWindowText(_T("OPEN ERROR!"));
UpdateData(FALSE);
AfxMessageBox(_T("Open port error!"));
}
}
}
void CEmbest_GPSDlg::play()
{
CClientDC dc(this);
CDC offDC;
CBitmap offBitmap;
CDC bmpDC;
CBitmap aniBmp;
offDC.CreateCompatibleDC(&dc);
offBitmap.CreateCompatibleBitmap(&dc,85,85);
offDC.SelectObject(&offBitmap);
//加载位图
aniBmp.LoadBitmap(IDB_BITMAP_ANIMATE);
bmpDC.CreateCompatibleDC(&offDC);
bmpDC.SelectObject(aniBmp);
for(int nCnt=0;nCnt<10;nCnt++)
{
offDC.PatBlt(9,28,85,85,WHITENESS);
TransparentImage(offDC.m_hDC,0,0,85,85,bmpDC.m_hDC,nCnt*85,0,85,85,RGB(255,255,255));
dc.BitBlt(9,28,85,85,&offDC,0,0,SRCCOPY);
Sleep(200);
}
aniBmp.DeleteObject();
bmpDC.DeleteDC();
offBitmap.DeleteObject();
offDC.DeleteDC();
}
void CEmbest_GPSDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1:
// AfxMessageBox(_T("receive!!"));
play();
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
void CEmbest_GPSDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
KillTimer(m_nTimer);
m_Port.ClosePort();//关闭串口
}
void CEmbest_GPSDlg::OnStaticStatus()
{
// TODO: Add your control notification handler code here
}
void CEmbest_GPSDlg::OnStaticNorsou()
{
// TODO: Add your control notification handler code here
}
void CEmbest_GPSDlg::OnChangeEditDate()
{
// 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
}
void CEmbest_GPSDlg::OnStaticEaswes()
{
// TODO: Add your control notification handler code here
}
void CEmbest_GPSDlg::OnChangeEditTime()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_CHANGE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -