fmradio/fmradioengine/src/fmradiordsreceiversimulator.cpp
changeset 0 f3d95d9c00ab
equal deleted inserted replaced
-1:000000000000 0:f3d95d9c00ab
       
     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:  The RDS receiver implementation for FM Radio
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "fmradiordsreceiversimulator.h"
       
    20 
       
    21 const TInt KFMRadioRdsEventSimulationDelay = 3000000;
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CFMRadioRdsReceiverSimulator::CFMRadioRdsReceiverSimulator
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CFMRadioRdsReceiverSimulator::CFMRadioRdsReceiverSimulator( TRadioSettings& aSettings ) : CFMRadioRdsReceiverBase(aSettings)
       
    30     {
       
    31     }
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CFMRadioRdsReceiverSimulator::ConstructL
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 void CFMRadioRdsReceiverSimulator::ConstructL()
       
    38     {    
       
    39     BaseConstructL();
       
    40     iEventSimulatorTimer = CPeriodic::NewL(CActive::EPriorityUserInput);
       
    41     SetAutomaticSwitchingL( iSettings.IsRdsAfSearchEnabled() );
       
    42     StartReceiver();
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CFMRadioRdsReceiverSimulator::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CFMRadioRdsReceiverSimulator* CFMRadioRdsReceiverSimulator::NewL( TRadioSettings& aSettings )
       
    50     {
       
    51     CFMRadioRdsReceiverSimulator* self = new ( ELeave ) CFMRadioRdsReceiverSimulator( aSettings );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CFMRadioRdsReceiverSimulator::~CFMRadioRdsReceiverSimulator
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CFMRadioRdsReceiverSimulator::~CFMRadioRdsReceiverSimulator()
       
    63     {    
       
    64     if( iEventSimulatorTimer && iEventSimulatorTimer->IsActive() )
       
    65         {
       
    66         iEventSimulatorTimer->Cancel();
       
    67         }
       
    68         
       
    69     delete iEventSimulatorTimer;
       
    70 	iEventSimulatorTimer = NULL;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CFMRadioRdsReceiverSimulator::InitL
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CFMRadioRdsReceiverSimulator::InitL( CRadioUtility& /*aRadioUtility*/, CFMRadioPubSub* aPubSub )
       
    78     {
       
    79     iPubSub = aPubSub;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CFMRadioRdsReceiverSimulator::StartReceiver
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CFMRadioRdsReceiverSimulator::StartReceiver()
       
    87     {
       
    88     if( !iEventSimulatorTimer->IsActive() )
       
    89         {
       
    90     	iEventSimulatorTimer->Start( TTimeIntervalMicroSeconds32(KFMRadioRdsEventSimulationDelay),
       
    91     					             TTimeIntervalMicroSeconds32(KFMRadioRdsEventSimulationDelay), 
       
    92     					             TCallBack(StaticRdsSimulationCallback, this));
       
    93         }
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CFMRadioRdsReceiverSimulator::StopReceiver
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CFMRadioRdsReceiverSimulator::StopReceiver()
       
   101     {
       
   102     iEventSimulatorTimer->Cancel();
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CFMRadioRdsReceiverSimulator::SetRadioEngineForRadioFmTunerSimulation
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CFMRadioRdsReceiverSimulator::SetRadioEngineForRadioFmTunerSimulation( CRadioEngine* aEngine )
       
   110 	{ 
       
   111 	iEngine = aEngine;
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CFMRadioRdsReceiverSimulator::StaticRdsSimulationCallback
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt CFMRadioRdsReceiverSimulator::StaticRdsSimulationCallback( TAny* aSelfPtr )
       
   119 	{
       
   120 	TFMRadioRdsSimulationEvent events[] = { EFMRadioRdsEventRadioTextPlus,
       
   121 	                                        EFMRadioRdsEventRadioTextPlus,
       
   122 	                                        EFMRadioRdsEventRadioTextPlus,
       
   123 	                                        EFMRadioRdsEventRadioTextPlus,
       
   124 	                                        EFMRadioRdsEventSignalOn,
       
   125 									//   EFMRadioRdsEventAFBegin,
       
   126 							        //   EFMRadioRdsEventAFEnd,
       
   127 									   EFMRadioRdsEventPS,
       
   128 									   EFMRadioRdsEventRadioText,
       
   129                                        //EFMRadioRdsEventSignalOff,
       
   130                                        //EFMRadioRdsEventSignalOn,
       
   131                                        EFMRadioRdsEventPS,
       
   132                                        EFMRadioRdsEventPS,
       
   133                                  //      EFMRadioRdsEventRadioText,
       
   134                                  //      EFMRadioRdsEventRadioText
       
   135                                        EFMRadioRdsEventAFBegin,
       
   136                                        EFMRadioRdsEventPS,
       
   137                                        EFMRadioRdsEventAFEnd,
       
   138                                        EFMRadioRdsEventSignalOff,
       
   139                                        EFMRadioRdsEventRadioTextPlus};
       
   140 
       
   141     TRdsPSName serviceNames[] = 
       
   142         { 
       
   143         _L("RadioXYZ"), 
       
   144         _L("Some"), 
       
   145         _L("program"), 
       
   146         _L("service"), 
       
   147         _L("text") 
       
   148         };
       
   149     
       
   150     TRdsRadioText radioTexts[] = 
       
   151         { 
       
   152         _L("radio text"),
       
   153 		_L("radio text radio text radio text"),
       
   154 		_L("full radio text full radio text full radio text full radio textt") 
       
   155 		};
       
   156     
       
   157     TRdsRadioText radioTextsPlus[] = 
       
   158         { 
       
   159         _L("The rock song"),
       
   160         _L("Album of the year"),
       
   161         _L("Rock 'n' Rollers"),
       
   162         _L("http://www.symbianfoundation.org/"),
       
   163         _L("Disco Dancers"),
       
   164         _L("The disco song"),
       
   165         _L("The Greatest"),
       
   166         _L("http://developer.symbian.org/"),
       
   167         };
       
   168     
       
   169     TRdsRTplusClass radioTextsPlusClasses[] = 
       
   170         { 
       
   171         ERTplusItemTitle,
       
   172         ERTplusItemAlbum,
       
   173         ERTplusItemArtist,
       
   174         ERTplusProgramHomepage,
       
   175         ERTplusItemArtist,
       
   176         ERTplusItemTitle,
       
   177         ERTplusItemAlbum,
       
   178         ERTplusProgramHomepage,
       
   179         };
       
   180     
       
   181     TInt frequencies[] = { 103100000, 95800000 }; // Frequencies in hz
       
   182     
       
   183     TInt numEvents = sizeof( events ) / sizeof( TFMRadioRdsSimulationEvent );
       
   184     TInt numServiceNames = sizeof( serviceNames ) / sizeof( TRdsPSName );
       
   185     TInt numRadioTexts = sizeof( radioTexts ) / sizeof( TRdsRadioText );
       
   186     TInt numRadioTextsPlus = sizeof( radioTextsPlus ) / sizeof( TRdsRadioText );
       
   187     TInt numFrequencies = sizeof( frequencies ) / sizeof( TInt );
       
   188     
       
   189 	CFMRadioRdsReceiverSimulator* self = static_cast<CFMRadioRdsReceiverSimulator*>(aSelfPtr);
       
   190 	if( self )
       
   191 		{
       
   192         switch( events[self->iEventIterator] )
       
   193             {
       
   194             case EFMRadioRdsEventSignalOn:
       
   195                 {
       
   196                 self->MrroRdsEventSignalChange( ETrue );
       
   197                 break;
       
   198                 }
       
   199                 
       
   200             case EFMRadioRdsEventSignalOff:
       
   201                 {
       
   202                 self->MrroRdsEventSignalChange( EFalse );
       
   203                 break;
       
   204                 }
       
   205                 
       
   206             case EFMRadioRdsEventPS:
       
   207                 {
       
   208                 self->MrroRdsDataPS( serviceNames[self->iPsIterator] );
       
   209                 self->iPsIterator++;
       
   210                 if( self->iPsIterator >= numServiceNames )
       
   211                     {
       
   212                     self->iPsIterator = 0;
       
   213                     }
       
   214                 break;
       
   215                 }
       
   216             case EFMRadioRdsEventRadioText:
       
   217                 {
       
   218                 self->MrroRdsDataRT( radioTexts[self->iRadioTextIterator] );
       
   219                 self->iRadioTextIterator++;
       
   220                 if( self->iRadioTextIterator >= numRadioTexts )
       
   221                     {
       
   222                     self->iRadioTextIterator = 0;
       
   223                     }
       
   224                 break;
       
   225                 }   
       
   226             case EFMRadioRdsEventAFBegin:
       
   227                 {
       
   228                 if ( self->AutomaticSwitchingEnabled() )
       
   229                 	{
       
   230                 	 self->MrroRdsSearchBeginAF();
       
   231                 	}
       
   232                 break;
       
   233                 }
       
   234                 
       
   235             case EFMRadioRdsEventAFEnd:
       
   236                 {
       
   237                 if ( self->AutomaticSwitchingEnabled() )
       
   238                 	{ 
       
   239                      // Simulate MrftoFrequencyChange method from MRadioFmTunerObserver
       
   240                      if( self->iEngine )
       
   241                      	{
       
   242                      	self->iEngine->MrftoFrequencyChange( frequencies[self->iFrequencyIterator] );
       
   243                      	}
       
   244                      
       
   245                      self->MrroRdsSearchEndAF( KErrNone, frequencies[self->iFrequencyIterator] );
       
   246                      
       
   247                      self->iFrequencyIterator++;
       
   248                      if( self->iFrequencyIterator >= numFrequencies )
       
   249                          {
       
   250                          self->iFrequencyIterator = 0;
       
   251                          }
       
   252                 	}
       
   253                 break;
       
   254                 }
       
   255             case EFMRadioRdsEventRadioTextPlus:
       
   256                 {
       
   257                 self->MrroRdsDataRTplus( radioTextsPlusClasses[self->iRadioTextPlusIterator], 
       
   258                                          radioTextsPlus[self->iRadioTextPlusIterator]);
       
   259                 self->iRadioTextPlusIterator++;
       
   260                 if( self->iRadioTextPlusIterator >= numRadioTextsPlus )
       
   261                     {
       
   262                     self->iRadioTextPlusIterator = 0;
       
   263                     }
       
   264                 break;
       
   265                 }                 
       
   266             default:
       
   267                 break;
       
   268             }
       
   269         self->iEventIterator++;
       
   270         if( self->iEventIterator >= numEvents )
       
   271             {
       
   272             self->iEventIterator = 0;
       
   273             }
       
   274 		}
       
   275 	return KErrNone;
       
   276 	}