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

📄 classone.cpp

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

		if( c3 & 0x02 )
		{
			//OutputDebugString( "Receiving T.6 encoding\n" );
			m_bT6Encoding = true;
			m_DCSParams.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
			}
		}
	}

	m_FaxFile.SetImageRes( m_DCSParams.p.VertRes != 0 );
	m_FaxFile.SetImageCompression( m_bT6Encoding ? 4 : 3 ); // Set to 4 for Group IV (T.6) encoding
	m_FaxFile.SetT4Options( m_b2D ? 0x01 : 0x00 );
	m_FaxFile.SetImageLength( 0 );

	SignalEvent( EVENT_RECV_DCS );

}



//////////////////////////////////////////////////////////////////////
// on End of Page
//////////////////////////////////////////////////////////////////////
void CClassOne::OnEOP(void)
{
	m_bGotEOP = true;
}

//////////////////////////////////////////////////////////////////////
// on End of Message
//////////////////////////////////////////////////////////////////////
void CClassOne::OnEOM(void)
{
	m_bGotEOM = true;
}

//////////////////////////////////////////////////////////////////////
// on MPS
//////////////////////////////////////////////////////////////////////
void CClassOne::OnMPS(void)
{
	m_bGotMPS = true;
}

//////////////////////////////////////////////////////////////////////
// on DCN
//////////////////////////////////////////////////////////////////////
void CClassOne::OnDCN(void)
{
	m_bGotDCN = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_DCN).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on PPS
//////////////////////////////////////////////////////////////////////
void CClassOne::OnPPS(void)
{
//	char szMsg[80];
//	wsprintf( szMsg, "OnPPS FCF=%x, Pages=%d, Blocks=%d, Frames=%d\n", 
//		     m_szHDLCBuff[3], m_szHDLCBuff[4], m_szHDLCBuff[5], m_szHDLCBuff[6] );
//	OutputDebugString( szMsg );

	if( m_nPPRCtr == 0 )
	{
		m_ECMFrameCount = m_szHDLCBuff[6];
	}

	switch( m_szHDLCBuff[3] & 0xfe )
	{
	case 0:	// partial page boundary
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PPSNULL).c_str() );
		break;

	case EOP:
		OnEOP();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PPSEOP).c_str() );
		break;

	case MPS:
		OnMPS();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PPSMPS).c_str() );
		break;

	case EOM:
		OnEOM();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PPSEOM).c_str() );
		break;
	}

}


//////////////////////////////////////////////////////////////////////
// on PPR
//////////////////////////////////////////////////////////////////////
void CClassOne::OnPPR(void)
{
	m_bGotPPR = true;

	m_nPPRCtr++;

	// save the PPR FIF
	memcpy( m_FaxFile.GetSeqMap(), m_szHDLCBuff + 3, SEQ_MAP_SIZE );

	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PPR).c_str() );

	// make sure we have a bad frame - sometimes the receiving
	// fax sends PPR with no bad bits when it should have sent MCF
	
	int nBadFrames = 0;
	int i,j;
	BYTE b;
	BYTE bit;
	int nSeqNum = 0;

	for(i = 0; i < SEQ_MAP_SIZE; i++ )
	{
		b = m_FaxFile.GetSeqMap()[i];

		for(j = 0; j < 8; j++, b >>= 1 )
		{
			bit = (b & 0x01);

			if( bit )
			{
				nBadFrames++;
			}

			nSeqNum++;

			// Ignore any sequence numbers which we didn't transmit
			if( nSeqNum > m_FaxFile.GetFrameCount() )
			{
				break;
			}
		}
		if( nSeqNum > m_FaxFile.GetFrameCount() )
		{
			break;
		}
	}

	if( nBadFrames == 0 )
	{
		m_bGotPPR = false;
		m_bGotMCF = true;
	}

}


//////////////////////////////////////////////////////////////////////
// on RNR - receive not ready
//////////////////////////////////////////////////////////////////////
void CClassOne::OnRNR(void)
{
	m_bGotRNR = true;

	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RNR).c_str() );

	if( m_dwRNRStart == 0 )
	{
		m_dwRNRStart = GetTickCount();
	}
}

//////////////////////////////////////////////////////////////////////
// on RR - receive ready
//////////////////////////////////////////////////////////////////////
void CClassOne::OnRR(void)
{
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RR).c_str() );
}


