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

📄 fakebtclientengine.cpp

📁 SYMBIAN GPS NMEA协议实现
💻 CPP
字号:
/************************************************************************/
/* Bluteooth Test           The.Berlin.Factor                 Juni 2003 */
/************************************************************************/

#include <E32Math.h>

#include "gps/bt/FakeBtClientEngine.h"
#include "gps/bt/BtDataListener.h"



CFakeBtClientEngine * CFakeBtClientEngine::NewL( ) {

	CFakeBtClientEngine * self = new ( ELeave ) CFakeBtClientEngine( );

	CleanupStack::PushL( self );
	self->ConstructL( );
	CleanupStack::Pop( );

	return( self );
}



CFakeBtClientEngine::CFakeBtClientEngine( ) : CActive( EPriorityStandard ) {

}



CFakeBtClientEngine::~CFakeBtClientEngine( ) {

	Cancel( );

	iTimer.Close( );

	iListener = NULL;

}



void CFakeBtClientEngine::ConstructL( ) {

	CActiveScheduler::Add( this );

	// Create a timer for periodic checking of data file
	iTimer.CreateLocal( );

	// Start the fakeing
	iTimer.After( iStatus, 500000 );
    SetActive( );

}



void CFakeBtClientEngine::RunL( ) {

	ReadData( );
	NotifyListener( );

    iTimer.After( iStatus, 2500000 );
    SetActive( );

}



void CFakeBtClientEngine::DoCancel( ) {

	iTimer.Cancel( );

}



void CFakeBtClientEngine::ReadData( ) {

	iDataBuffer.SetLength( 0 );

	TUint32 messageType = Math::Random( ) % 5;

	switch ( messageType ) {

		case 0:
			FakeGPGGAMsg( );
			FakeGPGGAMsg( );
			break;

		case 1:
			FakeGPVTGMsg( );
			break;

		default:
			FakeUnknownMsg( );
			break;

	}

}



void CFakeBtClientEngine::FakeGPGGAMsg( ) {

	TUint32 thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '?' );

	TTime time;					// time in microseconds since 0AD nominal Gregorian
	time.HomeTime();			// set time to home time

	TDateTime dateTime;			// year-month-day-hour-minute-second-microsecond
	dateTime = time.DateTime();	// convert to fields

	_LIT( KFakeID, "\n\r$GPGGA," );
	iDataBuffer.Append( KFakeID );

	iDataBuffer.AppendNumFixedWidth( dateTime.Hour( ), EDecimal, 2 );
	iDataBuffer.AppendNumFixedWidth( dateTime.Minute( ), EDecimal, 2 );
	iDataBuffer.AppendNumFixedWidth( dateTime.Second( ), EDecimal, 2 );

	_LIT( KFakeLatLon, ".00,5230.3877,N,1328.1953,E," );
	iDataBuffer.Append( KFakeLatLon );

	_LIT( KFakeStuff, "1,09,1.1,30.6,M,18.1,M,,*5D\n\r" );
	iDataBuffer.Append( KFakeStuff );

	thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '#' );

}



void CFakeBtClientEngine::FakeGPGLLMsg( ) {

	TUint32 thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '?' );

	_LIT( KFakeID, "\n\r$GPGLL," );
	iDataBuffer.Append( KFakeID );

	_LIT( KFakeLatLon, "5230.3877,N,1328.1953,E," );
	iDataBuffer.Append( KFakeLatLon );

	TTime time;					// time in microseconds since 0AD nominal Gregorian
	time.HomeTime();			// set time to home time

	TDateTime dateTime;			// year-month-day-hour-minute-second-microsecond
	dateTime = time.DateTime();	// convert to fields

	iDataBuffer.AppendNumFixedWidth( dateTime.Hour( ), EDecimal, 2 );
	iDataBuffer.AppendNumFixedWidth( dateTime.Minute( ), EDecimal, 2 );
	iDataBuffer.AppendNumFixedWidth( dateTime.Second( ), EDecimal, 2 );

	_LIT( KFakeStuff, ".00,A,A*5D\n\r" );
	iDataBuffer.Append( KFakeStuff );

	thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '#' );

}



void CFakeBtClientEngine::FakeGPVTGMsg( ) {

	TUint32 thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '?' );

	_LIT( KFakeMessage, "\n\r$GPVTG,165.6,T,165.6,M,0019.5,N,0036.0,K*46\n\r" );
	iDataBuffer.Append( KFakeMessage );

}



void CFakeBtClientEngine::FakeUnknownMsg( ) {

	TUint32 thrashBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '?' );

	_LIT( KFakeID, "\n\r$GPSXYZ," );
	iDataBuffer.Append( KFakeID );

	TUint32 dataBytes = Math::Random( ) % 20;
	for ( TUint32 idx = 0; idx < dataBytes; idx++ )
		iDataBuffer.Append( 'D' );

	_LIT( KFakeStuff, "*7A\n\r" );
	iDataBuffer.Append( KFakeStuff );

	thrashBytes = Math::Random( ) % 30;
	for ( TUint32 idx = 0; idx < thrashBytes; idx++ )
		iDataBuffer.Append( '_' );

}



void CFakeBtClientEngine::NotifyListener( ) {

	iListener->DataUpdate( iDataBuffer );

}

⌨️ 快捷键说明

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