Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_ampv.cpp
15 // Approval tests for the Pc Card Adapter.
20 #include <e32std_private.h>
27 const TInt KRxBufSize=20;
28 const TInt KAmpVTimeout=2000000;
31 #if defined (__WINS__)
32 #define PDD_NAME _L("ECDRV.PDD")
33 #define LDD_NAME _L("ECOMM.LDD")
35 #define PDD_NAME _L("EUART1.PDD")
36 #define LDD_NAME _L("ECOMM.LDD")
39 class RComm : public RBusDevComm
42 TInt WriteS(const TDesC8& aDes);
46 GLDEF_D CConsoleBase *theConsole;
47 GLDEF_D RComm *theSerialPort;
49 TInt RComm::WriteS(const TDesC8& aDes)
56 Write(s,aDes,aDes.Length());
57 User::WaitForRequest(s);
61 LOCAL_C void AmpVTest()
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
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"));
86 tim.After(tStat,KAmpVTimeout);
87 theConsole->Read(kStat);
88 theSerialPort->Read(sStat,rxDes,1);
92 User::WaitForAnyRequest();
93 if (sStat!=KRequestPending)
95 // got another character
98 // Bad character - initiate another try.
101 User::WaitForRequest(tStat);
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);
112 // Check if its CR/LF/OK/CR/LF
116 okStatus=(rxBuf[0]=='\x0D')?(okStatus+1):0;
119 if (rxBuf[0]=='\x0A')
122 okStatus=(rxBuf[0]=='\x0D')?1:0;
128 okStatus=(rxBuf[0]=='\x0D')?1:0;
134 okStatus=(rxBuf[0]=='\x0D')?1:0;
137 if (rxBuf[0]=='\x0D')
140 okStatus=(rxBuf[0]=='\x0D')?1:0;
143 if (rxBuf[0]=='\x0A')
145 // Success - initiate another try.
147 User::WaitForRequest(tStat);
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);
157 okStatus=(rxBuf[0]=='\x0D')?1:0;
163 // Queue another serial read
164 theSerialPort->Read(sStat,rxDes,1);
166 else if (tStat!=KRequestPending)
168 // Error - didn't get OK
169 theSerialPort->ReadCancel();
170 User::WaitForRequest(sStat);
172 // Initiate another try
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);
182 else if (kStat!=KRequestPending)
184 theSerialPort->ReadCancel();
185 User::WaitForRequest(sStat);
187 User::WaitForRequest(tStat);
192 theConsole->Printf(_L("ERROR - stray signal\r\n"));
193 theConsole->ReadCancel();
194 User::WaitForRequest(kStat);
195 theSerialPort->ReadCancel();
196 User::WaitForRequest(sStat);
198 User::WaitForRequest(tStat);
205 GLDEF_C TInt E32Main()
208 TCommConfigV01 &c=cBuf();
211 theConsole=Console::NewL(_L("T_AMPV"),TSize(KDefaultConsWidth,KDefaultConsHeight));
213 // Load Device Drivers
214 theConsole->Printf(_L("Load PDD\n\r"));
216 r=User::LoadPhysicalDevice(PDD_NAME);
217 if (r!=KErrNone&&r!=KErrAlreadyExists)
219 theConsole->Printf(_L("Load LDD\n\r"));
220 r=User::LoadLogicalDevice(LDD_NAME);
221 if (r!=KErrNone&&r!=KErrAlreadyExists)
224 // Create RComm object
225 theConsole->Printf(_L("Create RComm object\n\r"));
226 theSerialPort=new RComm;
227 if (theSerialPort==NULL)
231 theConsole->Printf(_L("Open Serial Port\n\r"));
232 r=theSerialPort->Open(KUnit0);
237 theConsole->Printf(_L("Setup serial port\n\r"));
238 theSerialPort->Config(cBuf);
242 c.iParity=EParityNone;
243 // c.iHandshake=KConfigObeyCTS;
245 r=theSerialPort->SetConfig(cBuf);
253 theSerialPort->Close();
254 delete theSerialPort;