//
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description: Location Based Services sample application
//
//
// Include Files
#include "Location.h"
#include <e32base.h>
#include <e32std.h>
#include <e32cons.h> // Console
// Constants
_LIT(KTextConsoleTitle, "Console");
_LIT(KTextFailed, " failed, leave code = %d");
_LIT(KTextPressAnyKey, " [press any key]\n");
// Global Variables
LOCAL_D CConsoleBase* console; // write all messages to this
#include <lbs.h>
#include <lbscommon.h>
#include <LbsErrors.h>
#include <LbsSatellite.h>
RPositionServer server;
RPositioner positioner;
TInt GetModuleIdsL(RArray<TPositionModuleId>& aModuleIds,
TPositionModuleInfo::TTechnologyType aType,
TPositionModuleInfo::TCapabilities aCaps)
{
TUint numModules;
TPositionModuleId modId;
TPositionModuleInfo modInfo;
TPositionModuleStatus modStatus;
aModuleIds.Reset();
// 2. Get the number of modules installed
User::LeaveIfError(server.GetNumModules(numModules));
// 3. Iterate over the modules to get information about each module
// 4. Get the availability of a module
// 5. Get information about the module technology, quality etc.
for (TUint i=0 ; i < numModules ; i++)
{
User::LeaveIfError(server.GetModuleInfoByIndex(i, modInfo));
console->Printf(_L("Found modId = %X\n"),modInfo.ModuleId().iUid);
/* Check module technology type and availability */
TBool modAvailable = modInfo.IsAvailable();
TPositionModuleInfo::TTechnologyType modType = modInfo.TechnologyType();
if ( modAvailable && (modType == aType) )
{
/* Check module capabilities
In this example does the module supply speed information? */
TPositionModuleInfo::TCapabilities caps = modInfo.Capabilities();
if (caps & aCaps == aCaps)
{
// Check module position quality
TPositionQuality quality;
modInfo.GetPositionQuality(quality);
// In this example, check for horizontal accuracy better than 10 metres
TReal horzAccuracy = quality.HorizontalAccuracy();
if ( !Math::IsNaN(horzAccuracy) &&
horzAccuracy < 1000 )
{
// This module has all the required characteristics!
modId = modInfo.ModuleId();
aModuleIds.AppendL(modId);
}
}
}
}
// 6. Close the server session
//CleanupStack::PopAndDestroy(&server);
return aModuleIds.Count();
}
void SetCriteriaL(TPositionCriteria& criteria)
{
// Define module selection criteria
TPositionQuality quality;
//TPositionSelectionOrder order;
// Set required capabilities - want altitude information...
criteria.AddRequiredCapabilities(TPositionModuleInfo::ECapabilityHorizontal);
// Set quality - want horizontal position within 500m
quality.SetHorizontalAccuracy(1000);
// Set ordering - make vertical accuracy a high priority
//User::LeaveIfError(order.SetOrderVerticalAccuracy(TPositionSelectionOrder::EOrderHigh));
criteria.SetRequiredQuality(quality);
//criteria.SetSelectionOrder(order);
}
void GetModuleStateL(TPositionModuleId& modId)
{
TPositionModuleStatus modStatus;
// Get module status
User::LeaveIfError(server.GetModuleStatus(modStatus, modId));
// Use the status
TPositionModuleStatus::TDeviceStatus deviceStatus =
modStatus.DeviceStatus();
TPositionModuleStatus::TDataQualityStatus qualityStatus =
modStatus.DataQualityStatus();
console->Printf(_L("ModuleId = {0x%X} deviceStatus = %d, qualityStatus = %d\n"),modId.iUid,(TInt)deviceStatus,(TInt)qualityStatus);
// Can check the status of the module device - for example check for
// device error
if (deviceStatus == TPositionModuleStatus::EDeviceError)
{
// Device error for this module
console->Printf(_L("Device Error\n"));
return;
}
// Can check the data quality for the module - for example check for loss of data quality
if (qualityStatus == TPositionModuleStatus::EDataQualityLoss)
{
// Loss of quality for this module
console->Printf(_L("Loss Of Quality\n"));
}
}
void GetDegreesString(const TReal64& aDegrees,
TBuf<16>& aDegreesString)
{
const TReal KSecondsInMinute = 60.0;
const TInt KNumWidth = 3;
// Degrees sign delimeter used in formatting methods
_LIT(KDelimDegree,"\xb0"); // "�" symbol
// Dot delimeter used in formatting methods
_LIT(KDelimDot,"\x2e"); // "." symbol
// Plus sign delimeter used in formatting methods
_LIT(KDelimPlus,"\x2b"); // "+" symbol
// Minus sign delimeter used in formatting methods
_LIT(KDelimMinus,"\x2d"); // "-" symbol
// Quotation sign delimeter used in formatting methods
_LIT(KDelimQuot,"\x22"); // "\"" symbol
// Apostrophe sign delimeter used in formatting methods
_LIT(KApostrophe,"\x27"); // "'" symbol
// Not-a-number string
_LIT(KNan,"NaN");
TReal realTmp = 0.0;
// Check if aDegree is a proper number and exit otherwise
if ( Math::IsNaN(aDegrees) )
{
aDegreesString = KNan;
return;
}
// Integer part of the degrees
TInt intDegrees = 0;
if ( Math::Int(realTmp,aDegrees) == KErrNone )
intDegrees = (TInt)realTmp;
// Positive float of the degrees
TReal64 realDegrees = aDegrees;
// Convert to positive values
if ( intDegrees < 0 )
{
intDegrees = -intDegrees;
realDegrees = -realDegrees;
}
// Minutes
TReal64 realMinutes = 0;
if ( Math::Frac(realMinutes,realDegrees) != KErrNone )
{
realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
}
else
{
realMinutes *= KSecondsInMinute;
}
// Integer part of the minutes
TInt intMinutes = 0;
if ( Math::Int(realTmp,realMinutes) == KErrNone )
intMinutes = (TInt)realTmp;
// Seconds
TReal64 realSeconds = 0;
if ( Math::Frac(realSeconds,realMinutes) != KErrNone )
{
realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
}
else
{
realSeconds *= KSecondsInMinute;
}
TInt intSeconds = 0;
if ( Math::Int(realTmp,realSeconds) == KErrNone )
intSeconds = (TInt)realTmp;
// Check the sign of the result
if ( aDegrees >= 0 )
{
aDegreesString.Append(KDelimPlus);
}
else
{
aDegreesString.Append(KDelimMinus);
}
// Add the degrees
TInt64 value = intDegrees;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimDegree);
// Add the minutes
value = intMinutes;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KApostrophe);
// Add the seconds
value = intSeconds;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimQuot);
// Add the separator
aDegreesString.Append(KDelimDot);
// Get six last digits
realSeconds -= intSeconds;
realSeconds *= 1000;
// Add the seconds
aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds), EDecimal, KNumWidth);
}
TInt GetPositionInfoL(TPosition& aPos)
{
RPositionServer serverEx;
RPositioner positionerEx;
// Create a session with the location server
User::Leave