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