ClassTwo.cpp
上传用户:glass0516
上传日期:2010-01-11
资源大小:104k
文件大小:37k
- /*****************************************************************************
- * RelayFax Open Source Project
- * Copyright 1996-2004 Alt-N Technologies, Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted only as authorized by the RelayFax Open
- * Source License. A copy of this license is available in file LICENSE
- * in the top-level directory of the distribution.
- *
- * RelayFax is a registered trademark of Alt-N Technologies, Ltd.
- *
- * Individual files and/or contributed packages may be copyright by
- * other parties and subject to additional restrictions.
- *****************************************************************************/
- ////////////////////////////////////////////////////////////////////////////////
- //
- // The purpose of CClassTwo is contain the protocol specifics of EIA
- // fax modem class 2
- //
- ////////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ClassTwo.h"
- #define CLASSTWO_CONNECT "+FCON"
- #define CLASSTWO_CONNECT_SIZE 5
- #define CLASSTWO_TSI "+FTSI"
- #define CLASSTWO_TSI_SIZE 5
- #define CLASSTWO_DCS "+FDCS"
- #define CLASSTWO_DCS_SIZE 5
- #define CLASSTWO_NSS " +FNSS"
- #define CLASSTWO_NSS_SIZE 5
- #define CLASSTWO_HNGUP "+FHNG"
- #define CLASSTWO_HNGUP_SIZE 5
- #define CLASSTWO_CSI "+FCSI"
- #define CLASSTWO_CSI_SIZE 5
- #define CLASSTWO_DIS "+FDIS"
- #define CLASSTWO_DIS_SIZE 5
- #define CLASSTWO_NSF "+FNSF"
- #define CLASSTWO_NSF_SIZE 5
- #define CLASSTWO_PTS "+FPTS"
- #define CLASSTWO_PTS_SIZE 5
- #define CLASSTWO_ET "+FET"
- #define CLASSTWO_ET_SIZE 4
- #define CLASSTWO_DR "AT+FDR"
- #define CLASSTWO_DR_SIZE 6
- #define CLASSTWO_DT "AT+FDT"
- #define CLASSTWO_DT_SIZE 6
- #define CLASSTWO_FK "AT+FK"
- #define CLASSTWO_FK_SIZE 5
- #define CLASSTWO_SETID "AT+FLID="%s""
- #define CLASSTWO_SETRECV "AT+FCR=%d"
- #define CLASSTWO_SETBOR "AT+FBOR=0"
- #define CLASSTWO_SETPARAMS "AT+FDIS=%d,%d,%d,%d,%d,%d,0,%d"
- #define CLASSTWO_SENDET "AT+FET=%d"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CClassTwo::CClassTwo()
- {
- m_sEIAClass = "2";
- m_nScanTime = 0;
- }
- CClassTwo::~CClassTwo()
- {
- }
- void CClassTwo::OnConnect(void)
- {
- SetState( STATE_INIT );
- m_bGotOK = false;
- SendCommand( COMMAND_INIT );
- m_nLoopCtr = 0;
- }
- bool CClassTwo::OnDisconnect(void)
- {
- switch( m_nState )
- {
- case STATE_INIT:
- SignalEvent( EVENT_ERROR );
- return true;
- case STATE_PHASE_A:
- case STATE_PHASE_B:
- case STATE_PHASE_C:
- case STATE_PHASE_D:
- case STATE_PHASE_E:
- Abort( true );
- return false;
- }
- return true;
- }
- //////////////////////////////////////////////////////////////////////
- // OnWrite
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::OnWrite(void)
- {
- m_dwActivityTimer = GetTickCount();
- if( m_nState == STATE_PHASE_C && !m_bReceiving && m_bGotDCS )
- {
- m_nPageBytes += m_BytesWritten;
- int nPercent = 100 * m_nPageBytes / m_FaxFile.GetPageBytes();
- if( nPercent > 100 )
- nPercent = 100;
- SignalEvent( EVENT_PAGE_DATA, nPercent );
- }
- }
- //////////////////////////////////////////////////////////////////////
- // OnReadLine
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::OnReadLine(void)
- {
- //char szMsg[256];
- //wsprintf( szMsg, "CClassTwo::OnReadLine: %s %dn", m_szLineBuff, m_nLineBuffPtr );
- //OutputDebugString( szMsg );
- switch( m_nState )
- {
- case STATE_IDLE:
- PhaseIdle();
- break;
- case STATE_INIT:
- PhaseInit();
- break;
- case STATE_PHASE_A:
- PhaseA();
- break;
- case STATE_PHASE_B:
- PhaseB();
- break;
- case STATE_PHASE_C:
- PhaseC();
- break;
- case STATE_PHASE_D:
- PhaseD();
- break;
- case STATE_PHASE_E:
- PhaseE();
- break;
- case STATE_RINGING:
- PhaseRinging();
- break;
- case STATE_DISCONNECT:
- PhaseDisconnect();
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // PhaseInit
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseInit(void)
- {
- if( stricmp( m_szLineBuff, m_LastCommandString.c_str() ) == 0 )
- {
- // Echo - ignore
- return;
- }
- if( IsRing() )
- {
- // RING
- m_nRingCount++;
- return;
- }
- switch( m_nLastCommand )
- {
- case COMMAND_INIT:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- m_bGotOK = true;
- }
- else
- {
- if( ++m_nLoopCtr >= 3 )
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- }
- break;
- case COMMAND_SETUP_STRING:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_DISABLE_ECHO );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_DISABLE_ECHO:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_SET_SPKR_VOL );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_SPKR_VOL:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_SET_SPKR_MODE );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_SPKR_MODE:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_SET_FCLASS_2 );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_FCLASS_2:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_QUERY_CLASS2_CAP );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_QUERY_CLASS2_CAP:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_QUERY_SEND_SPEEDS );
- }
- else if( stricmp( m_szLineBuff, "ERROR" ) == 0 )
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- else
- {
- ProcCapabilities( m_szLineBuff );
- VerifyOptions();
- }
- break;
- case COMMAND_QUERY_SEND_SPEEDS:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_QUERY_RECEIVE_SPEEDS );
- }
- else
- {
- ProcSupportedSpeeds( m_szLineBuff, true );
- }
- break;
- case COMMAND_QUERY_RECEIVE_SPEEDS:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetLocalID();
- }
- else
- {
- ProcSupportedSpeeds( m_szLineBuff, false );
- }
- break;
- case COMMAND_SET_LOCAL_ID:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetRecv();
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_RECV:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetBitOrder();
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_BIT_ORDER:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- m_nScanTime = 0;
- SetFaxParams( false );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_FAX_PARAMS:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetState( STATE_IDLE );
- KillTimer( TIMER_COMMAND );
- }
- else
- {
- ErrorUnexpectedResponse();
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_REDUCE_COMPRESSION_BAUD_RATE_OR_DISABLE_ECM).c_str() );
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // PhaseIdle
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseIdle(void)
- {
- if( IsRing() )
- {
- m_nRingCount = 1;
- SetState( STATE_RINGING );
- SignalEvent( EVENT_RING, m_nRingCount );
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase Ringing
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseRinging(void)
- {
- if( IsRing() )
- {
- m_nRingCount++;
- SignalEvent( EVENT_RING, m_nRingCount );
- /*
- if( OkToAnswer() )
- {
- m_bReceiving = true;
- m_bSuccessful = false;
- SendCommand( COMMAND_ANSWER );
- SetState( STATE_PHASE_B, STATE_RECEIVING );
- }
- */
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_CONNECT, CLASSTWO_CONNECT_SIZE ) == 0 )
- {
- EnableSoftFlowControl( false );
- m_FaxFile.SetSendEncoding( m_nSendEncoding );
- m_bReceiving = true;
- m_bSuccessful = false;
- SignalEvent( EVENT_START_RECV );
- SetState( STATE_PHASE_B, STATE_RECEIVING );
- }
- else
- {
- SignalEvent( EVENT_CALLERID );
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase A - call setup
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseA(void)
- {
- switch( m_nPhaseState )
- {
- case STATE_SET_PARAMS:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetLocalID();
- m_nPhaseState = STATE_SET_CSID;
- }
- else
- {
- // Error setting fax params
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_SETTING_FAX_PARAMETERS).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- PhaseDisconnect();
- }
- break;
-
- case STATE_SET_CSID:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- if( m_bReceiving )
- {
- SendCommand( COMMAND_ANSWER );
- SetState( STATE_PHASE_B, STATE_RECEIVING );
- }
- else
- {
- SendCommand( COMMAND_DIAL );
- m_nPhaseState = STATE_DIALING;
- }
- }
- else
- {
- // Error setting ID
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_SETTING_ID).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- PhaseDisconnect();
- }
- break;
- case STATE_DIALING:
- if( strnicmp( m_szLineBuff, CLASSTWO_CONNECT, CLASSTWO_CONNECT_SIZE ) == 0 )
- {
- m_nLoopCtr = 0;
- SetState( STATE_PHASE_B, STATE_SENDING );
- m_bGotDIS = false;
- SignalEvent( EVENT_START_SEND );
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- else
- {
- ErrorConnectResponse();
- Terminate();
- PhaseDisconnect();
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase B - negotiation and training
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseB(void)
- {
- switch( m_nPhaseState )
- {
- case STATE_RECEIVING:
- if( strnicmp( m_szLineBuff, "OK", 2 ) == 0 )
- {
- m_bGotEOP = false;
- m_bGotMPS = false;
- m_bGotEOM = false;
- // On to phase C
- DoWrite( CLASSTWO_DR, CLASSTWO_DR_SIZE, true );
- SetState( STATE_PHASE_C );
- m_FaxFile.WriteFileHeader();
- SignalEvent( EVENT_START_TRAINING );
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_CONNECT, CLASSTWO_CONNECT_SIZE ) == 0 )
- {
- SignalEvent( EVENT_START_RECV );
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_TSI, CLASSTWO_TSI_SIZE ) == 0 )
- {
- OnCSI();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_DCS, CLASSTWO_DCS_SIZE ) == 0 )
- {
- OnDCS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_NSS, CLASSTWO_NSS_SIZE ) == 0 )
- {
- OnNSS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- break;
- case STATE_SENDING:
- if( strnicmp( m_szLineBuff, "OK", 2 ) == 0 )
- {
- // Check DIS and re-set parameters if necessar
- if( m_bGotDIS && m_bResendFaxParams )
- {
- SetFaxParams( true );
- m_nPhaseState = STATE_RESET_PARAMS;
- }
- else
- {
- // On to Phase C
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- m_bGotDCS = false;
- SignalEvent( EVENT_START_TRAINING );
- m_bLastPageGood = false;
- }
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_CSI, CLASSTWO_CSI_SIZE ) == 0 )
- {
- OnCSI();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_DIS, CLASSTWO_DIS_SIZE ) == 0 )
- {
- OnDIS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_NSF, CLASSTWO_NSF_SIZE ) == 0 )
- {
- OnNSF();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- break;
- case STATE_RESET_PARAMS:
- if( strnicmp( m_szLineBuff, "OK", 2 ) == 0 )
- {
- // On to Phase C
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- m_bGotDCS = false;
- KillTimer( TIMER_COMMAND );
- SignalEvent( EVENT_START_TRAINING );
- m_bLastPageGood = false;
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- Terminate();
- PhaseDisconnect();
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase C - transmit/receive data
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseC(void)
- {
- if( m_bReceiving )
- {
- if( strnicmp( m_szLineBuff, "CONNECT", 7 ) == 0 )
- {
- if( !m_bGotDCS )
- {
- char can = CAN;
- DoWrite( &can, 1, false );
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_DCS_NOT_RECEIVED).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- else
- {
- char dc2 = DC2;
- DoWrite( &dc2, 1, false );
- InitHDLC();
- //EnableSoftFlowControl( false );
- m_bFirstFrame = true;
- SignalEvent( EVENT_START_PAGE );
- }
- }
- else if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- m_nLoopCtr = 0;
- m_bLastPageGood = m_FaxFile.WriteIFD();
- //EnableSoftFlowControl( true );
- if( m_bGotEOP || (!m_bGotEOP && !m_bGotEOM && !m_bGotMPS ))
- {
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- DoWrite( CLASSTWO_DR, CLASSTWO_DR_SIZE, true );
- m_bGotEOP = false;
- m_bGotMPS = false;
- m_bGotEOM = false;
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_PTS, CLASSTWO_PTS_SIZE ) == 0 )
- {
- OnFPTS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_ET, CLASSTWO_ET_SIZE ) == 0 )
- {
- OnFET();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- }
- else
- {
- if( strnicmp( m_szLineBuff, "CONNECT", 7 ) == 0 )
- {
- char xon = XON;
- DoWrite( &xon, 1, false );
- m_nPageBytes = 0;
- DoWrite( m_FaxFile.GetPageData(), m_FaxFile.GetPageBytes(), false );
- SignalEvent( EVENT_START_PAGE );
- SetMaxPageRetriesTimer();
- }
- else if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- char szCmdBuff[64];
- wsprintf( szCmdBuff, CLASSTWO_SENDET, m_FaxFile.MorePages() ? 0 : 2 );
- // on to phase D
- DoWrite( szCmdBuff, strlen(szCmdBuff), true );
- SetState( STATE_PHASE_D );
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_DCS, CLASSTWO_DCS_SIZE ) == 0 )
- {
- OnDCS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase D - post-page messages
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseD(void)
- {
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- if( m_bLastPageGood )
- {
- if( m_FaxFile.MorePages() )
- {
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- if( m_FaxFile.ReadNextHeader() == false )
- {
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_READING_TIFF_FILE).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- else
- {
- if( m_FaxFile.ReadPage( false, 0, m_wMinLineChars, false, true ) == false )
- {
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_READING_TIFF_FILE).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- }
- }
- else
- {
- m_FaxFile.IncrementPageCount();
- m_bSuccessful = true;
- DoWrite( CLASSTWO_FK, CLASSTWO_FK_SIZE, true );
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_FK_RESP );
- KillTimer( TIMER_MAXPAGERETRIES );
- }
- }
- else
- {
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- }
- m_bLastPageGood = false;
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_PTS, CLASSTWO_PTS_SIZE ) == 0 )
- {
- OnFPTS();
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase E - Disconnect
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::PhaseE(void)
- {
- switch( m_nPhaseState )
- {
- case STATE_WAIT_FOR_OK:
- if( strnicmp( m_szLineBuff, "OK", 2 ) == 0 )
- {
- DoWrite( CLASSTWO_FK, CLASSTWO_FK_SIZE, true );
- m_nPhaseState = STATE_WAIT_FOR_FK_RESP;
- }
- else if( strnicmp( m_szLineBuff, CLASSTWO_HNGUP, CLASSTWO_HNGUP_SIZE ) == 0 )
- {
- OnFHNG();
- }
- break;
- case STATE_WAIT_FOR_FK_RESP:
- Terminate();
- if( strnicmp( m_szLineBuff, "NO CARRIER", 2 ) == 0 )
- {
- PhaseDisconnect();
- }
- else
- {
- DoHangup();
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // OnSendFaxMsg
- //////////////////////////////////////////////////////////////////////
- void CClassTwo::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 headern" );
- 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 headern" );
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_INCOMPAT_TIFF_FILE).c_str() );
- //SignalEvent( EVENT_ERROR );
- SignalEvent( EVENT_TERMINATE );
- SignalEvent( EVENT_IDLE );
- return;
- }
- m_bReceiving = false;
- m_bHDLCMode = false;
- m_bSuccessful = false;
- SetState( STATE_PHASE_A, STATE_SET_PARAMS );
- EnableSoftFlowControl( true );
- m_nScanTime = 0;
- m_DISParams.p.BitRate = m_nSendBaud;
- m_DISParams.p.PageLength = 2;
- SetFaxParams( true );
- }
- void CClassTwo::OnRecvFaxMsg(MSG* pMsg)
- {
- CModem::OnRecvFaxMsg( pMsg );
- if( m_nState == STATE_IDLE || m_nState == STATE_RINGING )
- {
- EnableSoftFlowControl( false );
- m_FaxFile.Clear();
- m_FaxFile.SetSendEncoding( m_nSendEncoding );
- m_bReceiving = true;
- m_bSuccessful = false;
- SetState( STATE_PHASE_A, STATE_SET_CSID );
- SetLocalID();
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Handle wait timeout - do periodic processing
- //////////////////////////////////////////////////////////////////////
- bool CClassTwo::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 responsen", dwElapsed );
- //OutputDebugString( szMsg );
- OnDisconnectMsg();
- }
- }
- */
- return false;
- }
- void CClassTwo::SetState( int nNewState, int nNewPhaseState )
- {
- /*
- bool bSignalIt = false;
- if( m_nState != nNewState )
- {
- bSignalIt = true;
- }
- */
- m_nState = nNewState;
- m_nPhaseState = nNewPhaseState;
- if( nNewState == STATE_IDLE )
- {
- SignalEvent( EVENT_IDLE );
- }
- }
- void CClassTwo::Abort( bool bUserCancelled )
- {
- char endofframe[2] = { DLE, ETX };
- char byteCancel = CAN;
- if( bUserCancelled )
- {
- m_sLastError.assign( (char*)LoadString(GEN_FAX_CANCELLED).c_str() );
- }
- Terminate();
- switch( m_nState )
- {
- case STATE_PHASE_A:
- switch( m_nPhaseState )
- {
- case STATE_SET_PARAMS:
- case STATE_SET_CSID:
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_FK_RESP );
- break;
- case STATE_DIALING:
- DoWrite( &byteCancel, 1, false );
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_FK_RESP );
- break;
- }
- break;
- case STATE_PHASE_B:
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- break;
- case STATE_PHASE_C:
- if ( m_bReceiving )
- {
- DoWrite( &byteCancel, 1, false );
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- m_bHDLCMode = false;
- }
- else
- {
- DoWrite( endofframe, 2, false );
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- break;
- case STATE_PHASE_D:
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- break;
- //case STATE_PHASE_E:
- // break;
- }
- }
- void CClassTwo::SetLocalID( void )
- {
- char szCmdBuff[256];
- wsprintf( szCmdBuff, CLASSTWO_SETID, m_sLocalCSID.c_str() );
- SendCommand( COMMAND_SET_LOCAL_ID, szCmdBuff );
- }
- void CClassTwo::SetRecv(void)
- {
- char szCmdBuff[256];
- wsprintf( szCmdBuff, CLASSTWO_SETRECV, m_bEnableReceive ? 1 : 0 );
- SendCommand( COMMAND_SET_RECV, szCmdBuff );
- }
- void CClassTwo::SetBitOrder(void)
- {
- SendCommand( COMMAND_SET_BIT_ORDER, CLASSTWO_SETBOR );
- }
- void CClassTwo::SetFaxParams( bool bSending )
- {
- char szCmdBuff[256];
- m_DCSParams.p.VertRes = m_bFineSupported ? 1 : 0;
- m_DCSParams.p.BitRate = m_nRecvBaud;
- m_DCSParams.p.PageWidth = 0;
- m_DCSParams.p.PageLength = m_bUnlimitedSupported ? 2 : 0;
- m_DCSParams.p.DataFormat = m_FaxFile.GetSendEncoding();
- m_DCSParams.p.ECM = m_bECMSupported ? 2 : 0;
- // TODO: Check if ECM enabled for modem and maximum bit rate
- if( bSending )
- {
- if( m_DISParams.p.BitRate > m_nSendBaud )
- {
- m_DCSParams.p.BitRate = m_nSendBaud;
- }
- else
- {
- m_DCSParams.p.BitRate = m_DISParams.p.BitRate;
- }
- if( m_FaxFile.IsHiRes() == false )
- {
- m_DCSParams.p.VertRes = 0;
- }
- if( m_DISParams.p.PageLength == 0 )
- {
- m_DCSParams.p.PageLength = 0;
- }
- }
-
- wsprintf( szCmdBuff, CLASSTWO_SETPARAMS,
- m_DCSParams.p.VertRes, // resolution
- m_DCSParams.p.BitRate, // bit rate
- m_DCSParams.p.PageWidth, // page width
- m_DCSParams.p.PageLength, // page length
- m_DCSParams.p.DataFormat, // format
- m_DCSParams.p.ECM, // error checking
- m_nScanTime );
- SendCommand( COMMAND_SET_FAX_PARAMS, szCmdBuff );
- }
- void CClassTwo::OnDIS(void)
- {
- ParseFaxParams( 8, m_DISParams.n );
- m_bGotDIS = true;
- m_bResendFaxParams = false;
- m_nScanTime = m_DISParams.p.ScanTime;
- if( m_DISParams.p.ScanTime > 0 )
- {
- m_bResendFaxParams = true;
- }
- /*
- if( (m_DISParams.p.DataFormat != FAXAPI_ENC_CCITT_1D)
- && (m_DISParams.p.DataFormat < m_nSendEncoding ) )
- {
- //
- //OutputDebugString( "Need to re-set fax parameters!n" );
- m_bResendFaxParams = true;
- m_FaxFile.SetSendEncoding( FAXAPI_ENC_CCITT_1D );
- }
- // else if( m_DISParams.p.BitRate > 0 )
- // {
- // m_bResendFaxParams = true;
- // }
- */
- SignalEvent( EVENT_RECV_DIS );
- }
- void CClassTwo::OnDCS(void)
- {
- m_bGotDCS = true;
- ParseFaxParams( 8, m_DCSParams.n );
- if( m_bReceiving )
- {
- m_FaxFile.SetImageRes( m_DCSParams.p.VertRes != 0 );
- switch( m_DCSParams.p.PageWidth )
- {
- case 1:
- m_FaxFile.SetImageWidth( 2048 );
- break;
- case 2:
- m_FaxFile.SetImageWidth( 2432 );
- break;
- case 3:
- m_FaxFile.SetImageWidth( 1216 );
- break;
- case 4:
- m_FaxFile.SetImageWidth( 864 );
- break;
- default:
- m_FaxFile.SetImageWidth( 1728 );
- break;
- }
- switch( m_DCSParams.p.DataFormat )
- {
- case FAXAPI_ENC_CCITT_2D: // 2D modified Read
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0x01 );
- break;
- case FAXAPI_ENC_CCITT_UNC: // 2D uncompressed
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0 );
- break;
- case FAXAPI_ENC_CCITT_T6: // T.6
- m_FaxFile.SetImageCompression( 4 );
- m_FaxFile.SetT4Options( 0 );
- break;
- default: // CFaxFile::CCITT_1D = 1D modified huffman
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0 );
- break;
- }
- SignalEvent( EVENT_RECV_DCS );
- m_FaxFile.SetImageLength( 0 );
- }
- else
- {
- // TODO: What if we get multiple DCS (e.g. training failed)
- int nBaud = Cls2FaxParamBitRates[m_DCSParams.p.BitRate];
- int nScanTimeMs = (m_DCSParams.p.VertRes == 0) ?
- Cls2ScanTimes_normal[ m_DCSParams.p.ScanTime ] :
- Cls2ScanTimes_fine[ m_DCSParams.p.ScanTime ];
- m_wMinLineChars = ((nBaud/8) * nScanTimeMs)/1000;
- m_FaxFile.SelectEncoding( m_DCSParams.p.DataFormat );
- SignalEvent( EVENT_SENT_DCS );
- if( m_FaxFile.ReadPage( false, 0, m_wMinLineChars, false, true ) == false )
- {
- m_sLastError.assign( (char*)LoadString(GEN_ERROR_READING_TIFF_FILE).c_str() );
- //SignalEvent( EVENT_ERROR );
- Terminate();
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_OK );
- }
- }
- }
- void CClassTwo::OnCSI(void)
- {
- char szID[21];
- int i = 0;
- bool bNoQuotes = false;
- m_sRemoteCSID = "";
- //OutputDebugString( "OnCSIn" );
- char* p = m_szLineBuff + 5; // skip +FTSI
- if ( *p == ':' ) // skip the colon
- {
- p++;
- }
- while (*p && *p != '"' ) // skip white space before first quote
- {
- p++;
- }
- if( *p == 0 )
- {
- bNoQuotes = true;
- // Uh-oh! no quotes found, back up and try w/o quotes
- p = m_szLineBuff + 5;
- if ( *p == ':' ) // skip the colon
- {
- p++;
- }
- while (*p && *p == ' ' ) // skip white space
- {
- p++;
- }
- return;
- }
- else
- {
- p++; // skip first quote
- }
- while( *p && (*p != '"') && (i < 20) )
- {
- szID[i] = *p;
- p++;
- i++;
- }
- szID[i] = 0;
- m_sRemoteCSID.assign( szID );
- SignalEvent( EVENT_GOT_REMOTEID );
- }
- void CClassTwo::OnNSF(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_NSF).c_str() );
- }
- void CClassTwo::OnNSS(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_NSS).c_str() );
- }
- // Page Status Report
- void CClassTwo::OnFPTS(void)
- {
- int n[2];
- // OutputDebugString( "OnFPTSn" );
- int nParams = ParseFaxParams( 2, n );
- if( nParams > 0 )
- {
- switch( n[0] )
- {
- case 1:
- if( m_bReceiving )
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_SENT_MCF).c_str() );
- else
- {
- m_bLastPageGood = true;
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MCF).c_str() );
- }
- break;
- case 2:
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RTN).c_str() );
- m_bLastPageGood = false;
- break;
- case 3:
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_RTP).c_str() );
- m_bLastPageGood = true;
- break;
- case 4:
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PIN).c_str() );
- m_bLastPageGood = true;
- break;
- case 5:
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_PIP).c_str() );
- m_bLastPageGood = true;
- break;
- }
- }
- //if( nParams > 1 )
- //{
- // m_FaxFile.SetImageLength( n[1] );
- //}
- }
- void CClassTwo::OnFET(void)
- {
- int n;
- //OutputDebugString( "OnFETn" );
-
- ParseFaxParams( 1, &n );
- switch( n )
- {
- case 0:
- OnMPS();
- break;
- case 1:
- OnEOM();
- break;
- case 2:
- OnEOP();
- break;
- }
- }
- void CClassTwo::OnEOP(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOP).c_str() );
- m_bGotEOP = true;
- }
- void CClassTwo::OnEOM(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOM).c_str() );
- m_bGotEOM = true;
- }
- void CClassTwo::OnMPS(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MPS).c_str() );
- m_bGotMPS = true;
- }
- void CClassTwo::OnFHNG( void )
- {
- int n;
- //OutputDebugString( "OnFHNGn" );
- ParseFaxParams( 1, &n );
- // char szCode[32];
- // wsprintf( szCode, "==> %dn", n );
- // OutputDebugString( szCode );
- switch( n )
- {
- case 0:
- m_bSuccessful = true;
- if( !m_bReceiving )
- {
- m_FaxFile.IncrementPageCount();
- }
- break;
- case 1:
- m_sLastError.assign( (char*)LoadString(GEN_CALL_ANSWERED_WO_FAX_HANDSHAKE).c_str() );
- break;
- case 2:
- m_sLastError.assign( (char*)LoadString(GEN_CALL_ABORTED_BY_USER).c_str() );
- break;
- case 3:
- m_sLastError.assign( (char*)LoadString(GEN_NO_LOOP_CURRENT).c_str() );
- break;
- case 10:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_A_ERROR).c_str() );
- break;
- case 11:
- m_sLastError.assign( (char*)LoadString(GEN_NO_ANSWER_OR_NO_DIS).c_str() );
- break;
- case 20:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_B_TRANSMIT_ERROR).c_str() );
- break;
- case 21:
- m_sLastError.assign( (char*)LoadString(GEN_REMOTE_CANNOT_RECEIVE_OR_SEND).c_str() );
- break;
- case 22:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 23:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_INVALID_COMMAND_RECEIVED).c_str() );
- break;
- case 24:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 25:
- m_sLastError.assign( (char*)LoadString(GEN_DCS_SENT_THREE_TIMES_WITHOUT_RESPONSE).c_str() );
- break;
- case 26:
- m_sLastError.assign( (char*)LoadString(GEN_DISDTC_RECEIVED_3_TIMES_DCS_NOT_RECOGNISED).c_str() );
- break;
- case 27:
- m_sLastError.assign( (char*)LoadString(GEN_FAILURE_TO_TRAIN_AT_2400_BPS).c_str() );
- break;
- case 28:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_INVALID_RESPONSE_RECEIVED).c_str() );
- break;
- case 40:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_C_TRANSMIT_ERROR).c_str() );
- break;
- case 43:
- m_sLastError.assign( (char*)LoadString(GEN_DTE_TO_DCE_DATA_UNDERFLOW).c_str() );
- break;
- case 50:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_D_TRANSMIT_ERROR).c_str() );
- break;
- case 51:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_TRANSMIT_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 52:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_MPS_REPEATED_3_TIMES).c_str() );
- break;
- case 53:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_MPS).c_str() );
- break;
- case 54:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_EOP_REPEATED_3_TIMES).c_str() );
- break;
- case 55:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_EOP).c_str() );
- break;
- case 56:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_EOM_REPEATED_3_TIMES).c_str() );
- break;
- case 57:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_EOM).c_str() );
- break;
- case 58:
- m_sLastError.assign( (char*)LoadString(GEN_UNABLE_TO_CONTINUE_AFTER_PIN_OR_PIP).c_str() );
- break;
- case 70:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_B_RECEIVE_ERROR).c_str() );
- break;
- case 71:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_RECEIVE_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 72:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_RECEIVE_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 73:
- m_sLastError.assign( (char*)LoadString(GEN_T30_T2_TIMEOUT).c_str() );
- break;
- case 74:
- m_sLastError.assign( (char*)LoadString(GEN_FAILURE_TO_RESUME_PHASE_B_AFTER_EOM).c_str() );
- break;
- case 90:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_C_RECEIVE_ERROR).c_str() );
- break;
- case 91:
- m_sLastError.assign( (char*)LoadString(GEN_MISSING_EOL_AFTER_5_SEC).c_str() );
- break;
- case 93:
- m_sLastError.assign( (char*)LoadString(GEN_MODEM_RECEIVE_BUFFER_OVERFLOWED).c_str() );
- break;
- case 94:
- m_sLastError.assign( (char*)LoadString(GEN_CRC_OR_FRAME_ERROR_IN_ECM_MODE).c_str() );
- break;
- case 100:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_D_RECEIVE_ERROR).c_str() );
- break;
- case 101:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_RECEIVE_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 102:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_RECEIVE_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 103:
- m_sLastError.assign( (char*)LoadString(GEN_UNABLE_TO_CONTINUE_AFTER_PIN_OR_PIP).c_str() );
- break;
- default:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_ERROR).c_str() );
- break;
- }
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_FK_RESP );
- }
- void CClassTwo::OnHDLCFrame(void)
- {
- //OutputDebugString( "OnHDLCFramen" );
- if( m_nHDLCBuffPtr == 0 )
- {
- //OutputDebugString( "Empty HDLC Framen" );
- return;
- }
- if( m_nState == STATE_PHASE_C && m_bReceiving )
- {
- m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr, false );
- }
- }
- void CClassTwo::OnPartialHDLCFrame(void)
- {
- //OutputDebugString( "OnPartialHDLCFramen" );
- if( m_nState == STATE_PHASE_C && m_bReceiving )
- {
- if( m_bFirstFrame )
- {
- m_bFirstFrame = false;
- if( m_szHDLCBuff[0] == XON )
- {
- //OutputDebugString( "Skipping XONn" );
- m_FaxFile.WriteBuffer( m_szHDLCBuff+1, m_nHDLCBuffPtr-1, false );
- }
- else
- {
- m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr, false );
- }
- }
- else
- {
- m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr, false );
- }
- }
- else
- {
- //OutputDebugString( "HDLC buffer overflow!n" );
- }
- }
- /*
- int CClassTwo::ParseFaxParams( int nMaxParams )
- {
- char szNumBuff[21];
- int* pParams = (int*)&m_Params;
- int j;
- int i;
- ZeroMemory( &m_Params, sizeof(m_Params) );
- char* p = m_szLineBuff + 5; // Skip +XXXX
- if ( *p == ':' ) // skip the colon
- {
- p++;
- }
- // advance to first digit
- while( *p && (*p < '0') && (*p > '9') && (*p != ',') )
- {
- p++;
- }
- for( i = 0; i < nMaxParams; i++ )
- {
- // check for end of string
- if( *p == ' ' )
- {
- return i;
- }
- j = 0;
- // advance to next comma
- while( *p && (*p >='0') && (*p <= '9') && (j < 20) )
- {
- szNumBuff[j++] = *p++;
- }
- szNumBuff[j] = ' ';
- pParams[i] = atoi( szNumBuff );
- if( *p ) // advance past comma
- p++;
- }
- return i;
- }
- */
- void CClassTwo::OnTimer( UINT nID )
- {
- //OutputDebugString( "CClassTwo::OnTimern" );
- if( nID == TIMER_COMMAND )
- {
- switch( m_nLastCommand )
- {
- case COMMAND_QUERY_SEND_SPEEDS:
- SendCommand( COMMAND_QUERY_RECEIVE_SPEEDS );
- break;
- case COMMAND_QUERY_RECEIVE_SPEEDS:
- SetLocalID();
- break;
-
- case COMMAND_HANGUP:
- SetState( STATE_INIT );
- SendCommand( COMMAND_INIT );
- m_nLoopCtr = 0;
- break;
- default:
- if( m_bGotOK )
- {
- m_nLoopCtr = 0;
- KillTimer( TIMER_COMMAND );
- SendCommand( COMMAND_SETUP_STRING );
- }
- else
- {
- if( ++m_nLoopCtr >= 3 )
- {
- KillTimer( TIMER_COMMAND );
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_FROM_MODEM).c_str() );
- OnDisconnectMsg();
- }
- else
- {
- SendCommand( m_nLastCommand, (char*) m_LastCommandString.c_str() );
- }
- }
- break;
- }
- }
- }
- void CClassTwo::OnAbortFaxMsg(void)
- {
- Abort( true );
- }
- void CClassTwo::VerifyOptions(void)
- {
- bool bModemFine = m_ParamMatrix[0][1] ? true : false;
- bool bModemUnlimited = m_ParamMatrix[3][2] ? true : false;
- int nModemCompression = m_ParamMatrix[4][3] ? 3 : (m_ParamMatrix[4][1] ? 1 : 0 );
- bool bModemECM = m_ParamMatrix[5][2] ? true : false;
- if( nModemCompression < m_nSendEncoding )
- {
- char szMsg[FAXAPI_MODEMMSG_INFOLEN];
- wsprintf( szMsg,(char*)LoadString(GEN_FORMAT_UNSUPPORTED_IN_CLASS_2).c_str(),
- (m_nSendEncoding==3) ? "2D Group 4" : (m_nSendEncoding == 1 ? "2D Group 3" : "1D Group 3" ),
- (nModemCompression==3) ? "2D Group 4" : (nModemCompression == 1 ? "2D Group 3" : "1D Group 3" ) );
- SetSendEncoding( nModemCompression );
- SignalEventString( EVENT_INFO, szMsg );
- }
- if( !bModemECM && m_bECMSupported )
- {
- SetSendECM( false );
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_ECM_UNSUPPORTED_IN_CLASS_2).c_str() );
- }
- SetSendFine( bModemFine );
- SetSendUnlimited( bModemUnlimited );
- }
- void CClassTwo::CheckTimeouts( DWORD dwInActive )
- {
- switch( m_nState )
- {
- case STATE_PHASE_A:
- if( dwInActive > 90000 )
- {
- m_sLastError.assign( (char*)LoadString(GEN_TIMEOUT_CONNECTING_TO_REMOTE_FAX).c_str() );
- //SignalEvent( EVENT_ERROR );
- Abort( false );
- m_dwActivityTimer = GetTickCount();
- }
- break;
- case STATE_PHASE_E:
- if( dwInActive > 5000 )
- {
- Terminate();
- PhaseDisconnect();
- }
- break;
- case STATE_DISCONNECT:
- if( dwInActive > 1000 )
- {
- PhaseDisconnect();
- }
- break;
- default:
- if( m_nState > STATE_IDLE && m_nState != STATE_RINGING )
- {
- int nInActive = GetTickCount() - m_dwActivityTimer;
-
- if( nInActive > 60000 )
- {
- m_sLastError.assign( (char*)LoadString(GEN_TIMEOUT_IN_SENDRECEIVE).c_str() );
- //SignalEvent( EVENT_ERROR );
-
- Abort( false );
- m_dwActivityTimer = GetTickCount();
- }
- }
- break;
- }
- }