plugins/consoles/vt100cons/src/vtc_busdevcons.cpp
changeset 0 7f656887cf89
child 27 17e35ffe449b
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // vtc_busdevcons.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <d32comm.h>
       
    14 #include <fshell/vtc_base.h>
       
    15 #include <fshell/common.mmh>
       
    16 
       
    17 class TPortConfig
       
    18 	{
       
    19 public:
       
    20 	TPortConfig();
       
    21 
       
    22 	TPtrC iPdd;
       
    23 	TPtrC iLdd;
       
    24 	TInt iPort;
       
    25 	TBps iRate;
       
    26 	};
       
    27 
       
    28 
       
    29 NONSHARABLE_CLASS(CVtcBusDevCommConsole) : public CVtcConsoleBase
       
    30 	{
       
    31 public:
       
    32 	CVtcBusDevCommConsole();
       
    33 	~CVtcBusDevCommConsole();
       
    34 
       
    35 protected: // From CVtcConsoleBase.
       
    36 	virtual void ConstructL(const TDesC& aTitle);
       
    37 private: // From MConsoleOutput.
       
    38 	virtual TInt Output(const TDesC8& aDes);
       
    39 private: // From MConsoleInput.
       
    40 	virtual void Input(TDes8& aDes, TRequestStatus& aStatus);
       
    41 	virtual void CancelInput(TRequestStatus& aStatus);
       
    42 private:
       
    43 	TInt ReadConfig(const TDesC& aConfigDes, TPortConfig& aConfig);
       
    44 private:
       
    45 	RBusDevComm iComm;
       
    46 	};
       
    47 
       
    48 extern "C" EXPORT_C TAny* NewConsole()
       
    49 	{
       
    50 	return new CVtcBusDevCommConsole;
       
    51 	}
       
    52 
       
    53 CVtcBusDevCommConsole::CVtcBusDevCommConsole()
       
    54 	{
       
    55 	}
       
    56 
       
    57 CVtcBusDevCommConsole::~CVtcBusDevCommConsole()
       
    58 	{
       
    59 	iComm.Close();
       
    60 	}
       
    61 
       
    62 #ifdef __WINS__
       
    63 _LIT(KPdd, "ecdrv");
       
    64 #else
       
    65 _LIT(KPdd, "euart");
       
    66 #endif
       
    67 _LIT(KLdd, "ecomm");
       
    68 
       
    69 TPortConfig::TPortConfig()
       
    70 	:iPdd(KNullDesC), iLdd(KNullDesC), iPort(-1), iRate(EBpsAutobaud)
       
    71 	{
       
    72 	}
       
    73 
       
    74 TInt CVtcBusDevCommConsole::ReadConfig(const TDesC& aConfigDes, TPortConfig& aConfig)
       
    75 	{
       
    76 	_LIT(KKeywordPdd, "pdd");
       
    77 	_LIT(KKeywordLdd, "ldd");
       
    78 	_LIT(KKeywordPort, "port");
       
    79 	_LIT(KKeywordRate, "rate");
       
    80 
       
    81 	TBool keywordFound(EFalse);
       
    82 	TLex lex(aConfigDes);
       
    83 	while (!lex.Eos())
       
    84 		{
       
    85 		TPtrC keyword;
       
    86 		TPtrC value;
       
    87 		TInt err = ReadKeywordValuePair(lex, keyword, value);
       
    88 		if (err != KErrNone)
       
    89 			{
       
    90 			break;
       
    91 			}
       
    92 
       
    93 		if (keyword == KKeywordPdd)
       
    94 			{
       
    95 			aConfig.iPdd.Set(value);
       
    96 			keywordFound = ETrue;
       
    97 			}
       
    98 		else if (keyword == KKeywordLdd)
       
    99 			{
       
   100 			aConfig.iLdd.Set(value);
       
   101 			keywordFound = ETrue;
       
   102 			}
       
   103 		else if (keyword == KKeywordPort)
       
   104 			{
       
   105 			TLex lex(value);
       
   106 			User::LeaveIfError(lex.Val(aConfig.iPort));
       
   107 			keywordFound = ETrue;
       
   108 			}
       
   109 		else if (keyword == KKeywordRate)
       
   110 			{
       
   111 			TLex lex(value);
       
   112 			TUint rate;
       
   113 			if (lex.Val(rate) == KErrNone)
       
   114 				{
       
   115 				switch (rate)
       
   116 					{
       
   117 				case 115200:
       
   118 					aConfig.iRate = EBps115200; break;
       
   119 				case 9600:
       
   120 					aConfig.iRate = EBps9600; break;
       
   121 				case 19200:
       
   122 					aConfig.iRate = EBps19200; break;
       
   123 				case 57600:
       
   124 					aConfig.iRate = EBps57600; break;
       
   125 				default:
       
   126 					break;
       
   127 					}
       
   128 				}
       
   129 			keywordFound = ETrue;
       
   130 			}
       
   131 		}
       
   132 
       
   133 	if (!keywordFound)
       
   134 		{
       
   135 		// Treat unrecognised string as a port number (to preserve backwards compatibility with earlier releases).
       
   136 		TLex lex(aConfigDes);
       
   137 		lex.Val(aConfig.iPort);
       
   138 		}
       
   139 
       
   140 	return KErrNone;
       
   141 	}
       
   142 
       
   143 void CVtcBusDevCommConsole::ConstructL(const TDesC& aTitle)
       
   144 	{
       
   145 	TPortConfig portConfig;
       
   146 	User::LeaveIfError(ReadConfig(aTitle, portConfig));
       
   147 	if (portConfig.iPort < 0) User::Leave(KErrArgument);
       
   148 
       
   149 	TPtrC pdd(portConfig.iPdd);
       
   150 	if (pdd.Length() == 0) pdd.Set(KPdd());
       
   151 	TPtrC ldd(portConfig.iLdd);
       
   152 	if (ldd.Length() == 0) ldd.Set(KLdd());
       
   153 
       
   154 	TInt err = User::LoadPhysicalDevice(pdd);
       
   155 	Message(EDebug, _L("Loading %S returned %d"), &pdd, err);
       
   156 	if (err != KErrAlreadyExists && portConfig.iPdd.Length()) User::LeaveIfError(err); // Don't error if we failed to load the default PDD
       
   157 
       
   158 	err = User::LoadLogicalDevice(ldd);
       
   159 	Message(EDebug, _L("Loading %S returned %d"), &ldd, err);
       
   160 	if (err != KErrAlreadyExists && portConfig.iLdd.Length()) User::LeaveIfError(err); // Don't error if we failed to load the default LDD
       
   161 	err = iComm.Open(portConfig.iPort);
       
   162 	Message(EDebug, _L("Opening port %d returned %d"), portConfig.iPort, err);
       
   163 	User::LeaveIfError(err);
       
   164 
       
   165 	if (portConfig.iRate != EBpsAutobaud)
       
   166 		{
       
   167 		TCommConfig cfg;
       
   168 		cfg().iRate = portConfig.iRate;
       
   169 		cfg().iDataBits = EData8;
       
   170 		cfg().iStopBits = EStop1;
       
   171 		cfg().iParity = EParityNone;
       
   172 		cfg().iHandshake = 0;
       
   173 		cfg().iParityError = KConfigParityErrorFail;
       
   174 		cfg().iFifo = EFifoEnable;
       
   175 		cfg().iSpecialRate = 0;
       
   176 		cfg().iTerminatorCount = 0;
       
   177 		cfg().iSIREnable = ESIRDisable;
       
   178 		err = iComm.SetConfig(cfg);
       
   179 		Message(EDebug, _L("RBusDevComm::SetConfig returned %d"), err);
       
   180 		User::LeaveIfError(err);
       
   181 		}
       
   182 	iComm.ResetBuffers();
       
   183 	CVtcConsoleBase::ConstructL(aTitle);
       
   184 	}
       
   185 	
       
   186 TInt CVtcBusDevCommConsole::Output(const TDesC8& aDes)
       
   187 	{
       
   188 	TRequestStatus stat;
       
   189 #ifdef FSHELL_PLATFORM_OPP
       
   190 retry:
       
   191 #endif
       
   192 	iComm.Write(stat, aDes);
       
   193 	User::WaitForRequest(stat);
       
   194 #ifdef FSHELL_PLATFORM_OPP
       
   195 	// Temporary OPP specific change - the drivers for the mid-sized prototype currently complete requests with KErrAbort just before power management sends the device to sleep.
       
   196 	if (stat.Int() == KErrAbort)
       
   197 		{
       
   198 		goto retry;
       
   199 		}
       
   200 #endif
       
   201 	return stat.Int();
       
   202 	}
       
   203 
       
   204 void CVtcBusDevCommConsole::Input(TDes8& aDes, TRequestStatus& aStatus)
       
   205 	{
       
   206 	iComm.ReadOneOrMore(aStatus, aDes);
       
   207 	}
       
   208 
       
   209 void CVtcBusDevCommConsole::CancelInput(TRequestStatus&)
       
   210 	{
       
   211 	iComm.ReadCancel();
       
   212 	}