usbmgmt/usbmgrtest/t_usbmodem/src/t_usbmodem.cpp
branchRCL_3
changeset 43 012cc2ee6408
parent 42 f92a4f87e424
equal deleted inserted replaced
42:f92a4f87e424 43:012cc2ee6408
    44 	if(IsActive())
    44 	if(IsActive())
    45 		{
    45 		{
    46 		RDebug::Print(_L(": CSimplexRead::StartL Warning - Already active\n"));
    46 		RDebug::Print(_L(": CSimplexRead::StartL Warning - Already active\n"));
    47 		return;
    47 		return;
    48 		}
    48 		}
       
    49 	//iBuffer.SetMax();	
    49 	iCommPort->ReadOneOrMore(iStatus, iBuffer);
    50 	iCommPort->ReadOneOrMore(iStatus, iBuffer);
    50 	SetActive();
    51 	SetActive();
    51 	}
    52 	}
    52 
    53 
    53 void CSimplexRead::RunL()
    54 void CSimplexRead::RunL()
    54 	{
    55 	{
    55 #ifdef _DEBUG
    56 #ifdef _DEBUG
    56 	RDebug::Print(_L(": CSimplexRead::RunL - iStatus:%d iBuffer.Length:%d TotalAmount Left:%d\n"),iStatus.Int(),iBuffer.Length(),iTotalAmount);
    57 	RDebug::Print(_L(": CSimplexRead::RunL - iStatus:%d iBuffer.Length:%d TotalAmount Left:%d\n"),iStatus.Int(),iBuffer.Length(),iTotalAmount);
    57 #endif
    58 #endif
       
    59 	//RDebug::Print(_L(">%S<\n"),&iBuffer);
       
    60 	//Notify Duplex object
    58 	iDuplex.NotifyRead(iStatus.Int(),iBuffer.Length(), iBuffer);
    61 	iDuplex.NotifyRead(iStatus.Int(),iBuffer.Length(), iBuffer);
    59 	}
    62 	}
    60 
    63 
    61 void CSimplexRead::DoCancel(void)
    64 void CSimplexRead::DoCancel(void)
    62 	{
    65 	{
   337 				{
   340 				{
   338 #ifdef _DEBUG
   341 #ifdef _DEBUG
   339 				RDebug::Print(_L(": Serial RTS on"));
   342 				RDebug::Print(_L(": Serial RTS on"));
   340 #endif
   343 #endif
   341 				TheSerialPort.SetSignals( KSignalRTS, 0 );
   344 				TheSerialPort.SetSignals( KSignalRTS, 0 );
       
   345 				//TheUsbPort.SetSignals( KSignalCTS, 0 );
   342 				}
   346 				}
   343 			else
   347 			else
   344 				{
   348 				{
   345 #ifdef _DEBUG
   349 #ifdef _DEBUG
   346 				RDebug::Print(_L(": Serial RTS off"));
   350 				RDebug::Print(_L(": Serial RTS off"));
   347 #endif
   351 #endif
   348 				TheSerialPort.SetSignals( 0, KSignalRTS );
   352 				TheSerialPort.SetSignals( 0, KSignalRTS );
       
   353 				//TheUsbPort.SetSignals( 0, KSignalCTS );
   349 				}
   354 				}
   350 			}
   355 			}
   351 	
   356 	
   352 		if ( iInSignals & KDTRChanged )
   357 		if ( iInSignals & KDTRChanged )
   353 			{
   358 			{
   355 				{
   360 				{
   356 #ifdef _DEBUG
   361 #ifdef _DEBUG
   357 				RDebug::Print(_L(": Serial DTR on"));
   362 				RDebug::Print(_L(": Serial DTR on"));
   358 #endif
   363 #endif
   359 				TheSerialPort.SetSignals( KSignalDTR, 0 );
   364 				TheSerialPort.SetSignals( KSignalDTR, 0 );
       
   365 				//TheUsbPort.SetSignals( KSignalDSR, 0 );
   360 				}
   366 				}
   361 			else
   367 			else
   362 				{
   368 				{
   363 #ifdef _DEBUG
   369 #ifdef _DEBUG
   364 				RDebug::Print(_L(": Serial DTR off"));
   370 				RDebug::Print(_L(": Serial DTR off"));
   365 #endif
   371 #endif
   366 				TheSerialPort.SetSignals( 0, KSignalDTR );
   372 				TheSerialPort.SetSignals( 0, KSignalDTR );
       
   373 				//TheUsbPort.SetSignals( 0, KSignalDSR );
   367 				}
   374 				}
   368 			}
   375 			}
   369 
   376 
   370 		}
   377 		}
   371 	else 
   378 	else 
   525 	RDebug::Print(_L(": CActiveConsole::DoCancel()"));
   532 	RDebug::Print(_L(": CActiveConsole::DoCancel()"));
   526 #endif
   533 #endif
   527 	iUsbConfigChangeNotifier->Cancel();
   534 	iUsbConfigChangeNotifier->Cancel();
   528 	iSerialSignalChangeNotifier->Cancel();
   535 	iSerialSignalChangeNotifier->Cancel();
   529 	iUsbSignalChangeNotifier->Cancel();
   536 	iUsbSignalChangeNotifier->Cancel();
       
   537 	//iUsbFControlNotifier->Cancel();
   530 	
   538 	
   531 	iUsbToSerial->Cancel();
   539 	iUsbToSerial->Cancel();
   532 	iSerialToUsb->Cancel();
   540 	iSerialToUsb->Cancel();
   533 	
   541 	
   534 	iIsRunning = EFalse;
   542 	iIsRunning = EFalse;
   561 	iSerialToUsb->SetRxPort(&TheSerialPort);
   569 	iSerialToUsb->SetRxPort(&TheSerialPort);
   562 	iSerialToUsb->SetTxPort(&TheUsbPort);
   570 	iSerialToUsb->SetTxPort(&TheUsbPort);
   563 
   571 
   564 	iSerialSignalChangeNotifier = CSignalChangeNotifier::NewL(EFalse);
   572 	iSerialSignalChangeNotifier = CSignalChangeNotifier::NewL(EFalse);
   565 	iUsbSignalChangeNotifier = CSignalChangeNotifier::NewL(ETrue);
   573 	iUsbSignalChangeNotifier = CSignalChangeNotifier::NewL(ETrue);
       
   574 //	iUsbFControlNotifier = CFControlChangeNotifier::NewL();
   566 	iUsbConfigChangeNotifier = CConfigChangeNotifier::NewL();
   575 	iUsbConfigChangeNotifier = CConfigChangeNotifier::NewL();
   567 	}
   576 	}
   568 
   577 
   569 void CActiveConsole::Start()
   578 void CActiveConsole::Start()
   570 	{
   579 	{
   579 	iIsRunning = ETrue;
   588 	iIsRunning = ETrue;
   580 	TInt ignoreErr;
   589 	TInt ignoreErr;
   581 	TRAP(ignoreErr, iUsbConfigChangeNotifier->StartL());
   590 	TRAP(ignoreErr, iUsbConfigChangeNotifier->StartL());
   582 	TRAP(ignoreErr, iSerialSignalChangeNotifier->StartL());
   591 	TRAP(ignoreErr, iSerialSignalChangeNotifier->StartL());
   583 	TRAP(ignoreErr, iUsbSignalChangeNotifier->StartL());
   592 	TRAP(ignoreErr, iUsbSignalChangeNotifier->StartL());
       
   593 //	iUsbFControlNotifier->StartL();
   584 	
   594 	
   585 	TRAP(ignoreErr, iUsbToSerial->StartL());
   595 	TRAP(ignoreErr, iUsbToSerial->StartL());
   586 	TRAP(ignoreErr, iSerialToUsb->StartL());
   596 	TRAP(ignoreErr, iSerialToUsb->StartL());
   587 #ifdef _DEBUG
   597 #ifdef _DEBUG
   588 	RDebug::Print(_L(": CActiveConsole::Start() done"));
   598 	RDebug::Print(_L(": CActiveConsole::Start() done"));
   689 		default:
   699 		default:
   690 			TheWindow.Write(_L(": Invalid Key pressed\n"));
   700 			TheWindow.Write(_L(": Invalid Key pressed\n"));
   691 		}
   701 		}
   692 	}
   702 	}
   693 
   703 
       
   704 /*
       
   705 LOCAL_C TInt RateToInt(TBps aRate)
       
   706 	{
       
   707 	switch (aRate)
       
   708 		{
       
   709 	case EBps115200:	return 115200;
       
   710     case EBps57600:	return 57600;
       
   711     case EBps38400:	return 38400;
       
   712     case EBps19200:	return 19200;
       
   713     case EBps9600:	return 9600;
       
   714 	case EBps7200:	return 7200;
       
   715     case EBps4800:	return 4800;
       
   716 	case EBps3600:	return 3600;
       
   717     case EBps2400:	return 2400;
       
   718 	case EBps2000:	return 2000;
       
   719 	case EBps1800:	return 1800;
       
   720     case EBps1200:	return 1200;
       
   721     case EBps600:	return 600;
       
   722     case EBps300:	return 300;
       
   723     case EBps150:	return 150;
       
   724 	case EBps134:	return 134;
       
   725     case EBps110:	return 110;
       
   726 	case EBps75:	return 75;
       
   727 	case EBps50:	return 50;
       
   728 	default:	return -1;
       
   729 		}
       
   730 	}
       
   731 
       
   732 LOCAL_C void ConfigString(TDes &aBuf, const TCommNotificationV01 &aConfig)
       
   733 	{
       
   734 	// Config
       
   735 	aBuf.Format(_L(" %d "), RateToInt(aConfig.iRate));
       
   736 	switch (aConfig.iParity)
       
   737 		{
       
   738 	case EParityEven: aBuf.Append(_L("E")); break;
       
   739 	case EParityOdd: aBuf.Append(_L("O")); break;
       
   740 	case EParityNone: aBuf.Append(_L("N")); break;
       
   741     default: break;
       
   742 		}
       
   743 	switch (aConfig.iDataBits)
       
   744 		{
       
   745 	case EData5: aBuf.Append(_L("5")); break;
       
   746 	case EData6: aBuf.Append(_L("6")); break;
       
   747 	case EData7: aBuf.Append(_L("7")); break;
       
   748 	case EData8: aBuf.Append(_L("8")); break;
       
   749     default: break;
       
   750 		}
       
   751 	if (aConfig.iStopBits==EStop1)
       
   752 		aBuf.Append(_L("1 "));
       
   753 	else
       
   754 		aBuf.Append(_L("2 "));
       
   755 
       
   756 	aBuf.Append(_L("Use:"));
       
   757 	if (aConfig.iHandshake==0)
       
   758 		aBuf.Append(_L("NoControl "));
       
   759 	if (aConfig.iHandshake&(KConfigObeyXoff|KConfigSendXoff))
       
   760 		aBuf.Append(_L("XonXoff "));
       
   761 	if (aConfig.iHandshake&KConfigObeyCTS)
       
   762 		aBuf.Append(_L("CTS/RTS "));
       
   763 	if (aConfig.iHandshake&KConfigObeyDSR)
       
   764 		aBuf.Append(_L("DSR/DTR "));
       
   765 	if (aConfig.iHandshake&KConfigWriteBufferedComplete)
       
   766 		aBuf.Append(_L("Early "));
       
   767 	//|KConfigObeyDCD|KConfigFailDCD|))
       
   768 
       
   769 //	if (aConfig.iBreak==TEiger::EBreakOn)
       
   770 //		aBuf.Append(_L("Brk "));
       
   771 //	if (aConfig.iFifo==EFifoEnable)
       
   772 //		aBuf.Append(_L("Fifo "));
       
   773 	}
       
   774 	
       
   775 LOCAL_C void PrintCaps()
       
   776 	{
       
   777 	TCommCaps2 caps;
       
   778 	TheUsbPort.Caps(caps);
       
   779 	TUint notifycaps = caps().iNotificationCaps;
       
   780 	RDebug::Print(_L("Capabilities:\n"));
       
   781 	if (notifycaps&KNotifySignalsChangeSupported)
       
   782 		RDebug::Print(_L("Notify Signals Change supported\n"));
       
   783 	if (notifycaps&KNotifyRateChangeSupported)
       
   784 		RDebug::Print(_L("Notify Rate Change supported\n"));
       
   785 	if (notifycaps&KNotifyDataFormatChangeSupported)
       
   786 		RDebug::Print(_L("Notify Data Format Change supported\n"));
       
   787 	if (notifycaps&KNotifyHandshakeChangeSupported)
       
   788 		RDebug::Print(_L("Notify Handshake Change supported\n"));
       
   789 	if (notifycaps&KNotifyBreakSupported)
       
   790 		RDebug::Print(_L("Notify Break supported\n"));
       
   791 	if (notifycaps&KNotifyFlowControlChangeSupported)
       
   792 		RDebug::Print(_L("Notify Flow Control Change supported\n"));
       
   793 	if (notifycaps&KNotifyDataAvailableSupported)
       
   794 		RDebug::Print(_L("Notify Data Available supported\n"));
       
   795 	if (notifycaps&KNotifyOutputEmptySupported)
       
   796 		RDebug::Print(_L("Notify Output Empty supported\n"));
       
   797 	RDebug::Print(_L("\n"));
       
   798 	if ((caps().iRoleCaps)&KCapsRoleSwitchSupported)
       
   799 		RDebug::Print(_L("Role switching is supported\n"));
       
   800 	RDebug::Print(_L("\n"));
       
   801 	if ((caps().iFlowControlCaps)&KCapsFlowControlStatusSupported)
       
   802 		RDebug::Print(_L("Retrieve flow control status is supported\n"));
       
   803 	}
       
   804 */
   694 LOCAL_C void DoInitL()
   805 LOCAL_C void DoInitL()
   695 	{
   806 	{
   696 	// Do the necessary initialisation of the C32, 2 comm ports, USB stuff.
   807 	// Do the necessary initialisation of the C32, 2 comm ports, USB stuff.
   697 	// Load Device Drivers
   808 	// Load Device Drivers
   698 	TInt r;
   809 	TInt r;
   788 		RDebug::Print(_L("E32Main: Failed to Open Serial Comm Port. Error = %d"), r);
   899 		RDebug::Print(_L("E32Main: Failed to Open Serial Comm Port. Error = %d"), r);
   789 		User::Panic(_L("T_TERM"), EOpenErr);
   900 		User::Panic(_L("T_TERM"), EOpenErr);
   790 		}
   901 		}
   791 	RDebug::Print(_L("E32Main: Opened Serial Comm Port"));
   902 	RDebug::Print(_L("E32Main: Opened Serial Comm Port"));
   792 
   903 
       
   904 	// Print the caps
       
   905 	//PrintCaps();
   793 
   906 
   794 	RDebug::Print(_L("E32Main: Reading Serial Comm Port config"));
   907 	RDebug::Print(_L("E32Main: Reading Serial Comm Port config"));
   795 	TheSerialPort.Config(TheSerialConfigBuf);	// get config
   908 	TheSerialPort.Config(TheSerialConfigBuf);	// get config
   796 	RDebug::Print(_L("E32Main: Reading Usb Comm Port config"));
   909 	RDebug::Print(_L("E32Main: Reading Usb Comm Port config"));
   797 	TheUsbPort.Config(TheUsbConfigBuf);	// get config
   910 	TheUsbPort.Config(TheUsbConfigBuf);	// get config
   798 
   911 
   799 	TBuf<80> buf;
   912 	TBuf<80> buf;
   800 	buf.FillZ();
   913 	buf.FillZ();
       
   914 	//ConfigString(buf, TheUsbConfig);
   801 	RDebug::Print(_L("E32Main: Old USB Port Settings"));
   915 	RDebug::Print(_L("E32Main: Old USB Port Settings"));
   802 	RDebug::Print(buf);
   916 	RDebug::Print(buf);
   803 	RDebug::Print(_L(""));
   917 	RDebug::Print(_L(""));
   804 	buf.FillZ();
   918 	buf.FillZ();
       
   919 	//ConfigString(buf, TheSerialConfig);
   805 	RDebug::Print(_L("E32Main: Old Serial Port Settings"));
   920 	RDebug::Print(_L("E32Main: Old Serial Port Settings"));
   806 	RDebug::Print(buf);
   921 	RDebug::Print(buf);
   807 	RDebug::Print(_L(""));
   922 	RDebug::Print(_L(""));
   808 
   923 
   809 	TCommConfig serialConfig;
   924 	TCommConfig serialConfig;