24
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Queries the ME signal quality. Retrieves signal level and BitErrorRate (ber)
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <et_phone.h>
|
|
19 |
#include "Msignal.h"
|
|
20 |
#include "mSLOGGER.H"
|
|
21 |
#include "ATIO.H"
|
|
22 |
#include "Matstd.h"
|
|
23 |
|
|
24 |
CATGetSignal* CATGetSignal::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
|
|
25 |
{
|
|
26 |
CATGetSignal* signal = new(ELeave) CATGetSignal(aIo, aTelObject, aInit, aPhoneGlobals);
|
|
27 |
CleanupStack::PushL(signal);
|
|
28 |
signal->ConstructL();
|
|
29 |
CleanupStack::Pop();
|
|
30 |
return signal;
|
|
31 |
}
|
|
32 |
|
|
33 |
CATGetSignal::CATGetSignal(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
|
|
34 |
: CATCommands(aIo,aTelObject,aInit,aPhoneGlobals)
|
|
35 |
{}
|
|
36 |
|
|
37 |
void CATGetSignal::ConstructL()
|
|
38 |
{
|
|
39 |
CATCommands::ConstructL();
|
|
40 |
}
|
|
41 |
|
|
42 |
CATGetSignal::~CATGetSignal()
|
|
43 |
{
|
|
44 |
iIo->RemoveExpectStrings(this);
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
void CATGetSignal::Start(TTsyReqHandle aTsyReqHandle,TAny* aParams)
|
|
49 |
{
|
|
50 |
LOGTEXT(_L8("MMTsy:\tCATGetSignal:\tStarting ME signal quality query."));
|
|
51 |
iReqHandle = aTsyReqHandle;
|
|
52 |
|
|
53 |
//
|
|
54 |
// Validate the arguments
|
|
55 |
TTsySignalInfo* signal = static_cast<TTsySignalInfo*>(aParams);
|
|
56 |
__ASSERT_DEBUG(signal!=NULL,Panic(EATGetSignalNullParameter));
|
|
57 |
__ASSERT_DEBUG(signal->iBar!=NULL,Panic(EATGetSignalNullParameter));
|
|
58 |
__ASSERT_DEBUG(signal->iSignalStrength!=NULL,Panic(EATGetSignalNullParameter));
|
|
59 |
|
|
60 |
//
|
|
61 |
// Store the arguments
|
|
62 |
iSignalInfo.iSignalStrength = signal->iSignalStrength;
|
|
63 |
iSignalInfo.iBar = signal->iBar;
|
|
64 |
|
|
65 |
iTxBuffer.Format(KGetSignalQualityCommand);
|
|
66 |
iIo->Write(this, iTxBuffer);
|
|
67 |
iIo->SetTimeOut(this, 5000);
|
|
68 |
iState=EATSignalWaitForWriteComplete;
|
|
69 |
}
|
|
70 |
|
|
71 |
|
|
72 |
void CATGetSignal::EventSignal(TEventSource aSource)
|
|
73 |
{
|
|
74 |
if (aSource==ETimeOutCompletion)
|
|
75 |
{
|
|
76 |
LOGTEXT(_L8("MMTsy:\tCATGetSignal:\tTimeout Error during signal quality query"));
|
|
77 |
RemoveStdExpectStrings();
|
|
78 |
Complete(KErrTimedOut,aSource);
|
|
79 |
return;
|
|
80 |
}
|
|
81 |
|
|
82 |
switch(iState)
|
|
83 |
{
|
|
84 |
case EATSignalWaitForWriteComplete:
|
|
85 |
__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
86 |
{
|
|
87 |
iIo->WriteAndTimerCancel(this);
|
|
88 |
StandardWriteCompletionHandler(aSource, 5);
|
|
89 |
iState=EATSignalReadComplete;
|
|
90 |
}
|
|
91 |
break;
|
|
92 |
|
|
93 |
case EATSignalReadComplete:
|
|
94 |
__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
|
|
95 |
{
|
|
96 |
iIo->WriteAndTimerCancel(this);
|
|
97 |
TInt ret(ValidateExpectString());
|
|
98 |
RemoveStdExpectStrings();
|
|
99 |
if (ret)
|
|
100 |
{
|
|
101 |
Complete(ret,aSource);
|
|
102 |
return;
|
|
103 |
}
|
|
104 |
TRAP(ret,ParseSignalResponseL());
|
|
105 |
Complete(ret,aSource);
|
|
106 |
}
|
|
107 |
break;
|
|
108 |
|
|
109 |
default:
|
|
110 |
break;
|
|
111 |
}//switch
|
|
112 |
}//EventSignal
|
|
113 |
|
|
114 |
|
|
115 |
void CATGetSignal::Stop(TTsyReqHandle aTsyReqHandle)
|
|
116 |
{
|
|
117 |
__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle, Panic(EIllegalTsyReqHandle));
|
|
118 |
LOGTEXT2(_L8("CATGetSignal::Stop - Cancelling from state %d"), iState);
|
|
119 |
|
|
120 |
if (iState==EATSignalWaitForWriteComplete)
|
|
121 |
{
|
|
122 |
Complete(KErrCancel, EReadCompletion);
|
|
123 |
}
|
|
124 |
// else do nothing because we have already sent the AT command
|
|
125 |
// or have not actually started doing anything!
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
void CATGetSignal::Complete(TInt aError, TEventSource aSource)
|
|
130 |
{
|
|
131 |
iIo->WriteAndTimerCancel(this);
|
|
132 |
iIo->RemoveExpectStrings(this);
|
|
133 |
iOKExpectString = NULL;
|
|
134 |
iErrorExpectString = NULL;
|
|
135 |
|
|
136 |
CATCommands::Complete(aError, aSource);
|
|
137 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
138 |
|
|
139 |
LOGTEXT2(_L8("MMTsy:CATGetSignal:\tCATGetSignal completed with error code : %d"), aError);
|
|
140 |
iState = EATNotInProgress;
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
void CATGetSignal::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
|
|
145 |
{
|
|
146 |
if (iState!=EATNotInProgress)
|
|
147 |
{
|
|
148 |
iIo->WriteAndTimerCancel(this);
|
|
149 |
iTelObject->ReqCompleted(iReqHandle, aStatus);
|
|
150 |
iState = EATNotInProgress;
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
void CATGetSignal::ParseSignalResponseL()
|
|
155 |
{
|
|
156 |
ParseBufferLC();
|
|
157 |
CATParamListEntry* entry;
|
|
158 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
159 |
TBool first = ETrue;
|
|
160 |
TUint icounter = 0;
|
|
161 |
TInt ret;
|
|
162 |
|
|
163 |
while (entry = iter++, entry != NULL)
|
|
164 |
{
|
|
165 |
if (first)
|
|
166 |
{
|
|
167 |
first = EFalse;
|
|
168 |
while (entry->iResultPtr != KCSQResponseString)
|
|
169 |
{
|
|
170 |
entry->Deque();
|
|
171 |
delete entry;
|
|
172 |
entry = iter++;
|
|
173 |
if (entry == NULL)
|
|
174 |
{
|
|
175 |
CleanupStack::PopAndDestroy();
|
|
176 |
User::Leave(KErrNotFound);
|
|
177 |
}
|
|
178 |
} //while
|
|
179 |
LOGTEXT(_L8("MMTsy:\tCATGetSignal:\tFound +CSQ string!"));
|
|
180 |
}
|
|
181 |
else
|
|
182 |
{
|
|
183 |
TLex8 aLex((entry->iResultPtr).Ptr());
|
|
184 |
if (icounter++ == 0)
|
|
185 |
{
|
|
186 |
TInt32 signalStrength;
|
|
187 |
ret = aLex.Val(signalStrength);
|
|
188 |
if (ret == KErrNone)
|
|
189 |
{
|
|
190 |
//Calculate the number of signal bars
|
|
191 |
TInt8 numberOfBars;
|
|
192 |
numberOfBars = NumberOfSignalBars(signalStrength);
|
|
193 |
|
|
194 |
// Convert the the 0 to 31 range(in aSignalStrength) which the AT
|
|
195 |
// command returns to the corresponding dBm values(-113dBm to -51dBm).
|
|
196 |
signalStrength = (-113 + (2 * signalStrength));
|
|
197 |
|
|
198 |
if((iSignalInfo.iBar)) // Ensure we do not cause an access violation
|
|
199 |
*(iSignalInfo.iBar) = numberOfBars;
|
|
200 |
|
|
201 |
if((iSignalInfo.iSignalStrength)) // Ensure we do not cause an access violation
|
|
202 |
*(iSignalInfo.iSignalStrength) = signalStrength;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}//else
|
|
206 |
entry->Deque();
|
|
207 |
delete entry;
|
|
208 |
}//while
|
|
209 |
|
|
210 |
CleanupStack::PopAndDestroy();
|
|
211 |
}//ParsesignalResponseL
|
|
212 |
|
|
213 |
|
|
214 |
TInt8 CATGetSignal::NumberOfSignalBars(TInt32 aSignalStrength)
|
|
215 |
|
|
216 |
/** * Number of signalbars *
|
|
217 |
* This method returns the number of signal bars that the phone should show on the display.
|
|
218 |
* @param aSignalStrength points to the signalstrength given in the range 0 to 31. 0 to 31 is returned by the phone(ETSI standard) and represents -113dB to -51dB.
|
|
219 |
* @return number of bars. Can take the values (-1) to 5 (-1 represents KErrNotFound)
|
|
220 |
*/
|
|
221 |
{
|
|
222 |
TInt8 bars;
|
|
223 |
|
|
224 |
if(aSignalStrength == KSignalStrengthMinus113dBm)
|
|
225 |
{
|
|
226 |
bars = 0;
|
|
227 |
}
|
|
228 |
else if (aSignalStrength <= KSignalStrengthMinus101dBm)
|
|
229 |
{
|
|
230 |
bars = 1;
|
|
231 |
}
|
|
232 |
else if (aSignalStrength <= KSignalStrengthMinus89dBm)
|
|
233 |
{
|
|
234 |
bars = 2;
|
|
235 |
}
|
|
236 |
else if (aSignalStrength <= KSignalStrengthMinus77dBm)
|
|
237 |
{
|
|
238 |
bars = 3;
|
|
239 |
}
|
|
240 |
else if (aSignalStrength <= KSignalStrengthMinus53dBm)
|
|
241 |
{
|
|
242 |
bars = 4;
|
|
243 |
}
|
|
244 |
|
|
245 |
else if(aSignalStrength == KSignalStrengthMinus51dBm)
|
|
246 |
{
|
|
247 |
bars = 5;
|
|
248 |
}
|
|
249 |
else
|
|
250 |
{
|
|
251 |
bars=KErrNotFound;
|
|
252 |
}
|
|
253 |
|
|
254 |
return bars;
|
|
255 |
|
|
256 |
} //End of NumberOfSignalBars
|
|
257 |
|