radioengine/engine/src/t_cradiordsreceiversimulator.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 26 6bcf277166c1
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 // User includes
       
    19 #include "t_cradiordsreceiversimulator.h"
       
    20 #include "mradioenginesettings.h"
       
    21 
       
    22 const TInt KVRRdsEventSimulationDelay = 5000000;
       
    23 const TUint KItemRelatedTagsCount = 2; //songTitles, artistNames
       
    24 const TUint KRadioTextItemsCount = 3;
       
    25 const TUint KRtToRtPlusEventTimeout = 400000; // 400 ms
       
    26 const TUint KSubsequentRtPlusEventsTimeout = 200; // 0.02 ms
       
    27                        
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CRadioRdsReceiverSimulator::CRadioRdsReceiverSimulator( MRadioEngineSettings& aSettings )
       
    36     : CRadioRdsReceiverBase( aSettings )
       
    37     {
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CRadioRdsReceiverSimulator::ConstructL()
       
    45     {
       
    46     BaseConstructL();
       
    47     iEventSimulatorTimer = CPeriodic::NewL( CActive::EPriorityUserInput );
       
    48     iEventSimulatorTimer2 = CPeriodic::NewL( CActive::EPriorityUserInput );
       
    49     SetAutomaticSwitchingL( iSettings.RdsAfSearchEnabled() );
       
    50 
       
    51     StartReceiver();
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CRadioRdsReceiverSimulator* CRadioRdsReceiverSimulator::NewL( MRadioEngineSettings& aSettings )
       
    59     {
       
    60     CRadioRdsReceiverSimulator* self = new (ELeave) CRadioRdsReceiverSimulator( aSettings );
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CRadioRdsReceiverSimulator::~CRadioRdsReceiverSimulator()
       
    72     {
       
    73     if ( iEventSimulatorTimer )
       
    74         {
       
    75         iEventSimulatorTimer->Cancel();
       
    76 	    }      
       
    77     if( iEventSimulatorTimer2 )
       
    78         {
       
    79         iEventSimulatorTimer2->Cancel();
       
    80         }
       
    81     delete iEventSimulatorTimer;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CRadioRdsReceiverSimulator::InitL( CRadioUtility& /*aRadioUtility*/, CRadioPubSub* aPubSub )
       
    89     {
       
    90     iPubSub = aPubSub;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CRadioRdsReceiverSimulator::StartReceiver()
       
    98     {
       
    99     if ( !iEventSimulatorTimer->IsActive() )
       
   100         {
       
   101         iEventSimulatorTimer->Start( TTimeIntervalMicroSeconds32( KVRRdsEventSimulationDelay ),
       
   102                                      TTimeIntervalMicroSeconds32( KVRRdsEventSimulationDelay ),
       
   103                                      TCallBack( StaticRdsSimulationCallback, this ));
       
   104         }
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CRadioRdsReceiverSimulator::StopReceiver()
       
   112     {
       
   113     iEventSimulatorTimer->Cancel();
       
   114     iEventSimulatorTimer2->Cancel();
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 TInt CRadioRdsReceiverSimulator::StaticRdsSimulationCallback( TAny* aSelfPtr )
       
   122     {
       
   123     TRadioRdsSimulationEvent events[] = { ERadioRdsEventSignalOn,
       
   124                                        //ERadioRdsEventAFBegin,
       
   125                                        ERadioRdsEventPS,
       
   126                                        ERadioRdsEventRadioText,
       
   127                                        //ERadioRdsEventRadioTextPlus,
       
   128                                        ERadioRdsEventPS,
       
   129                                        ERadioRdsEventRadioText,
       
   130                                        //ERadioRdsEventRadioTextPlus,
       
   131                                        ERadioRdsEventPS,
       
   132                                        ERadioRdsEventRadioText,
       
   133                                        //ERadioRdsEventRadioTextPlus,
       
   134                                        ERadioRdsEventPS,
       
   135                                        ERadioRdsEventRadioText ,
       
   136                                        //ERadioRdsEventPS,
       
   137                                        //ERadioRdsEventAFEnd,
       
   138                                        ERadioRdsEventSignalOff };
       
   139 
       
   140     TRdsPSName serviceNames[] = { _L("Tesla" ), _L("Tesla" ), _L("Tesla" ) };
       
   141     TRdsRadioText radioTexts[] = { _L( "Now playing Madonna Material Girl" ),
       
   142                                    _L( "Hox! Get Motorhead Ace of Spades from music store now for free!" ),
       
   143                                    _L( "Abba station-Waterloo Abba station-Waterloo  Abba station" ) };
       
   144     
       
   145     TInt frequencies[] = { 103100000, 95800000 }; // Frequencies in hz
       
   146     TInt numEvents = sizeof( events ) / sizeof( TRadioRdsSimulationEvent );
       
   147     TInt numServiceNames = sizeof( serviceNames ) / sizeof( TRdsPSName );
       
   148     TInt numFrequencies = sizeof( frequencies ) / sizeof( TInt );
       
   149     // RT ( radioTexts[]) and RT+ ( songTitles[] and artistNames[]) information according to PS names ( serviceNames[]).
       
   150 
       
   151     CRadioRdsReceiverSimulator* self = reinterpret_cast<CRadioRdsReceiverSimulator*>( aSelfPtr );
       
   152     if ( self )
       
   153         {
       
   154         switch ( events[self->iEventIterator] )
       
   155             {
       
   156             case ERadioRdsEventSignalOn:
       
   157                 {
       
   158                 self->MrroRdsEventSignalChange( ETrue );
       
   159                 break;
       
   160                 }
       
   161 
       
   162             case ERadioRdsEventSignalOff:
       
   163                 {
       
   164                 self->MrroRdsEventSignalChange( EFalse );
       
   165                 break;
       
   166                 }
       
   167 
       
   168             case ERadioRdsEventPS:
       
   169                 {
       
   170                 // Set RT/RT+ iterator value according to PS name iterator: If ERadioRdsEventRadioText or
       
   171                 // ERadioRdsEventRadioTextPlus arrives, displays RT or RT+ according to radio station name.
       
   172                 self->iRadioTextIterator = self->iPsIterator;
       
   173                 self->MrroRdsDataPS( serviceNames[self->iPsIterator] );
       
   174                 self->iPsIterator++;
       
   175                 if ( self->iPsIterator >= numServiceNames )
       
   176                     {
       
   177                     self->iPsIterator = 0;
       
   178                     }
       
   179                 break;
       
   180                 }
       
   181 
       
   182             case ERadioRdsEventAFBegin:
       
   183                 {
       
   184                 if ( self->iSettings.RdsAfSearchEnabled() )
       
   185                     {
       
   186                     self->MrroRdsSearchBeginAF();
       
   187                     }
       
   188                 break;
       
   189                 }
       
   190 
       
   191             case ERadioRdsEventAFEnd:
       
   192                 {
       
   193                 if ( self->iSettings.RdsAfSearchEnabled() )
       
   194                     {
       
   195                     self->MrroRdsSearchEndAF( KErrNone, frequencies[self->iFrequencyIterator] );
       
   196                     }
       
   197                 self->iFrequencyIterator++;
       
   198                 if ( self->iFrequencyIterator >= numFrequencies )
       
   199                     {
       
   200                     self->iFrequencyIterator = 0;
       
   201                     }
       
   202                 break;
       
   203                 }
       
   204             case ERadioRdsEventRadioText:
       
   205                 {
       
   206                 // Display RT according to PS name.
       
   207                 self->MrroRdsDataRT( radioTexts[self->iRadioTextIterator] );
       
   208                 // how many times StaticRdsSimulationCallback2 entered
       
   209                 if ( self->iRtPlusIterator >= KItemRelatedTagsCount )
       
   210                     {
       
   211                     self->iRtPlusIterator = 0;
       
   212                     }
       
   213                                 
       
   214                 // start timer for displaying the two consequent RT+ events
       
   215                 self->startRTPlusTimer();
       
   216                 
       
   217                 // how many radio text tags received
       
   218                 if( self->iRtIterator >= KRadioTextItemsCount )
       
   219                     {
       
   220                     self->iRtIterator = 1;                    
       
   221                     }
       
   222                 else
       
   223                     {
       
   224                     self->iRtIterator++;
       
   225                     }
       
   226                 break;
       
   227                 }
       
   228             case ERadioRdsEventRadioTextPlus:
       
   229                 {
       
   230                 // Display RT+ information according to PS name.
       
   231 				
       
   232                 break;
       
   233                 }
       
   234             default:
       
   235                 break;
       
   236             }
       
   237         self->iEventIterator++;
       
   238         if ( self->iEventIterator >= numEvents )
       
   239             {
       
   240             self->iEventIterator = 0;
       
   241             }
       
   242         }
       
   243     return KErrNone;
       
   244     }
       
   245 
       
   246 void CRadioRdsReceiverSimulator::startRTPlusTimer()
       
   247     {
       
   248     
       
   249     iEventSimulatorTimer2->Cancel();
       
   250     if ( !iEventSimulatorTimer2->IsActive() )
       
   251         {        
       
   252         iEventSimulatorTimer2->Start( TTimeIntervalMicroSeconds32( KRtToRtPlusEventTimeout ),
       
   253             TTimeIntervalMicroSeconds32( KSubsequentRtPlusEventsTimeout ),
       
   254             TCallBack( StaticRdsSimulationCallback2, this ));
       
   255         }
       
   256     }
       
   257 
       
   258 TInt CRadioRdsReceiverSimulator::StaticRdsSimulationCallback2( TAny* aSelfPtr )
       
   259     {    
       
   260     TRdsRadioText songTitles[] = { _L( "Material Girl" ),
       
   261                                    _L( "Ace of Spades" ),
       
   262                                    _L( "Waterloo" ) };
       
   263     TRdsRadioText artistNames[] = { _L( "Madonna" ),
       
   264                                     _L( "Motorhead" ),
       
   265                                     _L( "Abba" ) };
       
   266 
       
   267     CRadioRdsReceiverSimulator* self = reinterpret_cast<CRadioRdsReceiverSimulator*>( aSelfPtr );
       
   268     
       
   269     if ( self )
       
   270         {
       
   271         if( self->iRtPlusIterator == 0 )
       
   272             {
       
   273             self->MrroRdsDataRTplus( ERTplusItemTitle, songTitles[self->iRtIterator-1] );
       
   274             }
       
   275         else if( self->iRtPlusIterator == 1 )
       
   276             {
       
   277             self->MrroRdsDataRTplus( ERTplusItemArtist, artistNames[self->iRtIterator-1] );
       
   278             }
       
   279         }
       
   280     self->iRtPlusIterator++;
       
   281         
       
   282     return KErrNone;
       
   283     }