//////////////////////////////////////////////////////////////////////
// on CRP - command repeat
//////////////////////////////////////////////////////////////////////
void CClassOne::OnCRP(void)
{
	m_bGotCRP = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_CRP).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on NSF - nonstandard facilities
//////////////////////////////////////////////////////////////////////
void CClassOne::OnNSF(void)
{
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_NSF).c_str() );
}


//////////////////////////////////////////////////////////////////////
// on CTC - Continue to correct
//////////////////////////////////////////////////////////////////////
void CClassOne::OnCTC(void)
{
//	OutputDebugString( "OnCTC\n" );
	m_bGotCTC = true;

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

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

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

	char jbuf[FAXAPI_MODEMMSG_INFOLEN];

	wsprintf( jbuf, (char*)LoadString(GEN_RECEIVED_CTC).c_str(), cls1Speeds[m_nClass1Speed].dwSpeed );
	SignalEventString( EVENT_INFO, jbuf );
}

//////////////////////////////////////////////////////////////////////
// on CTR - Continue to correct response
//////////////////////////////////////////////////////////////////////
void CClassOne::OnCTR(void)
{
	m_bGotCTC = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_CTR).c_str() );
}

//////////////////////////////////////////////////////////////////////
// on EOR - End of retransmission
//////////////////////////////////////////////////////////////////////
void CClassOne::OnEOR(void)
{
//	OutputDebugString( "OnEOR\n" );
	m_bGotEOR = true;

	switch( m_szHDLCBuff[3] & 0xfe )
	{
	case 0:	// partial page boundary
		break;

	case EOP:
		OnEOP();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOREOP).c_str() );
		break;

	case MPS:
		OnMPS();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EORMPS).c_str() );
		break;

	case EOM:
		OnEOM();
		SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOREOM).c_str() );
		break;
	}

}

//////////////////////////////////////////////////////////////////////
// on ERR - End of retransmission response
//////////////////////////////////////////////////////////////////////
void CClassOne::OnERR(void)
{
	m_bGotEOR = true;
	SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_ERR).c_str() );
}


//////////////////////////////////////////////////////////////////////
// Handle wait timeout - do periodic processing
//////////////////////////////////////////////////////////////////////
bool CClassOne::OnWaitTimeout( void )
{
	CModem::OnWaitTimeout();
/*
	if( m_nState == STATE_INIT )
	{
		DWORD dwElapsed = GetTickCount() - m_nLastCommandTickCount;

		// In case the modem doesn't respond with an OK
		if( dwElapsed > 1000 )
		{
			if( m_nLastCommand == COMMAND_QUERY_SEND_SPEEDS )
			{
				SendCommand( COMMAND_QUERY_RECEIVE_SPEEDS );
			}
			else if( m_nLastCommand == COMMAND_QUERY_RECEIVE_SPEEDS )
			{
				SetState( STATE_IDLE );
			}
		}

		if( dwElapsed > 4000 )
		{
			char szMsg[256];
			wsprintf( szMsg, "Timeout: %d ms waiting for response\n", dwElapsed );
			//OutputDebugString( szMsg );

			OnDisconnectMsg();
		}
	}
*/
	return false;
}


void CClassOne::OnPartialHDLCFrame(void)
{
	if( m_nState == STATE_PHASE_C && m_bReceiving )
	{
		if( m_bECM )
		{
			m_FaxFile.WriteECMBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
		}
		else
		{
			m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
		}
	}
	else
	{
		//OutputDebugString( "HDLC buffer overflow!\n" );
	}
}


