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

📄 positiondatadlg.cpp

📁 解析GPS数据消息GPRMC的程序,在VC6下完成,可以解析出经度,纬度,速度等信息.
💻 CPP
字号:
// positiondataDlg.cpp : implementation file
//

#include "stdafx.h"
#include "positiondata.h"
#include "positiondataDlg.h"

#include <atlconv.h>

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

/////////////////////////////////////////////////////////////////////////////
// CPositiondataDlg dialog



CPositiondataDlg::CPositiondataDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPositiondataDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPositiondataDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPositiondataDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPositiondataDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPositiondataDlg, CDialog)
	//{{AFX_MSG_MAP(CPositiondataDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPositiondataDlg message handlers

BOOL CPositiondataDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CPositiondataDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	int i,len;
	char *gprmc="$GPRMC,084647,A,3031.5925,N,11421.3974,E,000.0,194.7,160306,003.5,W,A*05";
	char *sms="123456";
	char gpstest[255];
	char smstest[255];	
	//positioning data frame
	memset(gpstest,0x00,sizeof(gpstest));

	PositionDataPKT(gpstest,gprmc);
	//attemper frame
	memset(smstest,0x00,sizeof(smstest));
	AttemperDataPKT(smstest,sms);
	
#ifdef _UNICODE
		USES_CONVERSION;
		CWnd *pWndPD = GetDlgItem(IDC_EDIT_PD); //得到句柄
		pWndPD->SetWindowText(A2W(gpstest)); //取得内容 付值给变量str

		CWnd *pWndAD = GetDlgItem(IDC_EDIT_AD); //得到句柄
		pWndAD->SetWindowText(A2W(smstest)); //取得内容 付值给变量str
#endif

}

void PositionDataPKT(char *PDstr1,char *strPD)
{
	int i;
	PositionData Pdstr;
	//frame head 0xffff
	Pdstr.framehead[1]=0xff;
	Pdstr.framehead[2]=0xff;
	//version "V10"
	Pdstr.versionNo[1]=0x56;
	Pdstr.versionNo[2]=0x31;
	Pdstr.versionNo[3]=0x30;
	// command number and frame length
	Pdstr.commandNo[1]=0x01;
	Pdstr.commandNo[2]=0x19;
	// car id 0x1000
	Pdstr.carID[1]=0x10;
	Pdstr.carID[2]=0x00;
	//GPS time 0xhh,0xmm,0xss
	Pdstr.GPSTime[1]=0x08;
	Pdstr.GPSTime[2]=0x19;
	Pdstr.GPSTime[3]=0x26;
	//longitude and latitude
	Pdstr.longilati[1]=0x03;
	Pdstr.longilati[2]=0x95;
	Pdstr.longilati[3]=0x81;
	Pdstr.longilati[4]=0x23;
	Pdstr.longilati[5]=0x41;
	Pdstr.longilati[6]=0x16;
	Pdstr.longilati[7]=0x12;
	Pdstr.longilati[8]=0x34;
	Pdstr.longilati[9]=0x56;
    //GPS speed
	Pdstr.speed[1]=0x12;
	Pdstr.speed[1]=0x09;
	//GPS heading
	Pdstr.heading[1]=0x35;
	Pdstr.heading[1]=0x06;
	//GPS mileage
	Pdstr.mileage[1]=0x12;
	Pdstr.mileage[2]=0x34;

	memcpy(PDstr1,(Pdstr.framehead),2);
	strcat(PDstr1,Pdstr.versionNo);
	strcat(PDstr1,Pdstr.commandNo);
	strcat(PDstr1,Pdstr.carID);
	strcat(PDstr1,Pdstr.GPSTime);
	strcat(PDstr1,Pdstr.longilati);
	strcat(PDstr1,Pdstr.speed);
	strcat(PDstr1,Pdstr.heading);
	strcat(PDstr1,Pdstr.mileage);
}
void AttemperDataPKT(char *ADstr1,char *str)
{
	int i;
	char buffer[10];
	AttemperData Adstr;	
	//frame head 0xffff
	Adstr.framehead[0]=0xff;
	Adstr.framehead[1]=0xff;
	//version "V10" 0x56,0x31,0x30
	Adstr.versionNo[0]=0x56;
	Adstr.versionNo[1]=0x31;
	Adstr.versionNo[2]=0x30;	
	//Get sms length
	i=strlen(str);
	//command number:0x20, frame length 2+2+1+n
	Adstr.commandNo[0]=0x02;	
	Adstr.commandNo[1]=i+5;
	//car ID	
	Adstr.carID[0]=0x10;
	Adstr.carID[1]=0x00;
	//sms length
	Adstr.SMSlength=i;	
	memset(Adstr.SMS,0x00,sizeof(Adstr.SMS));
	for(int j=0;j<i;j++)
	{
		Adstr.SMS[j*2]=0x7f;
		Adstr.SMS[j*2+1]=str[j];
	}	

	memcpy(ADstr1,(Adstr.framehead),2);
	strcat(ADstr1,Adstr.versionNo);
	strcat(ADstr1,Adstr.commandNo);
	strcat(ADstr1,Adstr.carID);
	_itoa( Adstr.SMSlength, buffer, 16 );
	//strcat(ADstr1,&Adstr.SMSlength);
	strcat(ADstr1,buffer);
	strcat(ADstr1,Adstr.SMS);
	strcat(ADstr1,"\r\n");
}

void CPositiondataDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	SendMessage(WM_CLOSE,0,0);	
}

⌨️ 快捷键说明

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