|
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_dceutl.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32base_private.h> |
|
20 #include <e32test.h> |
|
21 #include <e32cons.h> |
|
22 #include <e32svr.h> |
|
23 #include <e32hal.h> |
|
24 #include <d32comm.h> |
|
25 #include <e32uid.h> |
|
26 #include <hal.h> |
|
27 |
|
28 const TInt KDisplayTitleY=0; |
|
29 const TInt KDisplayMainY=2; |
|
30 const TInt KDisplayTextY=17; |
|
31 const TInt KUnit0=0; |
|
32 const TInt KUnit1=1; |
|
33 const TInt KTestPatternSize=250; |
|
34 enum TPanic {ECreatingConsole,ELoadingPDD,ELoadingLDD,ECreatingRComm,EOpeningPort,ESettingPort,ECircBuf,EStraySignal}; |
|
35 |
|
36 #if defined (__WINS__) |
|
37 #define PDD_NAME _L("ECDRV.PDD") |
|
38 #define LDD_NAME _L("ECOMM.LDD") |
|
39 #else |
|
40 #define PDD_NAME _L("EUARTn") |
|
41 #define LDD_NAME _L("ECOMM") |
|
42 #endif |
|
43 |
|
44 class RComm : public RBusDevComm |
|
45 { |
|
46 public: |
|
47 TInt WriteS(const TDesC8& aDes); |
|
48 }; |
|
49 |
|
50 CConsoleBase *TheConsole; |
|
51 RComm *TheSerialPort; |
|
52 TCommConfig TheConfigBuf; |
|
53 TCommConfigV01& TheConfig=TheConfigBuf(); |
|
54 TBool TheDtrState; |
|
55 TBool TheRtsState; |
|
56 TBuf8<KTestPatternSize> TheTestBuf; |
|
57 |
|
58 LOCAL_C void Panic(TPanic aPanic) |
|
59 // |
|
60 // Panic |
|
61 // |
|
62 { |
|
63 |
|
64 if (TheSerialPort) |
|
65 TheSerialPort->Close(); |
|
66 delete TheSerialPort; |
|
67 delete TheConsole; |
|
68 User::Panic(_L("T_DCEUTL"),aPanic); |
|
69 } |
|
70 |
|
71 LOCAL_C TPtrC BaudrateText(TBps aBaudrate) |
|
72 { |
|
73 switch(aBaudrate) |
|
74 { |
|
75 case EBps50: return(_L("50")); |
|
76 case EBps75: return(_L("75")); |
|
77 case EBps110: return(_L("110")); |
|
78 case EBps134: return(_L("134")); |
|
79 case EBps150: return(_L("150")); |
|
80 case EBps300: return(_L("300")); |
|
81 case EBps600: return(_L("600")); |
|
82 case EBps1200: return(_L("1200")); |
|
83 case EBps1800: return(_L("1800")); |
|
84 case EBps2000: return(_L("2000")); |
|
85 case EBps2400: return(_L("2400")); |
|
86 case EBps3600: return(_L("3600")); |
|
87 case EBps4800: return(_L("4800")); |
|
88 case EBps7200: return(_L("7200")); |
|
89 case EBps9600: return(_L("9600")); |
|
90 case EBps19200: return(_L("19200")); |
|
91 case EBps38400: return(_L("38400")); |
|
92 case EBps57600: return(_L("57600")); |
|
93 case EBps115200: return(_L("115200")); |
|
94 case EBps230400: return(_L("230400")); |
|
95 case EBps460800: return(_L("460800")); |
|
96 case EBps576000: return(_L("576000")); |
|
97 case EBps1152000: return(_L("1152000")); |
|
98 case EBps4000000: return(_L("4000000")); |
|
99 case EBpsSpecial: return(_L("Special")); |
|
100 default: return(_L("Unknown")); |
|
101 } |
|
102 } |
|
103 |
|
104 LOCAL_C TPtrC DtrText(TBool aDtrState) |
|
105 { |
|
106 if (aDtrState) |
|
107 return(_L("ASSERTED")); |
|
108 else |
|
109 return(_L("NEGATED")); |
|
110 } |
|
111 |
|
112 LOCAL_C TPtrC RtsText(TBool aRtsState) |
|
113 { |
|
114 if (aRtsState) |
|
115 return(_L("ASSERTED")); |
|
116 else |
|
117 return(_L("NEGATED")); |
|
118 } |
|
119 |
|
120 TInt RComm::WriteS(const TDesC8& aDes) |
|
121 // |
|
122 // Syncronous write |
|
123 // |
|
124 { |
|
125 |
|
126 TRequestStatus s; |
|
127 Write(s,aDes,aDes.Length()); |
|
128 User::WaitForRequest(s); |
|
129 return(s.Int()); |
|
130 } |
|
131 |
|
132 LOCAL_C void CenteredPrintf(TInt aLine,TRefByValue<const TDesC> aFmt,...) |
|
133 // |
|
134 // Print centrally on specified line |
|
135 // |
|
136 { |
|
137 VA_LIST list; |
|
138 VA_START(list,aFmt); |
|
139 TBuf<0x100> aBuf; |
|
140 aBuf.AppendFormatList(aFmt,list); |
|
141 TInt xPos = ((TheConsole->ScreenSize().iWidth)-aBuf.Length())/2; |
|
142 if (xPos<0) |
|
143 xPos=0; |
|
144 TheConsole->SetPos(0,aLine); |
|
145 TheConsole->ClearToEndOfLine(); |
|
146 TheConsole->SetPos(xPos,aLine); |
|
147 TheConsole->Write(aBuf); |
|
148 } |
|
149 |
|
150 LOCAL_C void Heading(TRefByValue<const TDesC> aFmt,...) |
|
151 // |
|
152 // Print a title |
|
153 // |
|
154 { |
|
155 VA_LIST list; |
|
156 VA_START(list,aFmt); |
|
157 TBuf<0x100> aBuf; |
|
158 aBuf.AppendFormatList(aFmt,list); |
|
159 CenteredPrintf(KDisplayTitleY,aBuf); |
|
160 } |
|
161 |
|
162 LOCAL_C void Instructions(TBool topLine,TRefByValue<const TDesC> aFmt,...) |
|
163 // |
|
164 // Print instructions (dont use top line with hex display). |
|
165 // |
|
166 { |
|
167 VA_LIST list; |
|
168 VA_START(list,aFmt); |
|
169 TBuf<0x100> aBuf; |
|
170 aBuf.AppendFormatList(aFmt,list); |
|
171 CenteredPrintf((topLine)?KDisplayTextY-1:KDisplayTextY,aBuf); |
|
172 } |
|
173 |
|
174 LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar) |
|
175 // |
|
176 // Mark a buffer with repeating byte pattern |
|
177 // |
|
178 { |
|
179 |
|
180 if (aStartChar==anEndChar) |
|
181 { |
|
182 aBuf.Fill(aStartChar); |
|
183 return; |
|
184 } |
|
185 |
|
186 TUint character=aStartChar; |
|
187 for (TInt i=0;i<aBuf.Length();i++) |
|
188 { |
|
189 aBuf[i]=(TText8)character; |
|
190 if(++character>anEndChar) |
|
191 character=aStartChar; |
|
192 } |
|
193 } |
|
194 |
|
195 #define COLUMN_HEADER _L(" RxBuf | Expected ") |
|
196 LOCAL_C void DumpDescriptors(TDes8 &aLeft,TDes8 &aRight) |
|
197 // |
|
198 // |
|
199 // |
|
200 { |
|
201 |
|
202 TBuf<80> b; |
|
203 CenteredPrintf(KDisplayMainY+2,_L("Compare failed:")); |
|
204 TInt minLen=Min(aLeft.Length(),aRight.Length()); |
|
205 CenteredPrintf(KDisplayMainY+3,COLUMN_HEADER); |
|
206 TInt i=0; |
|
207 TInt j=0; |
|
208 TInt pos=KDisplayMainY+4; |
|
209 while (i<=minLen) |
|
210 { |
|
211 b.Format(_L("%02x: "),i); |
|
212 for (j=0;j<8;j++) |
|
213 { |
|
214 if ((i+j)<minLen) |
|
215 { |
|
216 TInt v=aLeft[i+j]; |
|
217 b.AppendFormat(_L("%02x "),v); |
|
218 } |
|
219 else |
|
220 b.Append(_L(" ")); |
|
221 } |
|
222 b.Append(_L(" | ")); |
|
223 for (j=0;j<8;j++) |
|
224 { |
|
225 if ((i+j)<minLen) |
|
226 { |
|
227 TInt v=aRight[i+j]; |
|
228 b.AppendFormat(_L("%02x "),v); |
|
229 } |
|
230 else |
|
231 b.Append(_L(" ")); |
|
232 } |
|
233 CenteredPrintf(pos++,b); |
|
234 i+=8; |
|
235 if ((i%64)==0) |
|
236 { |
|
237 pos=KDisplayMainY+4; |
|
238 TheConsole->Getch(); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 LOCAL_C TInt ChangeBaudrate() |
|
244 // |
|
245 // Change baudrate |
|
246 // |
|
247 { |
|
248 |
|
249 CenteredPrintf(KDisplayMainY,_L("Select Baudrate:-")); |
|
250 CenteredPrintf(KDisplayMainY+1,_L("A - 4800 ")); |
|
251 CenteredPrintf(KDisplayMainY+2,_L("B - 9600 ")); |
|
252 CenteredPrintf(KDisplayMainY+3,_L("C - 19200 ")); |
|
253 CenteredPrintf(KDisplayMainY+4,_L("D - 38400 ")); |
|
254 CenteredPrintf(KDisplayMainY+5,_L("E - 57600 ")); |
|
255 CenteredPrintf(KDisplayMainY+6,_L("F - 115200")); |
|
256 TChar c; |
|
257 do |
|
258 { |
|
259 c=(TUint)TheConsole->Getch(); |
|
260 c.UpperCase(); |
|
261 } |
|
262 while(c<'A' && c>'F'); |
|
263 |
|
264 switch (c) |
|
265 { |
|
266 case 'A': TheConfig.iRate=EBps4800; break; |
|
267 case 'B': TheConfig.iRate=EBps9600; break; |
|
268 case 'C': TheConfig.iRate=EBps19200; break; |
|
269 case 'D': TheConfig.iRate=EBps38400; break; |
|
270 case 'E': TheConfig.iRate=EBps57600; break; |
|
271 case 'F': TheConfig.iRate=EBps115200; break; |
|
272 case 0x1b: return(KErrNone); |
|
273 } |
|
274 TInt r=TheSerialPort->SetConfig(TheConfigBuf); |
|
275 if (r!=KErrNone) |
|
276 { |
|
277 CenteredPrintf(KDisplayMainY+9,_L("Error (%d) changing baudrate"),r); |
|
278 TheConsole->Getch(); |
|
279 } |
|
280 |
|
281 return(KErrNone); |
|
282 } |
|
283 |
|
284 LOCAL_C TInt SendHayesCommand() |
|
285 // |
|
286 // Send short hayes command |
|
287 // |
|
288 { |
|
289 |
|
290 TInt r=TheSerialPort->WriteS(_L8("AT&f\r")); |
|
291 if (r!=KErrNone) |
|
292 { |
|
293 CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending data"),r); |
|
294 TheConsole->Getch(); |
|
295 } |
|
296 return(KErrNone); |
|
297 } |
|
298 |
|
299 LOCAL_C TInt SendLongHayesCommand() |
|
300 // |
|
301 // Send Long hayes command |
|
302 // |
|
303 { |
|
304 |
|
305 TInt r=TheSerialPort->WriteS(_L8("AT&f&f&f&f&f&f&f\r")); |
|
306 if (r!=KErrNone) |
|
307 { |
|
308 CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending data"),r); |
|
309 TheConsole->Getch(); |
|
310 } |
|
311 return(KErrNone); |
|
312 } |
|
313 |
|
314 const TInt KBufSize=0x100; |
|
315 LOCAL_C TInt Loopback() |
|
316 // |
|
317 // Loopback data from Rx to Tx |
|
318 // |
|
319 { |
|
320 |
|
321 CenteredPrintf(KDisplayMainY,_L("Loopback mode")); |
|
322 CenteredPrintf(KDisplayMainY+5,_L("Hit a key abort")); |
|
323 TheSerialPort->ResetBuffers(); |
|
324 |
|
325 CCirBuffer* cbufPtr=new CCirBuffer; |
|
326 __ASSERT_ALWAYS(cbufPtr!=NULL,Panic(ECircBuf)); |
|
327 TRAPD(r,cbufPtr->SetLengthL(KBufSize)); |
|
328 __ASSERT_ALWAYS(r==KErrNone,Panic(ECircBuf)); |
|
329 TRequestStatus kStat,rStat,tStat = 0; |
|
330 |
|
331 TBool TxActive=EFalse; |
|
332 TInt TxCount=0; |
|
333 TUint8 txChar; |
|
334 TPtr8 txPtr(&txChar,1); |
|
335 |
|
336 TUint8 rxChar; |
|
337 TPtr8 rxPtr(&rxChar,1); |
|
338 TheSerialPort->Read(rStat,rxPtr,1); |
|
339 |
|
340 TheConsole->Read(kStat); |
|
341 FOREVER |
|
342 { |
|
343 User::WaitForAnyRequest(); |
|
344 if (rStat!=KRequestPending) |
|
345 { |
|
346 if (rStat.Int()!=KErrNone) |
|
347 { // Rx error |
|
348 CenteredPrintf(KDisplayMainY+5,_L("Rx error(%d)"),rStat.Int()); |
|
349 TheConsole->ReadCancel(); |
|
350 User::WaitForRequest(kStat); |
|
351 goto LoopEnd; |
|
352 } |
|
353 cbufPtr->Put((TInt)rxChar); |
|
354 TheSerialPort->Read(rStat,rxPtr,1); |
|
355 if (!TxActive) |
|
356 { |
|
357 txChar=(TUint8)cbufPtr->Get(); |
|
358 TheSerialPort->Write(tStat,txPtr,1); |
|
359 TxActive=ETrue; |
|
360 } |
|
361 } |
|
362 else if (TxActive && tStat!=KRequestPending) |
|
363 { |
|
364 if (tStat.Int()!=KErrNone) |
|
365 { // Tx error |
|
366 CenteredPrintf(KDisplayMainY+5,_L("Tx error(%d)"),tStat.Int()); |
|
367 TheSerialPort->ReadCancel(); |
|
368 User::WaitForRequest(rStat); |
|
369 TheConsole->ReadCancel(); |
|
370 User::WaitForRequest(kStat); |
|
371 TxActive=EFalse; |
|
372 goto LoopEnd; |
|
373 } |
|
374 TxCount++; |
|
375 TInt t=cbufPtr->Get(); |
|
376 if (t==KErrGeneral) |
|
377 TxActive=EFalse; |
|
378 else |
|
379 { |
|
380 txChar=(TUint8)t; |
|
381 TheSerialPort->Write(tStat,txPtr,1); |
|
382 } |
|
383 } |
|
384 else if (kStat!=KRequestPending) |
|
385 { |
|
386 CenteredPrintf(KDisplayMainY+5,_L("Tx count (%d) - Hit another key"),TxCount); |
|
387 TheSerialPort->ReadCancel(); |
|
388 User::WaitForRequest(rStat); |
|
389 LoopEnd: |
|
390 if (TxActive) |
|
391 { |
|
392 TheSerialPort->WriteCancel(); |
|
393 User::WaitForRequest(tStat); |
|
394 } |
|
395 delete cbufPtr; |
|
396 TheConsole->Getch(); |
|
397 break; |
|
398 } |
|
399 else |
|
400 Panic(EStraySignal); |
|
401 } |
|
402 return(KErrNone); |
|
403 } |
|
404 |
|
405 LOCAL_C TInt ToggleDtr() |
|
406 // |
|
407 // Toggle state of DTR signal |
|
408 // |
|
409 { |
|
410 |
|
411 if (TheDtrState) |
|
412 { |
|
413 TheSerialPort->SetSignals(0,KSignalDTR); // Negate DTR |
|
414 TheDtrState=EFalse; |
|
415 } |
|
416 else |
|
417 { |
|
418 TheSerialPort->SetSignals(KSignalDTR,0); // Assert DTR |
|
419 TheDtrState=ETrue; |
|
420 } |
|
421 return(KErrNone); |
|
422 } |
|
423 |
|
424 LOCAL_C TInt ToggleRts() |
|
425 // |
|
426 // Toggle state of RTS signal |
|
427 // |
|
428 { |
|
429 |
|
430 if (TheRtsState) |
|
431 { |
|
432 TheSerialPort->SetSignals(0,KSignalRTS); // Negate RTS |
|
433 TheRtsState=EFalse; |
|
434 } |
|
435 else |
|
436 { |
|
437 TheSerialPort->SetSignals(KSignalRTS,0); // Assert RTS |
|
438 TheRtsState=ETrue; |
|
439 } |
|
440 return(KErrNone); |
|
441 } |
|
442 |
|
443 LOCAL_C TInt SendXoff() |
|
444 // |
|
445 // Send XOFF |
|
446 // |
|
447 { |
|
448 |
|
449 TInt r=TheSerialPort->WriteS(_L8("\x13")); |
|
450 if (r!=KErrNone) |
|
451 { |
|
452 CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending XOFF"),r); |
|
453 TheConsole->Getch(); |
|
454 } |
|
455 return(KErrNone); |
|
456 } |
|
457 |
|
458 LOCAL_C TInt ReceiveBlock() |
|
459 // |
|
460 // Receive a block |
|
461 // |
|
462 { |
|
463 |
|
464 CenteredPrintf(KDisplayMainY,_L("Waiting to recieve a block. Hit a key to abort")); |
|
465 TheSerialPort->ResetBuffers(); |
|
466 TRequestStatus kStat,rStat; |
|
467 TBuf8<KTestPatternSize> rdBuf(KTestPatternSize); |
|
468 TheSerialPort->Read(rStat,rdBuf); |
|
469 TheConsole->Read(kStat); |
|
470 User::WaitForRequest(kStat,rStat); |
|
471 if (rStat!=KRequestPending) |
|
472 { |
|
473 TheConsole->ReadCancel(); |
|
474 User::WaitForRequest(kStat); |
|
475 if (rStat.Int()!=KErrNone) |
|
476 { |
|
477 CenteredPrintf(KDisplayMainY+5,_L("Rx error(%d)"),rStat.Int()); |
|
478 TheConsole->Getch(); |
|
479 } |
|
480 else if (rdBuf.Compare(TheTestBuf)!=0) |
|
481 DumpDescriptors(rdBuf,TheTestBuf); |
|
482 else |
|
483 { |
|
484 CenteredPrintf(KDisplayMainY+5,_L("Success")); |
|
485 TheConsole->Getch(); |
|
486 } |
|
487 } |
|
488 else |
|
489 { |
|
490 TheSerialPort->ReadCancel(); |
|
491 User::WaitForRequest(rStat); |
|
492 } |
|
493 return(KErrNone); |
|
494 } |
|
495 |
|
496 LOCAL_C TInt TransmitBlock() |
|
497 // |
|
498 // Transmit a block |
|
499 // |
|
500 { |
|
501 |
|
502 TInt r; |
|
503 CenteredPrintf(KDisplayMainY,_L("Hit a key to transmit a block")); |
|
504 while ((TUint)TheConsole->Getch()!=0x1b) |
|
505 { |
|
506 r=TheSerialPort->WriteS(TheTestBuf); |
|
507 if (r!=KErrNone) |
|
508 { |
|
509 CenteredPrintf(KDisplayMainY+1,_L("Error (%d) transmitting block"),r); |
|
510 TheConsole->Getch(); |
|
511 } |
|
512 } |
|
513 return(KErrNone); |
|
514 } |
|
515 |
|
516 LOCAL_C TInt SendXon() |
|
517 // |
|
518 // Send XON |
|
519 // |
|
520 { |
|
521 |
|
522 TInt r=TheSerialPort->WriteS(_L8("\x11")); |
|
523 if (r!=KErrNone) |
|
524 { |
|
525 CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending XON"),r); |
|
526 TheConsole->Getch(); |
|
527 } |
|
528 return(KErrNone); |
|
529 } |
|
530 |
|
531 LOCAL_C void DceUtil() |
|
532 // |
|
533 // DCE Serial Driver test utilities |
|
534 // |
|
535 { |
|
536 TBuf<20> b(_L("BDHLOQRSTXY\x1b")); |
|
537 |
|
538 FOREVER |
|
539 { |
|
540 TheConsole->ClearScreen(); |
|
541 TPtrC br=BaudrateText(TheConfig.iRate); |
|
542 TPtrC dt=DtrText(TheDtrState); |
|
543 TPtrC rt=RtsText(TheRtsState); |
|
544 Heading(_L("T_DCEUTL 1.01 (Baudrate: %S DTR:%S RTS:%S)"),&br,&dt,&rt); |
|
545 Instructions(ETrue,_L("Change(B)aud Toggle(D)TR Send(H)ayes (L)oopBack Send X(O)FF")); |
|
546 Instructions(EFalse,_L("(Q)uit (R)xBlock Toggle RT(S) (T)xBlock Send(X)ON LongHayes(Y)?")); |
|
547 TChar c; |
|
548 do |
|
549 { |
|
550 c=(TUint)TheConsole->Getch(); |
|
551 c.UpperCase(); |
|
552 } |
|
553 while(b.Locate(c)==KErrNotFound); |
|
554 |
|
555 switch (c) |
|
556 { |
|
557 case 'B': // Change baudrate |
|
558 ChangeBaudrate(); |
|
559 break; |
|
560 case 'D': // Toggle state of DTR signal |
|
561 ToggleDtr(); |
|
562 break; |
|
563 case 'H': // Send short hayes command |
|
564 SendHayesCommand(); |
|
565 break; |
|
566 case 'L': // Loopback data from Rx to Tx |
|
567 Loopback(); |
|
568 break; |
|
569 case 'O': // Send XOFF |
|
570 SendXoff(); |
|
571 break; |
|
572 case 'Q': case 0x1b: // Quit |
|
573 return; |
|
574 case 'R': // Receive a block |
|
575 ReceiveBlock(); |
|
576 break; |
|
577 case 'S': // Toggle state of RTS signal |
|
578 ToggleRts(); |
|
579 break; |
|
580 case 'T': // Transmit a block |
|
581 TransmitBlock(); |
|
582 break; |
|
583 case 'X': // Send XON |
|
584 SendXon(); |
|
585 break; |
|
586 case 'Y': // Send long hayes command |
|
587 SendLongHayesCommand(); |
|
588 break; |
|
589 } |
|
590 } |
|
591 } |
|
592 |
|
593 GLDEF_C TInt E32Main() |
|
594 { |
|
595 |
|
596 // Create console |
|
597 TRAPD(r,TheConsole=Console::NewL(_L("T_DCEUTL"),TSize(KConsFullScreen,KConsFullScreen))) |
|
598 __ASSERT_ALWAYS(r==KErrNone,Panic(ECreatingConsole)); |
|
599 TheTestBuf.SetLength(KTestPatternSize); |
|
600 StripeMem(TheTestBuf,'A','Z'); |
|
601 |
|
602 TBuf <0x100> cmd; |
|
603 User::CommandLine(cmd); |
|
604 TInt port=0; |
|
605 if ((cmd.Length()>0) && (cmd[0]>='1' && cmd[0]<='4')) |
|
606 port=(TInt)(cmd[0]-'0'); |
|
607 |
|
608 // Load Device Drivers |
|
609 TheConsole->Printf(_L("Load PDD\n\r")); |
|
610 TBuf<9> pddName=PDD_NAME; |
|
611 #if !defined (__WINS__) |
|
612 pddName[5]=(TText)('1'+port); |
|
613 TInt muid=0; |
|
614 if (HAL::Get(HAL::EMachineUid, muid)==KErrNone) |
|
615 { |
|
616 // Brutus uses EUART4 for both COM3 and COM4 |
|
617 if (muid==HAL::EMachineUid_Brutus && port==4) |
|
618 pddName[5]=(TText)'4'; |
|
619 } |
|
620 #endif |
|
621 r=User::LoadPhysicalDevice(pddName); |
|
622 __ASSERT_ALWAYS(r==KErrNone||r==KErrAlreadyExists,Panic(ELoadingPDD)); |
|
623 TheConsole->Printf(_L("Load LDD\n\r")); |
|
624 r=User::LoadLogicalDevice(LDD_NAME); |
|
625 __ASSERT_ALWAYS(r==KErrNone||r==KErrAlreadyExists,Panic(ELoadingLDD)); |
|
626 |
|
627 // Create RComm object |
|
628 TheConsole->Printf(_L("Create RComm object\n\r")); |
|
629 TheSerialPort=new RComm; |
|
630 __ASSERT_ALWAYS(TheSerialPort!=NULL,Panic(ECreatingRComm)); |
|
631 |
|
632 // Open Serial Port |
|
633 TheConsole->Printf(_L("Open Serial Port (%d)\n\r"),port); |
|
634 r=TheSerialPort->Open(port); |
|
635 __ASSERT_ALWAYS(r==KErrNone,Panic(EOpeningPort)); |
|
636 |
|
637 // Setup serial port |
|
638 TheConsole->Printf(_L("Setup serial port\n\r")); |
|
639 TheSerialPort->Config(TheConfigBuf); |
|
640 TheConfig.iRate=EBps9600; |
|
641 TheConfig.iDataBits=EData8; |
|
642 TheConfig.iStopBits=EStop1; |
|
643 TheConfig.iParity=EParityNone; |
|
644 TheConfig.iHandshake=(KConfigFreeRTS|KConfigFreeDTR); // So we can control them ourselves |
|
645 r=TheSerialPort->SetConfig(TheConfigBuf); |
|
646 __ASSERT_ALWAYS((r==KErrNone||r==KErrNotSupported),Panic(ESettingPort)); |
|
647 if (r==KErrNotSupported) |
|
648 { |
|
649 // Port may not support the handshake settings |
|
650 TheConfig.iHandshake=0; |
|
651 r=TheSerialPort->SetConfig(TheConfigBuf); |
|
652 __ASSERT_ALWAYS(r==KErrNone,Panic(ESettingPort)); |
|
653 } |
|
654 |
|
655 // Assert DTR signal |
|
656 TheSerialPort->SetSignals(KSignalDTR,0); // Assert DTR |
|
657 TheDtrState=ETrue; |
|
658 // Assert RTS signal |
|
659 TheSerialPort->SetSignals(KSignalRTS,0); // Assert RTS |
|
660 TheRtsState=ETrue; |
|
661 |
|
662 DceUtil(); |
|
663 |
|
664 TheSerialPort->Close(); |
|
665 delete TheSerialPort; |
|
666 delete TheConsole; |
|
667 return(KErrNone); |
|
668 } |
|
669 |
|
670 |