|
1 // Copyright (c) 1998-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_dce.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 // Cogent uses two port loopback, Linda doesn't |
|
19 #define _TWO_PORT_LOOPBACK_ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <e32base_private.h> |
|
23 #include <e32test.h> |
|
24 #include <e32cons.h> |
|
25 #include <e32svr.h> |
|
26 #include <e32hal.h> |
|
27 #include <d32comm.h> |
|
28 #include <e32uid.h> |
|
29 |
|
30 const TInt KUnit0=0; |
|
31 const TInt KUnit1=1; |
|
32 const TInt KUnit2=2; |
|
33 |
|
34 #ifdef _TWO_PORT_LOOPBACK_ |
|
35 #define NOTIFY_TIMEOUT 2000000 // 2 seconds |
|
36 #else |
|
37 #define NOTIFY_TIMEOUT 10000000 // 10 seconds |
|
38 #endif |
|
39 |
|
40 const TInt KTestPatternSize=250; |
|
41 |
|
42 #if defined (__WINS__) |
|
43 // Running this test in WINS is fairly pointless since WINS uses the DTE driver. |
|
44 // The WINS version was just to get the basic test program working - i.e. to |
|
45 // speed up the debug process. |
|
46 #define PDD_NAME _L("ECDRV.PDD") |
|
47 #define LDD_NAME _L("ECOMM.LDD") |
|
48 const TInt KTestUnitDte=KUnit0; |
|
49 const TInt KTestUnitDce=KUnit1; |
|
50 const TInt KChangeSigIn=KSignalCTS; // DTE driver used on WINS so read DSR rather than RTS |
|
51 const TInt KOtherSigIn=KSignalDCD; // DTE driver used on WINS so read DCD rather than DTR |
|
52 const TInt KChangeSigOut=KSignalRTS; |
|
53 #else |
|
54 #define DTEPDD_NAME _L("EUART3") |
|
55 //#define DCEPDD_NAME _L("EUART1DCE") // Linda |
|
56 #define DCEPDD_NAME _L("EUART1") // Cogent |
|
57 #define DTELDD_NAME _L("ECOMM") |
|
58 #define DCELDD_NAME _L("ECOMMDCE") |
|
59 const TInt KTestUnitDte=KUnit2; |
|
60 const TInt KTestUnitDce=KUnit0; |
|
61 const TInt KChangeSigIn=KSignalRTS; // DCE input - Cogent |
|
62 const TInt KOtherSigIn=KSignalDTR; // DCE input - Cogent |
|
63 const TInt KChangeSigOut=KSignalRTS; // DTE output - Cogent |
|
64 //const TInt KChangeSigIn=KSignalDTR; // DCE input - Linda |
|
65 //const TInt KOtherSigIn=KSignalRTS; // DCE input - Linda |
|
66 //const TInt KChangeSigOut=KSignalDTR; // DTE output - Linda |
|
67 #endif |
|
68 |
|
69 // Our own comms object with synchronous writes |
|
70 class RComm : public RBusDevComm |
|
71 { |
|
72 public: |
|
73 TInt WriteS(const TDesC8& aDes); |
|
74 TInt WriteS(const TDesC8& aDes,TInt aLength); |
|
75 }; |
|
76 |
|
77 LOCAL_D RTest test(_L("T_DCE")); |
|
78 RComm* TheDteSerialPort; |
|
79 #if defined (__WINS__) |
|
80 RBusDevComm* TheDceSerialPort; |
|
81 #else |
|
82 RBusDevCommDCE* TheDceSerialPort; |
|
83 #endif |
|
84 |
|
85 TCommConfig TheConfigDceBuf; |
|
86 TCommConfigV01& TheConfigDce=TheConfigDceBuf(); |
|
87 TCommConfig TheConfigDteBuf; |
|
88 TCommConfigV01& TheConfigDte=TheConfigDteBuf(); |
|
89 TCommCaps2 TheCapsDceBuf; |
|
90 TCommCapsV02& TheCapsDce=TheCapsDceBuf(); |
|
91 |
|
92 |
|
93 TInt RComm::WriteS(const TDesC8& aDes) |
|
94 |
|
95 // Syncronous write |
|
96 |
|
97 { |
|
98 return(WriteS(aDes,aDes.Length())); |
|
99 } |
|
100 |
|
101 TInt RComm::WriteS(const TDesC8& aDes,TInt aLength) |
|
102 |
|
103 // Syncronous write |
|
104 |
|
105 { |
|
106 |
|
107 TRequestStatus s; |
|
108 Write(s,aDes,aLength); |
|
109 User::WaitForRequest(s); |
|
110 return(s.Int()); |
|
111 } |
|
112 |
|
113 LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar) |
|
114 // |
|
115 // Mark a buffer with repeating byte pattern |
|
116 // |
|
117 { |
|
118 |
|
119 if (aStartChar==anEndChar) |
|
120 { |
|
121 aBuf.Fill(aStartChar); |
|
122 return; |
|
123 } |
|
124 |
|
125 TUint character=aStartChar; |
|
126 for (TInt i=0;i<aBuf.Length();i++) |
|
127 { |
|
128 aBuf[i]=(TText8)character; |
|
129 if(++character>anEndChar) |
|
130 character=aStartChar; |
|
131 } |
|
132 } |
|
133 |
|
134 #define COLUMN_HEADER _L(" RxBuf | Expected \r\n") |
|
135 LOCAL_C void DumpDescriptors(TDes8 &aLeft,TDes8 &aRight) |
|
136 // |
|
137 // |
|
138 // |
|
139 { |
|
140 |
|
141 TBuf<80> b; |
|
142 test.Printf(_L("Compare failed:\r\n")); |
|
143 TInt minLen=Min(aLeft.Length(),aRight.Length()); |
|
144 test.Printf(COLUMN_HEADER); |
|
145 TInt i=0; |
|
146 TInt j=0; |
|
147 while (i<=minLen) |
|
148 { |
|
149 b.Format(_L("%02x: "),i); |
|
150 for (j=0;j<8;j++) |
|
151 { |
|
152 if ((i+j)<minLen) |
|
153 { |
|
154 TInt v=aLeft[i+j]; |
|
155 b.AppendFormat(_L("%02x "),v); |
|
156 } |
|
157 else |
|
158 b.Append(_L(" ")); |
|
159 } |
|
160 b.Append(_L(" | ")); |
|
161 for (j=0;j<8;j++) |
|
162 { |
|
163 if ((i+j)<minLen) |
|
164 { |
|
165 TInt v=aRight[i+j]; |
|
166 b.AppendFormat(_L("%02x "),v); |
|
167 } |
|
168 else |
|
169 b.Append(_L(" ")); |
|
170 } |
|
171 b.Append(_L("\r\n")); |
|
172 test.Printf(b); |
|
173 i+=8; |
|
174 if ((i%64)==0) |
|
175 test.Getch(); |
|
176 } |
|
177 } |
|
178 |
|
179 LOCAL_C TInt CheckedWrite(TInt aBufSize) |
|
180 // |
|
181 // Write/Read loopback test - requires either a loopback connector or a |
|
182 // connected device looping back the data (running T_DCEUTL). |
|
183 // |
|
184 { |
|
185 TUint8* inBuf=new TUint8[aBufSize]; |
|
186 test(inBuf!=NULL); |
|
187 TUint8* outBuf=new TUint8[aBufSize]; |
|
188 test(outBuf!=NULL); |
|
189 TPtr8 outDes(outBuf,aBufSize,aBufSize); |
|
190 TPtr8 inDes(inBuf,aBufSize,aBufSize); |
|
191 |
|
192 RTimer tim; |
|
193 tim.CreateLocal(); |
|
194 TRequestStatus readStatus; |
|
195 TRequestStatus timeStatus; |
|
196 |
|
197 StripeMem(outDes,'A','Z'); |
|
198 inDes.FillZ(); |
|
199 |
|
200 TheDceSerialPort->Read(readStatus,inDes,aBufSize+1); |
|
201 test(readStatus==KErrGeneral); |
|
202 |
|
203 TheDceSerialPort->Read(readStatus,inDes); |
|
204 test(readStatus==KRequestPending); |
|
205 |
|
206 TInt ret; |
|
207 #if defined (_TWO_PORT_LOOPBACK_) |
|
208 ret=TheDteSerialPort->WriteS(outDes,aBufSize); |
|
209 #else |
|
210 TRequestStatus ws; |
|
211 TheDceSerialPort->Write(ws,outDes,aBufSize); |
|
212 User::WaitForRequest(ws); |
|
213 ret=ws.Int(); |
|
214 #endif |
|
215 test(ret==KErrNone); |
|
216 const TUint KTimeOut=6000000; |
|
217 tim.After(timeStatus,KTimeOut); |
|
218 test(timeStatus==KRequestPending); |
|
219 User::WaitForRequest(readStatus,timeStatus); |
|
220 if (timeStatus==KErrNone) |
|
221 { |
|
222 TheDceSerialPort->ReadCancel(); |
|
223 User::WaitForRequest(readStatus); |
|
224 test.Printf(_L("Timed Out!\n\r")); |
|
225 test.Getch(); |
|
226 test(FALSE); |
|
227 } |
|
228 else |
|
229 { |
|
230 tim.Cancel(); |
|
231 User::WaitForRequest(timeStatus); |
|
232 if (readStatus!=KErrNone) |
|
233 { |
|
234 test.Printf(_L("Read Failed! (%d)\n\r"),readStatus.Int()); |
|
235 test.Getch(); |
|
236 test(FALSE); |
|
237 } |
|
238 test(readStatus==KErrNone); |
|
239 test.Printf(_L("Read %d of %d\n\r"),inDes.Length(),outDes.Length()); |
|
240 ret=outDes.Compare(inDes); |
|
241 if (ret!=0) |
|
242 DumpDescriptors(inDes,outDes); |
|
243 test(ret==0); |
|
244 } |
|
245 |
|
246 tim.Close(); |
|
247 delete inBuf; |
|
248 delete outBuf; |
|
249 |
|
250 return inDes.Length(); |
|
251 } |
|
252 |
|
253 LOCAL_C TInt TestingNotifySignalChange(TUint aChangeSignal) |
|
254 // |
|
255 // Test NotifySignalChange() |
|
256 // |
|
257 { |
|
258 |
|
259 RTimer tim; |
|
260 tim.CreateLocal(); |
|
261 TRequestStatus notifStatus; |
|
262 TRequestStatus timeStatus; |
|
263 |
|
264 if (!(TheCapsDce.iNotificationCaps & KNotifySignalsChangeSupported)) |
|
265 test.Printf(_L("Signal change notification not supported on this platform")); |
|
266 else |
|
267 { |
|
268 test.Next(_L("Testing NotifySignalChange() with no mask set")); |
|
269 #if defined (_TWO_PORT_LOOPBACK_) |
|
270 TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear |
|
271 #else |
|
272 test.Printf(_L("Make sure DTR negated(??D) - hit a key to start\n\r")); |
|
273 test.Getch(); |
|
274 test.Printf(_L("10 seconds to assert DTR(D)\n\r")); |
|
275 #endif |
|
276 |
|
277 TUint signals=0; |
|
278 TheDceSerialPort->NotifySignalChange(notifStatus,signals); |
|
279 test(notifStatus==KRequestPending); |
|
280 const TUint KTimeOut=NOTIFY_TIMEOUT; |
|
281 tim.After(timeStatus,KTimeOut); |
|
282 test(timeStatus==KRequestPending); |
|
283 #if defined (_TWO_PORT_LOOPBACK_) |
|
284 TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set |
|
285 #endif |
|
286 User::WaitForRequest(notifStatus,timeStatus); |
|
287 if (notifStatus==KErrNone) |
|
288 { |
|
289 tim.Cancel(); |
|
290 User::WaitForRequest(timeStatus); |
|
291 #ifndef __WINS__ |
|
292 TUint sigmask=((aChangeSignal*KSignalChanged)|aChangeSignal); |
|
293 test((signals&sigmask)==sigmask); |
|
294 #endif |
|
295 } |
|
296 else |
|
297 { |
|
298 TheDceSerialPort->NotifySignalChangeCancel(); |
|
299 User::WaitForRequest(notifStatus); |
|
300 test.Printf(_L("Timed Out!\n\r")); |
|
301 test.Getch(); |
|
302 test(FALSE); |
|
303 } |
|
304 TUint rdSignals=TheDceSerialPort->Signals(); |
|
305 test(rdSignals&aChangeSignal); |
|
306 |
|
307 test.Next(_L("Testing NotifySignalChange() when not expected")); |
|
308 // Test notification doesn't happen with mask set to some other signal |
|
309 signals=0; |
|
310 TheDceSerialPort->NotifySignalChange(notifStatus,signals,KOtherSigIn); |
|
311 test(notifStatus==KRequestPending); |
|
312 tim.After(timeStatus,KTimeOut); |
|
313 test(timeStatus==KRequestPending); |
|
314 #if defined (_TWO_PORT_LOOPBACK_) |
|
315 TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear |
|
316 #else |
|
317 test.Printf(_L("10 seconds to negate DTR(D)\n\r")); |
|
318 #endif |
|
319 User::WaitForRequest(notifStatus,timeStatus); |
|
320 if (notifStatus==KErrNone) |
|
321 { |
|
322 tim.Cancel(); |
|
323 User::WaitForRequest(timeStatus); |
|
324 test(FALSE); |
|
325 } |
|
326 else |
|
327 { |
|
328 test(timeStatus==KErrNone); // Success |
|
329 TheDceSerialPort->NotifySignalChangeCancel(); // Tests cancel |
|
330 User::WaitForRequest(notifStatus); |
|
331 } |
|
332 #ifndef __WINS__ |
|
333 rdSignals=TheDceSerialPort->Signals(); |
|
334 test(!(rdSignals&aChangeSignal)); |
|
335 #endif |
|
336 |
|
337 test.Next(_L("Testing NotifySignalChange() with mask set")); |
|
338 // Test notification happens with mask set to this signal |
|
339 signals=0; |
|
340 TheDceSerialPort->NotifySignalChange(notifStatus,signals,aChangeSignal); |
|
341 test(notifStatus==KRequestPending); |
|
342 tim.After(timeStatus,KTimeOut); |
|
343 test(timeStatus==KRequestPending); |
|
344 #if defined (_TWO_PORT_LOOPBACK_) |
|
345 TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set |
|
346 #else |
|
347 test.Printf(_L("10 seconds to assert DTR(D)\n\r")); |
|
348 #endif |
|
349 User::WaitForRequest(notifStatus,timeStatus); |
|
350 if (notifStatus==KErrNone) |
|
351 { |
|
352 tim.Cancel(); |
|
353 User::WaitForRequest(timeStatus); |
|
354 test(signals==((aChangeSignal*KSignalChanged)|aChangeSignal)); |
|
355 } |
|
356 else |
|
357 { |
|
358 TheDceSerialPort->NotifySignalChangeCancel(); |
|
359 User::WaitForRequest(notifStatus); |
|
360 test.Printf(_L("Timed Out!\n\r")); |
|
361 test.Getch(); |
|
362 test(FALSE); |
|
363 } |
|
364 rdSignals=TheDceSerialPort->Signals(); |
|
365 test(rdSignals&aChangeSignal); |
|
366 } |
|
367 |
|
368 return(KErrNone); |
|
369 } |
|
370 |
|
371 LOCAL_C TInt TestingNotifyReceiveDataAvailable() |
|
372 // |
|
373 // Test NotifyReceiveDataAvailable() |
|
374 // |
|
375 { |
|
376 |
|
377 RTimer tim; |
|
378 tim.CreateLocal(); |
|
379 TRequestStatus notifStatus; |
|
380 TRequestStatus timeStatus; |
|
381 |
|
382 if (!(TheCapsDce.iNotificationCaps & KNotifyDataAvailableSupported)) |
|
383 test.Printf(_L("Data available notification not supported on this platform")); |
|
384 else |
|
385 { |
|
386 test.Next(_L("Testing NotifyReceiveDataAvailable()")); |
|
387 #if !defined (_TWO_PORT_LOOPBACK_) |
|
388 test.Printf(_L("Hit a key to start\n\r")); |
|
389 test.Getch(); |
|
390 #endif |
|
391 TPtrC8 buf1(_S8("AT&f\r")); |
|
392 TBuf8<0x10> buf2(0x10); |
|
393 |
|
394 TheDceSerialPort->ResetBuffers(); |
|
395 TheDceSerialPort->NotifyReceiveDataAvailable(notifStatus); |
|
396 test(notifStatus==KRequestPending); |
|
397 const TUint KTimeOut=NOTIFY_TIMEOUT; |
|
398 tim.After(timeStatus,KTimeOut); |
|
399 test(timeStatus==KRequestPending); |
|
400 #if defined (_TWO_PORT_LOOPBACK_) |
|
401 test(TheDteSerialPort->WriteS(buf1)==KErrNone); |
|
402 #else |
|
403 test.Printf(_L("10 seconds to send hayes command(H)\n\r")); |
|
404 #endif |
|
405 User::WaitForRequest(notifStatus,timeStatus); |
|
406 if (notifStatus==KErrNone) |
|
407 { |
|
408 tim.Cancel(); |
|
409 User::WaitForRequest(timeStatus); |
|
410 } |
|
411 else |
|
412 { |
|
413 TheDceSerialPort->NotifyReceiveDataAvailableCancel(); |
|
414 test.Printf(_L("Timed Out!\n\r")); |
|
415 test.Getch(); |
|
416 test(FALSE); |
|
417 } |
|
418 User::After(500000); |
|
419 TInt len=TheDceSerialPort->QueryReceiveBuffer(); |
|
420 // test(len==buf1.Length()); |
|
421 buf2.FillZ(); |
|
422 TheDceSerialPort->Read(notifStatus,buf2,len); |
|
423 User::WaitForRequest(notifStatus); |
|
424 TInt ret=buf2.Compare(buf1); |
|
425 if (ret!=0) |
|
426 { |
|
427 test.Printf(_L("Compare error\r\n")); |
|
428 test.Getch(); |
|
429 } |
|
430 test(ret==0); |
|
431 } |
|
432 return(KErrNone); |
|
433 } |
|
434 |
|
435 #if !defined (__WINS__) |
|
436 LOCAL_C TInt TestingFlowControlChange() |
|
437 // |
|
438 // Test NotifyFlowControlChange() |
|
439 // |
|
440 { |
|
441 |
|
442 RTimer tim; |
|
443 tim.CreateLocal(); |
|
444 TRequestStatus notifStatus; |
|
445 TRequestStatus timeStatus; |
|
446 |
|
447 if (!(TheCapsDce.iNotificationCaps & KNotifyFlowControlChangeSupported)) |
|
448 test.Printf(_L("Flow Control change notification not supported on this platform")); |
|
449 else |
|
450 { |
|
451 #if !defined (_TWO_PORT_LOOPBACK_) |
|
452 test.Printf(_L("Hit a key to start\n\r")); |
|
453 test.Getch(); |
|
454 #endif |
|
455 |
|
456 test.Next(_L("Testing GetFlowControlStatus()")); |
|
457 TheConfigDce.iHandshake=KConfigObeyXoff; |
|
458 test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone); |
|
459 TFlowControl fc; |
|
460 TheDceSerialPort->GetFlowControlStatus(fc); |
|
461 test(fc==EFlowControlOff); |
|
462 |
|
463 test.Next(_L("Testing NotifyFlowControlChange() with s/w flow control")); |
|
464 TheDceSerialPort->NotifyFlowControlChange(notifStatus); |
|
465 test(notifStatus==KRequestPending); |
|
466 const TUint KTimeOut=NOTIFY_TIMEOUT; |
|
467 tim.After(timeStatus,KTimeOut); |
|
468 test(timeStatus==KRequestPending); |
|
469 #if defined (_TWO_PORT_LOOPBACK_) |
|
470 test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF |
|
471 #else |
|
472 test.Printf(_L("10 seconds to send XOFF(O)\n\r")); |
|
473 #endif |
|
474 User::WaitForRequest(notifStatus,timeStatus); |
|
475 if (notifStatus==KErrNone) |
|
476 { |
|
477 tim.Cancel(); |
|
478 User::WaitForRequest(timeStatus); |
|
479 } |
|
480 else |
|
481 { |
|
482 TheDceSerialPort->NotifyFlowControlChangeCancel(); |
|
483 test.Printf(_L("Timed Out!\n\r")); |
|
484 test.Getch(); |
|
485 test(FALSE); |
|
486 } |
|
487 |
|
488 test.Next(_L("Testing GetFlowControlStatus() again")); |
|
489 TheDceSerialPort->GetFlowControlStatus(fc); |
|
490 test(fc==EFlowControlOn); |
|
491 |
|
492 #if defined (_TWO_PORT_LOOPBACK_) |
|
493 test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON |
|
494 #else |
|
495 test.Printf(_L("Send XON(X)\n\r")); |
|
496 #endif |
|
497 User::After(1000000); // 1Sec |
|
498 TheDceSerialPort->GetFlowControlStatus(fc); |
|
499 test(fc==EFlowControlOff); |
|
500 TheConfigDce.iHandshake=0; |
|
501 test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone); |
|
502 |
|
503 #if defined (_TWO_PORT_LOOPBACK_) |
|
504 test.Next(_L("Testing NotifyFlowControlChange() with h/w flow control")); |
|
505 TheConfigDce.iHandshake=KConfigObeyRTS; |
|
506 test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone); |
|
507 TheDceSerialPort->GetFlowControlStatus(fc); |
|
508 test(fc==EFlowControlOff); |
|
509 |
|
510 TheDceSerialPort->NotifyFlowControlChange(notifStatus); |
|
511 test(notifStatus==KRequestPending); |
|
512 tim.After(timeStatus,KTimeOut); |
|
513 test(timeStatus==KRequestPending); |
|
514 TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear |
|
515 User::WaitForRequest(notifStatus,timeStatus); |
|
516 if (notifStatus==KErrNone) |
|
517 { |
|
518 tim.Cancel(); |
|
519 User::WaitForRequest(timeStatus); |
|
520 } |
|
521 else |
|
522 { |
|
523 TheDceSerialPort->NotifyFlowControlChangeCancel(); |
|
524 test.Printf(_L("Timed Out!\n\r")); |
|
525 test.Getch(); |
|
526 test(FALSE); |
|
527 } |
|
528 |
|
529 TheDceSerialPort->GetFlowControlStatus(fc); |
|
530 test(fc==EFlowControlOn); |
|
531 |
|
532 TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set |
|
533 User::After(1000000); // 1Sec |
|
534 TheDceSerialPort->GetFlowControlStatus(fc); |
|
535 test(fc==EFlowControlOff); |
|
536 |
|
537 test.Next(_L("Testing NotifyFlowControlChange() when not expected")); |
|
538 // Test notification doesn't happen when s/w flow control happens |
|
539 TheDceSerialPort->NotifyFlowControlChange(notifStatus); |
|
540 test(notifStatus==KRequestPending); |
|
541 tim.After(timeStatus,KTimeOut); |
|
542 test(timeStatus==KRequestPending); |
|
543 test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF |
|
544 User::WaitForRequest(notifStatus,timeStatus); |
|
545 if (notifStatus==KErrNone) |
|
546 { |
|
547 tim.Cancel(); |
|
548 User::WaitForRequest(timeStatus); |
|
549 test(FALSE); |
|
550 } |
|
551 else |
|
552 { |
|
553 test(timeStatus==KErrNone); // Success |
|
554 TheDceSerialPort->NotifyFlowControlChangeCancel(); // Tests cancel |
|
555 User::WaitForRequest(notifStatus); |
|
556 } |
|
557 test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON |
|
558 TheDceSerialPort->GetFlowControlStatus(fc); |
|
559 test(fc==EFlowControlOff); |
|
560 |
|
561 TheConfigDce.iHandshake=0; |
|
562 test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone); |
|
563 #endif |
|
564 } |
|
565 return(KErrNone); |
|
566 } |
|
567 |
|
568 LOCAL_C TInt TestingNotifyConfigChange() |
|
569 // |
|
570 // Test NotifyConfigChange() |
|
571 // |
|
572 { |
|
573 |
|
574 RTimer tim; |
|
575 tim.CreateLocal(); |
|
576 TRequestStatus notifStatus; |
|
577 TRequestStatus timeStatus; |
|
578 |
|
579 if (!(TheCapsDce.iNotificationCaps & KNotifyRateChangeSupported)) |
|
580 test.Printf(_L("Rate change notification not supported on this platform")); |
|
581 else |
|
582 { |
|
583 test.Next(_L("Testing NotifyConfigChange()")); |
|
584 #if defined (_TWO_PORT_LOOPBACK_) |
|
585 TheConfigDte.iRate=EBps9600; |
|
586 test(TheDteSerialPort->SetConfig(TheConfigDteBuf)==KErrNone); |
|
587 #else |
|
588 test.Printf(_L("Change baudrate to 9600(BB)\n\r")); |
|
589 test.Printf(_L("Hit a key to start\n\r")); |
|
590 test.Getch(); |
|
591 #endif |
|
592 TCommNotificationPckg cmBuf; |
|
593 TCommNotificationV01& cm=cmBuf(); |
|
594 |
|
595 // Test requesting before autobauding is enabled |
|
596 TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf); |
|
597 User::WaitForRequest(notifStatus); |
|
598 test(notifStatus==KErrGeneral); |
|
599 |
|
600 // Enable autobauding |
|
601 TheConfigDce.iRate=EBpsAutobaud; |
|
602 test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone); |
|
603 |
|
604 cm.iChangedMembers=0; |
|
605 cm.iRate=EBps50; |
|
606 TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf); |
|
607 test(notifStatus==KRequestPending); |
|
608 const TUint KTimeOut=NOTIFY_TIMEOUT; |
|
609 tim.After(timeStatus,KTimeOut); |
|
610 test(timeStatus==KRequestPending); |
|
611 #if defined (_TWO_PORT_LOOPBACK_) |
|
612 test(TheDteSerialPort->WriteS(_L8("AT&f\r"))==KErrNone); |
|
613 #else |
|
614 test.Printf(_L("10 seconds to send hayes command(H)\n\r")); |
|
615 #endif |
|
616 User::WaitForRequest(notifStatus,timeStatus); |
|
617 if (notifStatus==KErrNone) |
|
618 { |
|
619 tim.Cancel(); |
|
620 User::WaitForRequest(timeStatus); |
|
621 test(cm.iChangedMembers==KRateChanged); |
|
622 test(cm.iRate==EBps9600); |
|
623 } |
|
624 else |
|
625 { |
|
626 TheDceSerialPort->NotifyConfigChangeCancel(); |
|
627 test.Printf(_L("Timed Out!\n\r")); |
|
628 test.Getch(); |
|
629 test(FALSE); |
|
630 } |
|
631 } |
|
632 return(KErrNone); |
|
633 } |
|
634 #endif |
|
635 |
|
636 GLDEF_C TInt E32Main() |
|
637 // |
|
638 // Test DCE serial driver |
|
639 // |
|
640 { |
|
641 |
|
642 test.Title(); |
|
643 test.Start(_L("Turn off logging")); |
|
644 test.SetLogged(EFalse);//turn off serial port debugging! |
|
645 |
|
646 TInt r; |
|
647 test.Next(_L("Load drivers")); |
|
648 #if defined (__WINS__) |
|
649 r=User::LoadPhysicalDevice(PDD_NAME); |
|
650 test.Printf(_L("Load EUART Return %d\n\r"),r); |
|
651 r=User::LoadLogicalDevice(LDD_NAME); |
|
652 test.Printf(_L("Load ECOMM Return %d\n\r"),r); |
|
653 TheDceSerialPort=new RBusDevComm; |
|
654 #else |
|
655 r=User::LoadPhysicalDevice(DTEPDD_NAME); |
|
656 test.Printf(_L("Load DTE EUART Return %d\n\r"),r); |
|
657 r=User::LoadPhysicalDevice(DCEPDD_NAME); |
|
658 test.Printf(_L("Load DCE EUART Return %d\n\r"),r); |
|
659 r=User::LoadLogicalDevice(DTELDD_NAME); |
|
660 test.Printf(_L("Load DTE ECOMM Return %d\n\r"),r); |
|
661 r=User::LoadLogicalDevice(DCELDD_NAME); |
|
662 test.Printf(_L("Load DCE ECOMM Return %d\n\r"),r); |
|
663 TheDceSerialPort=new RBusDevCommDCE; |
|
664 #endif |
|
665 test(TheDceSerialPort!=NULL); |
|
666 TheDteSerialPort=new RComm; |
|
667 test(TheDteSerialPort!=NULL); |
|
668 // |
|
669 test.Next(_L("Open:")); |
|
670 r=TheDceSerialPort->Open(KTestUnitDce); |
|
671 test.Printf(_L("Open(DCE)=%d\n\r"),r); |
|
672 test(r==KErrNone); |
|
673 r=TheDteSerialPort->Open(KTestUnitDte); |
|
674 test.Printf(_L("Open(DTE)=%d\n\r"),r); |
|
675 test(r==KErrNone); |
|
676 |
|
677 // Setup serial ports |
|
678 test.Next(_L("Setup serial port")); |
|
679 TheDceSerialPort->Config(TheConfigDceBuf); |
|
680 TheConfigDce.iRate=EBps9600; |
|
681 TheConfigDce.iDataBits=EData8; |
|
682 TheConfigDce.iStopBits=EStop1; |
|
683 TheConfigDce.iParity=EParityNone; |
|
684 TheConfigDce.iHandshake=0; |
|
685 r=TheDceSerialPort->SetConfig(TheConfigDceBuf); |
|
686 test(r==KErrNone); |
|
687 |
|
688 TheDteSerialPort->Config(TheConfigDteBuf); |
|
689 TheConfigDte.iRate=EBps9600; |
|
690 TheConfigDte.iDataBits=EData8; |
|
691 TheConfigDte.iStopBits=EStop1; |
|
692 TheConfigDte.iParity=EParityNone; |
|
693 TheConfigDte.iHandshake=0; |
|
694 r=TheDteSerialPort->SetConfig(TheConfigDteBuf); |
|
695 test(r==KErrNone); |
|
696 |
|
697 test.Next(_L("Get DCE caps")); |
|
698 TheDceSerialPort->Caps(TheCapsDceBuf); |
|
699 test(r==KErrNone); |
|
700 |
|
701 #ifndef __WINS__ |
|
702 test.Next(_L("I/p signals")); |
|
703 #if defined (_TWO_PORT_LOOPBACK_) |
|
704 TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear |
|
705 #else |
|
706 test.Printf(_L("Negate DTR(D) - hit a key\n\r")); |
|
707 test.Getch(); |
|
708 #endif |
|
709 TUint sig=TheDceSerialPort->Signals(); |
|
710 test.Printf(_L("Check (%x) is negated: %x\n\r"),KChangeSigIn,sig); |
|
711 test(!(sig&KChangeSigIn)); |
|
712 #if defined (_TWO_PORT_LOOPBACK_) |
|
713 TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set |
|
714 #else |
|
715 test.Printf(_L("Assert DTR(D) - hit a key\n\r")); |
|
716 test.Getch(); |
|
717 #endif |
|
718 sig=TheDceSerialPort->Signals(); |
|
719 test.Printf(_L("Check (%x) is asserted: %x\n\r"),KChangeSigIn,sig); |
|
720 test(sig&KChangeSigIn); |
|
721 |
|
722 #if defined (_TWO_PORT_LOOPBACK_) |
|
723 test.Next(_L("O/p signals")); |
|
724 TheDceSerialPort->SetSignals(0,KSignalCTS); // Clear |
|
725 sig=TheDteSerialPort->Signals(); |
|
726 test.Printf(_L("Check (%x) is negated: %x\n\r"),KSignalCTS,sig); |
|
727 test(!(sig&KSignalCTS)); |
|
728 TheDceSerialPort->SetSignals(KSignalCTS,0); // Set |
|
729 sig=TheDteSerialPort->Signals(); |
|
730 test.Printf(_L("Check (%x) is asserted: %x\n\r"),KSignalCTS,sig); |
|
731 test(sig&KSignalCTS); |
|
732 #endif |
|
733 #endif |
|
734 test.Next(_L("Loopback test at 9600")); |
|
735 #if !defined (_TWO_PORT_LOOPBACK_) |
|
736 test.Printf(_L("Start loopback at 9600(L) - hit a key when ready\n\r")); |
|
737 test.Getch(); |
|
738 #endif |
|
739 test(CheckedWrite(KTestPatternSize)==KTestPatternSize); |
|
740 |
|
741 test.Next(_L("Loopback test at 115200")); |
|
742 TheConfigDce.iRate=EBps115200; |
|
743 r=TheDceSerialPort->SetConfig(TheConfigDceBuf); |
|
744 test(r==KErrNone); |
|
745 #if defined (_TWO_PORT_LOOPBACK_) |
|
746 TheConfigDte.iRate=EBps115200; |
|
747 r=TheDteSerialPort->SetConfig(TheConfigDteBuf); |
|
748 test(r==KErrNone); |
|
749 #else |
|
750 test.Printf(_L("Start loopback at 115200(??BFL) - hit a key when ready\n\r")); |
|
751 test.Getch(); |
|
752 #endif |
|
753 test(CheckedWrite(KTestPatternSize)==KTestPatternSize); |
|
754 |
|
755 test.Next(_L("Test signal change notification")); |
|
756 TestingNotifySignalChange(KChangeSigIn); |
|
757 |
|
758 test.Next(_L("Test receive data available notification")); |
|
759 TestingNotifyReceiveDataAvailable(); |
|
760 |
|
761 #if !defined (__WINS__) |
|
762 test.Next(_L("Test flow control change")); |
|
763 TestingFlowControlChange(); |
|
764 |
|
765 test.Next(_L("Test config change notification")); |
|
766 TestingNotifyConfigChange(); |
|
767 #endif |
|
768 |
|
769 TheDceSerialPort->Close(); |
|
770 TheDteSerialPort->Close(); |
|
771 test.Printf(_L("Hit a key")); |
|
772 test.Getch(); |
|
773 test.End(); |
|
774 return(KErrNone); |
|
775 } |
|
776 |
|
777 |