?? gpsview.cpp
字號:
// gpsView.cpp : implementation of the CGpsView class
//
#include "stdafx.h"
#include "gps.h"
#include "gpsDoc.h"
#include "gpsView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
long g_lon;
long g_lat;
FILE *fGpsLog=NULL;
SYSTEMTIME sttt;
char strGpsLogTime[256];
char strGpsLogMsg[256];
/////////////////////////////////////////////////////////////////////////////
// CGpsView
IMPLEMENT_DYNCREATE(CGpsView, CView)
BEGIN_MESSAGE_MAP(CGpsView, CView)
//{{AFX_MSG_MAP(CGpsView)
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGpsView construction/destruction
CGpsView::CGpsView()
{
// TODO: add construction code here
}
CGpsView::~CGpsView()
{
}
BOOL CGpsView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGpsView drawing
void CGpsView::OnDraw(CDC* pDC)
{
CGpsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CGpsView diagnostics
#ifdef _DEBUG
void CGpsView::AssertValid() const
{
CView::AssertValid();
}
void CGpsView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGpsDoc* CGpsView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGpsDoc)));
return (CGpsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGpsView message handlers
int CGpsView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//////////////
fGpsLog=fopen("\\Gpses\\Gps.log","w+");
////////////////////////
// 初始化location、dbpath和pApo...
ScStartupParams sp;
ZeroMemory( &sp, sizeof( ScStartupParams ) );
sp.hWnd = (ScLong)m_hWnd;
wcscpy( sp.sAppDir, APP_DIR );
wcscpy( sp.sWorkDir, WORK_DIR );
sp.reserved = (long)GetDC()->GetSafeHdc();
sp.pApo = this;
// 初始化,這里會自己加載SC的設置,所以不用調用ScLoadSetting
ScLong err = ScInit( &sp );
if ( 0 != err ){
MessageBox( _T("ScInit Failed!") );
return -1;
}
// 設置接收器
err = ScSetApObserver(this);
err = ScLoadDb( MAP_DIR);
if ( 0 != err )
{
MessageBox( _T("ScLoadDb Failed!") );
return -1;
}
ScGlobalSettings gs; //SC提供的外界可用的系統設置
ScQueryGlobalSettings(&gs);
ScSetUiPosition( gs.m_Vehicle.position);
gs_m_ScaleValue=gs.m_ScaleValue;
ScMapLocate(HAN_WANG_CENTER_LON, HAN_WANG_CENTER_LAT, gs.m_ScaleValue);
ScZoomScale(-1,-1,0);
ScRefreshMap( 0 );
ScOption op;
op.flags = SC_OP_NORTHUP | SC_OP_SCREENORIENT | SC_OP_RT;
op.autolocate = 1;
op.northup = 0; // 1 is not northup
op.iRecTrk = 0;//軌跡消除
op.voicevolume = 0;//靜音
ScUpdateOption(&op);
ScGpsParams gpsparams;
ZeroMemory( &gpsparams, sizeof( gpsparams ) );
gpsparams.option = SC_CO_SPECIFIED;
gpsparams.dcType = SC_DC_GPS;
gpsparams.commType = SC_SOCKET_COMM;
lstrcpy( gpsparams.SocketParam.sDeviceName, _T("GSpace GS-R232") );
//////////////
/*if(0 != ScModuleGpsOpen( &gpsparams ) )
{
MessageBox( _T("Open GPS Error!"),_T("Error"),MB_OK);
return -1;
}*/
long nFindGPS=ScAutoFindGPS(9600);
CString strFindGPS;
strFindGPS.Format(_T("FindGPS:%d"),nFindGPS);
// MessageBox(strFindGPS);
m_nGpsTimer=SetTimer(GPSTimer,GPS_INTERVAL,0);
return 0;
}
void CGpsView::OnTimer(UINT nIDEvent)
{
if (nIDEvent==GPSTimer)
{
///////////////////////////////GPS location
ScGPSStatusInfo sGpsInfo;
memset(&sGpsInfo,0,sizeof(sGpsInfo));
CDC* pdc=GetDC( );
RECT rectb;
rectb.top=10;
rectb.bottom=70;
rectb.left=10;
rectb.right=240;
/* CString strlonlatB;
strlonlatB.Format(_T("begore,lon:%d,lat:%d,status:%d"),
(long)(sGpsInfo.PositionInfo.position.longitude),
(long)(sGpsInfo.PositionInfo.position.latitude),
sGpsInfo.PositionInfo.status);
pdc->DrawText(strlonlatB,&rectb,DT_LEFT);
*/
ScGetGpsStatusInfo(&sGpsInfo); //獲取GPS定位狀態
int nGPS_Status=sGpsInfo.PositionInfo.status;
if (nGPS_Status==5)
{
///////////////
///////////////GPS Log
long llon=0;
long llat=0;
llon=(long)(sGpsInfo.PositionInfo.position.longitude);
llat=(long)(sGpsInfo.PositionInfo.position.latitude);
GetSystemTime(&sttt);
memset(strGpsLogTime,'\0',sizeof(strGpsLogTime));
sprintf(strGpsLogTime,"%d:%d:%d.%d",sttt.wHour,sttt.wMinute,sttt.wSecond,sttt.wMilliseconds);
memset(strGpsLogMsg,'\0',sizeof(strGpsLogMsg));
sprintf(strGpsLogMsg,"Time:%s,llon is:%d, llat is:%d\n",strGpsLogTime, llon, llat);
fwrite(strGpsLogMsg,strlen(strGpsLogMsg),1,fGpsLog);
fflush(fGpsLog);
///////////////End GPS Log
////////////////
RECT recta;
recta.top=100;
recta.bottom=250;
recta.left=10;
recta.right=240;
CString strlonlatA;
strlonlatA.Format(_T("afterA,lon:%d,lat:%d\n,status:%d"),
(long)(sGpsInfo.PositionInfo.position.longitude),
(long)(sGpsInfo.PositionInfo.position.latitude),
sGpsInfo.PositionInfo.status);
pdc->DrawText(strlonlatA,&recta,DT_LEFT);
}
}
CView::OnTimer(nIDEvent);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -