/** Adjusts system time if required. The decision whether the adjustment is needed or not
is based on the following criterias:
 - satellite time must be present in the location update
 - time threshold must be exceeded
 - time from a last adjustment is greater than a defined interval.
 
@param aStatus An error code.
@param TPositionSatelliteInfo Position and time information. 
							  If clock adjustment takes place the TPosition::iTime is 
							  re-set to the satellite time.
@see CLbsAdmin
@see TPositionSatelliteInfo
*/
void CAutoClockAdjust::LocationUpdate(TInt aStatus, TPositionSatelliteInfo& aPosInfo)
	{
	LBSLOG(ELogP1, "CAutoClockAdjust::LocationUpdate()\n");
	TTimeIntervalMicroSeconds timeCorr;
	TTime sysTime;
	TInt err;
	
	// If adjustment on, no error, and satellite information present
	if ((iClockAdjustSetting == CLbsAdmin::EClockAdjustOn) && (aStatus == KErrNone) &&
	    ((aPosInfo.PositionClassType() & EPositionSatelliteInfoClass) == EPositionSatelliteInfoClass))
		{
		// Is is time do do another time adjustment?
		sysTime.UniversalTime();
		if (Abs(sysTime.MicroSecondsFrom(iLastAdjustment).Int64()) > (1000*iAdjustInterval))
			{
			const TPositionSatelliteInfo& satInfo = static_cast<const TPositionSatelliteInfo&>(aPosInfo);
			err = CalculateTimeCorrection(satInfo, timeCorr);
			if (err == KErrNone)
				{
				// Is threshold exceeded? 
				if (Abs(timeCorr.Int64()) > (1000*iAdjustThreshold))
					{
					sysTime.UniversalTime();
					sysTime += timeCorr;
					LBSLOG(ELogP9, "->S CGpsSetClockBase::SetUTCTime() ClockModule\n");
					LBSLOG5(ELogP9, "  > TTime sysTime  = %02d:%02d:%02d.%06d\n", sysTime.DateTime().Hour(), 
																				sysTime.DateTime().Minute(),
																				sysTime.DateTime().Second(),
																				sysTime.DateTime().MicroSecond());

					err = iSetClockImpl->SetUTCTime(sysTime);
					LBSLOG2(ELogP9, "  Return  = %d\n", err);

					if (err == KErrNone)
						{				
						// Sync the position time with the satellite time
						// to avoid re-adjusting the system time by the manual clock adjustment component.
						TPosition pos;
						aPosInfo.GetPosition(pos);
						pos.SetTime(aPosInfo.SatelliteTime());
						aPosInfo.SetPosition(pos);
						LBSLOG2(ELogP2, "ACTION: Clock Adjusted by %ld\n", timeCorr.Int64());
						}
					}
					
				if (err == KErrNone)
					{				
					// Remember the current time even if threshold not exceeded
					iLastAdjustment = sysTime;
					}
				else
					{
					LBSLOG_WARN2(ELogP3, "Clock Adjustment failed. Error: %d\n", err);
					}
				}
			}
		}
	}
Ejemplo n.º 2
0
EXPORT_C void T_LbsUtils::GetConfigured_PosInfosL(const TDesC& aConfigFileName, const TDesC& aConfigSection, RPointerArray<TAny>& aPosInfoArr)
/** Fills a position info array with values read from a configuration ini file.

@param aConfigFileName	The name of the ini file to read. If the file name is empty (0 length) then
						the array will contain a single pos info item with default values.
@param aConfigSection	The section within the ini file to read data from.
@param aPosInfoArr		The pos info array to which the items are added. The array will cleared of
						existing items.
*/
	{
	// Clear array.
	ResetAndDestroy_PosInfoArr(aPosInfoArr);

	// Check for config file, if not present create a single default TPositionInfo.
	if (aConfigFileName.Length() == 0)
		{
		TPositionSatelliteInfo* posInfo = new(ELeave) TPositionSatelliteInfo();
		TPosition position;

		position.SetCoordinate(DEFAULT_NOTIFY_POS_UPDATE_LATITUDE, DEFAULT_NOTIFY_POS_UPDATE_LONGITUDE, DEFAULT_NOTIFY_POS_UPDATE_ALTITUDE);
		position.SetAccuracy(DEFAULT_NOTIFY_POS_UPDATE_HORIZONTAL_ACCURACY, DEFAULT_NOTIFY_POS_UPDATE_VERTICAL_ACCURACY);
		position.SetCurrentTime();
	
		posInfo->SetPosition(position);

		User::LeaveIfError(aPosInfoArr.Append(posInfo));			
		}
	
	else
		{
		CPosInfoConfigReader* reader;
	
		reader = CPosInfoConfigReader::NewL(aConfigFileName, aConfigSection, aPosInfoArr);
		CleanupStack::PushL(reader);
		
		reader->ProcessL();
	
		CleanupStack::PopAndDestroy(reader);
		}
	}
