hti/HtiCommPlugins/HtiUsbSerialCommPlugin/src/HtiUsbSerialCommEcomPlugin.cpp
branchRCL_3
changeset 4 73ff0d268e1d
parent 0 a03f92240627
equal deleted inserted replaced
1:28c1bd28d474 4:73ff0d268e1d
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <badesca.h>
    20 #include <badesca.h>
    21 #include <f32file.h>
    21 #include <f32file.h>
    22 
    22 
    23 #include "HtiUsbSerialCommEcomPlugin.h"
    23 #include "HtiUsbSerialCommEcomPlugin.h"
    24 #include <hticfg.h>
    24 #include <HtiCfg.h>
    25 #include <htilogging.h>
    25 #include <HtiLogging.h>
    26 
    26 
    27 // EXTERNAL DATA STRUCTURES
    27 // EXTERNAL DATA STRUCTURES
    28 
    28 
    29 // EXTERNAL FUNCTION PROTOTYPES
    29 // EXTERNAL FUNCTION PROTOTYPES
    30 
    30 
    34 
    34 
    35 _LIT( KHtiCfgPath,          "\\" ); // root of drive
    35 _LIT( KHtiCfgPath,          "\\" ); // root of drive
    36 _LIT( KHtiUsbSerialCommCfg, "HTIUsbSerialComm.cfg" );
    36 _LIT( KHtiUsbSerialCommCfg, "HTIUsbSerialComm.cfg" );
    37 _LIT8( KUsbPortNumber,      "PortNumber" );
    37 _LIT8( KUsbPortNumber,      "PortNumber" );
    38 _LIT8( KUsbDataRate,        "DataRate" );
    38 _LIT8( KUsbDataRate,        "DataRate" );
       
    39 _LIT8( KUsbRetryTimes,      "RetryTimes" );
       
    40 _LIT8( KUsbRetryInterval,   "RetryInterval" );
    39 
    41 
    40 // _LIT( KUsbPddName, "" );
    42 // _LIT( KUsbPddName, "" );
    41 _LIT( KUsbLddName, "EUSBC" );
    43 _LIT( KUsbLddName, "EUSBC" );
    42 _LIT( KUsbCsyName, "ECACM");
    44 _LIT( KUsbCsyName, "ECACM");
    43 
    45 
   304 
   306 
   305     // try to open the port
   307     // try to open the port
   306     err = iCommPort.Open( iCommServ, commPort, ECommExclusive, ECommRoleDTE );
   308     err = iCommPort.Open( iCommServ, commPort, ECommExclusive, ECommRoleDTE );
   307     if ( err )
   309     if ( err )
   308         {
   310         {
   309         HTI_LOG_FORMAT( "Failed to open port %d", err );
   311         //read retry parameters from cfg
   310         ShowErrorNotifierL( _L( "Failed to open port" ), err );
   312         TInt retryTimes = 10;
       
   313         TRAPD( paramRetryTimesErr,
       
   314                 retryTimes = iCfg->GetParameterIntL( KUsbRetryTimes ) );
       
   315         if ( paramRetryTimesErr != KErrNone )
       
   316             {
       
   317             HTI_LOG_TEXT( "RetryTimes is not defined in cfg, using default" );
       
   318             }
       
   319         HTI_LOG_FORMAT( " RetryTimes  = %d", retryTimes );
       
   320         
       
   321         TInt retryInterval = 10;
       
   322         TRAPD( paramRetryIntervalErr,
       
   323                 retryInterval = iCfg->GetParameterIntL( KUsbRetryInterval ) );
       
   324         if ( paramRetryIntervalErr != KErrNone )
       
   325             {
       
   326             HTI_LOG_TEXT( "RetryInterval is not defined in cfg, using default" );
       
   327             }
       
   328         HTI_LOG_FORMAT( " RetryInterval  = %d(s)", retryInterval );
       
   329 
       
   330         // retry to open the port
       
   331         for( TInt i=0; i<retryTimes; i++ )
       
   332             {
       
   333             User::After( retryInterval * 1000000 );
       
   334             err = iCommPort.Open( iCommServ, commPort, ECommExclusive, ECommRoleDTE );
       
   335             if( !err )
       
   336                 {
       
   337                 break;
       
   338                 }
       
   339             }
       
   340 
       
   341         if( err )
       
   342             {
       
   343             HTI_LOG_FORMAT( "Failed to open port %d", err );
       
   344             ShowErrorNotifierL( _L( "Failed to open port" ), err );
       
   345             }
   311         }
   346         }
   312     User::LeaveIfError( err );
   347     User::LeaveIfError( err );
   313     HTI_LOG_TEXT( "Port open - checking port capabilities" );
   348     HTI_LOG_TEXT( "Port open - checking port capabilities" );
   314 
   349 
   315     // check port data rate capability
   350     // check port data rate capability