📄 fakegpsreceiver.cpp
字号:
/************************************************************************/
/* Bluteooth Test The.Berlin.Factor Juni 2003 */
/************************************************************************/
#include <E32Math.h>
#include "gps/impl/FakeGpsReceiver.h"
#define PI 3.14145
static const TInt KDefaultInitialDelay = 1000; /*milli-seconds*/
static const TInt KDefaultPeriodicInterval = 1000; /*milli-seconds*/
static const TReal KDefaultLatitude = 13.4699217;
static const TReal KDefaultLongitude = 52.5064617;
static const TReal KDefaultRadius = 0.0125;
static const TReal KDefaultSimulationSpeed = 0.025;
CFakeGpsReceiver * CFakeGpsReceiver::NewL( ) {
CFakeGpsReceiver * self = NewLC( );
CleanupStack::Pop( );
return( self );
}
CFakeGpsReceiver * CFakeGpsReceiver::NewLC( ) {
CFakeGpsReceiver * self = new ( ELeave ) CFakeGpsReceiver( );
CleanupStack::PushL( self );
self->ConstructL( );
return( self );
}
CFakeGpsReceiver::CFakeGpsReceiver( ) {
}
CFakeGpsReceiver::~CFakeGpsReceiver( ) {
delete( iHeartBeat ); iHeartBeat = NULL;
}
void CFakeGpsReceiver::ConstructL( ) {
SetDefaults( );
TTimeIntervalMicroSeconds32 delay( KDefaultInitialDelay * 1000 );
TTimeIntervalMicroSeconds32 interval( KDefaultPeriodicInterval * 1000 );
TCallBack callBack( HeartBeat, this );
iHeartBeat = CPeriodic::New( CActive::EPriorityStandard );
iHeartBeat->Start( delay, interval, callBack );
iLastPos.SetTimeInfo( 0, 2425 );
}
void CFakeGpsReceiver::SetDefaults( ) {
iCenterPos.Set( KDefaultLatitude, KDefaultLongitude );
iRadius = KDefaultRadius;
iSimulationSpeed = KDefaultSimulationSpeed;
}
void CFakeGpsReceiver::AdvanceSimulation( ) {
TReal sin, cos;
Math::Sin( sin, iSimulationPosition );
Math::Cos( cos, iSimulationPosition );
TReal xPos = iCenterPos.Longitude( ) + sin * iRadius;
TReal yPos = iCenterPos.Latitude( ) + cos * iRadius;
TReal utcTime = iLastPos.UtcTime( ) + 1;
if ( utcTime > ( 60 * 60 * 24 ) )
utcTime = 0;
TReal heading = iSimulationPosition * 360 / 2 * PI + 90;
if ( heading > 360 ) heading -= 360;
iLastPos.Set( xPos, yPos );
iLastPos.SetExtendedInfo( ETrue, 8, 1.1 );
iLastPos.SetTimeInfo( utcTime, iLastPos.TickCount( ) + 12 );
iLastPos.SetCourseData( heading, 19.5, ETrue );
// TODO: Idealerweise geht man hier nicht synchron ab, sondern legt die
// neue Position in eine Queue und verarbeitet diese asynchron. Damit
// der CallBack nicht zu lange braucht.. wegen CPeriodic Timer..
SendUpdate( iLastPos );
iSimulationPosition += iSimulationSpeed;
while ( iSimulationPosition >= 2 * PI )
iSimulationPosition -= 2 * PI;
}
TInt CFakeGpsReceiver::HeartBeat( TAny * aPtr ) {
CFakeGpsReceiver * gpsReceiver = STATIC_CAST( CFakeGpsReceiver *, aPtr );
gpsReceiver->AdvanceSimulation( );
return( 0 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -