|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CTCChannelTilt class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ssycallback.h> |
|
20 #include <sensrvsensorchannels.h> |
|
21 #include <sensrvchanneldatatypes.h> |
|
22 #include <sensrvmagnetometersensor.h> |
|
23 #include <sensordatacompensator.h> |
|
24 |
|
25 #include "tcchanneltilt.h" |
|
26 #include "tcstatetiltidle.h" |
|
27 #include "tcstatetiltopen.h" |
|
28 #include "tcstatetiltlistendata.h" |
|
29 #include "tcstatetiltbufferfull.h" |
|
30 #include "tcstatetiltclosing.h" |
|
31 #include "tceventaccelerometer.h" |
|
32 #include "tceventmagnetometer.h" |
|
33 #include "tceventproperty.h" |
|
34 #include "tctransactionflushbuffer.h" |
|
35 #include "tcutil.h" |
|
36 #include "configuration.h" |
|
37 #include "common.h" |
|
38 #include "trace.h" |
|
39 |
|
40 // LOCAL DEFINITIONS |
|
41 |
|
42 const TInt KDesiredCount = 1; |
|
43 const TInt KMaximumCount = 1; |
|
44 const TInt KBufferingPeriod = 0; |
|
45 const TInt KMaximumDataRate = 10; |
|
46 |
|
47 CTCChannelTilt* CTCChannelTilt::NewL( MSsyCallback& aCallback ) |
|
48 { |
|
49 FUNC_LOG; |
|
50 |
|
51 CTCChannelTilt* self = CTCChannelTilt::NewLC( aCallback ); |
|
52 CleanupStack::Pop( self ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 CTCChannelTilt* CTCChannelTilt::NewLC( MSsyCallback& aCallback ) |
|
58 { |
|
59 FUNC_LOG; |
|
60 |
|
61 CTCChannelTilt* self = new( ELeave ) CTCChannelTilt( aCallback ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 CTCChannelTilt::~CTCChannelTilt() |
|
69 { |
|
70 FUNC_LOG; |
|
71 |
|
72 if( iAccelerometerChannel ) |
|
73 { |
|
74 delete iAccelerometerChannel; |
|
75 iAccelerometerChannel = NULL; |
|
76 } |
|
77 if( iMagnetometerChannel ) |
|
78 { |
|
79 delete iMagnetometerChannel; |
|
80 iMagnetometerChannel = NULL; |
|
81 } |
|
82 |
|
83 if( iCurrentTransaction ) |
|
84 { |
|
85 delete iCurrentTransaction; |
|
86 iCurrentTransaction = NULL; |
|
87 } |
|
88 iProperties.Close(); |
|
89 |
|
90 delete iMagnetometerCompensator; |
|
91 delete iAccelerometerCompensator; |
|
92 } |
|
93 |
|
94 CTCChannelTilt::CTCChannelTilt( MSsyCallback& aCallback ): |
|
95 CTCChannel( aCallback ) |
|
96 { |
|
97 FUNC_LOG; |
|
98 } |
|
99 |
|
100 void CTCChannelTilt::ConstructL() |
|
101 { |
|
102 FUNC_LOG; |
|
103 |
|
104 iIsSetFromListened = EFalse; |
|
105 |
|
106 BaseConstructL(); |
|
107 // Initialize properties |
|
108 for( TInt i = 0; i < EChannelPropertyTiltLast; i++ ) |
|
109 { |
|
110 switch( KTiltSsyChannelProperties[ i ].iPropertyType ) |
|
111 { |
|
112 case ESensrvIntProperty: |
|
113 { |
|
114 TSensrvProperty property( KTiltSsyChannelProperties[ i ].iPropertyId, |
|
115 KTiltSsyChannelProperties[ i ].iItemIndex, |
|
116 KTiltSsyChannelProperties[ i ].iIntValue, |
|
117 KTiltSsyChannelProperties[ i ].iIntMaxValue, |
|
118 KTiltSsyChannelProperties[ i ].iIntMinValue, |
|
119 KTiltSsyChannelProperties[ i ].iReadOnly, |
|
120 KTiltSsyChannelProperties[ i ].iPropertyType ); |
|
121 iProperties.AppendL( property ); |
|
122 break; |
|
123 } |
|
124 default: |
|
125 { |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 // METHODS |
|
133 |
|
134 // ---------------------------------------------------------------------------------- |
|
135 // CTCChannelTilt::RegisterChannelL |
|
136 // ---------------------------------------------------------------------------------- |
|
137 // |
|
138 void CTCChannelTilt::RegisterChannelL( RSensrvChannelInfoList& aChannels ) |
|
139 { |
|
140 FUNC_LOG; |
|
141 |
|
142 // Register tilt angle channel |
|
143 TChannelInfo infoStruct = KTiltSsyChannels[ EChannelTilt ]; |
|
144 TSensrvChannelInfo info( infoStruct.iChannelId, |
|
145 infoStruct.iContextType, |
|
146 infoStruct.iQuantity, |
|
147 infoStruct.iChannelType, |
|
148 TPtrC8( infoStruct.iLocation ), |
|
149 TPtrC8( infoStruct.iVendorId ), |
|
150 infoStruct.iDataItemSize, |
|
151 infoStruct.iDataTypeId ); |
|
152 aChannels.AppendL( info ); |
|
153 |
|
154 // Store channel info |
|
155 iChannelInfo = info; |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------------- |
|
159 // CTCChannelTilt::OpenChannelL |
|
160 // ---------------------------------------------------------------------------------- |
|
161 // |
|
162 void CTCChannelTilt::OpenChannelL() |
|
163 { |
|
164 FUNC_LOG; |
|
165 |
|
166 // Find and create accelerometer and magnetometer channels |
|
167 FindAndCreateAccelerometerChannelL(); |
|
168 |
|
169 FindAndCreateMagnetometerChannelL(); |
|
170 |
|
171 // Get current state and send open channel event |
|
172 CTCState* current = CurrentState(); |
|
173 if( current ) |
|
174 { |
|
175 current->HandleEventL( EEventIdHandleOpenChannel ); |
|
176 } |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------------- |
|
180 // CTCChannelTilt::CloseChannel |
|
181 // ---------------------------------------------------------------------------------- |
|
182 // |
|
183 void CTCChannelTilt::CloseChannelL() |
|
184 { |
|
185 FUNC_LOG; |
|
186 |
|
187 // Get current state and send close channel event |
|
188 CTCState* current = CurrentState(); |
|
189 if( current ) |
|
190 { |
|
191 current->HandleEventL( EEventIdHandleCloseChannel ); |
|
192 } |
|
193 } |
|
194 |
|
195 // ---------------------------------------------------------------------------------- |
|
196 // CTCChannelTilt::RegisterStateL |
|
197 // ---------------------------------------------------------------------------------- |
|
198 // |
|
199 void CTCChannelTilt::RegisterStateL( CTCState::TCStateId aStateId, |
|
200 RStateArray& aStateArray ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 |
|
204 switch( aStateId ) |
|
205 { |
|
206 case CTCState::ETCStateIdle: |
|
207 { |
|
208 CTCStateTiltIdle* state = CTCStateTiltIdle::NewL( *this, *this ); |
|
209 CleanupStack::PushL( state ); |
|
210 aStateArray.AppendL( state ); |
|
211 CleanupStack::Pop( state ); |
|
212 break; |
|
213 } |
|
214 case CTCState::ETCStateOpen: |
|
215 { |
|
216 CTCStateTiltOpen* state = CTCStateTiltOpen::NewL( *this, *this ); |
|
217 CleanupStack::PushL( state ); |
|
218 aStateArray.AppendL( state ); |
|
219 CleanupStack::Pop( state ); |
|
220 break; |
|
221 } |
|
222 case CTCState::ETCStateListenData: |
|
223 { |
|
224 CTCStateTiltListenData* state = CTCStateTiltListenData::NewL( *this, *this ); |
|
225 CleanupStack::PushL( state ); |
|
226 aStateArray.AppendL( state ); |
|
227 CleanupStack::Pop( state ); |
|
228 break; |
|
229 } |
|
230 case CTCState::ETCStateBufferFull: |
|
231 { |
|
232 CTCStateTiltBufferFull* state = CTCStateTiltBufferFull::NewL( *this, *this ); |
|
233 CleanupStack::PushL( state ); |
|
234 aStateArray.AppendL( state ); |
|
235 CleanupStack::Pop( state ); |
|
236 break; |
|
237 } |
|
238 case CTCState::ETCStateClosing: |
|
239 { |
|
240 CTCStateTiltClosing* state = CTCStateTiltClosing::NewL( *this, *this ); |
|
241 CleanupStack::PushL( state ); |
|
242 aStateArray.AppendL( state ); |
|
243 CleanupStack::Pop( state ); |
|
244 break; |
|
245 } |
|
246 default: |
|
247 { |
|
248 ERROR_GEN( "Oops. Invalid state" ); |
|
249 User::Leave( KErrGeneral ); |
|
250 break; |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 // ---------------------------------------------------------------------------------- |
|
256 // CTCChannelTilt::RunL |
|
257 // ---------------------------------------------------------------------------------- |
|
258 // |
|
259 void CTCChannelTilt::RunL() |
|
260 { |
|
261 FUNC_LOG; |
|
262 |
|
263 TInt status = iStatus.Int(); |
|
264 |
|
265 INFO_2( "Transaction [%S] completed with code [%d]", |
|
266 &TCUtil::TransactionIdAsDesC( iCurrentTransactionId ), status ); |
|
267 |
|
268 switch( iCurrentTransactionId ) |
|
269 { |
|
270 case ETCTransactionIdOpenChannel: |
|
271 { |
|
272 // Channel opened, finnish request to sensor server |
|
273 iCallback.ChannelOpened( iChannelInfo.iChannelId, status, this, this ); |
|
274 break; |
|
275 } |
|
276 case ETCTransactionIdCloseChannel: |
|
277 { |
|
278 // Channel closed, finnish request to sensor server |
|
279 iCallback.ChannelClosed( iChannelInfo.iChannelId ); |
|
280 break; |
|
281 } |
|
282 case ETCTransactionIdStopChannelData: |
|
283 { |
|
284 // Reset data |
|
285 iData = NULL; |
|
286 iCount = 0; |
|
287 break; |
|
288 } |
|
289 case ETCTransactionIdFlushBuffer: |
|
290 { |
|
291 ASSERT_DEBUG_TRACE( iCurrentTransaction, ENullPointer ); |
|
292 |
|
293 // Reset data |
|
294 iData = NULL; |
|
295 iCount = 0; |
|
296 |
|
297 // Buffer filled and needs to be flushed |
|
298 TTCTransactionFlushBuffer& transaction = |
|
299 static_cast<TTCTransactionFlushBuffer&>( *iCurrentTransaction ); |
|
300 iCallback.BufferFilled( iChannelInfo.iChannelId, |
|
301 transaction.iDataCount, |
|
302 iData, |
|
303 iCount ); |
|
304 |
|
305 INFO_2( "Received new data pointer [0x%x] and data count [%d]", |
|
306 iData, |
|
307 iCount ); |
|
308 break; |
|
309 } |
|
310 default: |
|
311 { |
|
312 // Nothing to do |
|
313 ERROR_GEN( "Incorrect transaction ID" ); |
|
314 break; |
|
315 } |
|
316 } |
|
317 |
|
318 // Clean up transaction |
|
319 if( iCurrentTransaction ) |
|
320 { |
|
321 delete iCurrentTransaction; |
|
322 iCurrentTransaction = NULL; |
|
323 } |
|
324 |
|
325 // Inform current state that transaction has been completed |
|
326 CTCState* current = CurrentState(); |
|
327 if( current ) |
|
328 { |
|
329 TTCTransactionId currentTransactionId = iCurrentTransactionId; |
|
330 iCurrentTransactionId = ETCTransactionIdNull; |
|
331 current->HandleTransactionCompletedL( currentTransactionId, status ); |
|
332 } |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------------- |
|
336 // CTCChannelTilt::CheckPropertyDependenciesL |
|
337 // ---------------------------------------------------------------------------------- |
|
338 // |
|
339 void CTCChannelTilt::CheckPropertyDependenciesL( const TSensrvChannelId /*aChannelId*/, |
|
340 const TSensrvProperty& /*aProperty*/, |
|
341 RSensrvChannelList& /*aAffectedChannels */) |
|
342 { |
|
343 FUNC_LOG; |
|
344 |
|
345 // No depencies to other channels |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------------- |
|
349 // CTCChannelTilt::SetPropertyL |
|
350 // ---------------------------------------------------------------------------------- |
|
351 // |
|
352 void CTCChannelTilt::SetPropertyL( const TSensrvChannelId aChannelId, |
|
353 const TSensrvProperty& aProperty ) |
|
354 { |
|
355 FUNC_LOG; |
|
356 |
|
357 // Check that we have a correct channel ID |
|
358 if( aChannelId == iChannelInfo.iChannelId ) |
|
359 { |
|
360 TInt err = KErrNotFound; |
|
361 TSensrvProperty* property = Property( aProperty.GetPropertyId() ); |
|
362 if( property ) |
|
363 { |
|
364 // Check that property is not read only |
|
365 INFO_1( "Property id [%d] found from supported properties list", |
|
366 property->GetPropertyId() ); |
|
367 |
|
368 if( !property->ReadOnly() ) |
|
369 { |
|
370 INFO_1( "Property id [%d] supports writing", |
|
371 property->GetPropertyId() ); |
|
372 |
|
373 // Check that value is correct |
|
374 switch( property->PropertyType() ) |
|
375 { |
|
376 case ESensrvIntProperty: |
|
377 { |
|
378 INFO_1( "Maximum data rate for tilt channel [%d]", |
|
379 iMaximumDataRate ); |
|
380 // Get new value |
|
381 TInt value = 0; |
|
382 aProperty.GetValue( value ); |
|
383 |
|
384 // Get allowed min and max |
|
385 TInt min = 0; |
|
386 TInt max = 0; |
|
387 property->GetMinValue( min ); |
|
388 property->GetMaxValue( max ); |
|
389 if( value >= min && value <= max && value <= iMaximumDataRate ) |
|
390 { |
|
391 property->SetValue( value ); |
|
392 INFO_2( "New value [%d] set for property id [%d]", |
|
393 value, |
|
394 property->GetPropertyId() ); |
|
395 err = KErrNone; |
|
396 } |
|
397 else |
|
398 { |
|
399 ERROR_GEN_2( "Value [%d] incorrect for property id [%d]", |
|
400 value, |
|
401 property->GetPropertyId() ); |
|
402 err = KErrArgument; |
|
403 } |
|
404 break; |
|
405 } |
|
406 case ESensrvRealProperty: |
|
407 // Fall through |
|
408 case ESensrvBufferProperty: |
|
409 // Fall through |
|
410 default: |
|
411 { |
|
412 // Other property types than Int not supported |
|
413 err = KErrArgument; |
|
414 break; |
|
415 } |
|
416 } |
|
417 } |
|
418 else |
|
419 { |
|
420 if( ( property->GetPropertyId() == KSensrvPropCalibrationLevel ) && |
|
421 iIsSetFromListened ) |
|
422 { |
|
423 // Check that value is correct |
|
424 switch( property->PropertyType() ) |
|
425 { |
|
426 case ESensrvIntProperty: |
|
427 { |
|
428 // Get new value |
|
429 TInt value = 0; |
|
430 aProperty.GetValue( value ); |
|
431 |
|
432 // Get allowed min and max |
|
433 property->SetValue( value ); |
|
434 INFO_2( "New value [%d] set for property id [%d]", |
|
435 value, |
|
436 property->GetPropertyId() ); |
|
437 iIsSetFromListened = EFalse; |
|
438 err = KErrNone; |
|
439 break; |
|
440 } |
|
441 case ESensrvRealProperty: |
|
442 // Fall through |
|
443 case ESensrvBufferProperty: |
|
444 // Fall through |
|
445 default: |
|
446 { |
|
447 // Other property types than Int not supported |
|
448 err = KErrArgument; |
|
449 break; |
|
450 } |
|
451 } |
|
452 } |
|
453 else |
|
454 { |
|
455 // Cannot modify read only property |
|
456 ERROR_GEN_1( "Property id [%d] does not support writing", |
|
457 property->GetPropertyId() ); |
|
458 err = KErrArgument; |
|
459 } |
|
460 } |
|
461 } |
|
462 |
|
463 ERROR_1( err, "Property set for id [%d] failed", aProperty.GetPropertyId() ); |
|
464 User::LeaveIfError( err ); |
|
465 |
|
466 TSensrvProperty property1; |
|
467 property1.SetPropertyId( KSensrvPropCalibrationLevel ); |
|
468 GetPropertyL( iChannelInfo.iChannelId, property1 ); |
|
469 RSensrvChannelList affectedChannels; |
|
470 affectedChannels.AppendL( iChannelInfo.iChannelId ); |
|
471 iCallback.PropertyChanged( iChannelInfo.iChannelId, affectedChannels, property1 ); |
|
472 affectedChannels.Close(); |
|
473 |
|
474 // Inform current state that property has changed |
|
475 CTCState* current = CurrentState(); |
|
476 if( current ) |
|
477 { |
|
478 TTCEventProperty event( aProperty ); |
|
479 current->HandleEventL( event.Id(), &event ); |
|
480 } |
|
481 } |
|
482 else |
|
483 { |
|
484 ERROR_GEN_1( "Incorrect channel id [%d]", aChannelId ); |
|
485 User::Leave( KErrNotSupported ); |
|
486 } |
|
487 } |
|
488 |
|
489 // ---------------------------------------------------------------------------------- |
|
490 // CTCChannelTilt::GetPropertyL |
|
491 // ---------------------------------------------------------------------------------- |
|
492 // |
|
493 void CTCChannelTilt::GetPropertyL( const TSensrvChannelId aChannelId, |
|
494 TSensrvProperty& aProperty ) |
|
495 { |
|
496 FUNC_LOG; |
|
497 |
|
498 // Check that we have a correct channel ID |
|
499 if( aChannelId == iChannelInfo.iChannelId ) |
|
500 { |
|
501 // Check if property exists |
|
502 TSensrvProperty* property = Property( aProperty.GetPropertyId() ); |
|
503 if( property ) |
|
504 { |
|
505 // Property found, set new values |
|
506 aProperty = *property; |
|
507 } |
|
508 else |
|
509 { |
|
510 ERROR_GEN_1( "Property id [%d] not supported", aProperty.GetPropertyId() ); |
|
511 User::Leave( KErrNotFound ); |
|
512 } |
|
513 } |
|
514 else |
|
515 { |
|
516 ERROR_GEN_1( "Incorrect channel ID: %d", aChannelId ); |
|
517 User::Leave( KErrNotSupported ); |
|
518 } |
|
519 } |
|
520 |
|
521 // ---------------------------------------------------------------------------------- |
|
522 // CTCChannelTilt::GetAllPropertiesL |
|
523 // ---------------------------------------------------------------------------------- |
|
524 // |
|
525 void CTCChannelTilt::GetAllPropertiesL( const TSensrvChannelId aChannelId, |
|
526 RSensrvPropertyList& aChannelPropertyList ) |
|
527 { |
|
528 FUNC_LOG; |
|
529 |
|
530 // Check that we have a correct channel ID |
|
531 if( aChannelId == iChannelInfo.iChannelId ) |
|
532 { |
|
533 // Get all properties |
|
534 TInt count = iProperties.Count(); |
|
535 for( TInt i = 0; i < count; i++ ) |
|
536 { |
|
537 aChannelPropertyList.AppendL( iProperties[i] ); |
|
538 } |
|
539 } |
|
540 else |
|
541 { |
|
542 ERROR_GEN_1( "Incorrect channel ID: %d", aChannelId ); |
|
543 User::Leave( KErrNotSupported ); |
|
544 } |
|
545 } |
|
546 |
|
547 // ----------------------------------------------------------------------------- |
|
548 // CTCChannelTilt::GetPropertyProviderInterfaceL |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 void CTCChannelTilt::GetPropertyProviderInterfaceL( TUid aInterfaceUid, |
|
552 TAny*& aInterface ) |
|
553 { |
|
554 FUNC_LOG; |
|
555 |
|
556 aInterface = NULL; |
|
557 |
|
558 if ( aInterfaceUid.iUid == KSsyPropertyProviderInterface1.iUid ) |
|
559 { |
|
560 aInterface = reinterpret_cast<TAny*>( |
|
561 static_cast<MSsyChannelDataProvider*>( this ) ); |
|
562 } |
|
563 } |
|
564 |
|
565 // ---------------------------------------------------------------------------------- |
|
566 // CTCChannelTilt::StartChannelDataL |
|
567 // ---------------------------------------------------------------------------------- |
|
568 // |
|
569 void CTCChannelTilt::StartChannelDataL( const TSensrvChannelId aChannelId, |
|
570 TUint8* aBuffer, |
|
571 TInt aCount ) |
|
572 { |
|
573 FUNC_LOG; |
|
574 |
|
575 // Check that we have a correct channel ID |
|
576 if( aChannelId == iChannelInfo.iChannelId ) |
|
577 { |
|
578 // Store data |
|
579 iData = aBuffer; |
|
580 iCount = aCount; |
|
581 |
|
582 // Get current state and send start channel data event |
|
583 CTCState* current = CurrentState(); |
|
584 if( current ) |
|
585 { |
|
586 current->HandleEventL( EEventIdHandleStartChannelData ); |
|
587 } |
|
588 } |
|
589 else |
|
590 { |
|
591 ERROR_GEN_1( "Incorrect channel id [%d]", aChannelId ); |
|
592 User::Leave( KErrNotSupported ); |
|
593 } |
|
594 } |
|
595 |
|
596 // ---------------------------------------------------------------------------------- |
|
597 // CTCChannelTilt::StopChannelDataL |
|
598 // ---------------------------------------------------------------------------------- |
|
599 // |
|
600 void CTCChannelTilt::StopChannelDataL( const TSensrvChannelId aChannelId ) |
|
601 { |
|
602 FUNC_LOG; |
|
603 |
|
604 // Check that we have a correct channel ID |
|
605 if( aChannelId == iChannelInfo.iChannelId ) |
|
606 { |
|
607 // Get current state and send stop channel data event |
|
608 CTCState* current = CurrentState(); |
|
609 if( current ) |
|
610 { |
|
611 current->HandleEventL( EEventIdHandleStopChannelData ); |
|
612 } |
|
613 } |
|
614 else |
|
615 { |
|
616 ERROR_GEN_1( "Incorrect channel id [%d]", aChannelId ); |
|
617 User::Leave( KErrNotSupported ); |
|
618 } |
|
619 } |
|
620 |
|
621 // ---------------------------------------------------------------------------------- |
|
622 // CTCChannelTilt::ForceBufferFilledL |
|
623 // ---------------------------------------------------------------------------------- |
|
624 // |
|
625 void CTCChannelTilt::ForceBufferFilledL( const TSensrvChannelId aChannelId ) |
|
626 { |
|
627 FUNC_LOG; |
|
628 |
|
629 // Check that we have a correct channel ID |
|
630 if( aChannelId == iChannelInfo.iChannelId ) |
|
631 { |
|
632 // Get current state and send stop channel data event |
|
633 CTCState* current = CurrentState(); |
|
634 if( current ) |
|
635 { |
|
636 current->HandleEventL( EEventIdHandleForceBufferFull ); |
|
637 } |
|
638 } |
|
639 else |
|
640 { |
|
641 ERROR_GEN_1( "Incorrect channel id [%d]", aChannelId ); |
|
642 User::Leave( KErrNotSupported ); |
|
643 } |
|
644 } |
|
645 |
|
646 // ----------------------------------------------------------------------------- |
|
647 // CTCChannelTilt::GetChannelDataProviderInterfaceL |
|
648 // ----------------------------------------------------------------------------- |
|
649 // |
|
650 void CTCChannelTilt::GetChannelDataProviderInterfaceL( TUid aInterfaceUid, |
|
651 TAny*& aInterface ) |
|
652 { |
|
653 FUNC_LOG; |
|
654 |
|
655 aInterface = NULL; |
|
656 |
|
657 if ( aInterfaceUid.iUid == KSsyChannelDataProviderInterface1.iUid ) |
|
658 { |
|
659 aInterface = reinterpret_cast<TAny*>( |
|
660 static_cast<MSsyChannelDataProvider*>( this ) ); |
|
661 } |
|
662 } |
|
663 |
|
664 // ---------------------------------------------------------------------------------- |
|
665 // CTCChannelTilt::ProcessTransactionL |
|
666 // ---------------------------------------------------------------------------------- |
|
667 // |
|
668 void CTCChannelTilt::ProcessTransactionL( TTCTransactionId aId, |
|
669 TTCTransaction* aTransaction ) |
|
670 { |
|
671 FUNC_LOG; |
|
672 |
|
673 ASSERT_DEBUG_TRACE( !IsActive(), EAlreadyServingTransaction ); |
|
674 |
|
675 INFO_1( "Handling transaction [%S]", &TCUtil::TransactionIdAsDesC( aId ) ); |
|
676 |
|
677 // Store current transaction id |
|
678 iCurrentTransactionId = aId; |
|
679 |
|
680 switch( aId ) |
|
681 { |
|
682 case ETCTransactionIdOpenChannel: |
|
683 { |
|
684 // Open channel |
|
685 // Need to trap to send code to sensor server |
|
686 TRAPD( err, DoOpenChannelL() ); |
|
687 |
|
688 // Complete transaction |
|
689 iStatus = KRequestPending; |
|
690 SetActive(); |
|
691 CompleteTransaction( err ); |
|
692 break; |
|
693 } |
|
694 case ETCTransactionIdCloseChannel: |
|
695 { |
|
696 // Close channel |
|
697 DoCloseChannel(); |
|
698 |
|
699 // Complete transaction |
|
700 iStatus = KRequestPending; |
|
701 SetActive(); |
|
702 CompleteTransaction( KErrNone ); |
|
703 break; |
|
704 } |
|
705 case ETCTransactionIdStartChannelData: |
|
706 { |
|
707 // Start channel data |
|
708 DoStartChannelDataL(); |
|
709 |
|
710 // Complete transaction |
|
711 iStatus = KRequestPending; |
|
712 SetActive(); |
|
713 CompleteTransaction( KErrNone ); |
|
714 break; |
|
715 } |
|
716 case ETCTransactionIdStopChannelData: |
|
717 { |
|
718 // Start channel data |
|
719 DoStopChannelData(); |
|
720 |
|
721 // Complete transaction |
|
722 iStatus = KRequestPending; |
|
723 SetActive(); |
|
724 CompleteTransaction( KErrNone ); |
|
725 break; |
|
726 } |
|
727 case ETCTransactionIdFlushBuffer: |
|
728 { |
|
729 ASSERT_DEBUG_TRACE( aTransaction, ENullPointer ); |
|
730 |
|
731 // Store current transaction, complete and finalize transaction |
|
732 if( iCurrentTransaction ) |
|
733 { |
|
734 delete iCurrentTransaction; |
|
735 iCurrentTransaction = NULL; |
|
736 } |
|
737 TTCTransactionFlushBuffer& transaction = |
|
738 static_cast<TTCTransactionFlushBuffer&>( *aTransaction ); |
|
739 iCurrentTransaction = new( ELeave ) |
|
740 TTCTransactionFlushBuffer( transaction.iDataCount ); |
|
741 |
|
742 // Complete transaction |
|
743 iStatus = KRequestPending; |
|
744 SetActive(); |
|
745 CompleteTransaction( KErrNone ); |
|
746 break; |
|
747 } |
|
748 default: |
|
749 { |
|
750 ERROR_GEN( "Should not be here! Incorrect transaction ID" ); |
|
751 break; |
|
752 } |
|
753 } |
|
754 } |
|
755 |
|
756 // ---------------------------------------------------------------------------------- |
|
757 // CTCChannelTilt::Properties |
|
758 // ---------------------------------------------------------------------------------- |
|
759 // |
|
760 const RSensrvPropertyList& CTCChannelTilt::Properties() const |
|
761 { |
|
762 FUNC_LOG; |
|
763 |
|
764 return iProperties; |
|
765 } |
|
766 |
|
767 // ---------------------------------------------------------------------------------- |
|
768 // CTCChannelTilt::DataReceived |
|
769 // ---------------------------------------------------------------------------------- |
|
770 // |
|
771 void CTCChannelTilt::DataReceived( CSensrvChannel& aChannel, |
|
772 TInt aCount, |
|
773 TInt /*aDataLost */) |
|
774 { |
|
775 FUNC_LOG; |
|
776 |
|
777 // Check data type |
|
778 const TSensrvChannelInfo& info = aChannel.GetChannelInfo(); |
|
779 switch( info.iChannelType ) |
|
780 { |
|
781 case KSensrvChannelTypeIdAccelerometerXYZAxisData: |
|
782 { |
|
783 INFO_1( "Received KSensrvChannelTypeIdAccelerometerXYZAxisData data. Data count [%d]", aCount ); |
|
784 if( aCount ) |
|
785 { |
|
786 TPckgBuf<TSensrvAccelerometerAxisData> dataPckgBuf; |
|
787 TInt err = aChannel.GetData( dataPckgBuf ); |
|
788 ERROR( err, "GetData failed." ); |
|
789 if( err == KErrNone ) |
|
790 { |
|
791 const TSensrvAccelerometerAxisData& axisData = dataPckgBuf(); |
|
792 INFO_3( "GetData succesfull. Accelerometer [X: %d], [Y: %d], [Z: %d]", |
|
793 axisData.iAxisX, |
|
794 axisData.iAxisY, |
|
795 axisData.iAxisZ ); |
|
796 |
|
797 // Compensate data before sending. |
|
798 if ( !iAccelerometerCompensator ) |
|
799 { |
|
800 INFO( "No compensator, creating" ); |
|
801 TRAP( err, iAccelerometerCompensator = CSensorDataCompensator::NewL( |
|
802 KSensrvChannelTypeIdAccelerometerXYZAxisData, |
|
803 ESensorCompensateDeviceAndUIOrientation ) ); |
|
804 ERROR( err, "Unable to create compensator, data won't be compensated!" ); |
|
805 } |
|
806 if ( iAccelerometerCompensator ) |
|
807 { |
|
808 err = iAccelerometerCompensator->Compensate( dataPckgBuf ); |
|
809 ERROR( err, "Data compensation failed, err=%d" ); |
|
810 } |
|
811 |
|
812 INFO_3( "Compensated data Accelerometer [X: %d], [Y: %d], [Z: %d]", |
|
813 axisData.iAxisX, |
|
814 axisData.iAxisY, |
|
815 axisData.iAxisZ ); |
|
816 |
|
817 // Send new accelerometer data event to current state |
|
818 CTCState* current = CurrentState(); |
|
819 if( current ) |
|
820 { |
|
821 TTCEventAccelerometer event( axisData ); |
|
822 TRAP_IGNORE( current->HandleEventL( event.Id(), &event ) ); |
|
823 } |
|
824 } |
|
825 } |
|
826 break; |
|
827 } |
|
828 case KSensrvChannelTypeIdMagnetometerXYZAxisData: |
|
829 { |
|
830 INFO_1( "Received KSensrvChannelTypeIdMagnetometerXYZAxisData data. Data count [%d]", aCount ); |
|
831 if( aCount ) |
|
832 { |
|
833 TPckgBuf<TSensrvMagnetometerAxisData> dataPckgBuf; |
|
834 TInt err = aChannel.GetData( dataPckgBuf ); |
|
835 ERROR( err, "GetData failed." ); |
|
836 if( err == KErrNone ) |
|
837 { |
|
838 const TSensrvMagnetometerAxisData& axisData = dataPckgBuf(); |
|
839 INFO_3( "GetData succesfull. Magnetometer [X: %d], [Y: %d], [Z: %d]", |
|
840 axisData.iAxisXCalibrated, |
|
841 axisData.iAxisYCalibrated, |
|
842 axisData.iAxisZCalibrated ); |
|
843 |
|
844 // Compensate data before sending. |
|
845 if ( !iMagnetometerCompensator ) |
|
846 { |
|
847 INFO( "No compensator, creating" ); |
|
848 TRAP( err, iMagnetometerCompensator = CSensorDataCompensator::NewL( |
|
849 KSensrvChannelTypeIdMagnetometerXYZAxisData, |
|
850 ESensorCompensateDeviceAndUIOrientation ) ); |
|
851 ERROR( err, "Unable to create compensator, data won't be compensated!" ); |
|
852 } |
|
853 if ( iMagnetometerCompensator ) |
|
854 { |
|
855 err = iMagnetometerCompensator->Compensate( dataPckgBuf ); |
|
856 ERROR( err, "Data compensation failed, err=%d" ); |
|
857 } |
|
858 INFO_3( "Compensated data Magnetometer [X: %d], [Y: %d], [Z: %d]", |
|
859 axisData.iAxisXCalibrated, |
|
860 axisData.iAxisYCalibrated, |
|
861 axisData.iAxisZCalibrated ); |
|
862 |
|
863 // Send new magnetometer data event to current state |
|
864 CTCState* current = CurrentState(); |
|
865 if( current ) |
|
866 { |
|
867 TTCEventMagnetometer event( axisData ); |
|
868 TRAP_IGNORE( current->HandleEventL( event.Id(), &event ) ); |
|
869 } |
|
870 } |
|
871 } |
|
872 break; |
|
873 } |
|
874 default: |
|
875 { |
|
876 ERROR_GEN( "Incorrect channel data received." ); |
|
877 break; |
|
878 } |
|
879 } |
|
880 } |
|
881 |
|
882 // ---------------------------------------------------------------------------------- |
|
883 // CTCChannelTilt::DataError |
|
884 // ---------------------------------------------------------------------------------- |
|
885 // |
|
886 void CTCChannelTilt::DataError( CSensrvChannel& /*aChannel*/, |
|
887 TSensrvErrorSeverity aError ) |
|
888 { |
|
889 FUNC_LOG; |
|
890 |
|
891 INFO_1( "Data error [%d]", aError ); |
|
892 |
|
893 } |
|
894 |
|
895 // ---------------------------------------------------------------------------------- |
|
896 // CTCChannelTilt::GetDataListenerInterfaceL() |
|
897 // ---------------------------------------------------------------------------------- |
|
898 // |
|
899 void CTCChannelTilt::GetDataListenerInterfaceL( TUid /*aInterfaceUid*/, |
|
900 TAny*& aInterface ) |
|
901 { |
|
902 FUNC_LOG; |
|
903 |
|
904 aInterface = NULL; |
|
905 } |
|
906 |
|
907 |
|
908 // ---------------------------------------------------------------------------------- |
|
909 // CTCChannelTilt::DoOpenChannelL |
|
910 // ---------------------------------------------------------------------------------- |
|
911 // |
|
912 void CTCChannelTilt::DoOpenChannelL() |
|
913 { |
|
914 FUNC_LOG; |
|
915 |
|
916 ASSERT_DEBUG_TRACE( iAccelerometerChannel, EAccelerometerChannelNotCreated ); |
|
917 ASSERT_DEBUG_TRACE( iMagnetometerChannel, EMagnetometerChannelNotCreated ); |
|
918 iMaximumDataRate = 10; |
|
919 |
|
920 iAccelerometerChannel->OpenChannelL(); |
|
921 iMagnetometerChannel->OpenChannelL(); |
|
922 TSensrvProperty property; |
|
923 /*iAccelerometerChannel->GetPropertyL( |
|
924 KSensrvPropIdDataRate, KSensrvItemIndexNone, property ); |
|
925 property.GetValue( iMaximumDataRate );*/ |
|
926 INFO_1( "Maximum data rate accelerometer %d", iMaximumDataRate ); |
|
927 INFO( "Listen property changes in accelometer channel" ); |
|
928 iAccelerometerChannel->SetPropertyListenerL( this ); |
|
929 TSensrvProperty property1; |
|
930 iMagnetometerChannel->GetPropertyL( |
|
931 KSensrvPropIdDataRate, KSensrvItemIndexNone, property1 ); |
|
932 TInt dataRateForMagChannel( 0 ); |
|
933 property1.GetValue( dataRateForMagChannel ); |
|
934 INFO_1( "Maximum data rate magnetometer %d", dataRateForMagChannel ); |
|
935 if( dataRateForMagChannel < iMaximumDataRate ) |
|
936 { |
|
937 iMaximumDataRate = dataRateForMagChannel; |
|
938 } |
|
939 iMagnetometerChannel->SetPropertyListenerL( this ); |
|
940 } |
|
941 |
|
942 // ---------------------------------------------------------------------------------- |
|
943 // CTCChannelTilt::DoOpenChannel |
|
944 // ---------------------------------------------------------------------------------- |
|
945 // |
|
946 void CTCChannelTilt::DoCloseChannel() |
|
947 { |
|
948 FUNC_LOG; |
|
949 |
|
950 ASSERT_DEBUG_TRACE( iAccelerometerChannel, EAccelerometerChannelNotCreated ); |
|
951 ASSERT_DEBUG_TRACE( iMagnetometerChannel, EMagnetometerChannelNotCreated ); |
|
952 |
|
953 iAccelerometerChannel->CloseChannel(); |
|
954 iMagnetometerChannel->CloseChannel(); |
|
955 } |
|
956 |
|
957 // ---------------------------------------------------------------------------------- |
|
958 // CTCChannelTilt::DoStartChannelDataL |
|
959 // ---------------------------------------------------------------------------------- |
|
960 // |
|
961 void CTCChannelTilt::DoStartChannelDataL() |
|
962 { |
|
963 FUNC_LOG; |
|
964 |
|
965 ASSERT_DEBUG_TRACE( iAccelerometerChannel, EAccelerometerChannelNotCreated ); |
|
966 ASSERT_DEBUG_TRACE( iMagnetometerChannel, EMagnetometerChannelNotCreated ); |
|
967 |
|
968 iAccelerometerChannel->StartDataListeningL( this, |
|
969 KDesiredCount, |
|
970 KMaximumCount, |
|
971 KBufferingPeriod ); |
|
972 |
|
973 iMagnetometerChannel->StartDataListeningL( this, |
|
974 KDesiredCount, |
|
975 KMaximumCount, |
|
976 KBufferingPeriod ); |
|
977 } |
|
978 |
|
979 // ---------------------------------------------------------------------------------- |
|
980 // CTCChannelTilt::DoStopChannelData |
|
981 // ---------------------------------------------------------------------------------- |
|
982 // |
|
983 void CTCChannelTilt::DoStopChannelData() |
|
984 { |
|
985 FUNC_LOG; |
|
986 |
|
987 ASSERT_DEBUG_TRACE( iAccelerometerChannel, EAccelerometerChannelNotCreated ); |
|
988 ASSERT_DEBUG_TRACE( iMagnetometerChannel, EMagnetometerChannelNotCreated ); |
|
989 |
|
990 iAccelerometerChannel->StopDataListening(); |
|
991 iMagnetometerChannel->StopDataListening(); |
|
992 } |
|
993 |
|
994 // ---------------------------------------------------------------------------------- |
|
995 // CTCChannelTilt::FindAndCreateAccelerometerChannelL |
|
996 // ---------------------------------------------------------------------------------- |
|
997 // |
|
998 void CTCChannelTilt::FindAndCreateAccelerometerChannelL() |
|
999 { |
|
1000 FUNC_LOG; |
|
1001 |
|
1002 if( !iAccelerometerChannel ) |
|
1003 { |
|
1004 // Create accelerometer channel |
|
1005 TSensrvChannelInfo channelInfo; |
|
1006 if( !FindChannelL( KSensrvChannelTypeIdAccelerometerXYZAxisData, |
|
1007 KNullDesC8, |
|
1008 KNullDesC8, |
|
1009 channelInfo ) ) |
|
1010 { |
|
1011 ERROR_GEN( "Accelerometer XYZ axis data channel not found." ); |
|
1012 User::Leave( KErrNotFound ); |
|
1013 } |
|
1014 |
|
1015 INFO( "Opening accelerometer channel..." ); |
|
1016 iAccelerometerChannel = CSensrvChannel::NewL( channelInfo ); |
|
1017 INFO( "Opening accelerometer channel... Success" ); |
|
1018 |
|
1019 // Get data rate for accelometer channel |
|
1020 |
|
1021 } |
|
1022 } |
|
1023 |
|
1024 // ---------------------------------------------------------------------------------- |
|
1025 // CTCChannelTilt::FindAndCreateMagnetometerChannelL |
|
1026 // ---------------------------------------------------------------------------------- |
|
1027 // |
|
1028 void CTCChannelTilt::FindAndCreateMagnetometerChannelL() |
|
1029 { |
|
1030 FUNC_LOG; |
|
1031 |
|
1032 if( !iMagnetometerChannel ) |
|
1033 { |
|
1034 // Create magnetometer channel |
|
1035 TSensrvChannelInfo channelInfo; |
|
1036 if( !FindChannelL( KSensrvChannelTypeIdMagnetometerXYZAxisData, |
|
1037 KNullDesC8, |
|
1038 KNullDesC8, |
|
1039 channelInfo ) ) |
|
1040 { |
|
1041 ERROR_GEN( "Magnetometer XYZ axis data channel not found." ); |
|
1042 User::Leave( KErrNotFound ); |
|
1043 } |
|
1044 |
|
1045 INFO( "Opening magnetometer channel..." ); |
|
1046 iMagnetometerChannel = CSensrvChannel::NewL( channelInfo ); |
|
1047 INFO( "Opening magnetometer channel... Success" ); |
|
1048 |
|
1049 // Get data rate for magnetometer channel |
|
1050 |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 // ---------------------------------------------------------------------------------- |
|
1055 // CTCChannelTilt::Property |
|
1056 // ---------------------------------------------------------------------------------- |
|
1057 // |
|
1058 TSensrvProperty* CTCChannelTilt::Property( TSensrvPropertyId aId ) |
|
1059 { |
|
1060 FUNC_LOG; |
|
1061 |
|
1062 TSensrvProperty* property = NULL; |
|
1063 TInt count = iProperties.Count(); |
|
1064 for( TInt i = 0; i < count; i++ ) |
|
1065 { |
|
1066 if( iProperties[ i ].GetPropertyId() == aId ) |
|
1067 { |
|
1068 property = &iProperties[ i ]; |
|
1069 break; |
|
1070 } |
|
1071 } |
|
1072 |
|
1073 return property; |
|
1074 } |
|
1075 |
|
1076 // ---------------------------------------------------------------------------------- |
|
1077 // CTCChannelTilt::PropertyChanged |
|
1078 // ---------------------------------------------------------------------------------- |
|
1079 // |
|
1080 void CTCChannelTilt::PropertyChanged( CSensrvChannel& aChannel, |
|
1081 const TSensrvProperty& aChangedProperty ) |
|
1082 { |
|
1083 FUNC_LOG; |
|
1084 if( aChangedProperty.GetPropertyId() == KSensrvPropIdDataRate && |
|
1085 ( ( aChannel.GetChannelInfo().iChannelDataTypeId |
|
1086 == KSensrvChannelTypeIdAccelerometerXYZAxisData ) || |
|
1087 ( aChannel.GetChannelInfo().iChannelDataTypeId |
|
1088 == KSensrvChannelTypeIdMagnetometerXYZAxisData ) ) ) |
|
1089 { |
|
1090 TInt valueOfProp( 0 ); |
|
1091 aChangedProperty.GetValue( valueOfProp ); |
|
1092 if( ( valueOfProp < iMaximumDataRate ) |
|
1093 && ( valueOfProp < KMaximumDataRate ) && ( valueOfProp != 0 ) ) |
|
1094 { |
|
1095 // Inform current state that property has changed |
|
1096 iMaximumDataRate = valueOfProp; |
|
1097 TSensrvProperty property; |
|
1098 TInt count = iProperties.Count(); |
|
1099 for( TInt i = 0; i < count; i++ ) |
|
1100 { |
|
1101 if( iProperties[ i ].GetPropertyId() == KSensrvPropIdDataRate ) |
|
1102 { |
|
1103 property = iProperties[ i ]; |
|
1104 break; |
|
1105 } |
|
1106 } |
|
1107 property.SetValue( valueOfProp ); |
|
1108 TRAP_IGNORE( SetPropertyL( iChannelInfo.iChannelId, property ) ); |
|
1109 } |
|
1110 } |
|
1111 if( aChangedProperty.GetPropertyId() == KSensrvPropCalibrationLevel && |
|
1112 ( aChannel.GetChannelInfo().iChannelDataTypeId |
|
1113 == KSensrvChannelTypeIdMagnetometerXYZAxisData ) ) |
|
1114 { |
|
1115 iIsSetFromListened = ETrue; |
|
1116 TInt valueOfProp( 0 ); |
|
1117 aChangedProperty.GetValue( valueOfProp ); |
|
1118 // Inform current state that property has changed |
|
1119 TSensrvProperty property; |
|
1120 TInt count = iProperties.Count(); |
|
1121 for( TInt i = 0; i < count; i++ ) |
|
1122 { |
|
1123 if( iProperties[ i ].GetPropertyId() == KSensrvPropCalibrationLevel ) |
|
1124 { |
|
1125 property = iProperties[ i ]; |
|
1126 break; |
|
1127 } |
|
1128 } |
|
1129 property.SetValue( valueOfProp ); |
|
1130 TRAP_IGNORE( SetPropertyL( iChannelInfo.iChannelId, property ) ); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 // ---------------------------------------------------------------------------------- |
|
1135 // CTCChannelTilt::PropertyChanged |
|
1136 // ---------------------------------------------------------------------------------- |
|
1137 // |
|
1138 void CTCChannelTilt::PropertyError( CSensrvChannel& /*aChannel*/, |
|
1139 TSensrvErrorSeverity aError ) |
|
1140 { |
|
1141 FUNC_LOG; |
|
1142 INFO_1( "Property error [%d]", aError ); |
|
1143 } |
|
1144 |
|
1145 // ----------------------------------------------------------------------------- |
|
1146 // CTCChannelTilt::SetPropertySuccessIndicationChanged |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 // |
|
1149 void CTCChannelTilt::SetPropertySuccessIndicationChanged( TSetPropertySuccessIndicator aIndication ) |
|
1150 { |
|
1151 FUNC_LOG; |
|
1152 |
|
1153 INFO_1( "TSetPropertySuccessIndicator [%d]", aIndication ); |
|
1154 } |
|
1155 |
|
1156 // ----------------------------------------------------------------------------- |
|
1157 // CTCChannelTilt::GetPropertyListenerInterfaceL |
|
1158 // ----------------------------------------------------------------------------- |
|
1159 // |
|
1160 void CTCChannelTilt::GetPropertyListenerInterfaceL( TUid /*aInterfaceUid*/, |
|
1161 TAny*& aInterface ) |
|
1162 { |
|
1163 FUNC_LOG; |
|
1164 aInterface = NULL; |
|
1165 } |
|
1166 |
|
1167 // End of File |