void CClassOne::OnHDLCFrame(void)
{
//	char szDigit[16];
//	OutputDebugString( "CClassOne::OnHDLCFrame\n" );

	if( m_nHDLCBuffPtr == 0 )
	{
		//OutputDebugString( "Empty HDLC Frame\n" );
		m_bRecvHDLCError = true;
		return;
	}

//	int i;
//	for( i = 0; i < m_nHDLCBuffPtr; i++ )
//	{
//		wsprintf( szDigit, "%02.2x ", m_szHDLCBuff[i] );
//		OutputDebugString( szDigit );
//	}
//	OutputDebugString( "\n" );


	if( m_nState == STATE_PHASE_C && m_bReceiving )
	{
		if( m_bECM )
		{
			m_FaxFile.WriteECMBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
		}
		else
		{
			m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
		}
	}
	else if( m_nPhaseState == STATE_RECEIVE_TRAINING )
	{
		int i;
		bool bStart = false;
		int nZeros = 0;

		for( i = 0; i < m_nHDLCBuffPtr; i++ )
		{
			if( bStart == false )
			{
				if( m_szHDLCBuff[i] == 0 ) 
				{
					bStart = true;
					nZeros = 1;
				}
			}
			else
			{
				if( m_szHDLCBuff[i] == 0 ) 
				{
					nZeros++;
				}
			}
		}

		int nBytesExpected = (int)(((float)(cls1Speeds[m_nClass1Speed].dwSpeed / 8)) * 1.5) + 2;

		m_nCorrect = (int)(100 * nZeros / nBytesExpected);

		//char szMsg[180];
		//wsprintf( szMsg, "Zeros: %d, Correct=%d%%, Total=%d, Expected=%d\n", nZeros, m_nCorrect, m_nHDLCBuffPtr, nBytesExpected );
		//OutputDebugString( szMsg );
	}
	else
	{

		if( (unsigned char)m_szHDLCBuff[0] != 0xff )
		{
			bool bFoundFrame = false;

			for( int i = 1; i < m_nHDLCBuffPtr; i++ )
			{
				if( (unsigned char)m_szHDLCBuff[i] == 0xff )
				{
					memmove( m_szHDLCBuff, m_szHDLCBuff + i, m_nHDLCBuffPtr - i );
					bFoundFrame = true;
				}
			}

			if( bFoundFrame == false )
				return;
		}

		if( m_szHDLCBuff[1] & 0x10 )
		{
			/// final frame
			//OutputDebugString( "Final Frame\n" );
			m_bFinalHDLCFrame = true;
		}

		switch( (m_szHDLCBuff[2] & 0xfe) )  // set LSB to zero
		{
		case DIS:
			OnDIS();
			break;

		case CSI:
		case TSI:
			OnCSI();
			break;

		case CFR:
			OnCFR();
			break;

		case MCF:
			OnMCF();
			break;

		case RTP:
			OnRTP();
			break;

		case RTN:
			OnRTN();
			break;

		case FTT:
			OnFTT();
			break;

		case DCS:
			OnDCS();
			break;

		case EOP:
			OnEOP();
			SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOP).c_str() );
			break;

		case EOM:
			OnEOM();
			SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOM).c_str() );
			break;

		case MPS:
			OnMPS();
			SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MPS).c_str() );
			break;

		case DCN:
			OnDCN();
			break;

		case PPS:
			OnPPS();
			break;

		case PPR:
			OnPPR();
			break;

		case RR:
			OnRR();
			break;

		case RNR:
			OnRNR();
			break;

		case CRP:
			OnCRP();
			break;

		case NSF:
			OnNSF();
			break;

		case CTC:
			OnCTC();
			break;

		case CTR:
			OnCTR();
			break;

		case EOR:
			OnEOR();
			break;

		case ERR:
			OnERR();
			break;


		default:
			{
				//char szMsg[256];
				//wsprintf( szMsg, "Unknown FCF: %d\n", m_szHDLCBuff[2] );
				//OutputDebugString( szMsg );
			}
		}
	}
}


//////////////////////////////////////////////////////////////////////
// OnSendFaxMsg
//////////////////////////////////////////////////////////////////////
void CClassOne::OnSendFaxMsg(MSG* pMsg)
{
	CModem::OnSendFaxMsg( pMsg );

	if( !m_bConnected )
	{
		// Error!
		return;
	}

	if( m_nState != STATE_IDLE )
	{
		// Error!
		return;
	}

	m_FaxFile.SetSendEncoding( m_nSendEncoding );

	int nRet = m_FaxFile.ReadFirstHeader();

	if( nRet == 1 )
	{
		//OutputDebugString( "Error reading first header\n" );
		m_sLastError.assign( (char*)LoadString(GEN_ERROR_READING_TIFF_FILE).c_str() );
//		SignalEvent( EVENT_ERROR );
		SignalEvent( EVENT_TERMINATE );
		SignalEvent( EVENT_IDLE );
		return;
	}
	else if( nRet == 2 )
	{
		//OutputDebugString( "Error reading first header\n" );
		m_sLastError.assign( (char*)LoadString(GEN_ERROR_INCOMPAT_TIFF_FILE).c_str() );
//		SignalEvent( EVENT_ERROR );
		SignalEvent( EVENT_TERMINATE );
		SignalEvent( EVENT_IDLE );
		return;
	}

	m_dwRNRStart

⌨️ 快捷键说明

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