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

📄 bluegpsclientappui.cpp

📁 S60系统下的蓝牙GPS连接程序 包括client和server端的连接方式
💻 CPP
字号:
/*****************************************************************************
 File: BlueGPSClientUi.cpp

 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 The use of the software is subject to the terms of the end-user license
 agreement which accompanies or is included with the software. The software is
 provided "as is" and Sony Ericsson specifically disclaim any warranty or
 condition whatsoever regarding merchantability or fitness for a specific
 purpose, title or non-infringement. No warranty of any kind is made in
 relation to the condition, suitability, availability, accuracy, reliability,
 merchantability and/or non-infringement of the software provided herein.

 *****************************************************************************/


#include "BlueGPSClientAppUi.h"
#include "BlueGPSClientDocument.h"


#define infoPrint(text, secs) { \
	RNotifier notifier; \
	notifier.Connect(); \
	notifier.InfoPrint(text); \
	User::After( 1000000 * secs); \
	notifier.Close(); \
}


void CBlueGPSClientAppUi::ConstructL()
{
	iReadBuffer = &y;
	CQikAppUi::ConstructL();
	iAppView = CBlueGPSClientAppView::NewL( ClientRect() );
	
	// Connect through ServSession to our server
	TInt res = iServSession.Connect();
	if( res != KErrNone )
	{
		infoPrint( _L("Error connecting to server"), 2 );
		iConnectedToServer = EFalse;
	}
	else
	{
		iConnectedToServer = ETrue;
		//infoPrint( _L("Connected to Server"), 2 );
	}	

	iInfoUpdater = CInfoUpdater::NewL( &iServSession, iConnectedToServer, iAppView );
}	


CBlueGPSClientAppUi::CBlueGPSClientAppUi() 
{
}


CBlueGPSClientAppUi::~CBlueGPSClientAppUi()
{
	delete iInfoUpdater;
	delete iAppView;
}


/***********************************************************
/*	HandleCommandL(TInt aCommand)
/***********************************************************/
void CBlueGPSClientAppUi::HandleCommandL(TInt aCommand)
{
	TBuf<64> gpsBuf;
	//_LIT( tempText, "Longitude: %d, %d %d.%d Latitude: %d, %d %d.%d" );
	TBool connected = EFalse;
	TInt res;

	switch (aCommand)
    {

  	// Select remote device   
	case EBlueGPSClientCmd0:
		iInfoUpdater->Cancel();

		res = SelectRemoteBTDeviceL();
		if ( res == KErrNone )
		{
			iServSession.NewDevice();
			iInfoUpdater->Start();	
		}

		// Cancel is chosen and we are still connected to a device 
		else if( res == KErrCancel && iServSession.GetConnectStatus())
		{ 
			iInfoUpdater->Start();
		}

		break;

	// Connect
    case EBlueGPSClientCmd1:	
		// Kan orsaka fel, kolla om den alltid st鋗mer!!!
		connected = iServSession.GetConnectStatus();

		if ( !connected )
		{
			iServSession.ConnectToDevice();
			iInfoUpdater->Start();	
		}
		else 
			infoPrint( _L("Already connected!"), 1 );
		break;

    case EBlueGPSClientCmd2:	
		iInfoUpdater->iViewMode = ETextViewMode;
		iAppView->SetViewMode(ETextViewMode);
		break;

	case EBlueGPSClientCmd3:
		iInfoUpdater->iViewMode = EGraphicsViewMode;
		iAppView->SetViewMode(EGraphicsViewMode);

		//CloseConnection();
		break;

	// FFF Disconnect
	case EBlueGPSClientCmd4:
		connected = iServSession.GetConnectStatus();

		if ( connected )
		{
		iServSession.DisconnectDevice();
		}
		else
			infoPrint( _L("Not connected!"), 1 );
		break;

	case EEikCmdExit:
		
		iConnectedToServer = EFalse;
		iServSession.Close();
		
		infoPrint( _L("BlueGPS closed"), 1 );
		Exit();
		break;
	}
}
  

/***********************************************************
/*	SelectRemoteBTDeviceL()
/*
/***********************************************************/
TInt CBlueGPSClientAppUi::SelectRemoteBTDeviceL()
{
	TInt serviceFilter = -1;	// Can be used to only display devices with certain services
	
	// M錽te sen kolla med servern om vi har btuppkoppling eller ej
	//if ( !iConnected )
	//{	// 
		CQBTUISelectDialog* dialog = 
				new (ELeave) CQBTUISelectDialog(iRemoteDevAddr, 
												iRemoteDevName, 
												iRemoteDevClass, 
												CQBTUISelectDialog::EQBTDeviceFilterAll, 
												serviceFilter/*, ETrue*/);
		CleanupStack::PushL(dialog);
		// Launch Select Bluetooth device dialog 
		if(dialog->LaunchSingleSelectDialogLD())
		{
			CleanupStack::Pop(dialog);
			//infoPrint( _L("Device selected:"), 1);
			//infoPrint( iRemoteDevName, 1);

			// For the logfile...	
			RFs fileSession;
			TBuf<64> fileName;	
			_LIT( KFile, "C:\\documents\\BlueGPS_devAddr.txt");
			fileName = KFile;
			User::LeaveIfError( fileSession.Connect() );

			TInt err = iFile.Replace( fileSession, fileName, EFileWrite );
			if ( err == KErrNone )
			{
				TBuf16<128> iTemp;
				iTemp.Copy(iRemoteDevAddr.Des());
				PrintLog( iTemp );
			}	


			iFile.Close();
			fileSession.Close();
			//iServSession.NewDevice();	
			return KErrNone;
			
		}
		else
		{
			CleanupStack::Pop(dialog);
			return KErrCancel;
		}
	/*}
	else
	{
		return KErrNotReady;
	}*/
}


