|
<div id="postmessage_56" class="t_msgfont"> GPS接收头文件
// GPSProc.h: interface for the CGPSProc class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GPSPROC_H__269CB4AA_ABCE_4E9D_B27E_CB2B485C9B8B__INCLUDED_)
#define AFX_GPSPROC_H__269CB4AA_ABCE_4E9D_B27E_CB2B485C9B8B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include
#include
#include
#include
#include
#include "GPSView.h"
#include"DAView.h"
typedef struct _GPSData
{
double LGTD; //中心点X
double LTTD; //中心点Y
double High;//高度
double Angle; //角度
double Speed;
CString GpsTime;
TCHAR Status;
} GPSData;
extern GPSData g_GPSData;
#define MAXSIZE 255
class CGPSProc
{
public:
CGPSProc();
virtual ~CGPSProc();
public:
};
#endif // !defined(AFX_GPSPROC_H__269CB4AA_ABCE_4E9D_B27E_CB2B485C9B8B__INCLUDED_)
UINT pGPSProcThread(PVOID pArg);
BOOL GPSDataProc(BYTE szText[]);
void GetMsg(BYTE Msg[]);
// GPSProc.cpp: implementation of the CGPSProc class.
//
//////////////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include "stdafx.h"
#include "GPSProc.h"
#include
#include
#include "afxmt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CCriticalSection cri_GPS;
extern CWinThread *pReadThread ;
extern HANDLE hGPSComPort ;
extern BOOL fContinue,fFRContinue,fMRContinue,fSRContinue;
extern int nSpeed ;
extern int nLastDev ;
GPSData g_GPSData;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGPSProc::CGPSProc()
{
}
CGPSProc::~CGPSProc()
{
}
/*GPS数据接收线程*/
UINT pGPSProcThread(PVOID pArg)
{
DWORD cBytes;
DWORD dwMask;
BYTE szText[MAXSIZE] ;
BYTE *pPtr=szText;
int i,sFlag=0;
TCHAR tch;
CPDAView *pView= (CPDAView *)pArg;
// 指定监视串口的一组数据
SetCommMask (hGPSComPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
while (hGPSComPort != INVALID_HANDLE_VALUE)
{
tch = 0;
i = 0;
CString strDataInfo;
// 指定监视串口的一组数据.
WaitCommEvent (hGPSComPort, &dwMask, 0);
//重新指定监视串口的一组数据.
SetCommMask (hGPSComPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
if (dwMask & EV_RXCHAR)
{
// 循环等待数据.
do
{
// 从串口中读取数据.
ReadFile (hGPSComPort, pPtr, 1, &cBytes, 0);
// 显示或处理读到的字符.
if (cBytes == 1)
{
if (*pPtr==&#39;$&#39; && sFlag==0)
{
sFlag = 1;
pPtr++;
}
else if (sFlag ==1 && *pPtr!=&#39;$&#39;)
{
if (*pPtr == 0x0A )
{ /*把收到的GPS数据交由函数处理,处理后返回一个结构变量*/
if(GPSDataProc(szText))
{
keybd_event(1,1,KEYEVENTF_SILENT,0);
PostMessage((HWND)pView,WM_GPSPROC,0,0);
}
pPtr = szText;
sFlag = 0;
}
else
{
pPtr++;
}
}
}
} while (cBytes == 1);
}
}
return 0;
}
/*GPS数据处理程序*/
BOOL GPSDataProc(BYTE szText[])
{
GPSData m_GPSData;
BYTE info[MAXSIZE];
char *GGAhead,*RMChead;
GGAhead = "GPGGA";
RMChead = "GPRMC";
BYTE ptr ;
ptr = 0;
double mdata=0;
/*计算校验和*/
for(int i=1 ; ; i++)
{
info = szText;
if (info==&#39;*&#39;) break;
ptr = ptr^info;
}
int Len = i++;//Len为&#39;*&#39;的位置
info=szText;
i++;
info=szText;
char m_CC[2];
sprintf(m_CC,"%2X",ptr);
<em><em><em><em><em><em><em><em>/*校验和正确则解析数据*/
if (memcmp(m_CC,&info[Len+1],2) == 0 )
{
char infohead[5];
for (int i=0 ; i |
|