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