|
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 #include "cradioenginelogger.h" |
|
19 |
|
20 #include "cradiordsreceiver.h" |
|
21 #include "mradioenginesettings.h" |
|
22 #include "mradiordsdataobserver.h" |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CRadioRdsReceiver::CRadioRdsReceiver( MRadioEngineSettings& aSettings ) |
|
31 : CRadioRdsReceiverBase( aSettings ) |
|
32 { |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 void CRadioRdsReceiver::ConstructL() |
|
40 { |
|
41 BaseConstructL(); |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CRadioRdsReceiver* CRadioRdsReceiver::NewL( MRadioEngineSettings& aSettings ) |
|
49 { |
|
50 CRadioRdsReceiver* self = new ( ELeave ) CRadioRdsReceiver( aSettings ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CRadioRdsReceiver::~CRadioRdsReceiver() |
|
62 { |
|
63 if ( iRdsUtility ) |
|
64 { |
|
65 iRdsUtility->Close(); |
|
66 } |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CRadioRdsReceiver::InitL( CRadioUtility& aRadioUtility, CRadioPubSub* aPubSub ) |
|
74 { |
|
75 LOG_METHOD_AUTO; |
|
76 iPubSub = aPubSub; |
|
77 |
|
78 iRdsUtility = &aRadioUtility.RadioRdsUtilityL( *this ); |
|
79 |
|
80 LogReceiverCapabilities(); |
|
81 |
|
82 SetAutomaticSwitchingL( iSettings.RdsAfSearchEnabled() ); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CRadioRdsReceiver::SetAutomaticSwitchingL( TBool aEnable ) |
|
90 { |
|
91 if ( iRdsUtility ) |
|
92 { |
|
93 User::LeaveIfError( iRdsUtility->SetAutomaticSwitching( aEnable ) ); |
|
94 } |
|
95 |
|
96 // Notifies the observers |
|
97 CRadioRdsReceiverBase::SetAutomaticSwitchingL( aEnable ); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CRadioRdsReceiver::StartReceiver() |
|
105 { |
|
106 // Request to be notified of almost all RDS data. |
|
107 // Unwanted RDS values: |
|
108 // ERdsClockTime |
|
109 // ERdsTrafficProgramme |
|
110 // ERdsTrafficAnnouncement |
|
111 // ERdsAlternateFrequency |
|
112 TRdsData rdsData; |
|
113 rdsData.iRdsFunctions = ERdsProgrammeIdentification | |
|
114 ERdsProgrammeType | |
|
115 ERdsProgrammeService | |
|
116 ERdsRadioText | |
|
117 ERdsRadioTextPlus; |
|
118 |
|
119 rdsData.iAdditionalFunctions1 = 0; |
|
120 rdsData.iAdditionalFunctions2 = 0; |
|
121 |
|
122 LOG_ASSERT( iRdsUtility, LOG( "CRadioRdsReceiver::StartReceiverL. Error: RDS utility not created!" ) ); |
|
123 if ( iRdsUtility && !iStarted ) |
|
124 { |
|
125 TInt err = iRdsUtility->NotifyRdsDataChange( rdsData ); |
|
126 if ( !err ) |
|
127 { |
|
128 // Avoid further calls |
|
129 iStarted = ETrue; |
|
130 LOG( "CRadioRdsReceiver::StartReceiverL: Requested RDS notifications from receiver." ); |
|
131 } |
|
132 else |
|
133 { |
|
134 LOG_FORMAT( "CRadioRdsReceiver::StartReceiverL. Failed to request RDS data with err %d", err ); |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CRadioRdsReceiver::StopReceiver() |
|
144 { |
|
145 LOG( "CRadioRdsReceiver::StopReceiver" ); |
|
146 |
|
147 if ( iRdsUtility ) |
|
148 { |
|
149 iRdsUtility->CancelNotifyRdsDataChange(); |
|
150 } |
|
151 iStarted = EFalse; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Logs the RDS receiver capabilities if logging is enabled |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CRadioRdsReceiver::LogReceiverCapabilities() |
|
159 { |
|
160 #ifdef LOGGING_ENABLED |
|
161 // Log the RDS utility capabilities |
|
162 if ( iRdsUtility ) |
|
163 { |
|
164 TRdsCapabilities caps; |
|
165 caps.iRdsFunctions = 0; |
|
166 caps.iAdditionalFunctions1 = 0; |
|
167 caps.iAdditionalFunctions2 = 0; |
|
168 TInt err = iRdsUtility->GetCapabilities( caps ); |
|
169 if ( !err ) |
|
170 { |
|
171 TBuf<100> capsBuf; |
|
172 if ( caps.iRdsFunctions & ERdsProgrammeIdentification == ERdsProgrammeIdentification ) |
|
173 { |
|
174 capsBuf.Append( _L("PI ") ); |
|
175 } |
|
176 if ( caps.iRdsFunctions & ERdsProgrammeType == ERdsProgrammeType ) |
|
177 { |
|
178 capsBuf.Append( _L("Genre ") ); |
|
179 } |
|
180 if ( caps.iRdsFunctions & ERdsProgrammeService == ERdsProgrammeService ) |
|
181 { |
|
182 capsBuf.Append( _L("PS ") ); |
|
183 } |
|
184 if ( caps.iRdsFunctions & ERdsRadioText == ERdsRadioText ) |
|
185 { |
|
186 capsBuf.Append( _L("RT ") ); |
|
187 } |
|
188 if ( caps.iRdsFunctions & ERdsRadioTextPlus == ERdsRadioTextPlus ) |
|
189 { |
|
190 capsBuf.Append( _L("RT+ ") ); |
|
191 } |
|
192 if ( caps.iRdsFunctions & ERdsAlternateFrequency == ERdsAlternateFrequency ) |
|
193 { |
|
194 capsBuf.Append( _L("AF ") ); |
|
195 } |
|
196 if ( caps.iRdsFunctions & ERdsClockTime == ERdsClockTime ) |
|
197 { |
|
198 capsBuf.Append( _L("Time ") ); |
|
199 } |
|
200 if ( caps.iRdsFunctions & ERdsTrafficProgramme == ERdsTrafficProgramme ) |
|
201 { |
|
202 capsBuf.Append( _L("TrafficProgramme ") ); |
|
203 } |
|
204 if ( caps.iRdsFunctions & ERdsTrafficAnnouncement == ERdsTrafficAnnouncement ) |
|
205 { |
|
206 capsBuf.Append( _L("TrafficAnnouncement ") ); |
|
207 } |
|
208 LOG_FORMAT( "CRadioRdsReceiver::LogReceiverCapabilities. RDS receiver capabilities: %S", &capsBuf ); |
|
209 LOG_FORMAT( "CRadioRdsReceiver::LogReceiverCapabilities. Functions: %d, AdditionalFunctions1: %d, iAdditionalFunctions2: %d", |
|
210 caps.iRdsFunctions, caps.iAdditionalFunctions1, caps.iAdditionalFunctions2 ); |
|
211 } |
|
212 else |
|
213 { |
|
214 LOG_FORMAT( "CRadioRdsReceiver::LogReceiverCapabilities: Failed to get RDS utility capabilities: err %d", err ); |
|
215 } |
|
216 } |
|
217 #endif // LOGGING_ENABLED |
|
218 } |