|
1 // Copyright (c) 2007-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 |
|
18 #include <e32std.h> // basic types |
|
19 |
|
20 #include <ecom/implementationproxy.h> // for TImplementationProxy |
|
21 #include <lbspositioninfo.h> // for TPositionInfoBase |
|
22 #include <lbssatellite.h> // for TPositionSatelliteInfo |
|
23 |
|
24 #include <lbs/epos_mpositionerstatus.h> |
|
25 |
|
26 #include "extgpspsy2.h" |
|
27 #include "extgpspsy2.hrh" |
|
28 |
|
29 |
|
30 const TInt KSecondToMicro = 1000000; |
|
31 |
|
32 const TImplementationProxy KFactoryPtr = {{KExtGpsPsy2ImplUid}, (TProxyNewLPtr)CExtGpsPsy2::NewL}; |
|
33 |
|
34 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
35 TInt& aTableCount) |
|
36 { |
|
37 aTableCount = 1; |
|
38 return &KFactoryPtr; |
|
39 } |
|
40 |
|
41 CExtGpsPsy2* CExtGpsPsy2::NewL(TAny* aConstructionParameters) |
|
42 { |
|
43 CExtGpsPsy2* self = new(ELeave) CExtGpsPsy2; |
|
44 |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aConstructionParameters); |
|
47 CleanupStack::Pop(self); |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CExtGpsPsy2::ConstructL(TAny* aConstructionParameters) |
|
53 { |
|
54 BaseConstructL(aConstructionParameters); |
|
55 iUid = ImplementationUid(); |
|
56 iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
57 } |
|
58 |
|
59 |
|
60 CExtGpsPsy2::~CExtGpsPsy2() |
|
61 { |
|
62 iPsyConfigArray.Close(); |
|
63 if(iTimer) |
|
64 { |
|
65 iTimer->Cancel(); |
|
66 delete iTimer; |
|
67 } |
|
68 } |
|
69 |
|
70 |
|
71 void CExtGpsPsy2::NotifyPositionUpdate( |
|
72 TPositionInfoBase& aPosInfo, |
|
73 TRequestStatus& aStatus) |
|
74 { |
|
75 iRequestStatus = &aStatus; |
|
76 iPositionInfoBase = &aPosInfo; |
|
77 if(aPosInfo.PositionClassType() & EPositionGenericInfoClass) |
|
78 { |
|
79 //Check if this is confiuration request |
|
80 HPositionGenericInfo* genInfo = |
|
81 static_cast<HPositionGenericInfo*>(&aPosInfo); |
|
82 if(genInfo->IsRequestedField(KIntGpsPsy1ConfigItemsNumber)) |
|
83 { |
|
84 //Config PSY |
|
85 TRAPD(err, ConfigPsyL(*genInfo)); |
|
86 CompleteRequest(err); |
|
87 StartTimerIfNeeded(); |
|
88 return; |
|
89 } |
|
90 } |
|
91 |
|
92 StartTimerIfNeeded(); |
|
93 } |
|
94 |
|
95 void CExtGpsPsy2::ConfigPsyL(const HPositionGenericInfo& aGenInfo) |
|
96 { |
|
97 TInt32 configUid; |
|
98 User::LeaveIfError(aGenInfo.GetValue(KIntGpsPsy1ConfigPsyUid, configUid)); |
|
99 if(configUid!=iUid.iUid) |
|
100 { |
|
101 User::Leave(KErrNotSupported); |
|
102 } |
|
103 |
|
104 iPsyConfigArray.Reset(); |
|
105 iCurrentIndex = 0; |
|
106 TInt32 numOfItem; |
|
107 User::LeaveIfError(aGenInfo.GetValue(KIntGpsPsy1ConfigItemsNumber, numOfItem)); |
|
108 for(TInt i=0; i<numOfItem; i++) |
|
109 { |
|
110 TPsyConfig psyConfig; |
|
111 TPckg<TPsyConfig> configBuf(psyConfig); |
|
112 |
|
113 User::LeaveIfError(aGenInfo.GetValue(KIntGpsPsy1ConfigItemsNumber+i+1, configBuf)); |
|
114 User::LeaveIfError(iPsyConfigArray.Append(psyConfig)); |
|
115 } |
|
116 } |
|
117 |
|
118 TInt CExtGpsPsy2::TimerCallback(TAny* aAny) |
|
119 { |
|
120 reinterpret_cast<CExtGpsPsy2*>(aAny)->TimerCompleted(); |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 void CExtGpsPsy2::TimerCompleted() |
|
125 { |
|
126 TPsyConfig& config(iPsyConfigArray[iCurrentIndex]); |
|
127 if(config.iType==TPsyConfig::EConfigLRResponse) |
|
128 { |
|
129 //If no pending LR, then just return |
|
130 if(!iRequestStatus) |
|
131 { |
|
132 return; |
|
133 } |
|
134 |
|
135 TInt err = config.iData.iLRConfig.iErr; |
|
136 //complete location request |
|
137 if(iPositionInfoBase->PositionClassType() & EPositionInfoClass) |
|
138 { |
|
139 //Set TPositionInfo |
|
140 TPosition pos; |
|
141 pos.SetCoordinate( |
|
142 config.iData.iLRConfig.iLat, |
|
143 config.iData.iLRConfig.iLon, |
|
144 config.iData.iLRConfig.iAlt); |
|
145 |
|
146 TPositionInfo* posInfo = reinterpret_cast<TPositionInfo*>(iPositionInfoBase); |
|
147 posInfo->SetPosition(pos); |
|
148 } |
|
149 if(iPositionInfoBase->PositionClassType() & EPositionGenericInfoClass) |
|
150 { |
|
151 //Set HGeneric Info |
|
152 HPositionGenericInfo* genInfo = |
|
153 static_cast<HPositionGenericInfo*>(iPositionInfoBase); |
|
154 if(genInfo->IsRequestedField(EPositionFieldNMEASentences)) |
|
155 { |
|
156 genInfo->SetValue(EPositionFieldNMEASentences, TInt8(1)); |
|
157 HBufC8* nmea = NULL; |
|
158 TRAP(err, nmea = HBufC8::NewL(config.iData.iLRConfig.iNmeaDataSize)); |
|
159 if(KErrNone == err) |
|
160 { |
|
161 TPtr8 nmeaPtr(nmea->Des()); |
|
162 nmeaPtr.Fill('H', config.iData.iLRConfig.iNmeaDataSize); |
|
163 err = genInfo->SetValue(EPositionFieldNMEASentences+1, *nmea); |
|
164 } |
|
165 delete nmea; |
|
166 } |
|
167 } |
|
168 CompleteRequest(err); |
|
169 if(config.iData.iLRConfig.iNumOfResponse>1) |
|
170 { |
|
171 config.iData.iLRConfig.iNumOfResponse--; |
|
172 } |
|
173 else if(config.iData.iLRConfig.iNumOfResponse>0) |
|
174 { |
|
175 iCurrentIndex++; |
|
176 } |
|
177 else |
|
178 { |
|
179 //0 means forever response with this |
|
180 } |
|
181 } |
|
182 else //ECinfigModuleStatus |
|
183 { |
|
184 //Change module status |
|
185 TPositionModuleStatus modStatus; |
|
186 modStatus.SetDataQualityStatus(config.iData.iStatusConfig.iDataQuality); |
|
187 modStatus.SetDeviceStatus(config.iData.iStatusConfig.iDeviceStatus); |
|
188 MPositionerStatus* observer = PositionerStatus(); |
|
189 observer->ReportStatus(modStatus); |
|
190 iCurrentIndex++; |
|
191 } |
|
192 iTimer->Cancel(); |
|
193 |
|
194 if(iCurrentIndex>=iPsyConfigArray.Count()) |
|
195 { |
|
196 //When all items are used, then clean the config items |
|
197 iPsyConfigArray.Reset(); |
|
198 iCurrentIndex = 0; |
|
199 } |
|
200 |
|
201 StartTimerIfNeeded(); |
|
202 } |
|
203 |
|
204 void CExtGpsPsy2::StartTimerIfNeeded() |
|
205 { |
|
206 //If timer is already runing, then we don't do anything |
|
207 if(iTimer->IsActive()) |
|
208 { |
|
209 return; |
|
210 } |
|
211 |
|
212 if(iCurrentIndex>=0 && iCurrentIndex<iPsyConfigArray.Count()) |
|
213 { |
|
214 TPsyConfig& config(iPsyConfigArray[iCurrentIndex]); |
|
215 if(config.iType==TPsyConfig::EConfigLRResponse) |
|
216 { |
|
217 if(iRequestStatus) |
|
218 { |
|
219 //If there is location request waiting then start timer |
|
220 iTimer->Start( |
|
221 config.iData.iLRConfig.iResponseTime*KSecondToMicro, |
|
222 1, |
|
223 TCallBack(TimerCallback, this)); |
|
224 } |
|
225 } |
|
226 else //ECinfigModuleStatus |
|
227 { |
|
228 //Start timer |
|
229 iTimer->Start( |
|
230 config.iData.iStatusConfig.iResponseTime*KSecondToMicro, |
|
231 1, |
|
232 TCallBack(TimerCallback, this)); |
|
233 } |
|
234 } |
|
235 |
|
236 //If we don't start timer but there is LR pending, we shall complete the |
|
237 //request by default. |
|
238 if(!iTimer->IsActive() && iRequestStatus) |
|
239 { |
|
240 CompleteRequestByDefault(); |
|
241 } |
|
242 } |
|
243 |
|
244 void CExtGpsPsy2::CompleteRequestByDefault() |
|
245 { |
|
246 if(!iRequestStatus) |
|
247 { |
|
248 return; |
|
249 } |
|
250 |
|
251 if(iPositionInfoBase->PositionClassType() & EPositionInfoClass) |
|
252 { |
|
253 TPositionInfo* posInfo = static_cast<TPositionInfo*>(iPositionInfoBase); |
|
254 TPosition pos; |
|
255 pos.SetCoordinate(1.0, 1.0, 1.0); |
|
256 pos.SetAccuracy(1.0, 1.0); |
|
257 posInfo->SetPosition(pos); |
|
258 } |
|
259 |
|
260 CompleteRequest(KErrNone); |
|
261 } |
|
262 |
|
263 void CExtGpsPsy2::CompleteRequest(TInt aCompletionCode) |
|
264 { |
|
265 if(iRequestStatus) |
|
266 { |
|
267 iPositionInfoBase->SetModuleId(iUid); |
|
268 User::RequestComplete(iRequestStatus, aCompletionCode); |
|
269 } |
|
270 } |
|
271 |
|
272 void CExtGpsPsy2::CancelNotifyPositionUpdate() |
|
273 { |
|
274 if(iRequestStatus && |
|
275 iCurrentIndex>=0 && iCurrentIndex<iPsyConfigArray.Count()) |
|
276 { |
|
277 TPsyConfig& config(iPsyConfigArray[iCurrentIndex]); |
|
278 |
|
279 if(config.iData.iLRConfig.iNumOfResponse>1) |
|
280 { |
|
281 config.iData.iLRConfig.iNumOfResponse--; |
|
282 } |
|
283 else if(config.iData.iLRConfig.iNumOfResponse>0) |
|
284 { |
|
285 iCurrentIndex++; |
|
286 if(iCurrentIndex>=iPsyConfigArray.Count()) |
|
287 { |
|
288 //When all items are used, then clean the config items |
|
289 iPsyConfigArray.Reset(); |
|
290 iCurrentIndex = 0; |
|
291 } |
|
292 } |
|
293 else |
|
294 { |
|
295 //0 means forever response with this |
|
296 } |
|
297 iTimer->Cancel(); |
|
298 } |
|
299 CompleteRequest(KErrCancel); |
|
300 StartTimerIfNeeded(); |
|
301 } |
|
302 |
|
303 |
|
304 TBool CExtGpsPsy2::TrackingOverridden() const |
|
305 { |
|
306 return ETrue; |
|
307 } |
|
308 |
|
309 void CExtGpsPsy2::StartTrackingL(const TTimeIntervalMicroSeconds& /*aInterval*/) |
|
310 { |
|
311 } |
|
312 |
|
313 void CExtGpsPsy2::StopTracking() |
|
314 { |
|
315 } |
|
316 |
|
317 // End of file |
|
318 |