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_sirco2.cpp
21 #include <e32std_private.h>
25 #if defined(__VC32__) && _MSC_VER==1100
26 // Disable MSVC++ 5.0 aggressive warnings about non-expansion of inline functions.
27 #pragma warning(disable : 4710) // function '...' not expanded
30 #if defined (__WINS__)
31 #define PDD_NAME _L("ECDRV.PDD")
32 #define LDD_NAME _L("ECOMM.LDD")
34 #define PDD_NAME _L("EUART")
35 #define LDD_NAME _L("ECOMM")
38 #define PDD2_NAME _L("EUART")
45 #define FIND_NAME _L("Comm.*")
51 //LOCAL_D RTest test(_L("T_SlowIR"));
55 TInt iTimeDelay=1000000;
57 TBool iRWToWrite=EFalse;
59 void ResetReadBuffer()
62 ReadBuf.SetLength(2060);
67 void ResetWriteBuffer()
69 // Mark a buffer with repeating byte pattern
74 WriteBuf.SetLength(2060);
76 TUint character=startChar;
77 for (TInt i=0;i<WriteBuf.Length();i++)
79 WriteBuf[i]=(TText8)character;
80 if(++character>endChar)
85 TInt CActiveRW::ErrorStats()
86 { // Computes error %ge
88 return (iRxErrCount*200+iRxCount)/(2*iRxCount);
93 TBool CActiveRW::CompareBuffers(TInt aLen)
96 if(aLen !=ReadBuf.Length() || aLen !=WriteBuf.Length())
101 if(ReadBuf[i]!=WriteBuf[i]){
114 CActiveConsole::CActiveConsole(CConsoleBase* aConsole)
115 : CActive(EPriorityNormal)
122 CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole)
124 CActiveConsole* self = new (ELeave) CActiveConsole(aConsole);
129 void CActiveConsole::ConstructL ()
132 TCommCapsV01& aCaps=aCapsBuf();
133 TCommConfig aConfigBuf;
134 TCommConfigV01& aConfig=aConfigBuf();
135 iConsole->Printf(_L("\r\n"));
136 CActiveScheduler::Add(this); // Add to active scheduler
138 TBuf<10> pddName=PDD_NAME;
139 #if defined (__MARM__)
140 const TInt KMaxPdds=10;
141 iConsole->Printf(_L("Load MARM PDDs\n\r"));
142 RDebug::Print(_L("Load MARM PDDs\n\r"));
144 const TInt KMaxPdds=0;
145 iConsole->Printf(_L("Load WINS PDD\n\r"));
146 iConsole->Printf(PDD_NAME);
148 // iConsole->Read(iStatus);
152 for (i=-1; i<KMaxPdds; ++i)
155 pddName.Append(TChar('0'));
157 pddName[pddName.Length()-1] = (TText)('0'+i);
158 r=User::LoadPhysicalDevice(pddName);
159 if (r==KErrNone || r==KErrAlreadyExists)
161 iConsole->Printf(_L("PDD %S loaded\n"),&pddName);
162 RDebug::Print(_L("PDD %S loaded\n"),&pddName);
166 RDebug::Print(_L("Load MARM LDD\n\r"));
167 RDebug::Print(LDD_NAME);
168 iConsole->Printf(_L("Load LDD\n\r"));
169 iConsole->Printf(LDD_NAME);
170 r=User::LoadLogicalDevice(LDD_NAME);
171 RDebug::Print(_L("\n\rReturn %d\n\r"),r);
172 iConsole->Printf(_L("\n\rReturn %d\n\r"),r);
173 // test(r==KErrNone || r==KErrAlreadyExists);
175 RDebug::Print(_L("\n\rFind PDDs\n\r"));
176 iConsole->Printf(_L("Find PDDs\n"));
177 TFindPhysicalDevice findPDD(FIND_NAME);
178 TFullName findResult;
179 TInt res=findPDD.Next(findResult);
180 while (res==KErrNone)
182 RDebug::Print(_L("Found Driver: %S\n\r"),&findResult);
183 iConsole->Printf(_L("Found Driver: %S\n\r"),&findResult);
184 res=findPDD.Next(findResult);
187 iConsole->Printf(_L("Found drivers\n\r"));
190 // test(iPort!=NULL);
195 TInt ret=HAL::Get(HAL::EMachineUid, muid);
197 iConsole->Printf(_L("Error %d reading MachineUid\r\n"),ret);
198 if(muid==HAL::EMachineUid_Integrator)
199 iConsole->Printf(_L("Platform is Integrator\r\n"));
201 if(muid==HAL::EMachineUid_Integrator) ret=iPort->Open(KUnit2); // unit =2 for Integrator
202 else ret=iPort->Open(KUnit1); // unit == 1 for brutus
204 iConsole->Printf(_L("Error %d on opening Slow ir port\r\n"),ret);
206 iConsole->Printf(_L("Successfully opened Slow ir port\r\n"));
208 iPort->Caps(aCapsBuf);
211 iConsole->Printf(_L("Error %d on getting caps\r\n"),ret);
213 iConsole->Printf(_L("Sir Caps: %d\r\n"),aCaps.iRate);
215 iPort->Config(aConfigBuf);
217 iConsole->Printf(_L("Error %d getting config\r\n"),ret);
219 iConsole->Printf(_L("IR port config read\r\n"));
221 iConsole->Printf(_L("****Choose Rate*****\r\n"));
222 iConsole->Printf(_L("press '1' for 9600\r\n"));
223 iConsole->Printf(_L("press '2' for 19200\r\n"));
224 iConsole->Printf(_L("press '3' for 38400\r\n"));
225 iConsole->Printf(_L("press '4' for 57600\r\n"));
226 iConsole->Printf(_L("press '5' for 115200\r\n"));
230 User::WaitForRequest(key);
231 TChar pressedkey = TChar(iConsole->KeyCode());
236 aConfig.iRate=EBps9600;
239 aConfig.iRate=EBps19200;
242 aConfig.iRate=EBps38400;
245 aConfig.iRate=EBps57600;
248 aConfig.iRate=EBps115200;
251 aConfig.iRate=EBps115200;
255 aConfig.iHandshake=0;
256 aConfig.iSIREnable=ESIREnable;
257 aConfig.iParity=EParityNone;
258 aConfig.iDataBits=EData8;
259 aConfig.iStopBits=EStop1;
261 ret=iPort->SetConfig(aConfigBuf);
264 iConsole->Printf(_L("Error %d setting config\r\n"),ret);
266 iConsole->Printf(_L("Have configured port\n"));
269 iRW=CActiveRW::NewL(iConsole,iPort);
273 iConsole->Printf(_L("Have created writer\r\n"));
275 iConsole->Printf(_L("Failed to create writer\r\n"));
278 CActiveConsole::~CActiveConsole()
280 // Make sure we're cancelled
289 void CActiveConsole::DoCancel()
291 iConsole->ReadCancel();
294 void CActiveConsole::RunL()
296 ProcessKeyPressL(TChar(iConsole->KeyCode()));
297 // iConsole->Printf(_L("CActiveConsole - Completed with code %d\r\n\r\n"), iStatus.Int ());
300 void CActiveConsole::RequestCharacter()
312 // A request is issued to the CConsoleBase to accept a
313 // character from the keyboard.
314 iConsole->Printf(_L("*********************************\r\n"));
315 iConsole->Printf(_L("press Escape to quit\r\n"));
316 iConsole->Printf(_L("press 'r' to start as reader\r\n"));
317 iConsole->Printf(_L("press 'w' to start as writer\r\n"));
318 iConsole->Printf(_L("press 's' stop \r\n"));
320 iConsole->Read(iStatus);
324 void CActiveConsole::Options1()
326 iConsole->Printf(_L("*****Choose Delay*****\r\n"));
327 iConsole->Printf(_L("press '1' 1.00 sec delay\r\n"));
328 iConsole->Printf(_L("press '2' 0.10 sec delay\r\n"));
329 iConsole->Printf(_L("press '3' 0.01 sec delay\r\n"));
330 iConsole->Printf(_L("press '4' 0.00 sec delay\r\n"));
331 iConsole->Read(iStatus);
335 void CActiveConsole::Options2()
337 iConsole->Printf(_L("****Choose Buf Sz*****\r\n"));
338 iConsole->Printf(_L("press '1' 1 byte \r\n"));
339 iConsole->Printf(_L("press '2' 4 bytes\r\n"));
340 iConsole->Printf(_L("press '3' 2000 bytes\r\n"));
341 iConsole->Printf(_L("press '4' 2051 bytes\r\n"));
342 iConsole->Read(iStatus);
346 void CActiveConsole::ProcessKeyPressL(TChar aChar)
348 if (aChar == EKeyEscape)
350 CActiveScheduler::Stop();
374 iConsole->Printf(_L("Time Delay: %d\r\n"),iTimeDelay);
399 // check that we have enough space
400 if(iBufSz>iPort->ReceiveBufferLength())
401 iPort->SetReceiveBufferLength(iBufSz);
402 // if it won't do it, then settle for what it is by default
403 if(iBufSz>iPort->ReceiveBufferLength())
404 iBufSz=iPort->ReceiveBufferLength();
406 iConsole->Printf(_L("Buffer size: %d\r\n"),iBufSz);
414 case 'r'://start reader
415 case 'R'://start reader
418 case 'w'://start writer
419 case 'W'://start writer
422 case 's'://stop reader
423 case 'S'://stop reader
427 iConsole->Printf(_L("\r\nUnknown Command\r\n\r\n"));
440 CActiveRW::CActiveRW(CConsoleBase* aConsole,RCommDev* aPort)
441 : CActive (EPriorityNormal)
451 CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole,RCommDev* aPort)
453 CActiveRW* self = new (ELeave) CActiveRW(aConsole,aPort);
455 CleanupStack::PushL (self);
457 CActiveScheduler::Add (self);
458 CleanupStack::Pop ();
462 void CActiveRW::ConstructL()
466 CActiveRW::~CActiveRW()
471 void CActiveRW::RunL ()
475 if(iNextXfer==EWriteXfer)
478 if (iStatus != KErrNone)
480 if(iNextXfer==EWriteXfer)
483 iConsole->Printf(_L("Error %d on reading, error = %d%%\r\n"),iStatus.Int(),ErrorStats());
484 iPort->ResetBuffers();
485 iNextXfer=EDiscardXfer;
490 iConsole->Printf(_L("Error %d on writing\r\n"),iStatus.Int());
491 iConsole->Printf(_L("Received %d characters\r\n"),iPort->QueryReceiveBuffer());
497 User::After(iTimeDelay);
499 if(iNextXfer==EReadXfer)
501 // iPort->ResetBuffers();
503 ReadBuf.SetLength(iBufSz);
504 iConsole->Printf(_L("Reading(%d)"),ReadBuf.Length());
505 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
506 iNextXfer=EWriteXfer;
508 else // EWriteXfer || EDiagXfer || EDiscardXfer
510 if(iNextXfer==EWriteXfer)
512 if(!CompareBuffers(iBufSz))
514 iConsole->Printf(_L("\n***** Buffers don't match *****\n"));
515 for (i=0;i<ReadBuf.Length();i++)
517 iConsole->Printf(_L("WriteBuf[%d] = %02x, ReadBuf[%d] = %02x\n"),i,WriteBuf[i],i,ReadBuf[i]);
520 iUnrecovered=iPort->QueryReceiveBuffer();
521 iConsole->Printf(_L("Unrecovered %d characters\r\n"),iUnrecovered);
524 ReadBuf.SetLength(Max(iBufSz,iUnrecovered));
526 iConsole->Printf(_L("\n***** Doing Diagnostic read *****\n"));
527 iPort->Read(iStatus, ReadBuf, iUnrecovered);
534 iConsole->Printf(_L("ok\n"));
537 else if(iNextXfer==EDiagXfer)//EDiagXfer
539 iConsole->Printf(_L("\n***** Diagnostic dump %d *****\n"),iUnrecovered);
541 for (i=0;i<iUnrecovered;i++)
543 iConsole->Printf(_L("ReadBuf[%d] = %02x\n"),i,ReadBuf[i]);
546 WriteBuf.SetLength(iBufSz);
547 iConsole->Printf(_L("\nWriting(%d), "),WriteBuf.Length());
548 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
556 void CActiveRW::Start(TBool StartWriting)
558 iPort->ResetBuffers();
563 // iConsole->Printf(_L("Starting with write.%d....\r\n"),iBufSz);
564 WriteBuf.SetLength(iBufSz);
565 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
570 ReadBuf.SetLength(iBufSz);
571 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
572 // iConsole->Printf(_L("Starting with read.%d....\r\n"),ReadBuf.Length());
573 iNextXfer=EWriteXfer;
578 void CActiveRW::Stop()
580 iConsole->Printf(_L("Stopping.....\r\n"));
581 iConsole->Printf(_L("Unrecovered %d characters\r\n"),iPort->QueryReceiveBuffer());
585 void CActiveRW::DoCancel()
587 iPort->WriteCancel();
591 #pragma warning (default:4710)