|
1 // Copyright (c) 2004-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 FILES |
|
19 #include <e32std.h> |
|
20 #include <bt_sock.h> |
|
21 #include "BTGPSNokDeviceHandler.h" |
|
22 #include "BtGpsPsyPrivateCRKeys.h" |
|
23 #include "BTGPSConnectManager.h" |
|
24 #include "BTGPSSettingManager.h" |
|
25 #include "BTGPSDeviceManager.h" |
|
26 #include "BTGPSNmeaParser.h" |
|
27 #include "BTGPSMessageDef.h" |
|
28 #include "BTGPSConstantsManager.h" |
|
29 #include "BTGPSNokNightModeHandler.h" |
|
30 #include "BTGPSPanic.h" |
|
31 #include "BTGPSLogging.h" |
|
32 #include "btgpsdevicelistmanager.h" |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CBTGPSNokDeviceHandler::NewL |
|
39 // ----------------------------------------------------------------------------- |
|
40 CBTGPSNokDeviceHandler* CBTGPSNokDeviceHandler::NewL( |
|
41 CBTGPSConnectManager& aConnectManager, |
|
42 CBTGPSSettingManager& aSettingManager, |
|
43 CBTGPSConstantsManager& aConstantsManager, |
|
44 CBTGPSDeviceManager& aDeviceManager, |
|
45 CBTGPSDeviceListManager& aDeviceListManager) |
|
46 { |
|
47 CBTGPSNokDeviceHandler* self = new (ELeave) CBTGPSNokDeviceHandler( |
|
48 aConnectManager, |
|
49 aSettingManager, |
|
50 aConstantsManager, |
|
51 aDeviceManager, |
|
52 aDeviceListManager); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CBTGPSNokDeviceHandler::~CBTGPSNokDeviceHandler |
|
61 // ----------------------------------------------------------------------------- |
|
62 CBTGPSNokDeviceHandler::~CBTGPSNokDeviceHandler() |
|
63 { |
|
64 iConnectManager.RemoveMessageListener(*this); |
|
65 iSettingManager.RemoveListener(*this); |
|
66 iDeviceManager.RemoveListener(*this); |
|
67 |
|
68 delete iNightModeHandler; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CBTGPSNokDeviceHandler::ConstructL |
|
73 // ----------------------------------------------------------------------------- |
|
74 void CBTGPSNokDeviceHandler::ConstructL() |
|
75 { |
|
76 iConnectManager.AddMessageListenerL(*this); |
|
77 iSettingManager.AddListenerL(*this); |
|
78 iDeviceManager.AddListenerL(*this); |
|
79 |
|
80 iPreviousDeviceType = iDeviceManager.DeviceType(); |
|
81 |
|
82 //Get Night Mode setting |
|
83 if(iSettingManager.GetNightModeSetting( |
|
84 (TBTGPSSettingsApi::TNightModeState &)iNightModeSetting) != KErrNone) |
|
85 { |
|
86 //In error case, turn night mode off |
|
87 iNightModeSetting = TBTGPSSettingsApi::ENightModeOff; |
|
88 } |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CBTGPSNokDeviceHandler::CBTGPSNokDeviceHandler |
|
93 // C++ default constructor can NOT contain any code, that |
|
94 // might leave. |
|
95 // ----------------------------------------------------------------------------- |
|
96 CBTGPSNokDeviceHandler::CBTGPSNokDeviceHandler( |
|
97 CBTGPSConnectManager& aConnectManager, |
|
98 CBTGPSSettingManager& aSettingManager, |
|
99 CBTGPSConstantsManager& aConstantsManager, |
|
100 CBTGPSDeviceManager& aDeviceManager, |
|
101 CBTGPSDeviceListManager& aDeviceListManager) |
|
102 : iConnectManager(aConnectManager), |
|
103 iSettingManager(aSettingManager), |
|
104 iConstantsManager(aConstantsManager), |
|
105 iDeviceManager(aDeviceManager), |
|
106 iDeviceListManager(aDeviceListManager), |
|
107 iNightModeSetting(TBTGPSSettingsApi::ENightModeNA), |
|
108 iBattStatus(KErrNotFound), |
|
109 iExtPowerStatus(KErrNotFound), |
|
110 iExtAntennaStatus(KErrNotFound) |
|
111 { |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CBTGPSNokDeviceHandler::HandleMessage |
|
116 // ----------------------------------------------------------------------------- |
|
117 void CBTGPSNokDeviceHandler::HandleMessage(const TBTGPSNmeaParser& aParser) |
|
118 { |
|
119 TRACESTRING("CBTGPSNokDeviceHandler::HandleMessage start...") |
|
120 TInt msgId = aParser.MessageId(); |
|
121 TInt status(0); |
|
122 |
|
123 switch(msgId) |
|
124 { |
|
125 case ENmeaPNokPeriodicEvents: |
|
126 //Handler PNok STAT message |
|
127 HandleStatMessage(aParser); |
|
128 break; |
|
129 case ENmeaPNokNightMode: |
|
130 if(aParser.GetFieldData(ENmeaFieldPNOKNightModeStatus, status)==KErrNone) |
|
131 { |
|
132 CheckNightModeStatus(status); |
|
133 } |
|
134 break; |
|
135 case ENmeaPNokVersionInfo: |
|
136 UpdateDeviceVersion(aParser); |
|
137 break; |
|
138 default: |
|
139 //do nothing |
|
140 break; |
|
141 } |
|
142 TRACESTRING("CBTGPSNokDeviceHandler::HandleMessage end") |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CBTGPSNokDeviceHandler::HandleNightModeChange |
|
147 // ----------------------------------------------------------------------------- |
|
148 void CBTGPSNokDeviceHandler::HandleNightModeChange( |
|
149 const TBTGPSSettingsApi::TNightModeState aSetting ) |
|
150 { |
|
151 TRACESTRING("CBTGPSNokDeviceHandler::HandleNightModeChange start...") |
|
152 //Set night mode |
|
153 UpdateNightMode(aSetting); |
|
154 TRACESTRING("CBTGPSNokDeviceHandler::HandleNightModeChange end") |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CBTGPSNokDeviceHandler::HandleStatMessage |
|
159 // ----------------------------------------------------------------------------- |
|
160 void CBTGPSNokDeviceHandler::HandleStatMessage(const TBTGPSNmeaParser& aParser) |
|
161 { |
|
162 TRACESTRING("CBTGPSNokDeviceHandler::HandleStatMessage start...") |
|
163 TInt battStatus(KErrNotFound); |
|
164 TInt battLevel(KErrNotFound); |
|
165 TInt extPowStatus(KErrNotFound); |
|
166 TInt extAntStatus(KErrNotFound); |
|
167 |
|
168 //Check battery status |
|
169 if(aParser.GetFieldData(ENmeaFieldPNOKBatteryStatus, battStatus)==KErrNone) |
|
170 { |
|
171 //Tuning is needed after testing |
|
172 if(battStatus != iBattStatus) |
|
173 { |
|
174 iBattStatus = battStatus; |
|
175 } |
|
176 } |
|
177 |
|
178 //Check ext power status |
|
179 if(aParser.GetFieldData(ENmeaFieldPNOKExtPowerStatus, extPowStatus)==KErrNone) |
|
180 { |
|
181 iExtPowerStatus = extPowStatus; |
|
182 } |
|
183 |
|
184 //Check ext antenna status |
|
185 if(aParser.GetFieldData(ENmeaFieldPNOKExtAntennaStatus, extAntStatus)==KErrNone) |
|
186 { |
|
187 iExtAntennaStatus = extAntStatus; |
|
188 } |
|
189 |
|
190 //Get battery level. Error ignored |
|
191 aParser.GetFieldData(ENmeaFieldPNOKBatteryLevel, battLevel); |
|
192 |
|
193 // Update device status to setting manager |
|
194 UpdateDeviceStatus(battLevel,battStatus, extPowStatus, extAntStatus); |
|
195 TRACESTRING("CBTGPSNokDeviceHandler::HandleStatMessage end") |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CBTGPSNokDeviceHandler::UpdateDeviceVersion |
|
200 // ----------------------------------------------------------------------------- |
|
201 void CBTGPSNokDeviceHandler::UpdateDeviceVersion(const TBTGPSNmeaParser& aParser) |
|
202 { |
|
203 TPtrC8 id; |
|
204 TPtrC8 btHwVersion; |
|
205 TPtrC8 btSwVersion; |
|
206 TPtrC8 gpsHwVersion; |
|
207 TPtrC8 gpsSwVersion; |
|
208 |
|
209 //all errors are ignored |
|
210 aParser.GetFieldBlock(ENmeaFieldPNOKProductID, id); |
|
211 aParser.GetFieldBlock(ENmeaFieldPNOKBTHWVersionNumber, btHwVersion); |
|
212 aParser.GetFieldBlock(ENmeaFieldPNOKBTSWVersionNumber, btSwVersion); |
|
213 aParser.GetFieldBlock(ENmeaFieldPNOKGPSHWVersionNumber, gpsHwVersion); |
|
214 aParser.GetFieldBlock(ENmeaFieldPNOKGPSSWVersionNumber, gpsSwVersion); |
|
215 |
|
216 //Update settings in setting manager. Error ignored |
|
217 iSettingManager.UpdateVersions( |
|
218 id, |
|
219 btHwVersion, |
|
220 btSwVersion, |
|
221 gpsHwVersion, |
|
222 gpsSwVersion); |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CBTGPSNokDeviceHandler::UpdateDeviceStatus |
|
228 // ----------------------------------------------------------------------------- |
|
229 void CBTGPSNokDeviceHandler::UpdateDeviceStatus( |
|
230 TInt aBattLevel, |
|
231 TInt aBattStatus, |
|
232 TInt aExtPowStatus, |
|
233 TInt aExtAntStatus) |
|
234 { |
|
235 //Set batt level |
|
236 TInt battLevel(0); |
|
237 if(aBattLevel!=KErrNotFound) |
|
238 { |
|
239 battLevel = aBattLevel; |
|
240 } |
|
241 |
|
242 //Set batt status |
|
243 TBTGPSBatteryState battState(EBatteryStateNA); |
|
244 switch(aBattStatus) |
|
245 { |
|
246 case KPNOKStatBattNormal: |
|
247 battState = EBatteryStateNormal; |
|
248 break; |
|
249 case KPNOKStatBattFull: |
|
250 battState = EBatteryStateFull; |
|
251 break; |
|
252 case KPNOKStatBattLow: |
|
253 battState = EBatteryStateLow; |
|
254 break; |
|
255 default: |
|
256 //do nothing |
|
257 break; |
|
258 } |
|
259 |
|
260 //Set ext power state |
|
261 TBTGPSExtPowerState extPowState(EExtPowerNA); |
|
262 switch (aExtPowStatus) |
|
263 { |
|
264 case KPNOKStatExtPowerConnected: |
|
265 extPowState = EExtPowerOn; |
|
266 break; |
|
267 case KPNOKStatExtPowerNotConnected: |
|
268 extPowState = EExtPowerOff; |
|
269 break; |
|
270 default: |
|
271 //do nothing |
|
272 break; |
|
273 } |
|
274 |
|
275 //Set ext antenna state |
|
276 TBTGPSExtAntennaState extAntState(EExtAntennaNA); |
|
277 switch(aExtAntStatus) |
|
278 { |
|
279 case KPNOKStatExtAntennaNotConnected: |
|
280 extAntState = EExtAntennaOff; |
|
281 break; |
|
282 case KPNOKStatExtAntennaConnected: |
|
283 extAntState = EExtAntennaOn; |
|
284 break; |
|
285 default: |
|
286 //do nothing |
|
287 break; |
|
288 } |
|
289 |
|
290 //Set device status to setting manager. Error is ignored |
|
291 iSettingManager.UpdateDeviceStatus( |
|
292 battLevel, |
|
293 extPowState, |
|
294 extAntState, |
|
295 battState); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CBTGPSNokDeviceHandler::CheckNightModeStatus |
|
300 // ----------------------------------------------------------------------------- |
|
301 void CBTGPSNokDeviceHandler::CheckNightModeStatus(TInt aStatus) |
|
302 { |
|
303 if( iNightModeSetting == TBTGPSSettingsApi::ENightModeOn && |
|
304 aStatus == KPNOKNightNightModeOn || |
|
305 iNightModeSetting == TBTGPSSettingsApi::ENightModeOff && |
|
306 aStatus == KPNOKNightNightModeOff) |
|
307 { |
|
308 //Correctly set |
|
309 delete iNightModeHandler; |
|
310 iNightModeHandler = NULL; |
|
311 } |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CBTGPSNokDeviceHandler::UpdateNightMode |
|
316 // ----------------------------------------------------------------------------- |
|
317 void CBTGPSNokDeviceHandler::UpdateNightMode( |
|
318 TBTGPSSettingsApi::TNightModeState aSetting) |
|
319 { |
|
320 if(iDeviceManager.DeviceType()!=EBTDeviceTypeNokGps) |
|
321 { |
|
322 return; |
|
323 } |
|
324 |
|
325 delete iNightModeHandler; |
|
326 iNightModeHandler = NULL; |
|
327 |
|
328 if(aSetting != TBTGPSSettingsApi::ENightModeNA) |
|
329 { |
|
330 //ignore error if night mode can't be set |
|
331 TInt ignore(KErrNone); |
|
332 TRAP(ignore, |
|
333 iNightModeHandler = CBTGPSNokNightModeHandler::NewL( |
|
334 iConnectManager, |
|
335 aSetting)); |
|
336 } |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CBTGPSNokDeviceHandler::BTDeviceStatusChanged |
|
341 // ----------------------------------------------------------------------------- |
|
342 void CBTGPSNokDeviceHandler::BTDeviceStatusChanged( |
|
343 TInt aConnectStatus, |
|
344 TInt aDeviceType, |
|
345 TInt /*aErr*/) |
|
346 { |
|
347 //Update night mode setting |
|
348 if(aConnectStatus==EBTDeviceConnected && aDeviceType ==EBTDeviceTypeNokGps) |
|
349 { |
|
350 //Set night mode |
|
351 TBTGPSSettingsApi::TNightModeState setting; |
|
352 if(iSettingManager.GetNightModeSetting(setting) == KErrNone) |
|
353 { |
|
354 UpdateNightMode(setting); |
|
355 } |
|
356 } |
|
357 else |
|
358 { |
|
359 //Cancel night mode setting |
|
360 delete iNightModeHandler; |
|
361 iNightModeHandler = NULL; |
|
362 } |
|
363 |
|
364 //Update PSY state in setting |
|
365 UpdatePsyState(aConnectStatus, aDeviceType); |
|
366 |
|
367 //Update connected device info in setting |
|
368 UpdateBtDeviceInfo(aConnectStatus, aDeviceType); |
|
369 |
|
370 //Update previous bt device type |
|
371 iPreviousDeviceType = aDeviceType; |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CBTGPSNokDeviceHandler::UpdatePsyState |
|
376 // ----------------------------------------------------------------------------- |
|
377 void CBTGPSNokDeviceHandler::UpdatePsyState( |
|
378 TInt aConnectStatus, |
|
379 TInt aDeviceType) |
|
380 { |
|
381 TBTGPSPSYState psyState(EPSYLoaded); |
|
382 |
|
383 switch(aConnectStatus) |
|
384 { |
|
385 case EBTDeviceDisconnected: |
|
386 if(aDeviceType==EBTDeviceTypeNonNokGps || |
|
387 aDeviceType==EBTDeviceTypeNokGps) |
|
388 { |
|
389 psyState = EPSYInStandBy; |
|
390 } |
|
391 break; |
|
392 case EBTDeviceConnected: |
|
393 if(aDeviceType == EBTDeviceTypeNonNokGps) |
|
394 { |
|
395 psyState = EPSYLoadedAndPNOKNotSupportedBTGPSUsed; |
|
396 } |
|
397 else if(aDeviceType == EBTDeviceTypeNokGps) |
|
398 { |
|
399 psyState = EPSYLoadedAndPNOKSupportedBTGPSUsed; |
|
400 } |
|
401 else |
|
402 { |
|
403 //do nothing |
|
404 } |
|
405 break; |
|
406 case EBTDeviceConnecting: |
|
407 case EBTDeviceConnectError: |
|
408 default: |
|
409 //do nothing |
|
410 break; |
|
411 } |
|
412 |
|
413 //Update to setting manager |
|
414 iSettingManager.UpdatePsyState(psyState); |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // CBTGPSNokDeviceHandler::UpdateBtDeviceInfo |
|
419 // ----------------------------------------------------------------------------- |
|
420 void CBTGPSNokDeviceHandler::UpdateBtDeviceInfo( |
|
421 TInt aConnectStatus, |
|
422 TInt aDeviceType) |
|
423 { |
|
424 //Update bt device info when device type is changed from unkown or not GPS to |
|
425 //NokGps or NonNokGps |
|
426 if(aConnectStatus == EBTDeviceConnected && |
|
427 aDeviceType != iPreviousDeviceType && |
|
428 (aDeviceType == EBTDeviceTypeNonNokGps || |
|
429 aDeviceType == EBTDeviceTypeNokGps)) |
|
430 { |
|
431 //Get bt sock address from device manager |
|
432 TBTSockAddr btSockAddr; |
|
433 iDeviceManager.BtSockAddr(btSockAddr); |
|
434 |
|
435 #ifdef SYMBIAN_LOCATION_BTGPSCONFIG |
|
436 iDeviceListManager.SetDeviceInfo(aDeviceType, btSockAddr); |
|
437 #else |
|
438 //Determine if the device is valid |
|
439 TInt valid = (aDeviceType==EBTDeviceTypeNonNokGps)? |
|
440 TBTGPSSettingsApi::EBtDeviceNonNokGps : TBTGPSSettingsApi::EBtDeviceNokGps; |
|
441 |
|
442 //Update device info in setting manager |
|
443 iSettingManager.UpdateBTDeviceInfo(valid, btSockAddr); |
|
444 #endif |
|
445 } |
|
446 #ifdef SYMBIAN_LOCATION_BTGPSCONFIG |
|
447 else if(aConnectStatus == EBTDeviceConnected) |
|
448 { |
|
449 //Device address and type has not changed,, but it needs to be moved to the top of the list |
|
450 TBTSockAddr btSockAddr; |
|
451 iDeviceManager.BtSockAddr(btSockAddr); |
|
452 iDeviceListManager.SetDeviceInfo(aDeviceType, btSockAddr); |
|
453 } |
|
454 #endif |
|
455 } |
|
456 |
|
457 |
|
458 // End of File |
|
459 |
|
460 |
|
461 |