⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classone.cpp

📁 fax engine 传真引擎 relay fax 的开源项目 商业软件使用 高质量 高可靠
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CClassOne::PhaseE(void)
{

	switch( m_nPhaseState )
	{
	case STATE_WAIT_FOR_OK:
		if( stricmp( m_szLineBuff, "OK" ) == 0 )
		{
			SendHDLCFrame();
			m_nPhaseState = STATE_SEND_DCN;
		}
		break;

	case STATE_SEND_DCN:
		if( stricmp( m_szLineBuff, "CONNECT" ) == 0 )
		{			
			SendDCN();
			m_nPhaseState = STATE_DCN_SENT;
		}
		else /* if( stricmp( m_szLineBuff, "OK" ) == 0 ) */
		{
			Terminate();
			DoHangup();
		}
		break;

	case STATE_DCN_SENT:
		Terminate();
		DoHangup();
		break;

	case STATE_RECEIVE_DCN:
		if( stricmp( m_szLineBuff, "OK" ) == 0 )
		{
			if( m_bGotDCN )
			{
				Terminate();
				DoHangup();
			}
			else
			{
				// ask for 
				//OutputDebugString( "Waiting for DCN\n" );
				//EnableSoftFlowControl( false );
				//RecvHDLCFrame();

				Terminate();
				DoHangup();
			}
		}
		else if( stricmp( m_szLineBuff, "CONNECT" ) == 0 )
		{
			m_bGotConnect = true;
			// get ready for another HDLC frame
			InitHDLC();
			KillTimer( TIMER_HDLC_RECV );
		}
		else if ( m_szLineBuff[0] == DLE && m_szLineBuff[1] == ETX )
		{
			m_bRecvHDLCError = true;
		}
		else 
		{
			DoHangup();
			Terminate();
		}
		break;
	}
}


