1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/ymodemu.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,102 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\misc\ymodemu.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32std_private.h>
1.23 +#include <d32comm.h>
1.24 +#include "ymodemu.h"
1.25 +
1.26 +//#include <e32test.h>
1.27 +//GLREF_C RTest test;
1.28 +
1.29 +YModemU::YModemU(TBool aG)
1.30 + : YModem(aG)
1.31 + {
1.32 + }
1.33 +
1.34 +YModemU::~YModemU()
1.35 + {
1.36 + iComm.Close();
1.37 + iTimer.Close();
1.38 + }
1.39 +
1.40 +TInt YModemU::Create(TInt aPort)
1.41 + {
1.42 + TInt r=iComm.Open(aPort);
1.43 + if (r!=KErrNone)
1.44 + return r;
1.45 + TCommConfig cfg;
1.46 + TCommConfigV01& c=cfg();
1.47 + iComm.Config(cfg);
1.48 + c.iRate=EBps115200;
1.49 + c.iDataBits=EData8;
1.50 + c.iStopBits=EStop1;
1.51 + c.iParity=EParityNone;
1.52 +// c.iHandshake=KConfigFreeRTS|KConfigFreeDTR;
1.53 + c.iHandshake=0;
1.54 + c.iFifo=EFifoEnable;
1.55 + c.iTerminatorCount=0;
1.56 + r=iComm.SetConfig(cfg);
1.57 + if (r!=KErrNone)
1.58 + return r;
1.59 + r=iComm.SetReceiveBufferLength(8192);
1.60 + if (r!=KErrNone)
1.61 + return r;
1.62 + return iTimer.CreateLocal();
1.63 + }
1.64 +
1.65 +YModemU* YModemU::NewL(TInt aPort, TBool aG)
1.66 + {
1.67 + YModemU* p=new YModemU(aG);
1.68 + TInt r=p->Create(aPort);
1.69 + if (r!=KErrNone)
1.70 + {
1.71 + delete p;
1.72 + User::Leave(r);
1.73 + }
1.74 + return p;
1.75 + }
1.76 +
1.77 +void YModemU::WriteC(TUint aChar)
1.78 + {
1.79 + TBuf8<1> b;
1.80 + b.SetLength(1);
1.81 + b[0]=(TUint8)aChar;
1.82 + TRequestStatus s;
1.83 + iComm.Write(s,b);
1.84 + User::WaitForRequest(s);
1.85 + }
1.86 +
1.87 +TInt YModemU::ReadBlock(TDes8& aDest)
1.88 + {
1.89 + aDest.Zero();
1.90 + TRequestStatus s1, s2;
1.91 + iTimer.After(s1,iTimeout);
1.92 +// test.Printf(_L("@%dms %d\n"),User::NTickCount(),iComm.QueryReceiveBuffer());
1.93 + iComm.Read(s2,aDest);
1.94 + User::WaitForRequest(s1,s2);
1.95 + if (s2!=KRequestPending)
1.96 + {
1.97 + iTimer.Cancel();
1.98 + User::WaitForRequest(s1);
1.99 + return s2.Int();
1.100 + }
1.101 + iComm.ReadCancel();
1.102 + User::WaitForRequest(s2);
1.103 + return KErrTimedOut;
1.104 + }
1.105 +