networkprotocolmodules/common/suplrrlpasn1/src/rrlpmeasureposrequest.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19  
       
    20 */
       
    21 
       
    22 #include "RRLP-Messages.h"
       
    23 #include "rrlpmeasureposrequest.h"
       
    24 #include "supldevloggermacros.h" 
       
    25 #include "suplrrlpasn1common.h"
       
    26 #include <math.h>
       
    27 
       
    28 /**
       
    29 Static factory constructor
       
    30 */
       
    31 EXPORT_C CRrlpMeasurePositionRequest* CRrlpMeasurePositionRequest::NewL()
       
    32 	{
       
    33 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::NewL() Begin\n");
       
    34 	CRrlpMeasurePositionRequest* self = new (ELeave) CRrlpMeasurePositionRequest();
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL();
       
    37 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::NewL() End\n");
       
    38 	CleanupStack::Pop(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 /** 
       
    43 Default constructor 
       
    44 */
       
    45 CRrlpMeasurePositionRequest::CRrlpMeasurePositionRequest()
       
    46  : CRrlpMessageBase(ERrlpMeasurePositionReq, EFalse)
       
    47  	{
       
    48  	}
       
    49 
       
    50 /** 
       
    51 Second stage constructor 
       
    52 */
       
    53 void CRrlpMeasurePositionRequest::ConstructL()
       
    54 	{
       
    55 	}
       
    56 		
       
    57 /**
       
    58 Destructor
       
    59 */
       
    60 CRrlpMeasurePositionRequest::~CRrlpMeasurePositionRequest()
       
    61 	{
       
    62 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::~CRrlpMeasurePositionRequest() Begin\n");
       
    63 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::~CRrlpMeasurePositionRequest() End\n");
       
    64 	}
       
    65 
       
    66 /** 
       
    67 PositionInstruct()
       
    68 
       
    69 Populates the Requested Positioning Methods and Quality according to the 
       
    70 Positioning Instructions component of the Measure Position Request message.
       
    71 
       
    72 Note that the field Multiple Sets is ignored (indicates if multiple 
       
    73 information sets may be sent if the device supports this GaNSS feature.
       
    74 
       
    75 Note also that Environment Characterization component is also ignored. This
       
    76 relates to expected multipath and NLOS in the current area.
       
    77 
       
    78 @param aQuality QoP, populated as per received PositionInstruction parameters
       
    79 @param aMethod  Request method, populated according to received PositionInstruction parameters
       
    80 @return error indication, KErrNone otherwise
       
    81 */
       
    82 EXPORT_C TInt CRrlpMeasurePositionRequest::GetPositionInstruct(TLbsNetPosRequestQuality& aQuality, TLbsNetPosRequestMethod&  aMethod)
       
    83 	{
       
    84 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::PositionInstruct() Begin\n");
       
    85 	__ASSERT_DEBUG(iData->component.u.msrPositionReq != NULL, User::Invariant());
       
    86 	
       
    87 	ASN1T_MsrPosition_Req* msgBody = iData->component.u.msrPositionReq;
       
    88 
       
    89 	TInt index = 0;
       
    90 	TInt uncertainty = 0;
       
    91 	TBool uncertaintySpecified = ETrue;
       
    92 	TLbsNetPosMethod posMethods[4];
       
    93 	
       
    94 	// populate aMethod according to requested positioning methods
       
    95 	TBool gpsSupported = (msgBody->positionInstruct.positionMethod != PositionMethod::eotd);
       
    96 	TBool eotdSupported = (msgBody->positionInstruct.positionMethod != PositionMethod::gps);
       
    97 
       
    98 	// build an array of requested pos methods, and set the uncertainty value
       
    99 	switch (msgBody->positionInstruct.methodType.t)
       
   100 		{
       
   101 		case T_MethodType_msAssisted:
       
   102 			if (gpsSupported)
       
   103 				{
       
   104 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   105 				++index;
       
   106 				}
       
   107 			if (eotdSupported)
       
   108 				{
       
   109 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   110 				++index;
       
   111 				}
       
   112 			//Accuracy is an optional parameter in the case of TA 
       
   113 			if (msgBody->positionInstruct.methodType.u.msAssisted->m.accuracyPresent)
       
   114 				{
       
   115 				uncertainty = msgBody->positionInstruct.methodType.u.msAssisted->accuracy;
       
   116 				}
       
   117 			else
       
   118 			    {
       
   119 			     //if accuracy is not being specified
       
   120 			    uncertaintySpecified = EFalse;
       
   121 			    }
       
   122 			break;
       
   123 
       
   124 		case T_MethodType_msBased:
       
   125 			if (gpsSupported)
       
   126 				{
       
   127 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   128 				++index;
       
   129 				}
       
   130 			if (eotdSupported)
       
   131 				{
       
   132 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   133 				++index;
       
   134 				}
       
   135 			
       
   136 			uncertainty = msgBody->positionInstruct.methodType.u.msBased;
       
   137 			break;
       
   138 
       
   139 		case T_MethodType_msBasedPref:
       
   140 			if (gpsSupported)
       
   141 				{
       
   142 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   143 				++index;
       
   144 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   145 				++index;
       
   146 				}
       
   147 			if (eotdSupported)
       
   148 				{
       
   149 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   150 				++index;
       
   151 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   152 				++index;
       
   153 				}
       
   154 			uncertainty = msgBody->positionInstruct.methodType.u.msBasedPref;
       
   155 			break;
       
   156 
       
   157 		case T_MethodType_msAssistedPref:
       
   158 			if (gpsSupported)
       
   159 				{
       
   160 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   161 				++index;
       
   162 				posMethods[index].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);		
       
   163 				++index;
       
   164 				}
       
   165 			if (eotdSupported)
       
   166 				{
       
   167 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   168 				++index;
       
   169 				posMethods[index].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);		
       
   170 				++index;
       
   171 				}
       
   172 			uncertainty = msgBody->positionInstruct.methodType.u.msAssistedPref;
       
   173 			break;
       
   174 
       
   175 		default:
       
   176 			__ASSERT_DEBUG(0, User::Invariant());
       
   177 			return KErrCorrupt;
       
   178 		}
       
   179 	
       
   180 	// populate the return pos method array
       
   181 	// index now indicates number of pos methods in the array
       
   182 	TInt err = aMethod.SetPosMethods(posMethods, index);
       
   183 	if (KErrNone != err)
       
   184 		{
       
   185 		return err;
       
   186 		}
       
   187 	
       
   188 	// set the uncertainty values
       
   189 	if (uncertaintySpecified)
       
   190 	    {
       
   191 	    TReal32 uncertMeters = UncertaintyToMeters(uncertainty);
       
   192 	    aQuality.SetMinHorizontalAccuracy(uncertMeters);
       
   193 	    aQuality.SetMinVerticalAccuracy(uncertMeters);
       
   194 	    }
       
   195 	else
       
   196 	    {
       
   197         // Set accuracy to NaN to prompt LBS to use accuracies from its pre-configured
       
   198         // profiles if available.
       
   199 	    TRealX nan;
       
   200 	    nan.SetNaN();
       
   201         aQuality.SetMinHorizontalAccuracy(nan);
       
   202         aQuality.SetMinVerticalAccuracy(nan);
       
   203 	    }
       
   204     
       
   205 	// set the maximum fix time
       
   206 	TInt fixTimeSec;
       
   207 	fixTimeSec = 1 << msgBody->positionInstruct.measureResponseTime;
       
   208 	TTimeIntervalMicroSeconds timeMs(fixTimeSec * KLbsMilliSeconds);
       
   209 	aQuality.SetMaxFixTime(timeMs);
       
   210 	
       
   211 	// indicate if GPS Timing Of Cell Frames data has been requested
       
   212 	//   see ASN1T_Rel98_MsrPosition_Req_Extension
       
   213 	if (msgBody->m.rel98_MsrPosition_Req_extensionPresent != 0
       
   214 	   && msgBody->rel98_MsrPosition_Req_extension.m.gpsTimeAssistanceMeasurementRequestPresent != 0)
       
   215 	    {
       
   216 	    aMethod.SetGpsTimingOfCellFramesRequested(ETrue);
       
   217 	    }
       
   218 	
       
   219 	// no RRLP component to populate the max fix age parameter.
       
   220 
       
   221 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::PositionInstruct() End\n");
       
   222 	return KErrNone;
       
   223 	}
       
   224 
       
   225 /**
       
   226 UncertaintyToMeters()
       
   227 
       
   228 Converts from uncertainty code to meters, as defined in 3GPP TS 23.032:
       
   229 uncertainty r = C( (1+x)^k - 1 )
       
   230 
       
   231 r = uncertainty in meters
       
   232 C = 10;
       
   233 x = 0.1
       
   234 k = uncertainty code
       
   235 
       
   236 @param  aUncertainty uncertainty value k, as per the above formula
       
   237 @return TReal32 uncertainty in meters
       
   238 */
       
   239 TReal32 CRrlpMeasurePositionRequest::UncertaintyToMeters(TInt aUncertainty)
       
   240 	{
       
   241 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::UncertaintyToMeters() Begin\n");
       
   242 	TReal64 r;
       
   243 	TReal64 xPow;
       
   244 	Math::Pow(xPow, 1.1, aUncertainty);
       
   245 	r = (xPow-1)*10;
       
   246 
       
   247 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::UncertaintyToMeters() End\n");
       
   248 	return (TReal32)r;
       
   249 	}
       
   250 	
       
   251 /** 
       
   252 AssistanceDataPresent()
       
   253 
       
   254 Indicates whether supported assistance data is present in the received message.
       
   255 This implementation supports only receipt of GPS assistance data, hence this
       
   256 method returns ETrue if GPS assistance data is present in the received content.
       
   257 
       
   258 @return ETrue if valid assistance data is present in the received message 
       
   259 */
       
   260 EXPORT_C TBool CRrlpMeasurePositionRequest::AssistanceDataPresent()
       
   261 	{
       
   262 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::AssistanceDataPresent() Begin\n");
       
   263 	__ASSERT_DEBUG(iData != NULL, User::Invariant());
       
   264 	__ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant());
       
   265 	__ASSERT_DEBUG(iData->component.u.msrPositionReq != NULL, User::Invariant());
       
   266 		
       
   267 	if (iData->component.u.msrPositionReq->m.gps_AssistDataPresent == 0)
       
   268 		{
       
   269 		SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::AssistanceDataPresent(EFalse) End\n");
       
   270 		return EFalse;
       
   271 		}
       
   272 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::AssistanceDataPresent(ETrue) End\n");
       
   273 	return ETrue;
       
   274 	}
       
   275 	
       
   276 /** 
       
   277 BuildAssistanceData()
       
   278 
       
   279 @param  aDataMask populated to indicate what assistance data exists
       
   280 @param  aData     reference to assistance data builder object to populate with
       
   281                   received assistance data
       
   282 @return error indication, KErrNone otherwise
       
   283 */
       
   284 EXPORT_C TInt CRrlpMeasurePositionRequest::BuildAssistanceData(TLbsAsistanceDataGroup& aDataMask, RLbsAssistanceDataBuilderSet& aAssistanceDataBuilderSet)
       
   285 	{
       
   286 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::BuildAssistanceData() Begin\n");
       
   287 	__ASSERT_DEBUG(iData != NULL, User::Invariant());
       
   288 	__ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant());
       
   289 	__ASSERT_DEBUG(iData->component.u.msrPositionReq != NULL, User::Invariant());
       
   290 
       
   291 	
       
   292 	// return immediately if no gps assistance data present
       
   293 	if (iData->component.u.msrPositionReq->m.gps_AssistDataPresent == 0)
       
   294 		{
       
   295 		SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::BuildAssistanceData() End (no GPS data present)\n");
       
   296 		return KErrNone;
       
   297 		}
       
   298 
       
   299 	// pointer to the GPS Assistance Data component
       
   300 	ASN1T_ControlHeader& gpsData = iData->component.u.msrPositionReq->gps_AssistData.controlHeader;
       
   301 
       
   302 	SUPLLOG(ELogP1, "CRrlpMeasurePositionRequest::BuildAssistanceData() End\n");
       
   303 	return CRrlpMessageBase::BuildAssistanceData(aDataMask, aAssistanceDataBuilderSet, gpsData);
       
   304 	}
       
   305 
       
   306 
       
   307 /**
       
   308 GetExtendedReference()
       
   309 
       
   310 Populates aRrlpRef if Rel-5 Extended Reference is present in the received message
       
   311 
       
   312 @param  aRrlpRef local copy of the session reference details
       
   313 @return KErrNotFound if the extended reference parameters are not present,
       
   314         KErrNone otherwise
       
   315 */
       
   316 TInt CRrlpMeasurePositionRequest::GetExtendedReference(TRrlpReference& aRrlpRef)
       
   317 	{
       
   318 	__ASSERT_DEBUG(iData->component.u.msrPositionReq != NULL, User::Invariant());
       
   319 	
       
   320 	if (iData->component.u.msrPositionReq->m.rel5_MsrPosition_Req_extensionPresent != 0)
       
   321 		{
       
   322 		aRrlpRef.aRel5EntendedRefPresent = ETrue;
       
   323 		aRrlpRef.aRel5SmlcCode = iData->component.u.msrPositionReq->rel5_MsrPosition_Req_extension.extended_reference.smlc_code;
       
   324 		aRrlpRef.aRel5TransactionId = iData->component.u.msrPositionReq->rel5_MsrPosition_Req_extension.extended_reference.transaction_ID;
       
   325 		}
       
   326 	else	
       
   327 		{
       
   328 		return KErrNotFound;
       
   329 		}
       
   330 	return KErrNone;
       
   331 	}