plugins/consoles/vt100cons/src/vtc_busdevcons.cpp
changeset 27 17e35ffe449b
parent 0 7f656887cf89
child 62 60f47003f4b1
equal deleted inserted replaced
26:5d370dafea69 27:17e35ffe449b
    21 
    21 
    22 	TPtrC iPdd;
    22 	TPtrC iPdd;
    23 	TPtrC iLdd;
    23 	TPtrC iLdd;
    24 	TInt iPort;
    24 	TInt iPort;
    25 	TBps iRate;
    25 	TBps iRate;
       
    26 	TBool iDebug;
    26 	};
    27 	};
    27 
    28 
       
    29 #define ErrOrDebug(err) (((err) < 0  && (err) != KErrAlreadyExists) ? EError : EDebug)
    28 
    30 
    29 NONSHARABLE_CLASS(CVtcBusDevCommConsole) : public CVtcConsoleBase
    31 NONSHARABLE_CLASS(CVtcBusDevCommConsole) : public CVtcConsoleBase
    30 	{
    32 	{
    31 public:
    33 public:
    32 	CVtcBusDevCommConsole();
    34 	CVtcBusDevCommConsole();
    65 _LIT(KPdd, "euart");
    67 _LIT(KPdd, "euart");
    66 #endif
    68 #endif
    67 _LIT(KLdd, "ecomm");
    69 _LIT(KLdd, "ecomm");
    68 
    70 
    69 TPortConfig::TPortConfig()
    71 TPortConfig::TPortConfig()
    70 	:iPdd(KNullDesC), iLdd(KNullDesC), iPort(-1), iRate(EBpsAutobaud)
    72 	:iPdd(KNullDesC), iLdd(KNullDesC), iPort(-1), iRate(EBpsAutobaud), iDebug(EFalse)
    71 	{
    73 	{
    72 	}
    74 	}
    73 
    75 
    74 TInt CVtcBusDevCommConsole::ReadConfig(const TDesC& aConfigDes, TPortConfig& aConfig)
    76 TInt CVtcBusDevCommConsole::ReadConfig(const TDesC& aConfigDes, TPortConfig& aConfig)
    75 	{
    77 	{
    76 	_LIT(KKeywordPdd, "pdd");
    78 	_LIT(KKeywordPdd, "pdd");
    77 	_LIT(KKeywordLdd, "ldd");
    79 	_LIT(KKeywordLdd, "ldd");
    78 	_LIT(KKeywordPort, "port");
    80 	_LIT(KKeywordPort, "port");
    79 	_LIT(KKeywordRate, "rate");
    81 	_LIT(KKeywordRate, "rate");
       
    82 	_LIT(KKeywordDebug, "debug");
    80 
    83 
    81 	TBool keywordFound(EFalse);
    84 	TBool keywordFound(EFalse);
    82 	TLex lex(aConfigDes);
    85 	TLex lex(aConfigDes);
    83 	while (!lex.Eos())
    86 	while (!lex.Eos())
    84 		{
    87 		{
   126 					break;
   129 					break;
   127 					}
   130 					}
   128 				}
   131 				}
   129 			keywordFound = ETrue;
   132 			keywordFound = ETrue;
   130 			}
   133 			}
       
   134 		else if (keyword == KKeywordDebug)
       
   135 			{
       
   136 			aConfig.iDebug = ETrue;
       
   137 			keywordFound = ETrue;
       
   138 			}
   131 		}
   139 		}
   132 
   140 
   133 	if (!keywordFound)
   141 	if (!keywordFound)
   134 		{
   142 		{
   135 		// Treat unrecognised string as a port number (to preserve backwards compatibility with earlier releases).
   143 		// Treat unrecognised string as a port number (to preserve backwards compatibility with earlier releases).
   143 void CVtcBusDevCommConsole::ConstructL(const TDesC& aTitle)
   151 void CVtcBusDevCommConsole::ConstructL(const TDesC& aTitle)
   144 	{
   152 	{
   145 	TPortConfig portConfig;
   153 	TPortConfig portConfig;
   146 	User::LeaveIfError(ReadConfig(aTitle, portConfig));
   154 	User::LeaveIfError(ReadConfig(aTitle, portConfig));
   147 	if (portConfig.iPort < 0) User::Leave(KErrArgument);
   155 	if (portConfig.iPort < 0) User::Leave(KErrArgument);
       
   156 
       
   157 	if (portConfig.iDebug) SetDebug(ETrue);
   148 
   158 
   149 	TPtrC pdd(portConfig.iPdd);
   159 	TPtrC pdd(portConfig.iPdd);
   150 	if (pdd.Length() == 0) pdd.Set(KPdd());
   160 	if (pdd.Length() == 0) pdd.Set(KPdd());
   151 	TPtrC ldd(portConfig.iLdd);
   161 	TPtrC ldd(portConfig.iLdd);
   152 	if (ldd.Length() == 0) ldd.Set(KLdd());
   162 	if (ldd.Length() == 0) ldd.Set(KLdd());
   153 
   163 
   154 	TInt err = User::LoadPhysicalDevice(pdd);
   164 	TInt err = User::LoadPhysicalDevice(pdd);
   155 	Message(EDebug, _L("Loading %S returned %d"), &pdd, err);
   165 	Message(ErrOrDebug(err), _L("Loading PDD %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
   166 	if (err != KErrAlreadyExists && portConfig.iPdd.Length()) User::LeaveIfError(err); // Don't error if we failed to load the default PDD
   157 
   167 
   158 	err = User::LoadLogicalDevice(ldd);
   168 	err = User::LoadLogicalDevice(ldd);
   159 	Message(EDebug, _L("Loading %S returned %d"), &ldd, err);
   169 	Message(ErrOrDebug(err), _L("Loading LDD %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
   170 	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);
   171 	err = iComm.Open(portConfig.iPort);
   162 	Message(EDebug, _L("Opening port %d returned %d"), portConfig.iPort, err);
   172 	Message(ErrOrDebug(err), _L("Opening port %d returned %d"), portConfig.iPort, err);
   163 	User::LeaveIfError(err);
   173 	User::LeaveIfError(err);
   164 
   174 
   165 	if (portConfig.iRate != EBpsAutobaud)
   175 	if (portConfig.iRate != EBpsAutobaud)
   166 		{
   176 		{
   167 		TCommConfig cfg;
   177 		TCommConfig cfg;
   174 		cfg().iFifo = EFifoEnable;
   184 		cfg().iFifo = EFifoEnable;
   175 		cfg().iSpecialRate = 0;
   185 		cfg().iSpecialRate = 0;
   176 		cfg().iTerminatorCount = 0;
   186 		cfg().iTerminatorCount = 0;
   177 		cfg().iSIREnable = ESIRDisable;
   187 		cfg().iSIREnable = ESIRDisable;
   178 		err = iComm.SetConfig(cfg);
   188 		err = iComm.SetConfig(cfg);
   179 		Message(EDebug, _L("RBusDevComm::SetConfig returned %d"), err);
   189 		Message(ErrOrDebug(err), _L("RBusDevComm::SetConfig returned %d"), err);
   180 		User::LeaveIfError(err);
   190 		User::LeaveIfError(err);
   181 		}
   191 		}
   182 	iComm.ResetBuffers();
   192 	iComm.ResetBuffers();
   183 	CVtcConsoleBase::ConstructL(aTitle);
   193 	CVtcConsoleBase::ConstructL(aTitle);
   184 	}
   194 	}