📄 pocketgpsdlg.cpp
字号:
// PocketGPSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PocketGPS.h"
#include "PocketGPSDlg.h"
#define COLLECT_COUNT 12
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPocketGPSDlg dialog
CPocketGPSDlg::CPocketGPSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPocketGPSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPocketGPSDlg)
m_strLocation = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bCollecting = FALSE;
m_pFile = NULL;
}
void CPocketGPSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPocketGPSDlg)
DDX_Control(pDX, IDC_COMBO_COM, m_Combo_Com);
DDX_Text(pDX, IDC_EDIT_LOCATION, m_strLocation);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPocketGPSDlg, CDialog)
//{{AFX_MSG_MAP(CPocketGPSDlg)
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPocketGPSDlg message handlers
BOOL CPocketGPSDlg::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
m_Combo_Com.SetCurSel(7);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPocketGPSDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_pFile == NULL){
CString strFileName = _T("\\"+m_strLocation+".txt");
//AfxMessageBox(strFileName);
m_pFile = _wfopen(strFileName,_T("a"));
}
CString strSerial;
UpdateData(TRUE);
m_Combo_Com.GetWindowText(strSerial);
if(!m_Serial.IsOpen())
m_Serial.OpenCom(strSerial);
m_bCollecting = TRUE;
AfxBeginThread(CPocketGPSDlg::ReceiveThread,0);
AfxBeginThread(CPocketGPSDlg::SpliteThread,0);
}
void CPocketGPSDlg::OnButtonClose()
{
// TODO: Add your control notification handler code here
if(m_Serial.IsOpen())
m_Serial.CloseCom();
m_bCollecting = FALSE;
if(m_pFile!=NULL){
fclose(m_pFile);
m_pFile = NULL;
}
}
UINT CPocketGPSDlg::ReceiveThread(LPVOID lpVoid)
{
char str[101];
DWORD wCount; //读取的字节数
CPocketGPSDlg* pMainWnd = (CPocketGPSDlg*)g_pMainWnd;
while(pMainWnd->m_bCollecting)
{
ReadFile(pMainWnd->m_Serial.m_hCom,str, 100, &wCount, NULL);
if(wCount > 0)//收到数据
{
str[wCount] = '\0';
//TRACE((CString)str);
pMainWnd->m_Serial.m_CriticalSection.Lock(1000);
pMainWnd->m_Serial.m_strBuffer+=str;
pMainWnd->m_Serial.m_CriticalSection.Unlock();
}
}
pMainWnd->m_Serial.CloseCom();
return 0;
}
UINT CPocketGPSDlg::SpliteThread(LPVOID lpVoid)
{
CString strGpsInfo;
CPocketGPSDlg* pMainWnd = (CPocketGPSDlg*)g_pMainWnd;
int nLen = 0;
int nCount=0;
BOOL bValid = FALSE;
while (pMainWnd->m_bCollecting)
{
nLen = pMainWnd->m_Serial.m_strBuffer.GetLength();
if(nLen<=0)
continue;
int nIndex = pMainWnd->m_Serial.m_strBuffer.Find(_T("\n"),0);
if(nIndex>0)
{
pMainWnd->m_Serial.m_CriticalSection.Lock(1000);
strGpsInfo = pMainWnd->m_Serial.m_strBuffer.Left(nIndex)+"\0";
pMainWnd->m_Serial.m_CriticalSection.Unlock();
strGpsInfo+= _T("\n");
pMainWnd->m_Serial.m_strBuffer = pMainWnd->m_Serial.m_strBuffer.Right(nLen - nIndex - 1);
//TRACE(strGpsInfo);
CString strHead = strGpsInfo.Left(6);
if(strHead.CompareNoCase(_T("$GPGSA"))==0)
{
if(strGpsInfo.GetAt(9)=='1'){
bValid = FALSE;
}
else{
if(!bValid)
::MessageBox(pMainWnd->m_hWnd,_T("get valid data!"),_T("PocketGPS"),MB_OK|MB_ICONINFORMATION);
//::AfxMessageBox(_T("get valid data!"));
bValid = TRUE;
}
}
if(bValid &&
((strHead.CompareNoCase(_T("$GPGGA"))==0)||
(strHead.CompareNoCase(_T("$GPRMC"))==0))){
fwprintf(pMainWnd->m_pFile,strGpsInfo.GetBuffer(0));
nCount++;
}
}
if(nCount>=COLLECT_COUNT)
{
::AfxMessageBox(_T("collect complete"));
//pMainWnd->m_bCollecting=FALSE;
break;
}
}
pMainWnd->OnButtonClose();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -