|
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 // This file implements the base methods for the CATBase class. It deals primarily |
|
15 // expect string handling and event notification. |
|
16 // used by the current etel regression test harness. |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 @note Only the constructors, destructors, panic function,and event handling code are |
|
23 */ |
|
24 |
|
25 #include "Te_LoopBackATBASE.H" |
|
26 #include "Te_LoopBackATIO.H" |
|
27 #include "Te_LoopBackSLOGGER.H" |
|
28 |
|
29 _LIT(KCsyName,"LOOPBACK"); |
|
30 _LIT(KPortName,"LOOPBACK::1"); |
|
31 |
|
32 const TBps KBaudRate=EBps115200; |
|
33 const TDataBits KDataBits=EData8; |
|
34 const TStopBits KStopBits=EStop1; |
|
35 const TUint KHandshake=0; |
|
36 |
|
37 // |
|
38 // Panic Function |
|
39 // |
|
40 GLDEF_C void HayesPanic(THayesPanic aPanicNumber) |
|
41 /** |
|
42 * This global method implements a test harness specific panic, identified as the Hayes |
|
43 * TSY. The panic reason is passed as a parameter. |
|
44 * |
|
45 * @param aPanicNumber, one of the reasons specified in the THayesPanic enumeration. |
|
46 * @return None |
|
47 */ |
|
48 { |
|
49 _LIT(KPanicHayesTSY,"Hayes TSY"); |
|
50 User::Panic(KPanicHayesTSY,aPanicNumber); |
|
51 } |
|
52 |
|
53 // |
|
54 // CATParamListEntry |
|
55 // A pointer to a meaningful result in the received buffer from the modem |
|
56 // |
|
57 CATParamListEntry::CATParamListEntry(const TPtrC8& aPtr) |
|
58 /** |
|
59 * This function is currently not used by the Etel regression test harness. |
|
60 */ |
|
61 { |
|
62 iResultPtr.Set(aPtr); |
|
63 } |
|
64 |
|
65 CATParamListEntry::~CATParamListEntry() |
|
66 /** |
|
67 * This function is currently not used by the Etel regression test harness. |
|
68 */ |
|
69 {} |
|
70 |
|
71 void CATParamListEntry::Deque() |
|
72 /** |
|
73 * This function is currently not used by the Etel regression test harness. |
|
74 */ |
|
75 { |
|
76 iLink.Deque(); |
|
77 } |
|
78 |
|
79 // |
|
80 // The Command Base Class |
|
81 // |
|
82 CATBase::CATBase() |
|
83 /** |
|
84 * This constructor determines the offset of the iLink member of the a CATParamListEntry |
|
85 * and stores this offset in the iRxResults member of the CATBase object. |
|
86 * |
|
87 * @return None |
|
88 */ |
|
89 { |
|
90 iRxResults.SetOffset(_FOFF(CATParamListEntry,iLink)); |
|
91 } |
|
92 |
|
93 CATBase::~CATBase() |
|
94 // |
|
95 // Assumes CATIO pointer is still valid |
|
96 // |
|
97 /** |
|
98 * This destructor first checks to see if the iResults list is empty. If it is not, it |
|
99 * clears the list and deletes the entry. |
|
100 */ |
|
101 { |
|
102 if(!iRxResults.IsEmpty()) |
|
103 { |
|
104 CATParamListEntry* entry; |
|
105 TDblQueIter<CATParamListEntry> iter(iRxResults); |
|
106 while (entry = iter++,entry!=NULL) |
|
107 { |
|
108 entry->Deque(); |
|
109 delete entry; |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 void CATBase::ConstructL() |
|
115 /** |
|
116 * This is the second phase constructor for the CATBase class. It configures the port |
|
117 * specified by the combination of KCsyName and KPortName. Configuration data includes |
|
118 * baud rate, data bits, stop bits, and handshake. |
|
119 * |
|
120 * @leave This method leaves if there is an error configuring the port or potentially |
|
121 * from the NewL method which is called. |
|
122 */ |
|
123 { |
|
124 TFileName csyName(KCsyName); |
|
125 TName portName(KPortName); |
|
126 iIo=CATIO::NewL(csyName,portName); |
|
127 TCommConfigV01 commConfig; |
|
128 commConfig.iRate=KBaudRate; |
|
129 commConfig.iDataBits=KDataBits; |
|
130 commConfig.iStopBits=KStopBits; |
|
131 commConfig.iHandshake=KHandshake; |
|
132 |
|
133 TCommConfig commConfigWrapper(commConfig); |
|
134 TInt r=iIo->ConfigurePort(commConfigWrapper); |
|
135 User::LeaveIfError(r); |
|
136 } |
|
137 |
|
138 void CATBase::GenericEventSignal(TEventSource aEventSource, TInt aStatus) |
|
139 // |
|
140 // If an IO error has occurred, complete this ATBase-object with the error. |
|
141 // |
|
142 /** |
|
143 * This method is the general event signal routine. If an IO error occurred, |
|
144 * the Complete method is called with the errored status. If there is no |
|
145 * error (aStatus is KErrNone) the EventSignal routine is called. |
|
146 * |
|
147 * @param aEventSource a TEventSource member which indicates Read, Write, |
|
148 * or Timeout completion. |
|
149 * @param aStatus status from the IO operation. If this status is NOT |
|
150 * KErrNone, the Complete method will be called instead of the |
|
151 * EventSignal method. |
|
152 */ |
|
153 { |
|
154 if (aStatus!=KErrNone) |
|
155 { |
|
156 LOGTEXT2(_L8("CATBase EventSignal received error status %d"),aStatus); |
|
157 Complete(aStatus); |
|
158 } |
|
159 else |
|
160 EventSignal(aEventSource); |
|
161 } |
|
162 |
|
163 void CATBase::AddStdExpectStrings() |
|
164 /** |
|
165 * This function is currently not used by the Etel regression test harness. |
|
166 */ |
|
167 { |
|
168 if (!iOKExpectString) |
|
169 iOKExpectString=iIo->AddExpectString(this,KOKString); |
|
170 if (!iErrorExpectString) |
|
171 iErrorExpectString=iIo->AddExpectString(this,KErrorString); |
|
172 } |
|
173 |
|
174 void CATBase::ValidateExpectStringL() |
|
175 /** |
|
176 * This function is currently not used by the Etel regression test harness. |
|
177 */ |
|
178 { |
|
179 if(iIo->FoundChatString()==iErrorExpectString) |
|
180 { |
|
181 LOGTEXT(_S8("CATBase Modem returned ERROR in response to command")); |
|
182 User::Leave(KErrGeneral); |
|
183 } |
|
184 if(iIo->FoundChatString()==iOKExpectString) |
|
185 return; |
|
186 LOGTEXT(_S8("CATBase Modem returned unexpected response to command")); |
|
187 User::Leave(KErrUnknown); |
|
188 } |
|
189 |
|
190 void CATBase::RemoveStdExpectStrings() |
|
191 /** |
|
192 * This function is currently not used by the Etel regression test harness. |
|
193 */ |
|
194 { |
|
195 LOGTEXT(_S8("RemoveStdExpectStrings()")); |
|
196 iIo->RemoveExpectString(iOKExpectString); |
|
197 iOKExpectString=NULL; |
|
198 iIo->RemoveExpectString(iErrorExpectString); |
|
199 iErrorExpectString=NULL; |
|
200 } |
|
201 |
|
202 void CATBase::ParseBufferLC() |
|
203 // |
|
204 // Parses buffer |
|
205 // |
|
206 /** |
|
207 * This function is currently not used by the Etel regression test harness. |
|
208 */ { |
|
209 LOGTEXT(_S8("CATBase Parse the Buffer List")); |
|
210 iBuffer.Set(iIo->GetRxBufferLC(iBufferMarker)); |
|
211 TInt pos=iBuffer.FindF(KOKString); |
|
212 if(pos==KErrNotFound) |
|
213 { |
|
214 LOGTEXT(_S8("CATBase Error - Cannot find OK'")); |
|
215 User::Leave(pos); |
|
216 } |
|
217 // Place everything before the OK into buffer |
|
218 iBuffer.Set(iBuffer.Left(pos)); |
|
219 |
|
220 TLex8 yyLex(iBuffer); |
|
221 TChar peek; |
|
222 // Look for '=' sign and move seeker cursor to the right of it if it exists |
|
223 pos=iBuffer.Find(_L8("=")); |
|
224 if (pos!=KErrNotFound) |
|
225 { |
|
226 yyLex.Inc(pos+1); |
|
227 } |
|
228 // Move cursor past any spaces or open brackets |
|
229 yyLex.SkipSpace(); |
|
230 peek=yyLex.Peek(); |
|
231 if ((TUint)peek=='(' || (TUint)peek=='[' || (TUint)peek=='{') |
|
232 yyLex.Inc(); |
|
233 |
|
234 yyLex.SkipSpace(); |
|
235 peek = yyLex.Peek(); |
|
236 do |
|
237 { |
|
238 // Search for the next character that is not a comma, and mark it. Keep looking at |
|
239 // subsequent characters until it is a space,comma,closing bracket or end of string. |
|
240 // Store the string (between marked character and current character) as an item in |
|
241 // an array of CATParamListEntry object pointers. |
|
242 if (peek!=',') |
|
243 { |
|
244 yyLex.Mark(); |
|
245 do |
|
246 { |
|
247 yyLex.Inc(); |
|
248 peek=yyLex.Peek(); |
|
249 } |
|
250 while (peek!=',' && !peek.IsSpace() && peek!=')'&& peek!=']'&& peek!='}' && !yyLex.Eos()); |
|
251 CATParamListEntry* aParamListEntry = new (ELeave) CATParamListEntry(yyLex.MarkedToken()); |
|
252 iRxResults.AddLast(*aParamListEntry); |
|
253 } |
|
254 // Move cursor to the next non-space character, and end the loop if it is a closing |
|
255 // bracket or the end of the buffer. |
|
256 yyLex.Inc(); |
|
257 yyLex.SkipSpace(); |
|
258 peek = yyLex.Peek(); |
|
259 } |
|
260 while (!yyLex.Eos() && peek!=')'&& peek!=']'&& peek!='}'); |
|
261 } |
|
262 |
|
263 void CATBase::StandardWriteCompletionHandler(TEventSource aSource,TInt aTimeOut) |
|
264 /** |
|
265 * This function is currently not used by the Etel regression test harness. |
|
266 */ |
|
267 { |
|
268 __ASSERT_ALWAYS(aSource==EWriteCompletion,HayesPanic(EATCommand_IllegalCompletionWriteExpected)); |
|
269 iIo->SetTimeOut(this,aTimeOut * KOneSecondPause); |
|
270 AddStdExpectStrings(); |
|
271 } |
|
272 |
|
273 void CATBase::Write(const TPtrC8& aCommand,TInt aTimeOut) |
|
274 /** |
|
275 * This function is currently not used by the Etel regression test harness. |
|
276 */ |
|
277 { |
|
278 iTxBuffer.Format(_L8("%S\r"),&aCommand); |
|
279 iIo->Write(this,iTxBuffer); |
|
280 iIo->SetTimeOut(this,aTimeOut * KOneSecondPause); |
|
281 } |
|
282 |
|
283 void CATBase::Write(const TPtrC8& aCommand,TInt aTimeOut,TInt aValue) |
|
284 /** |
|
285 * This function is currently not used by the Etel regression test harness. |
|
286 */ { |
|
287 iTxBuffer.Format(_L8("%S%d\r"),&aCommand,aValue); |
|
288 iIo->Write(this,iTxBuffer); |
|
289 iIo->SetTimeOut(this,aTimeOut * KOneSecondPause); |
|
290 } |
|
291 |
|
292 void CATBase::WriteExpectingResults(const TPtrC8& aCommand,TInt aTimeOut) |
|
293 /** |
|
294 * This function is currently not used by the Etel regression test harness. |
|
295 */ { |
|
296 iIo->MarkRxBuffer(iBufferMarker); |
|
297 Write(aCommand,aTimeOut); |
|
298 } |