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_ampv.cpp
|
sl@0
|
15 |
// Approval tests for the Pc Card Adapter.
|
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 <e32cons.h>
|
sl@0
|
22 |
#include <e32svr.h>
|
sl@0
|
23 |
#include <e32hal.h>
|
sl@0
|
24 |
#include <e32uid.h>
|
sl@0
|
25 |
#include <d32comm.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KRxBufSize=20;
|
sl@0
|
28 |
const TInt KAmpVTimeout=2000000;
|
sl@0
|
29 |
const TInt KUnit0=0;
|
sl@0
|
30 |
|
sl@0
|
31 |
#if defined (__WINS__)
|
sl@0
|
32 |
#define PDD_NAME _L("ECDRV.PDD")
|
sl@0
|
33 |
#define LDD_NAME _L("ECOMM.LDD")
|
sl@0
|
34 |
#else
|
sl@0
|
35 |
#define PDD_NAME _L("EUART1.PDD")
|
sl@0
|
36 |
#define LDD_NAME _L("ECOMM.LDD")
|
sl@0
|
37 |
#endif
|
sl@0
|
38 |
|
sl@0
|
39 |
class RComm : public RBusDevComm
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
TInt WriteS(const TDesC8& aDes);
|
sl@0
|
43 |
};
|
sl@0
|
44 |
|
sl@0
|
45 |
|
sl@0
|
46 |
GLDEF_D CConsoleBase *theConsole;
|
sl@0
|
47 |
GLDEF_D RComm *theSerialPort;
|
sl@0
|
48 |
|
sl@0
|
49 |
TInt RComm::WriteS(const TDesC8& aDes)
|
sl@0
|
50 |
//
|
sl@0
|
51 |
// Syncronous write
|
sl@0
|
52 |
//
|
sl@0
|
53 |
{
|
sl@0
|
54 |
|
sl@0
|
55 |
TRequestStatus s;
|
sl@0
|
56 |
Write(s,aDes,aDes.Length());
|
sl@0
|
57 |
User::WaitForRequest(s);
|
sl@0
|
58 |
return(s.Int());
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
LOCAL_C void AmpVTest()
|
sl@0
|
62 |
//
|
sl@0
|
63 |
// Perform the test
|
sl@0
|
64 |
//
|
sl@0
|
65 |
{
|
sl@0
|
66 |
|
sl@0
|
67 |
TInt errCount=0;
|
sl@0
|
68 |
TInt okStatus=0;
|
sl@0
|
69 |
|
sl@0
|
70 |
TRequestStatus tStat,sStat,kStat;
|
sl@0
|
71 |
TUint8 rxBuf[KRxBufSize];
|
sl@0
|
72 |
TPtr8 rxDes(&rxBuf[0],KRxBufSize,KRxBufSize);
|
sl@0
|
73 |
theSerialPort->Read(sStat,rxDes,0); // Raise DTR and wake up the PCA
|
sl@0
|
74 |
User::WaitForRequest(sStat);
|
sl@0
|
75 |
User::After(4000000); // 4Secs while PC card starts up
|
sl@0
|
76 |
|
sl@0
|
77 |
theSerialPort->WriteS(_L8("AT\r"));
|
sl@0
|
78 |
theSerialPort->WriteS(_L8("AT&f\r"));
|
sl@0
|
79 |
User::After(500000); // 0.5S
|
sl@0
|
80 |
theSerialPort->ResetBuffers();
|
sl@0
|
81 |
theConsole->Printf(_L("Sending AT&V\n\r"));
|
sl@0
|
82 |
theSerialPort->WriteS(_L8("AT&V\r"));
|
sl@0
|
83 |
|
sl@0
|
84 |
RTimer tim;
|
sl@0
|
85 |
tim.CreateLocal();
|
sl@0
|
86 |
tim.After(tStat,KAmpVTimeout);
|
sl@0
|
87 |
theConsole->Read(kStat);
|
sl@0
|
88 |
theSerialPort->Read(sStat,rxDes,1);
|
sl@0
|
89 |
|
sl@0
|
90 |
FOREVER
|
sl@0
|
91 |
{
|
sl@0
|
92 |
User::WaitForAnyRequest();
|
sl@0
|
93 |
if (sStat!=KRequestPending)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
// got another character
|
sl@0
|
96 |
if (sStat!=KErrNone)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
// Bad character - initiate another try.
|
sl@0
|
99 |
errCount++;
|
sl@0
|
100 |
tim.Cancel();
|
sl@0
|
101 |
User::WaitForRequest(tStat);
|
sl@0
|
102 |
User::After(200000);
|
sl@0
|
103 |
theSerialPort->ResetBuffers();
|
sl@0
|
104 |
theConsole->Printf(_L("Errors:%d (Bad char-%d)\r\n"),errCount,sStat.Int());
|
sl@0
|
105 |
theConsole->Printf(_L("Sending AT&V\n\r"));
|
sl@0
|
106 |
theSerialPort->WriteS(_L8("AT&V\r"));
|
sl@0
|
107 |
tim.After(tStat,KAmpVTimeout);
|
sl@0
|
108 |
okStatus=0;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
else
|
sl@0
|
111 |
{
|
sl@0
|
112 |
// Check if its CR/LF/OK/CR/LF
|
sl@0
|
113 |
switch(okStatus)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
case 0:
|
sl@0
|
116 |
okStatus=(rxBuf[0]=='\x0D')?(okStatus+1):0;
|
sl@0
|
117 |
break;
|
sl@0
|
118 |
case 1:
|
sl@0
|
119 |
if (rxBuf[0]=='\x0A')
|
sl@0
|
120 |
okStatus++;
|
sl@0
|
121 |
else
|
sl@0
|
122 |
okStatus=(rxBuf[0]=='\x0D')?1:0;
|
sl@0
|
123 |
break;
|
sl@0
|
124 |
case 2:
|
sl@0
|
125 |
if (rxBuf[0]=='O')
|
sl@0
|
126 |
okStatus++;
|
sl@0
|
127 |
else
|
sl@0
|
128 |
okStatus=(rxBuf[0]=='\x0D')?1:0;
|
sl@0
|
129 |
break;
|
sl@0
|
130 |
case 3:
|
sl@0
|
131 |
if (rxBuf[0]=='K')
|
sl@0
|
132 |
okStatus++;
|
sl@0
|
133 |
else
|
sl@0
|
134 |
okStatus=(rxBuf[0]=='\x0D')?1:0;
|
sl@0
|
135 |
break;
|
sl@0
|
136 |
case 4:
|
sl@0
|
137 |
if (rxBuf[0]=='\x0D')
|
sl@0
|
138 |
okStatus++;
|
sl@0
|
139 |
else
|
sl@0
|
140 |
okStatus=(rxBuf[0]=='\x0D')?1:0;
|
sl@0
|
141 |
break;
|
sl@0
|
142 |
case 5:
|
sl@0
|
143 |
if (rxBuf[0]=='\x0A')
|
sl@0
|
144 |
{
|
sl@0
|
145 |
// Success - initiate another try.
|
sl@0
|
146 |
tim.Cancel();
|
sl@0
|
147 |
User::WaitForRequest(tStat);
|
sl@0
|
148 |
User::After(200000);
|
sl@0
|
149 |
theSerialPort->ResetBuffers();
|
sl@0
|
150 |
theConsole->Printf(_L("Errors:%d\r\n"),errCount);
|
sl@0
|
151 |
theConsole->Printf(_L("Sending AT&V\n\r"));
|
sl@0
|
152 |
theSerialPort->WriteS(_L8("AT&V\r"));
|
sl@0
|
153 |
tim.After(tStat,KAmpVTimeout);
|
sl@0
|
154 |
okStatus=0;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
else
|
sl@0
|
157 |
okStatus=(rxBuf[0]=='\x0D')?1:0;
|
sl@0
|
158 |
break;
|
sl@0
|
159 |
default:
|
sl@0
|
160 |
okStatus=0;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
}
|
sl@0
|
163 |
// Queue another serial read
|
sl@0
|
164 |
theSerialPort->Read(sStat,rxDes,1);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
else if (tStat!=KRequestPending)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
// Error - didn't get OK
|
sl@0
|
169 |
theSerialPort->ReadCancel();
|
sl@0
|
170 |
User::WaitForRequest(sStat);
|
sl@0
|
171 |
errCount++;
|
sl@0
|
172 |
// Initiate another try
|
sl@0
|
173 |
User::After(200000);
|
sl@0
|
174 |
theSerialPort->ResetBuffers();
|
sl@0
|
175 |
theConsole->Printf(_L("Errors:%d (Timeout)\r\n"),errCount);
|
sl@0
|
176 |
theConsole->Printf(_L("Sending AT&V\n\r"));
|
sl@0
|
177 |
theSerialPort->WriteS(_L8("AT&V\r"));
|
sl@0
|
178 |
tim.After(tStat,KAmpVTimeout);
|
sl@0
|
179 |
theSerialPort->Read(sStat,rxDes,1);
|
sl@0
|
180 |
okStatus=0;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
else if (kStat!=KRequestPending)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
theSerialPort->ReadCancel();
|
sl@0
|
185 |
User::WaitForRequest(sStat);
|
sl@0
|
186 |
tim.Cancel();
|
sl@0
|
187 |
User::WaitForRequest(tStat);
|
sl@0
|
188 |
return;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
else
|
sl@0
|
191 |
{
|
sl@0
|
192 |
theConsole->Printf(_L("ERROR - stray signal\r\n"));
|
sl@0
|
193 |
theConsole->ReadCancel();
|
sl@0
|
194 |
User::WaitForRequest(kStat);
|
sl@0
|
195 |
theSerialPort->ReadCancel();
|
sl@0
|
196 |
User::WaitForRequest(sStat);
|
sl@0
|
197 |
tim.Cancel();
|
sl@0
|
198 |
User::WaitForRequest(tStat);
|
sl@0
|
199 |
theConsole->Getch();
|
sl@0
|
200 |
return;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
}
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
GLDEF_C TInt E32Main()
|
sl@0
|
206 |
{
|
sl@0
|
207 |
TCommConfig cBuf;
|
sl@0
|
208 |
TCommConfigV01 &c=cBuf();
|
sl@0
|
209 |
|
sl@0
|
210 |
// Create console
|
sl@0
|
211 |
theConsole=Console::NewL(_L("T_AMPV"),TSize(KDefaultConsWidth,KDefaultConsHeight));
|
sl@0
|
212 |
|
sl@0
|
213 |
// Load Device Drivers
|
sl@0
|
214 |
theConsole->Printf(_L("Load PDD\n\r"));
|
sl@0
|
215 |
TInt r;
|
sl@0
|
216 |
r=User::LoadPhysicalDevice(PDD_NAME);
|
sl@0
|
217 |
if (r!=KErrNone&&r!=KErrAlreadyExists)
|
sl@0
|
218 |
goto AmpvEnd;
|
sl@0
|
219 |
theConsole->Printf(_L("Load LDD\n\r"));
|
sl@0
|
220 |
r=User::LoadLogicalDevice(LDD_NAME);
|
sl@0
|
221 |
if (r!=KErrNone&&r!=KErrAlreadyExists)
|
sl@0
|
222 |
goto AmpvEnd;
|
sl@0
|
223 |
|
sl@0
|
224 |
// Create RComm object
|
sl@0
|
225 |
theConsole->Printf(_L("Create RComm object\n\r"));
|
sl@0
|
226 |
theSerialPort=new RComm;
|
sl@0
|
227 |
if (theSerialPort==NULL)
|
sl@0
|
228 |
goto AmpvEnd;
|
sl@0
|
229 |
|
sl@0
|
230 |
// Open Serial Port
|
sl@0
|
231 |
theConsole->Printf(_L("Open Serial Port\n\r"));
|
sl@0
|
232 |
r=theSerialPort->Open(KUnit0);
|
sl@0
|
233 |
if (r!=KErrNone)
|
sl@0
|
234 |
goto AmpvEnd;
|
sl@0
|
235 |
|
sl@0
|
236 |
// Setup serial port
|
sl@0
|
237 |
theConsole->Printf(_L("Setup serial port\n\r"));
|
sl@0
|
238 |
theSerialPort->Config(cBuf);
|
sl@0
|
239 |
c.iRate=EBps57600;
|
sl@0
|
240 |
c.iDataBits=EData8;
|
sl@0
|
241 |
c.iStopBits=EStop1;
|
sl@0
|
242 |
c.iParity=EParityNone;
|
sl@0
|
243 |
// c.iHandshake=KConfigObeyCTS;
|
sl@0
|
244 |
c.iHandshake=0;
|
sl@0
|
245 |
r=theSerialPort->SetConfig(cBuf);
|
sl@0
|
246 |
if (r!=KErrNone)
|
sl@0
|
247 |
goto AmpvEnd;
|
sl@0
|
248 |
|
sl@0
|
249 |
AmpVTest();
|
sl@0
|
250 |
|
sl@0
|
251 |
AmpvEnd:
|
sl@0
|
252 |
if (theSerialPort)
|
sl@0
|
253 |
theSerialPort->Close();
|
sl@0
|
254 |
delete theSerialPort;
|
sl@0
|
255 |
delete theConsole;
|
sl@0
|
256 |
return(KErrNone);
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
|