void CBlueGPSClientAppUi::PrintLog( const TDesC& aText )
{
	iWriteBuf.Copy( aText );				// TBuf8<1024> iWriteBuf;
	//iFile.Open();
	iFile.Write( 2000, iWriteBuf );			// TInt Write( TInt aPos,const TDesC8& aDes );
	//iFile.Close();
}


/*
 *********************************************************************
 * CInfoUpdater
 *
 *********************************************************************
 */
CBlueGPSClientAppUi::CInfoUpdater::CInfoUpdater( TBool& aConnectedToServer ) : CActive(EPriorityStandard), 
																			   iConnectedToServer(aConnectedToServer)
{
	//iConnectedToServer = aConnectedToServer;
	CActiveScheduler::Add(this);
}


CBlueGPSClientAppUi::CInfoUpdater::~CInfoUpdater()
{
	Cancel();
	iTimer.Close();
}


CBlueGPSClientAppUi::CInfoUpdater* CBlueGPSClientAppUi::CInfoUpdater::NewL( CBlueGPSClientSession* aServSession, 
																		    TBool& aConnectedToServer,
																			CBlueGPSClientAppView* aAppView)
{
	CInfoUpdater* self = new (ELeave) CInfoUpdater( aConnectedToServer  );
	CleanupStack::PushL( self );
	self->ConstructL( aServSession, aAppView );
	CleanupStack::Pop();
	return self;
}


void CBlueGPSClientAppUi::CInfoUpdater::ConstructL( CBlueGPSClientSession* aServSession, CBlueGPSClientAppView* aAppView )
{
	User::LeaveIfError(iTimer.CreateLocal());
	iServSession = aServSession;
	iAppView = aAppView;
	iViewMode = ETextViewMode;
	iAppView->SetViewMode(ETextViewMode);
	iUpperLeftPositionX = 17.941343;
	iUpperLeftPositionY = 59.483529;
	iLowerRightPositionX = 18.026460;
	iLowerRightPositionY = 59.441469;
	//iConnectedToServer = aConnectedToServer;
}


void CBlueGPSClientAppUi::CInfoUpdater::Start()
{
	if (!IsActive())
	{
		iTimer.After( iStatus, 2000000 );
		SetActive();
	}
}


void CBlueGPSClientAppUi::CInfoUpdater::DoCancel()
{
	iTimer.Cancel();
}


void CBlueGPSClientAppUi::CInfoUpdater::RunL()
{
	TBuf<64> gpsBuf;
	_LIT( longitude, "Long: %c, %d %d.%d"); 
	_LIT( latitude,  "Lat: %c, %d %d.%d" );
	_LIT( time,"UTC: %-B%:0%J%:1%T%:2%S%+B");//.%*C4%:3%+B");
	_LIT( satellites, "Satellites: %d");
	_LIT( speed, "Speed: %d");
	_LIT( heading, "Heading: %d");
	TChar CPLong, CPLat;


	if ( iConnectedToServer )
	{
		TBlueGPSInfo info = iServSession->GetGPSInfo();
		switch(iViewMode)
		{
			case ETextViewMode:
				if (info.iLongitudeCP == EEast) CPLong = 'E';
				else CPLong = 'W';
				if (info.iLatitudeCP == ENorth) CPLat = 'N';
				else CPLat = 'S';

				
				gpsBuf.Format( longitude, CPLong, info.iLongitudeYYY, 
										 info.iLongitudeMM, info.iLongitudeDDDD); 
				iAppView->SetText1( gpsBuf );


				gpsBuf.Format( latitude , CPLat, info.iLatitudeXX, 
										 info.iLatitudeMM, info.iLatitudeDDDD );
				iAppView->SetText2( gpsBuf );
			
				info.iGPSTime.FormatL(gpsBuf,time);
				iAppView->SetText3( gpsBuf );

				gpsBuf.Format( speed , info.iSpeed );

				iAppView->SetText4( gpsBuf );

				gpsBuf.Format( heading , info.iHeading );
				
				iAppView->SetText5( gpsBuf );

				gpsBuf.Format( satellites , info.iNumberSatellites );

				iAppView->SetText6( gpsBuf );




				iAppView->DrawNow();
			break;
			case EGraphicsViewMode:
				TReal64 tempLat	= (TReal64)info.iLatitudeXX 
								+ (TReal64)info.iLatitudeMM / 60
								+ (TReal64)info.iLatitudeDDDD / 60000;
				
				TReal64 tempLong = (TReal64)info.iLongitudeYYY
								 + (TReal64)info.iLongitudeMM / 60
								 + (TReal64)info.iLongitudeDDDD / 60000;

//				tempLat = 59.405552;
//				tempLong = 17.950612;
				TInt mapX = (TInt)(500 * (tempLong - iUpperLeftPositionX) / (iLowerRightPositionX - iUpperLeftPositionX));
				TInt mapY = (TInt)(500 * (tempLat - iUpperLeftPositionY) / (iLowerRightPositionY - iUpperLeftPositionY));
				//TInt mapX = 250;
				//TInt mapY = 250;
				iAppView->UpdatePosition( mapX, mapY );
				iAppView->DrawNow();
				break;
		}

		//infoPrint( gpsBuf, 2 );
	}
	Start();
}

⌨️ 快捷键说明

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