// ---------------------------------------------------------
// CPosPSYClearPositionDataTest::HandlePositionCompleteL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosPSYClearPositionDataTest::HandlePositionCompleteL(
	TInt aCompleteCode,
	TTimeIntervalMicroSeconds /*aRequestTime*/)
	{
	if (iTestStatus == KErrCancel)
		{
		CompleteClearPositionDataTest(iTestStatus);
		return;
		}

	if (iCurrentTestClass == 0 || iCurrentTestClass == EPositionInfoClass)
		{
		_LIT(KTitleTestInfo, "==== Testing clearing of TPositionInfo ====");
		AddTestResultL(KTitleTestInfo, EDisplayMessage);
		if (iPSYInfo.ClassesSupported() & EPositionInfoClass && 
			!(iClassesTested & EPositionInfoClass))
			{
			iCurrentTestClass = EPositionInfoClass;
			
			if (iRequestNumber == 0) 
				{
				iClassesTested |= EPositionInfoClass;
				PerformTestL(aCompleteCode);
				}
			}
		else
			{
			_LIT(KTestInfo, "Clearing of position data tests not performed with TPositionInfo because PSY didn't support it.");
			AddTestResultL(KTestInfo, EInfoMessage);
			}
		}

	if (iCurrentTestClass == 0 || iCurrentTestClass == EPositionGenericInfoClass)
		{
		if (iRequestNumber == 0)
			{
			_LIT(KTestInfoGeneric, "==== Testing clearing of HPositionGenericInfo ====");
			AddTestResultL(KTestInfoGeneric, EDisplayMessage);
			}
		if (iPSYInfo.ClassesSupported() & EPositionGenericInfoClass && 
			!(iClassesTested & EPositionGenericInfoClass))
			{
			iCurrentTestClass = EPositionGenericInfoClass;
			
			if (iRequestNumber == 1) 
				{
				iClassesTested |= EPositionGenericInfoClass;
				PerformTestL(aCompleteCode);	
				}
			else
				{
				HPositionGenericInfo* genInfo = HPositionGenericInfo::NewLC(KPositionGenericInfoDefaultBufferSize * 2, 
													  KPositionGenericInfoDefaultMaxFields * 2);

				SetHPositionGenericInfoDataL(*genInfo);
				CleanupStack::Pop(genInfo);
				genInfo->SetPosition(iPosition);
				iPosInfo = static_cast<TPositionInfo*> (genInfo);
				iRequester->MakeRequest(*iPosInfo);
				iRequestNumber++;
				}
			}
		else
			{
			_LIT(KTestInfo, "Clearing of position data tests not performed with HPositionGenericInfo because PSY didn't support it.");
			AddTestResultL(KTestInfo, EInfoMessage);
			}
		}
    
	if (iCurrentTestClass == 0 || iCurrentTestClass == EPositionCourseInfoClass)
		{
		if (iRequestNumber == 0)
			{
			_LIT(KTestInfo, "==== Testing clearing of TPositionCourseInfo ====");
			AddTestResultL(KTestInfo, EDisplayMessage);
			}
		if (iPSYInfo.ClassesSupported() & EPositionCourseInfoClass && 
			!(iClassesTested & EPositionCourseInfoClass))
			{
			iCurrentTestClass = EPositionCourseInfoClass;
			if (iRequestNumber == 1) 
				{
				iClassesTested |= EPositionCourseInfoClass;
				PerformTestL(aCompleteCode);
				}
			else
				{
				TPositionCourseInfo* courseInfo = new (ELeave) TPositionCourseInfo;
				courseInfo->SetCourse(iCourse);
				courseInfo->SetPosition(iPosition);
				iPosInfo = static_cast<TPositionInfo*> (courseInfo);
				iRequester->MakeRequest(*iPosInfo);
				iRequestNumber++;
				}
			}
		else
			{
			_LIT(KTestInfo, "Clearing of position data tests not performed with TPositionCourseInfo because PSY didn't support it.");
			AddTestResultL(KTestInfo, EInfoMessage);
			}
		}

	if (iCurrentTestClass == 0 || iCurrentTestClass == EPositionSatelliteInfoClass)
		{
		if (iRequestNumber == 0)
			{
			_LIT(KTestInfo, "==== Testing clearing of TPositionSatelliteInfo ====");
			AddTestResultL(KTestInfo, EDisplayMessage);
			}
		if (iPSYInfo.ClassesSupported() & EPositionSatelliteInfoClass &&
			!(iClassesTested & EPositionSatelliteInfoClass))
			{
			iCurrentTestClass = EPositionSatelliteInfoClass;
			if (iRequestNumber == 1)
				{
				iClassesTested |= EPositionSatelliteInfoClass;
				PerformTestL(aCompleteCode);
				}
			else
				{
				TPositionSatelliteInfo* satInfo = new (ELeave) TPositionSatelliteInfo;
				
				satInfo->SetSatelliteTime(KSatelliteTime);
				satInfo->SetHorizontalDoP(KSatelliteHorizontalDoP);
				satInfo->SetVerticalDoP(KSatelliteVerticalDoP);
				satInfo->SetTimeDoP(KSatelliteTimeDoP);

				for (TInt  i = 0; i < KSatelliteNumInView; i++)
					{
					TSatelliteData satellite;
					satellite.SetSatelliteId(KSatelliteId+i);
					satellite.SetAzimuth(KAzimuth);
					satellite.SetElevation(KElevation);
					satellite.SetIsUsed(KIsUsed);
					satellite.SetSignalStrength(KSignalStrength);
	
					satInfo->AppendSatelliteData(satellite);
					}
				
				satInfo->SetCourse(iCourse);
				satInfo->SetPosition(iPosition);
				iPosInfo = static_cast<TPositionInfo*> (satInfo);
				iRequester->MakeRequest(*iPosInfo);
				iRequestNumber++;
				}
			}
		else
			{
			_LIT(KTestInfo, "Clearing of position data tests not performed with TPositionSatelliteInfo because PSY didn't support it.");
			AddTestResultL(KTestInfo, EInfoMessage);
			}
		}
	}