//////////////////////////////////////////////////////////////////////
// on DIS frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnDIS(void)
{
	BOOL bSupported[MAX_CLS1SPEEDS];
	int i;

	m_bGotDIS = true;

	for( i = 0; i < MAX_CLS1SPEEDS; i++ )
	{
		bSupported[i] = 0;
	}

	//OutputDebugString( "OnDIS\n" );

	BYTE c1 = CFaxFile::s_FlipTable[ m_szHDLCBuff[4] ];
	BYTE c2 = CFaxFile::s_FlipTable[ m_szHDLCBuff[5] ];

	WORD wBitRate = (c1 & 0x3c) >> 2;

	WORD wScanTime = (c2 & 0x0E) >> 1; 

	m_DISParams.p.VertRes = (c1 & 0x02) >> 1;

	WORD wWidth = (c2 & 0xc0) >> 6;
	WORD wLength = (c2 & 0x30) >> 4;
	m_b2D = (c1 & 0x01);

	switch( wBitRate )
	{
	case DIS_V27_FALLBACK:
		//OutputDebugString( "V.27 ter fallback supported\n" );
		bSupported[0] = 1;
		m_DISParams.p.BitRate = 0;
		break;

	case DIS_V27:
		//OutputDebugString( "V.27 ter supported\n" );
		bSupported[0] = 1;
		bSupported[1] = 1;
		m_DISParams.p.BitRate = 1;
		break;

	case DIS_V29:
		//OutputDebugString( "V.29 supported\n" );
		bSupported[2] = 1;
		bSupported[3] = 1;
		m_DISParams.p.BitRate = 3;
		break;

	case DIS_V27_V29:
		//OutputDebugString( "V.27 ter and V.29 supported\n" );
		for( i = 0; i < 4; i++ )
			bSupported[i] = 1;
		m_DISParams.p.BitRate = 3;
		break;

	case DIS_V27_V29_V33:
		//OutputDebugString( "V.27 ter, V.29, and V.33 supported\n" );
		for( i = 0; i < 6; i++ )
			bSupported[i] = 1;
		m_DISParams.p.BitRate = 5;
		break;

	case DIS_V27_V29_V33_V17:
		//OutputDebugString( "V.27 ter, V.29, V.33, and V.17 supported\n" );
		for( i = 0; i < 10; i++ )
			bSupported[i] = 1;
		m_DISParams.p.BitRate = 5;
		break;
	}

	//char jbuf[256];


	for( i = 9; i >= 0; i-- )
		if( bSupported[i] && m_bSendSupported[i] && m_nSendBaud >= cls1Speeds[i].ndx )
			break;

	if( i >= 0 ) {
		m_nClass1Speed = i;
	}	
	else
	{
		m_nClass1Speed = 0;
	}

	if (!m_DISParams.p.VertRes)
	{
		//OutputDebugString( "Normal resolution supported\n" );
		m_wScanTimeMs = Cls1ScanTimes_normal[wScanTime];
	}
	else
	{
		//OutputDebugString( "Fine resolution supported\n" );
		m_wScanTimeMs = Cls1ScanTimes_fine[wScanTime];
	}

	switch( m_wScanTimeMs )
	{
	case 0:
		m_DISParams.p.ScanTime = 0;
		break;

	case 5:
		m_DISParams.p.ScanTime = 1;
		break;

	case 10:
		m_DISParams.p.ScanTime = 3;
		break;

	case 20:
		m_DISParams.p.ScanTime = 5;
		break;

	case 40:
		m_DISParams.p.ScanTime = 7;
		break;
	}

	//wsprintf( jbuf, "Minimum Scan Time: %dms\n", m_wScanTimeMs );
	//OutputDebugString( jbuf );

	m_DISParams.p.DataFormat = FAXAPI_ENC_CCITT_1D;

	if( m_b2D )
	{
		//OutputDebugString( "Receiver supports 2D encoding\n" );
		m_DISParams.p.DataFormat = FAXAPI_ENC_CCITT_2D;
	}

	m_DISParams.p.PageLength = 0;

	switch( wLength )
	{
	case 0:
		//OutputDebugString( "Receiver supports A4 length\n" );
		break;
	case 1:
		//OutputDebugString( "Receiver supports unlimited length\n" );
		m_DISParams.p.PageLength = 2;
		break;
	case 2:
		//OutputDebugString( "Receiver supports A4 and B4 length\n" );
		break;
	case 3:
		//OutputDebugString( "Invalid length\n" );
		break;
	}


	switch( wWidth )
	{
	case 0:
		//OutputDebugString( "Receiver supports 1728 width\n" );
		m_DISParams.p.PageWidth = 0;
		break;
	case 2:
		//OutputDebugString( "Receiver supports 1728 or 2048 width\n" );
		m_DISParams.p.PageWidth = 1;
		break;
	default:
		//OutputDebugString( "Receiver supports 1728, 2048, or 2432 width\n" );
		m_DISParams.p.PageWidth = 2;
		break;
	}

	m_DISParams.p.ECM = 0;

	m_bECM = false;
	m_bT6Encoding = false;

	if( (c2 & 0x01)	 && // extension bit
        m_nHDLCBuffPtr > 6 )
	{
		BYTE c3 = CFaxFile::s_FlipTable[ m_szHDLCBuff[6] ];

		//if( c3 & 0x80 )
		//{
		//	OutputDebugString( "Receiver supports 2400bps handshaking\n" );
		//}

		//if( c3 & 0x40 )
		//{
		//	OutputDebugString( "Receiver supports uncompressed mode\n" );
		//}

		if( c3 & 0x20 )
		{
			m_bECM = true;
			if( c3 & 0x10 )
			{
				m_FaxFile.SetECMFrameSize( 64 );
				//OutputDebugString( "Receiver supports ECM w/ 64 octet frames\n" );
				m_DISParams.p.ECM = 1;
			}
			else
			{
				m_FaxFile.SetECMFrameSize( 256 );
				//OutputDebugString( "Receiver supports ECM w/ 256 octet frames\n" );
				m_DISParams.p.ECM = 2;
			}
		}

		//if( c3 & 0x08 )
		//{
		//	OutputDebugString( "Receiver supports error limiting mode\n" );
		//}

		//if( c3 & 0x04 )
		//{
		//	OutputDebugString( "Receiver supports G4 on PSTN\n" );
		//}

		if( c3 & 0x02 )
		{
			//OutputDebugString( "Receiver supports T.6 encoding\n" );
			m_bT6Encoding = true;
			m_DISParams.p.DataFormat = FAXAPI_ENC_CCITT_T6;
		}

		if( (c3 & 0x01)	 && // extension bit
			m_nHDLCBuffPtr > 7 )
		{
			BYTE c4 = CFaxFile::s_FlipTable[ m_szHDLCBuff[7] ];

			// width expansion byte

			if( (c4 & 0x01)	 && // extension bit
				m_nHDLCBuffPtr > 8 )
			{
				BYTE c5 = CFaxFile::s_FlipTable[ m_szHDLCBuff[8] ];

				// more recent extensions
			}
		}
	}

	switch( m_FaxFile.GetSendEncoding() )
	{

	case (FAXAPI_ENC_CCITT_2D):
		if( m_b2D )
		{
			m_FaxFile.SelectEncoding( m_FaxFile.GetSendEncoding() );
		}
		else
		{
			m_FaxFile.SelectEncoding( FAXAPI_ENC_CCITT_1D );
		}
		break;

	case (FAXAPI_ENC_CCITT_T6):
		if( m_b2D && m_bT6Encoding && m_bECM && m_bECMSupported )
		{
			m_FaxFile.SelectEncoding( m_FaxFile.GetSendEncoding() );
		}
		else if( m_b2D )
		{
			m_FaxFile.SelectEncoding( FAXAPI_ENC_CCITT_2D );
		}
		else
		{
			m_FaxFile.SelectEncoding( FAXAPI_ENC_CCITT_1D );
		}
		break;

	default:
		m_FaxFile.SelectEncoding( m_FaxFile.GetSendEncoding() );
		break;
	}

	SignalEvent( EVENT_RECV_DIS );
}


