plugins/consoles/vt100cons/src/serial/vtc_serial.cpp
changeset 27 17e35ffe449b
parent 0 7f656887cf89
equal deleted inserted replaced
26:5d370dafea69 27:17e35ffe449b
    13 #include <fshell/common.mmh>
    13 #include <fshell/common.mmh>
    14 #include "vtc_serial.h"
    14 #include "vtc_serial.h"
    15 
    15 
    16 const TInt KMaxWriteLength = 2 * 1024; // Some serial drivers fail with KErrNoMemory if writes are too big, so they have to be broken up.
    16 const TInt KMaxWriteLength = 2 * 1024; // Some serial drivers fail with KErrNoMemory if writes are too big, so they have to be broken up.
    17 
    17 
    18 #define LEAVE_IF_ERROR_ALLOW_ALREADY_EXISTS(_x) { TInt _err = _x; if ((_err < 0) && (_err != KErrAlreadyExists)) { User::Leave(_err); } }
    18 #define ErrOrDebug(err) (((err) < 0  && (err) != KErrAlreadyExists) ? EError : EDebug)
    19 
    19 
    20 EXPORT_C CVtcSerialConsole::CVtcSerialConsole()
    20 EXPORT_C CVtcSerialConsole::CVtcSerialConsole()
    21 	{
    21 	{
    22 	}
    22 	}
    23 
    23 
    32 	_LIT(KKeywordPdd, "pdd");
    32 	_LIT(KKeywordPdd, "pdd");
    33 	_LIT(KKeywordLdd, "ldd");
    33 	_LIT(KKeywordLdd, "ldd");
    34 	_LIT(KKeywordCsy, "csy");
    34 	_LIT(KKeywordCsy, "csy");
    35 	_LIT(KKeywordPort, "port");
    35 	_LIT(KKeywordPort, "port");
    36 	_LIT(KKeywordRate, "rate");
    36 	_LIT(KKeywordRate, "rate");
       
    37 	_LIT(KKeywordDebug, "debug");
    37 
    38 
    38 	TBool keywordFound(EFalse);
    39 	TBool keywordFound(EFalse);
    39 	TLex lex(aConfigDes);
    40 	TLex lex(aConfigDes);
    40 	while (!lex.Eos())
    41 	while (!lex.Eos())
    41 		{
    42 		{
    87 					break;
    88 					break;
    88 					}
    89 					}
    89 				}
    90 				}
    90 			keywordFound = ETrue;
    91 			keywordFound = ETrue;
    91 			}
    92 			}
       
    93 		else if (keyword == KKeywordDebug)
       
    94 			{
       
    95 			aConfig.iDebug = ETrue;
       
    96 			keywordFound = ETrue;
       
    97 			}
    92 		}
    98 		}
    93 
    99 
    94 	if (!keywordFound)
   100 	if (!keywordFound)
    95 		{
   101 		{
    96 		// Treat unrecognised string as a port name (to preserve backwards compatibility with earlier releases).
   102 		// Treat unrecognised string as a port name (to preserve backwards compatibility with earlier releases).
   101 	}
   107 	}
   102 
   108 
   103 EXPORT_C void CVtcSerialConsole::ConstructL(const TDesC& aTitle)
   109 EXPORT_C void CVtcSerialConsole::ConstructL(const TDesC& aTitle)
   104 	{
   110 	{
   105 	TPortConfig portConfig;
   111 	TPortConfig portConfig;
   106 	User::LeaveIfError(ReadConfig(aTitle, portConfig));
   112 	TInt err = ReadConfig(aTitle, portConfig);
       
   113 	if (err)
       
   114 		{
       
   115 		Message(EError, _L("Error reading config: %d"), err);
       
   116 		User::LeaveIfError(err);
       
   117 		}
       
   118 
   107 	if (portConfig.iPort.Length() == 0)
   119 	if (portConfig.iPort.Length() == 0)
   108 		{
   120 		{
   109 		User::Leave(KErrArgument);
   121 		User::Leave(KErrArgument);
   110 		}
   122 		}
       
   123 
       
   124 	if (portConfig.iDebug) SetDebug(ETrue);
       
   125 
   111 	if (portConfig.iPdd.Length())
   126 	if (portConfig.iPdd.Length())
   112 		{
   127 		{
   113 		LEAVE_IF_ERROR_ALLOW_ALREADY_EXISTS(User::LoadPhysicalDevice(portConfig.iPdd));
   128 		err = User::LoadPhysicalDevice(portConfig.iPdd);
       
   129 		Message(ErrOrDebug(err), _L("Loading PDD %S returned %d"), &portConfig.iPdd, err);
       
   130 		if (err != KErrAlreadyExists) User::LeaveIfError(err);
   114 		}
   131 		}
   115 	else
   132 	else
   116 		{
   133 		{
   117 		// If not specified, assume they probably intended the standard ones (but don't error if they fail, since the user might actually know what they're doing
   134 		// If not specified, assume they probably intended the standard ones (but don't error if they fail, since the user might actually know what they're doing)
   118 #ifdef __WINS__
   135 #ifdef __WINS__
   119 		User::LoadPhysicalDevice(_L("ecdrv"));
   136 		User::LoadPhysicalDevice(_L("ecdrv"));
   120 #else
   137 #else
   121 		User::LoadPhysicalDevice(_L("euart1"));
   138 		User::LoadPhysicalDevice(_L("euart1"));
   122 #endif
   139 #endif
   123 		}
   140 		}
   124 
   141 
   125 	if (portConfig.iLdd.Length())
   142 	if (portConfig.iLdd.Length())
   126 		{
   143 		{
   127 		LEAVE_IF_ERROR_ALLOW_ALREADY_EXISTS(User::LoadLogicalDevice(portConfig.iLdd));
   144 		err = User::LoadLogicalDevice(portConfig.iLdd);
       
   145 		Message(ErrOrDebug(err), _L("Loading LDD %S returned %d"), &portConfig.iLdd, err);
       
   146 		if (err != KErrAlreadyExists) User::LeaveIfError(err);
   128 		}
   147 		}
   129 	else
   148 	else
   130 		{
   149 		{
   131 		User::LoadLogicalDevice(_L("ecomm"));
   150 		User::LoadLogicalDevice(_L("ecomm"));
   132 		}
   151 		}
   133 
   152 
   134 	User::LeaveIfError(iCommServ.Connect());
   153 	err = iCommServ.Connect();
       
   154 	Message(ErrOrDebug(err), _L("Connecting to RCommServ returned %d"), err);
       
   155 	User::LeaveIfError(err);
   135 	if (portConfig.iCsy.Length())
   156 	if (portConfig.iCsy.Length())
   136 		{
   157 		{
   137 		LEAVE_IF_ERROR_ALLOW_ALREADY_EXISTS(iCommServ.LoadCommModule(portConfig.iCsy));
   158 		err = iCommServ.LoadCommModule(portConfig.iCsy);
       
   159 		Message(ErrOrDebug(err), _L("Loading CSY %S returned %d"), &portConfig.iCsy, err);
       
   160 		if (err != KErrAlreadyExists) User::LeaveIfError(err);
   138 		}
   161 		}
   139 	else
   162 	else
   140 		{
   163 		{
   141 		iCommServ.LoadCommModule(_L("ecuart"));
   164 		iCommServ.LoadCommModule(_L("ecuart"));
   142 		}
   165 		}
   143 	User::LeaveIfError(iCommPort.Open(iCommServ, portConfig.iPort, ECommExclusive));
   166 	err = iCommPort.Open(iCommServ, portConfig.iPort, ECommExclusive);
       
   167 	Message(ErrOrDebug(err), _L("Opening port %S returned %d"), &portConfig.iPort, err);
       
   168 	User::LeaveIfError(err);
   144 
   169 
   145 #ifdef __WINS__
   170 #ifdef __WINS__
   146 	// For BC reasons, we always set rate on WINS
   171 	// For BC reasons, we always set rate on WINS
   147 	if (portConfig.iRate == EBpsAutobaud) portConfig.iRate = EBps115200;
   172 	if (portConfig.iRate == EBpsAutobaud) portConfig.iRate = EBps115200;
   148 #endif
   173 #endif
   158 		cfg().iParityError = KConfigParityErrorFail;
   183 		cfg().iParityError = KConfigParityErrorFail;
   159 		cfg().iFifo = EFifoEnable;
   184 		cfg().iFifo = EFifoEnable;
   160 		cfg().iSpecialRate = 0;
   185 		cfg().iSpecialRate = 0;
   161 		cfg().iTerminatorCount = 0;
   186 		cfg().iTerminatorCount = 0;
   162 		cfg().iSIREnable = ESIRDisable;
   187 		cfg().iSIREnable = ESIRDisable;
   163 		User::LeaveIfError(iCommPort.SetConfig(cfg));
   188 		err = iCommPort.SetConfig(cfg);
       
   189 		Message(ErrOrDebug(err), _L("Setting port config returned %d"), err);
       
   190 		User::LeaveIfError(err);
   164 		}
   191 		}
   165 	
   192 	
   166 	User::LeaveIfError(iCommPort.ResetBuffers());
   193 	User::LeaveIfError(iCommPort.ResetBuffers());
   167 	CVtcConsoleBase::ConstructL(aTitle);
   194 	CVtcConsoleBase::ConstructL(aTitle);
   168 	}
   195 	}