kerneltest/e32test/misc/ymodemu.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     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\misc\ymodemu.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32std_private.h>
       
    20 #include <d32comm.h>
       
    21 #include "ymodemu.h"
       
    22 
       
    23 //#include <e32test.h>
       
    24 //GLREF_C RTest test;
       
    25 
       
    26 YModemU::YModemU(TBool aG)
       
    27 	: YModem(aG)
       
    28 	{
       
    29 	}
       
    30 
       
    31 YModemU::~YModemU()
       
    32 	{
       
    33 	iComm.Close();
       
    34 	iTimer.Close();
       
    35 	}
       
    36 
       
    37 TInt YModemU::Create(TInt aPort)
       
    38 	{
       
    39 	TInt r=iComm.Open(aPort);
       
    40 	if (r!=KErrNone)
       
    41 		return r;
       
    42 	TCommConfig cfg;
       
    43 	TCommConfigV01& c=cfg();
       
    44 	iComm.Config(cfg);
       
    45 	c.iRate=EBps115200;
       
    46 	c.iDataBits=EData8;
       
    47 	c.iStopBits=EStop1;
       
    48 	c.iParity=EParityNone;
       
    49 //	c.iHandshake=KConfigFreeRTS|KConfigFreeDTR;
       
    50 	c.iHandshake=0;
       
    51 	c.iFifo=EFifoEnable;
       
    52 	c.iTerminatorCount=0;
       
    53 	r=iComm.SetConfig(cfg);
       
    54 	if (r!=KErrNone)
       
    55 		return r;
       
    56 	r=iComm.SetReceiveBufferLength(8192);
       
    57 	if (r!=KErrNone)
       
    58 		return r;
       
    59 	return iTimer.CreateLocal();
       
    60 	}
       
    61 
       
    62 YModemU* YModemU::NewL(TInt aPort, TBool aG)
       
    63 	{
       
    64 	YModemU* p=new YModemU(aG);
       
    65 	TInt r=p->Create(aPort);
       
    66 	if (r!=KErrNone)
       
    67 		{
       
    68 		delete p;
       
    69 		User::Leave(r);
       
    70 		}
       
    71 	return p;
       
    72 	}
       
    73 
       
    74 void YModemU::WriteC(TUint aChar)
       
    75 	{
       
    76 	TBuf8<1> b;
       
    77 	b.SetLength(1);
       
    78 	b[0]=(TUint8)aChar;
       
    79 	TRequestStatus s;
       
    80 	iComm.Write(s,b);
       
    81 	User::WaitForRequest(s);
       
    82 	}
       
    83 
       
    84 TInt YModemU::ReadBlock(TDes8& aDest)
       
    85 	{
       
    86 	aDest.Zero();
       
    87 	TRequestStatus s1, s2;
       
    88 	iTimer.After(s1,iTimeout);
       
    89 //	test.Printf(_L("@%dms %d\n"),User::NTickCount(),iComm.QueryReceiveBuffer());
       
    90 	iComm.Read(s2,aDest);
       
    91 	User::WaitForRequest(s1,s2);
       
    92 	if (s2!=KRequestPending)
       
    93 		{
       
    94 		iTimer.Cancel();
       
    95 		User::WaitForRequest(s1);
       
    96 		return s2.Int();
       
    97 		}
       
    98 	iComm.ReadCancel();
       
    99 	User::WaitForRequest(s2);
       
   100 	return KErrTimedOut;
       
   101 	}
       
   102