//////////////////////////////////////////////////////////////////////
// on CSI frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnCSI(void)
{
	char szCSI[21];

	for( int i = 0; i < 20; i++ )
	{
		if( (22 - i) < m_nHDLCBuffPtr )
		{
			szCSI[i] = m_szHDLCBuff[ 22 - i ];
		}
		else
		{
			szCSI[i] = '\0';
		}
	}
	szCSI[20] = '\0';

	m_sRemoteCSID.assign( szCSI );

	SignalEvent( EVENT_GOT_REMOTEID );
}

//////////////////////////////////////////////////////////////////////
// on CFR frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnCFR(void)
{
	m_bGotCFR = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_CFR).c_str() );
}


//////////////////////////////////////////////////////////////////////
// on MCF frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnMCF(void)
{
	m_bGotMCF = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MCF).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on RTP frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnRTP(void)
{
	m_bGotRTP = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RTP).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on RTN frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnRTN(void)
{
	m_bGotRTN = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RTN).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on Failure To Train frame
//////////////////////////////////////////////////////////////////////
void CClassOne::OnFTT(void)
{
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_FTT).c_str() );
	m_bGotCFR = false;
}


//////////////////////////////////////////////////////////////////////
// on DCS
//////////////////////////////////////////////////////////////////////
void CClassOne::OnDCS(void)
{
	int i;

	m_bGotDCS = true;

//	OutputDebugString( "OnDCS\n" );
	
	BYTE c1 = CFaxFile::s_FlipTable[ m_szHDLCBuff[4] ];
	BYTE c2 = CFaxFile::s_FlipTable[ m_szHDLCBuff[5] ];

	WORD wBitRate = (c1 & 0x3c) >> 2;
	WORD wScanTime = (c2 & 0x0E) >> 1; 
	WORD wWidth = (c2 & 0xc0) >> 6;
	WORD wLength = (c2 & 0x30) >> 4;

	m_DCSParams.p.VertRes = (c1 & 0x02) >> 1;

	m_b2D = (c1 & 0x01);

	m_nClass1Speed = 0;
	m_bT6Encoding = false;
	m_bECM = false;

	for( i = 0; i < MAX_CLS1SPEEDS; i++ )
	{
		if( cls1Speeds[i].cDCSBits == wBitRate )
		{
			m_nClass1Speed = i;
			break;
		}
	}

	//char jbuf[256];
	//wsprintf( jbuf, "Baud rate bits: %d\n", wBitRate );
	//OutputDebugString( jbuf );
	//wsprintf( jbuf, "Selected baud rate: %d\n", cls1Speeds[m_nClass1Speed].dwSpeed );
	//OutputDebugString( jbuf );

	m_DCSParams.p.BitRate = cls1Speeds[m_nClass1Speed].ndx;

	if( m_DCSParams.p.VertRes )
	{
		//OutputDebugString( "Receiving fine quality\n" );
	}

	m_DCSParams.p.DataFormat = FAXAPI_ENC_CCITT_1D;

	if( m_b2D )
	{
		m_DCSParams.p.DataFormat = FAXAPI_ENC_CCITT_2D;
		//OutputDebugString( "Receiving 2D\n" );
	}

	switch( wLength )
	{
	case 0:
		m_DCSParams.p.PageLength = 0;
		break;

	case 2:
		m_DCSParams.p.PageLength = 1;
		break;

	default:
		m_DCSParams.p.PageLength = 2;
		break;
	}

	switch( wWidth )
	{
	case 0:
		m_FaxFile.SetImageWidth( 1728 );
		m_DCSParams.p.PageWidth = 0;
		break;

	case 1:
	case 3:
		m_FaxFile.SetImageWidth( 2432 );
		m_DCSParams.p.PageWidth = 2;
		break;

	case 2:
		m_FaxFile.SetImageWidth( 2048 );
		m_DCSParams.p.PageWidth = 1;
		break;
	}

	if (!m_DISParams.p.VertRes)
	{
		//OutputDebugString( "Normal resolution supported\n" );
		m_wScanTimeMs = Cls1ScanTimes_normal[wScanTime];
	}
	else
	{
		//OutputDebugString( "Fine resolution supported\n" );
		m_wScanTimeMs = Cls1ScanTimes_fine[wScanTime];
	}

	switch( m_wScanTimeMs )
	{
	case 0:
		m_DCSParams.p.ScanTime = 0;
		break;

	case 5:
		m_DCSParams.p.ScanTime = 1;
		break;

	case 10:
		m_DCSParams.p.ScanTime = 3;
		break;

	case 20:
		m_DCSParams.p.ScanTime = 5;
		break;

	case 40:
		m_DCSParams.p.ScanTime = 7;
		break;
	}

	m_DCSParams.p.ECM = 0;

	if( (c2 & 0x01)	 && // extension bit
        m_nHDLCBuffPtr > 6 )
	{
		BYTE c3 = CFaxFile::s_FlipTable[ m_szHDLCBuff[6] ];

		//if( c3 & 0x80 )
		//{
			//OutputDebugString( "Receiving with 2400bps handshaking\n" );
		//}

		//if( c3 & 0x40 )
		//{
		//	OutputDebugString( "Receiving uncompressed mode\n" );
		//}

		if( c3 & 0x20 )
		{
			m_bECM = true;
			if( c3 & 0x10 )
			{
				m_FaxFile.SetECMFrameSize( 64 );
				//OutputDebugString( "Receiving ECM w/ 64 octet frames\n" );
				m_DCSParams.p.ECM = 1;
			}
			else
			{
				m_FaxFile.SetECMFrameSize( 256 );
				//OutputDebugString( "Receiving ECM w/ 256 octet frames\n" );
				m_DCSParams.p.ECM = 2;
			}
		}

		//if( c3 & 0x08 )
		//{
		//	OutputDebugString( "Receiving with error limiting mode\n" );
		//}

		//if( c3 & 0x04 )
		//{
		//	OutputDebugString( "Receiving G4 on PSTN\n" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -