sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\device\t_modem1.cpp
|
sl@0
|
15 |
// Test program for PC Card Serial Port Driver - Requires Dacom GoldCard Modem.
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include <e32std_private.h>
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
#include <e32cons.h>
|
sl@0
|
23 |
#include <e32svr.h>
|
sl@0
|
24 |
#include <e32hal.h>
|
sl@0
|
25 |
#include <e32uid.h>
|
sl@0
|
26 |
#include <d32comm.h>
|
sl@0
|
27 |
#include <hal.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
class RComm : public RBusDevComm
|
sl@0
|
30 |
{
|
sl@0
|
31 |
public:
|
sl@0
|
32 |
TInt WriteS(const TDesC8& aDes);
|
sl@0
|
33 |
};
|
sl@0
|
34 |
|
sl@0
|
35 |
const TInt KBlockSize=256;
|
sl@0
|
36 |
// Block size Line rate
|
sl@0
|
37 |
const TInt KBlocksShort=4; // 4*256=1K - <1200
|
sl@0
|
38 |
const TInt KBlocksMedium=12; // 12*256=3K - <4800
|
sl@0
|
39 |
const TInt KBlocksLong=64; // 64*256=16K - <28800
|
sl@0
|
40 |
const TInt KBlocksVeryLong=128; // 128*256=32K - 28800
|
sl@0
|
41 |
|
sl@0
|
42 |
enum TLineRate {EV21_300,EBell103_300,EV22_1200,EBell212_1200,EV22bis_2400,
|
sl@0
|
43 |
EV32_4800,EV32_9600,EV32bis_14400,EV34_28800,ELineRateEnd};
|
sl@0
|
44 |
const TInt KMaxLineRates=ELineRateEnd;
|
sl@0
|
45 |
const TInt KStandardRxBufferSize=0x400;
|
sl@0
|
46 |
|
sl@0
|
47 |
#if !defined (__WINS__)
|
sl@0
|
48 |
#define PDD_NAME _L("EUARTn")
|
sl@0
|
49 |
#define LDD_NAME _L("ECOMM")
|
sl@0
|
50 |
#else
|
sl@0
|
51 |
#define PDD_NAME _L("ECDRV.PDD")
|
sl@0
|
52 |
#define LDD_NAME _L("ECOMM.LDD")
|
sl@0
|
53 |
#endif
|
sl@0
|
54 |
|
sl@0
|
55 |
LOCAL_D RTest test(_L("T_MODEM1"));
|
sl@0
|
56 |
LOCAL_D TInt LineModeData[KMaxLineRates]={0,64,1,69,2,9,9,10,11};
|
sl@0
|
57 |
LOCAL_D TInt LineRateData[KMaxLineRates]={300,300,1200,1200,2400,4800,9600,14400,28800};
|
sl@0
|
58 |
LOCAL_D TInt LineConnectData[KMaxLineRates]={1200,1200,1200,1200,2400,4800,9600,14400,28800};
|
sl@0
|
59 |
LOCAL_D RComm *theSerialPort;
|
sl@0
|
60 |
|
sl@0
|
61 |
|
sl@0
|
62 |
TInt RComm::WriteS(const TDesC8& aDes)
|
sl@0
|
63 |
//
|
sl@0
|
64 |
// Syncronous write
|
sl@0
|
65 |
//
|
sl@0
|
66 |
{
|
sl@0
|
67 |
|
sl@0
|
68 |
TRequestStatus s;
|
sl@0
|
69 |
Write(s,aDes,aDes.Length());
|
sl@0
|
70 |
User::WaitForRequest(s);
|
sl@0
|
71 |
return(s.Int());
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
LOCAL_C TPtrC BaudRateInText(TBps aRate)
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Convert into Baudrate text
|
sl@0
|
77 |
//
|
sl@0
|
78 |
{
|
sl@0
|
79 |
|
sl@0
|
80 |
switch (aRate)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
case EBps50: return(_L("50")); break;
|
sl@0
|
83 |
case EBps75: return(_L("75")); break;
|
sl@0
|
84 |
case EBps110: return(_L("110")); break;
|
sl@0
|
85 |
case EBps134: return(_L("134")); break;
|
sl@0
|
86 |
case EBps150: return(_L("150")); break;
|
sl@0
|
87 |
case EBps300: return(_L("300")); break;
|
sl@0
|
88 |
case EBps600: return(_L("600")); break;
|
sl@0
|
89 |
case EBps1200: return(_L("1200")); break;
|
sl@0
|
90 |
case EBps1800: return(_L("1800")); break;
|
sl@0
|
91 |
case EBps2000: return(_L("2000")); break;
|
sl@0
|
92 |
case EBps2400: return(_L("2400")); break;
|
sl@0
|
93 |
case EBps3600: return(_L("3600")); break;
|
sl@0
|
94 |
case EBps4800: return(_L("4800")); break;
|
sl@0
|
95 |
case EBps7200: return(_L("7200")); break;
|
sl@0
|
96 |
case EBps9600: return(_L("9600")); break;
|
sl@0
|
97 |
case EBps19200: return(_L("19200")); break;
|
sl@0
|
98 |
case EBps38400: return(_L("38400")); break;
|
sl@0
|
99 |
case EBps57600: return(_L("57600")); break;
|
sl@0
|
100 |
case EBps115200: return(_L("115000")); break;
|
sl@0
|
101 |
default: return(_L("Unknown")); break;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
LOCAL_C TInt TranslateCrLf(TDes8 &aDes)
|
sl@0
|
106 |
//
|
sl@0
|
107 |
// Search for CR/LF characters in a string and replace them with
|
sl@0
|
108 |
// '\r' '\n' format. Also replaces unprintable characters with "?"
|
sl@0
|
109 |
//
|
sl@0
|
110 |
{
|
sl@0
|
111 |
|
sl@0
|
112 |
TText8 buf[KBlockSize];
|
sl@0
|
113 |
TText8 *pS=(TText8*)aDes.Ptr();
|
sl@0
|
114 |
TText8 *pSE=pS+aDes.Size();
|
sl@0
|
115 |
TText8 *pT=&buf[0];
|
sl@0
|
116 |
TText8 *pTMax=pT+(KBlockSize-1);
|
sl@0
|
117 |
for (;pS<pSE;pS++,pT++)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
if (pT>=pTMax)
|
sl@0
|
120 |
return(KErrTooBig);
|
sl@0
|
121 |
if (*pS=='\xD'||*pS=='\xA')
|
sl@0
|
122 |
{
|
sl@0
|
123 |
*pT++='\\';
|
sl@0
|
124 |
*pT=(*pS=='\xD')?'r':'n';
|
sl@0
|
125 |
}
|
sl@0
|
126 |
else if (((TChar)*pS).IsPrint())
|
sl@0
|
127 |
*pT=*pS;
|
sl@0
|
128 |
else
|
sl@0
|
129 |
*pT='\?';
|
sl@0
|
130 |
}
|
sl@0
|
131 |
*pT=0;
|
sl@0
|
132 |
if ((pT-&buf[0])>aDes.MaxLength())
|
sl@0
|
133 |
return(KErrTooBig);
|
sl@0
|
134 |
aDes.Copy(&buf[0]);
|
sl@0
|
135 |
return(KErrNone);
|
sl@0
|
136 |
}
|
sl@0
|
137 |
/* ???
|
sl@0
|
138 |
LOCAL_C void PrintBuf(TDes8 &aBuf)
|
sl@0
|
139 |
//
|
sl@0
|
140 |
// Print the contents of a buffer
|
sl@0
|
141 |
//
|
sl@0
|
142 |
{
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt len=aBuf.Length();
|
sl@0
|
145 |
for (TInt i=0;i<=len/8;i++)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
test.Printf(_L("%4d: "),i*8);
|
sl@0
|
148 |
|
sl@0
|
149 |
for (TInt j=0;j<8;j++)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
if ((i*8)+j>=len)
|
sl@0
|
152 |
break;
|
sl@0
|
153 |
TInt v=aBuf[(i*8)+j];
|
sl@0
|
154 |
test.Printf(_L("%02x "),v);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
test.Printf(_L("\n\r"));
|
sl@0
|
157 |
}
|
sl@0
|
158 |
}
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
LOCAL_C void testLoopBack(TLineRate aLineRate,TBps aBaudRate)
|
sl@0
|
161 |
//
|
sl@0
|
162 |
// Perform an analogue loopback test at the specified linerate
|
sl@0
|
163 |
//
|
sl@0
|
164 |
{
|
sl@0
|
165 |
|
sl@0
|
166 |
TInt err;
|
sl@0
|
167 |
TBuf<64> b;
|
sl@0
|
168 |
TPtrC bd=BaudRateInText(aBaudRate);
|
sl@0
|
169 |
b.Format(_L("Loopback test(%S)"),&bd);
|
sl@0
|
170 |
test.Start(b);
|
sl@0
|
171 |
|
sl@0
|
172 |
TBuf8<KBlockSize> txBuf;
|
sl@0
|
173 |
theSerialPort->ResetBuffers();
|
sl@0
|
174 |
txBuf.Format(_L8("AT&F+MS=%d,0,%d,%d\\N0&K3&D2M0\r"),LineModeData[aLineRate],LineRateData[aLineRate],LineRateData[aLineRate]);
|
sl@0
|
175 |
test(theSerialPort->WriteS(txBuf)==KErrNone);
|
sl@0
|
176 |
|
sl@0
|
177 |
TBuf8<KBlockSize> rxBuf;
|
sl@0
|
178 |
User::After(2000000); // 2Secs
|
sl@0
|
179 |
err=theSerialPort->QueryReceiveBuffer();
|
sl@0
|
180 |
test(err>0);
|
sl@0
|
181 |
rxBuf.SetLength(err);
|
sl@0
|
182 |
TRequestStatus rxStat;
|
sl@0
|
183 |
theSerialPort->ReadOneOrMore(rxStat,rxBuf);
|
sl@0
|
184 |
User::WaitForRequest(rxStat);
|
sl@0
|
185 |
// test.Printf(_L(" Rx(%d):"),rxStat); // ???
|
sl@0
|
186 |
test(rxStat==KErrNone);
|
sl@0
|
187 |
txBuf.Append(_L("\r\nOK\r\n"));
|
sl@0
|
188 |
err=rxBuf.Compare(txBuf);
|
sl@0
|
189 |
// test(TranslateCrLf(rxBuf)==KErrNone); // ???
|
sl@0
|
190 |
// test.Printf(_L(" %S\r\n"),&rxBuf); // ???
|
sl@0
|
191 |
test(err==0);
|
sl@0
|
192 |
|
sl@0
|
193 |
test.Next(_L("Get loopback"));
|
sl@0
|
194 |
txBuf.Format(_L8("AT&T1\r"));
|
sl@0
|
195 |
test(theSerialPort->WriteS(txBuf)==KErrNone);
|
sl@0
|
196 |
User::After(5000000); // 5Secs
|
sl@0
|
197 |
err=theSerialPort->QueryReceiveBuffer();
|
sl@0
|
198 |
test(err>0);
|
sl@0
|
199 |
rxBuf.SetLength(err);
|
sl@0
|
200 |
theSerialPort->ReadOneOrMore(rxStat,rxBuf);
|
sl@0
|
201 |
User::WaitForRequest(rxStat);
|
sl@0
|
202 |
test.Printf(_L(" Rx(%d):"),rxStat);
|
sl@0
|
203 |
test(rxStat==KErrNone);
|
sl@0
|
204 |
txBuf.AppendFormat(_L8("\r\nCONNECT %d\r\n"),LineConnectData[aLineRate]);
|
sl@0
|
205 |
err=rxBuf.Compare(txBuf);
|
sl@0
|
206 |
test(TranslateCrLf(rxBuf)==KErrNone);
|
sl@0
|
207 |
test.Printf(_L(" %S\r\n"),&rxBuf); // Print what we got back (without CR/LF etc).
|
sl@0
|
208 |
// Sometimes get extra character as modem goes on-line so just look for command echo + connect
|
sl@0
|
209 |
test(err>=0);
|
sl@0
|
210 |
User::After(2000000); // 2Secs
|
sl@0
|
211 |
|
sl@0
|
212 |
TInt totalBlocksToTransfer;
|
sl@0
|
213 |
if (aBaudRate<EBps1200||aLineRate<EV22_1200)
|
sl@0
|
214 |
totalBlocksToTransfer=KBlocksShort;
|
sl@0
|
215 |
else if (aBaudRate<EBps4800||aLineRate<EV32_4800)
|
sl@0
|
216 |
totalBlocksToTransfer=KBlocksMedium;
|
sl@0
|
217 |
else if (aLineRate<EV34_28800)
|
sl@0
|
218 |
totalBlocksToTransfer=KBlocksLong;
|
sl@0
|
219 |
else
|
sl@0
|
220 |
totalBlocksToTransfer=KBlocksVeryLong;
|
sl@0
|
221 |
b.Format(_L("Transfering data(%dK)"),(totalBlocksToTransfer*KBlockSize)/1024);
|
sl@0
|
222 |
test.Next(b);
|
sl@0
|
223 |
TInt loopBackFail=KErrGeneral;
|
sl@0
|
224 |
TRequestStatus txStat;
|
sl@0
|
225 |
txBuf.SetLength(KBlockSize);
|
sl@0
|
226 |
TInt i;
|
sl@0
|
227 |
for (i=0;i<KBlockSize;i++)
|
sl@0
|
228 |
txBuf[i]=(TUint8)i;
|
sl@0
|
229 |
theSerialPort->Write(txStat,txBuf,KBlockSize);
|
sl@0
|
230 |
TInt txBlks=(totalBlocksToTransfer-1);
|
sl@0
|
231 |
rxBuf.Fill(0,KBlockSize);
|
sl@0
|
232 |
theSerialPort->Read(rxStat,rxBuf,KBlockSize);
|
sl@0
|
233 |
TInt rxBlks=0;
|
sl@0
|
234 |
TRequestStatus tStat;
|
sl@0
|
235 |
RTimer tim;
|
sl@0
|
236 |
test(tim.CreateLocal()==KErrNone);
|
sl@0
|
237 |
tim.After(tStat,40000000); // 40Secs
|
sl@0
|
238 |
test.Printf(_L(">"));
|
sl@0
|
239 |
FOREVER
|
sl@0
|
240 |
{
|
sl@0
|
241 |
User::WaitForAnyRequest();
|
sl@0
|
242 |
if (tStat!=KRequestPending)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
// test.Printf(_L("t")); // Timed out
|
sl@0
|
245 |
theSerialPort->ReadCancel(); // Cancel serial read
|
sl@0
|
246 |
User::WaitForRequest(rxStat);
|
sl@0
|
247 |
if (txBlks>0)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
theSerialPort->WriteCancel(); // Cancel serial write
|
sl@0
|
250 |
User::WaitForRequest(txStat);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
loopBackFail=KErrTimedOut; // Test failed
|
sl@0
|
253 |
break;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
else if (rxStat!=KRequestPending)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
// test.Printf(_L("r")); // Serial rx request complete
|
sl@0
|
258 |
if (rxStat!=0)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
loopBackFail=rxStat.Int(); // Test failed
|
sl@0
|
261 |
goto endSerial;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
for (i=0;i<KBlockSize;i++)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
if (rxBuf[i]!=i)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
loopBackFail=KErrCorrupt; // Test failed
|
sl@0
|
268 |
rxBuf[KBlockSize-1]=0;
|
sl@0
|
269 |
// PrintBuf(rxBuf); // ???
|
sl@0
|
270 |
// goto endSerial; // !!!Ignore compare fails for now!!!
|
sl@0
|
271 |
}
|
sl@0
|
272 |
}
|
sl@0
|
273 |
test.Printf(_L("<"));
|
sl@0
|
274 |
if (++rxBlks<totalBlocksToTransfer)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
rxBuf.Fill(0,KBlockSize);
|
sl@0
|
277 |
theSerialPort->Read(rxStat,rxBuf,KBlockSize);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
else
|
sl@0
|
280 |
{
|
sl@0
|
281 |
loopBackFail=KErrNone;
|
sl@0
|
282 |
endSerial:
|
sl@0
|
283 |
tim.Cancel(); // Cancel timer request.
|
sl@0
|
284 |
User::WaitForRequest(tStat);
|
sl@0
|
285 |
if (txBlks>0)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
theSerialPort->WriteCancel(); // Cancel serial write
|
sl@0
|
288 |
User::WaitForRequest(txStat);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
break;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
}
|
sl@0
|
293 |
else if (txStat!=KRequestPending)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
// test.Printf(_L("s")); // Serial tx request complete
|
sl@0
|
296 |
if (txBlks>0)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
theSerialPort->Write(txStat,txBuf,KBlockSize);
|
sl@0
|
299 |
test.Printf(_L(">"));
|
sl@0
|
300 |
txBlks--;
|
sl@0
|
301 |
}
|
sl@0
|
302 |
}
|
sl@0
|
303 |
else
|
sl@0
|
304 |
{
|
sl@0
|
305 |
// test.Printf(_L("?")); // Stray signal - cancel everything
|
sl@0
|
306 |
theSerialPort->ReadCancel(); // Cancel serial read
|
sl@0
|
307 |
User::WaitForRequest(rxStat);
|
sl@0
|
308 |
tim.Cancel(); // Cancel timer request.
|
sl@0
|
309 |
User::WaitForRequest(tStat);
|
sl@0
|
310 |
if (txBlks>0)
|
sl@0
|
311 |
{
|
sl@0
|
312 |
theSerialPort->WriteCancel(); // Cancel serial write
|
sl@0
|
313 |
User::WaitForRequest(txStat);
|
sl@0
|
314 |
}
|
sl@0
|
315 |
loopBackFail=KErrDied;
|
sl@0
|
316 |
break;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
}
|
sl@0
|
319 |
test.Printf(_L(" (%d)\r\n"),loopBackFail);
|
sl@0
|
320 |
// !!! At this point RTS may or may not be asserted following the write cancel. The
|
sl@0
|
321 |
// following seems necessary to make sure RTS is asserted so any remaining Rx data
|
sl@0
|
322 |
// can be received.and thrown away
|
sl@0
|
323 |
User::After(2000000);
|
sl@0
|
324 |
theSerialPort->ResetBuffers();
|
sl@0
|
325 |
User::After(1000000); // Wait 1Secs for any remaining Rx data
|
sl@0
|
326 |
tim.Close();
|
sl@0
|
327 |
|
sl@0
|
328 |
test.Next(_L("Disconnect"));
|
sl@0
|
329 |
theSerialPort->ResetBuffers(); // Through away any remaining Rx data.
|
sl@0
|
330 |
txBuf.Format(_L8("+++"));
|
sl@0
|
331 |
test(theSerialPort->WriteS(txBuf)==KErrNone);
|
sl@0
|
332 |
User::After(2000000); // 2Secs
|
sl@0
|
333 |
err=theSerialPort->QueryReceiveBuffer();
|
sl@0
|
334 |
test(err>0);
|
sl@0
|
335 |
rxBuf.SetLength(err);
|
sl@0
|
336 |
theSerialPort->ReadOneOrMore(rxStat,rxBuf);
|
sl@0
|
337 |
User::WaitForRequest(rxStat);
|
sl@0
|
338 |
test(rxStat==KErrNone);
|
sl@0
|
339 |
txBuf.Append(_L("\r\nOK\r\n"));
|
sl@0
|
340 |
err=rxBuf.Compare(txBuf);
|
sl@0
|
341 |
// test(TranslateCrLf(rxBuf)==KErrNone); // ???
|
sl@0
|
342 |
// test.Printf(_L(" %S\r\n"),&rxBuf); // ???
|
sl@0
|
343 |
test(err==0);
|
sl@0
|
344 |
|
sl@0
|
345 |
txBuf.Format(_L8("ATH0\r"));
|
sl@0
|
346 |
test(theSerialPort->WriteS(txBuf)==KErrNone);
|
sl@0
|
347 |
User::After(4000000); // 4Secs
|
sl@0
|
348 |
err=theSerialPort->QueryReceiveBuffer();
|
sl@0
|
349 |
test(err>0);
|
sl@0
|
350 |
rxBuf.SetLength(err);
|
sl@0
|
351 |
theSerialPort->ReadOneOrMore(rxStat,rxBuf);
|
sl@0
|
352 |
User::WaitForRequest(rxStat);
|
sl@0
|
353 |
test(rxStat==KErrNone);
|
sl@0
|
354 |
txBuf.Append(_L("\r\nOK\r\n"));
|
sl@0
|
355 |
err=rxBuf.Compare(txBuf);
|
sl@0
|
356 |
// test(TranslateCrLf(rxBuf)==KErrNone); // ???
|
sl@0
|
357 |
// test.Printf(_L(" %S\r\n"),&rxBuf); // ???
|
sl@0
|
358 |
test(err==0);
|
sl@0
|
359 |
|
sl@0
|
360 |
test.Next(_L("Check result"));
|
sl@0
|
361 |
test(loopBackFail==KErrNone || loopBackFail==KErrCorrupt); // !!!Ignore compare fails for now!!!
|
sl@0
|
362 |
// test(loopBackFail==KErrNone);
|
sl@0
|
363 |
|
sl@0
|
364 |
test.End();
|
sl@0
|
365 |
}
|
sl@0
|
366 |
|
sl@0
|
367 |
LOCAL_C void testAllLineRates(TBps aRate)
|
sl@0
|
368 |
//
|
sl@0
|
369 |
// Perform loopback test at the specified baudrate in as many line modes that
|
sl@0
|
370 |
// are supported at this baudrate
|
sl@0
|
371 |
//
|
sl@0
|
372 |
{
|
sl@0
|
373 |
|
sl@0
|
374 |
test.Start(_L("Setting baudrate"));
|
sl@0
|
375 |
TCommConfig cBuf;
|
sl@0
|
376 |
TCommConfigV01 &c=cBuf();
|
sl@0
|
377 |
theSerialPort->Config(cBuf);
|
sl@0
|
378 |
c.iRate=aRate;
|
sl@0
|
379 |
c.iDataBits=EData8;
|
sl@0
|
380 |
c.iStopBits=EStop1;
|
sl@0
|
381 |
c.iParity=EParityNone;
|
sl@0
|
382 |
c.iHandshake=KConfigObeyCTS;
|
sl@0
|
383 |
// c.iHandshake=0;
|
sl@0
|
384 |
test(theSerialPort->SetConfig(cBuf)==KErrNone);
|
sl@0
|
385 |
|
sl@0
|
386 |
if (aRate>=EBps38400)
|
sl@0
|
387 |
{
|
sl@0
|
388 |
test.Next(_L("Testing at V.34-28800"));
|
sl@0
|
389 |
testLoopBack(EV34_28800,aRate);
|
sl@0
|
390 |
}
|
sl@0
|
391 |
|
sl@0
|
392 |
if (aRate>=EBps19200)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
test.Next(_L("Testing at V.32bis-14400"));
|
sl@0
|
395 |
testLoopBack(EV32bis_14400,aRate);
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
if (aRate>=EBps9600)
|
sl@0
|
399 |
{
|
sl@0
|
400 |
test.Next(_L("Testing at V.32-9600"));
|
sl@0
|
401 |
testLoopBack(EV32_9600,aRate);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
|
sl@0
|
404 |
// if (aRate>=EBps4800)
|
sl@0
|
405 |
// {
|
sl@0
|
406 |
// test.Next(_L("Testing at V.32-4800"));
|
sl@0
|
407 |
// testLoopBack(EV32_4800,aRate);
|
sl@0
|
408 |
// }
|
sl@0
|
409 |
|
sl@0
|
410 |
if (aRate>=EBps2400)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
test.Next(_L("Testing at V.22bis-2400"));
|
sl@0
|
413 |
testLoopBack(EV22bis_2400,aRate);
|
sl@0
|
414 |
}
|
sl@0
|
415 |
|
sl@0
|
416 |
// if (aRate>=EBps1200)
|
sl@0
|
417 |
// {
|
sl@0
|
418 |
// test.Next(_L("Testing at Bell212-1200"));
|
sl@0
|
419 |
// testLoopBack(EBell212_1200,aRate);
|
sl@0
|
420 |
// }
|
sl@0
|
421 |
|
sl@0
|
422 |
// if (aRate>=EBps1200)
|
sl@0
|
423 |
// {
|
sl@0
|
424 |
// test.Next(_L("Testing at V.22-1200"));
|
sl@0
|
425 |
// testLoopBack(EV22_1200,aRate);
|
sl@0
|
426 |
// }
|
sl@0
|
427 |
|
sl@0
|
428 |
// test.Next(_L("Testing at Bell103-300"));
|
sl@0
|
429 |
// testLoopBack(EBell103_300,aRate);
|
sl@0
|
430 |
|
sl@0
|
431 |
test.Next(_L("Testing at V.21-300"));
|
sl@0
|
432 |
testLoopBack(EV21_300,aRate);
|
sl@0
|
433 |
|
sl@0
|
434 |
test.End();
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
GLDEF_C TInt E32Main()
|
sl@0
|
438 |
{
|
sl@0
|
439 |
// test.SetLogged(EFalse); // Turn off serial port debugging!
|
sl@0
|
440 |
|
sl@0
|
441 |
TInt r;
|
sl@0
|
442 |
test.Title();
|
sl@0
|
443 |
|
sl@0
|
444 |
test.Start(_L("PC Card Modem Test Program"));
|
sl@0
|
445 |
|
sl@0
|
446 |
RProcess proc;
|
sl@0
|
447 |
TBuf <0x100> cmd;
|
sl@0
|
448 |
proc.CommandLine(cmd);
|
sl@0
|
449 |
|
sl@0
|
450 |
// First parameter (if present) sets the serial port number
|
sl@0
|
451 |
TInt port=0;
|
sl@0
|
452 |
if ((cmd.Length()>0) && (cmd[0]>='1' && cmd[0]<='4'))
|
sl@0
|
453 |
port=(TInt)(cmd[0]-'0');
|
sl@0
|
454 |
|
sl@0
|
455 |
// 2nd parameter (if present) sets the start speed
|
sl@0
|
456 |
// (4=115K,3=57600,2=38400,1=19200,0=9600)
|
sl@0
|
457 |
TInt startSpeed=4;
|
sl@0
|
458 |
if ((cmd.Length()>3) && (cmd[2]>='0' && cmd[2]<='4'))
|
sl@0
|
459 |
startSpeed=(TInt)(cmd[2]-'0');
|
sl@0
|
460 |
|
sl@0
|
461 |
test.Next(_L("Load Device Drivers"));
|
sl@0
|
462 |
TBuf<10> pddName=PDD_NAME;
|
sl@0
|
463 |
#if !defined (__WINS__)
|
sl@0
|
464 |
pddName[5]=(TText)('1'+port);
|
sl@0
|
465 |
TInt muid=0;
|
sl@0
|
466 |
if (HAL::Get(HAL::EMachineUid, muid)==KErrNone)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
// Brutus uses EUART4 for both COM3 and COM4
|
sl@0
|
469 |
if (muid==HAL::EMachineUid_Brutus && port==4)
|
sl@0
|
470 |
pddName[5]=(TText)'4';
|
sl@0
|
471 |
}
|
sl@0
|
472 |
#endif
|
sl@0
|
473 |
r=User::LoadPhysicalDevice(pddName);
|
sl@0
|
474 |
test(r==KErrNone||r==KErrAlreadyExists);
|
sl@0
|
475 |
r=User::LoadLogicalDevice(LDD_NAME);
|
sl@0
|
476 |
test(r==KErrNone||r==KErrAlreadyExists);
|
sl@0
|
477 |
|
sl@0
|
478 |
test.Next(_L("Open serial port"));
|
sl@0
|
479 |
theSerialPort=new RComm;
|
sl@0
|
480 |
test(theSerialPort!=NULL);
|
sl@0
|
481 |
r=theSerialPort->Open(port);
|
sl@0
|
482 |
test(r==KErrNone);
|
sl@0
|
483 |
// TCommCaps capsBuf;
|
sl@0
|
484 |
// TCommCapsV01& caps=capsBuf();
|
sl@0
|
485 |
// theSerialPort->Caps(capsBuf);
|
sl@0
|
486 |
|
sl@0
|
487 |
// Check that the driver powering sequence has completed successfully by
|
sl@0
|
488 |
// issueing a few simple driver control functions.
|
sl@0
|
489 |
test.Next(_L("Modem power tests"));
|
sl@0
|
490 |
test(theSerialPort->SetReceiveBufferLength(KStandardRxBufferSize)==KErrNone);
|
sl@0
|
491 |
r=theSerialPort->ReceiveBufferLength();
|
sl@0
|
492 |
// test.Printf(_L("(%d)"),r); // ???
|
sl@0
|
493 |
test(r==KStandardRxBufferSize);
|
sl@0
|
494 |
r=(TInt)theSerialPort->Signals();
|
sl@0
|
495 |
// test.Printf(_L("(%d)"),r); // ???
|
sl@0
|
496 |
test(r>=0);
|
sl@0
|
497 |
|
sl@0
|
498 |
RTimer timer;
|
sl@0
|
499 |
TRequestStatus rs;
|
sl@0
|
500 |
test(timer.CreateLocal()==KErrNone);
|
sl@0
|
501 |
TTime tim;
|
sl@0
|
502 |
tim.HomeTime();
|
sl@0
|
503 |
tim+=TTimeIntervalSeconds(8);
|
sl@0
|
504 |
timer.At(rs,tim);
|
sl@0
|
505 |
UserHal::SwitchOff();
|
sl@0
|
506 |
User::WaitForRequest(rs);
|
sl@0
|
507 |
test(rs.Int()==KErrNone);
|
sl@0
|
508 |
|
sl@0
|
509 |
r=theSerialPort->ReceiveBufferLength();
|
sl@0
|
510 |
// test.Printf(_L("(%d)"),r); // ???
|
sl@0
|
511 |
test(r==KStandardRxBufferSize);
|
sl@0
|
512 |
r=(TInt)theSerialPort->Signals();
|
sl@0
|
513 |
// test.Printf(_L("(%d)"),r); // ???
|
sl@0
|
514 |
test(r>=0);
|
sl@0
|
515 |
User::After(2000000); // 2Secs !!!
|
sl@0
|
516 |
|
sl@0
|
517 |
if (startSpeed>=4)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
test.Next(_L("Testing at 115K"));
|
sl@0
|
520 |
testAllLineRates(EBps115200);
|
sl@0
|
521 |
}
|
sl@0
|
522 |
|
sl@0
|
523 |
if (startSpeed>=3)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
test.Next(_L("Testing at 57600"));
|
sl@0
|
526 |
testAllLineRates(EBps57600);
|
sl@0
|
527 |
}
|
sl@0
|
528 |
|
sl@0
|
529 |
if (startSpeed>=2)
|
sl@0
|
530 |
{
|
sl@0
|
531 |
test.Next(_L("Testing at 38400"));
|
sl@0
|
532 |
testAllLineRates(EBps38400);
|
sl@0
|
533 |
}
|
sl@0
|
534 |
|
sl@0
|
535 |
if (startSpeed>=1)
|
sl@0
|
536 |
{
|
sl@0
|
537 |
test.Next(_L("Testing at 19200"));
|
sl@0
|
538 |
testAllLineRates(EBps19200);
|
sl@0
|
539 |
}
|
sl@0
|
540 |
|
sl@0
|
541 |
test.Next(_L("Testing at 9600"));
|
sl@0
|
542 |
testAllLineRates(EBps9600);
|
sl@0
|
543 |
|
sl@0
|
544 |
test.Next(_L("Close serial port"));
|
sl@0
|
545 |
theSerialPort->Close();
|
sl@0
|
546 |
delete theSerialPort;
|
sl@0
|
547 |
test.End();
|
sl@0
|
548 |
return(KErrNone);
|
sl@0
|
549 |
}
|
sl@0
|
550 |
|