ClassTwoPointZero.cpp
上传用户:glass0516
上传日期:2010-01-11
资源大小:104k
文件大小:40k
源码类别:
传真(Fax)编程
开发平台:
Visual C++
- /*****************************************************************************
- * 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 CClassTwoPointZero is contain the protocol specifics of EIA
- // fax modem class 2.0
- //
- ////////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ClassTwoPointZero.h"
- #define CLASSTWO_CONNECT "+FCO"
- #define CLASSTWO_CONNECT_SIZE 4
- #define CLASSTWO_TSI "+FTI"
- #define CLASSTWO_TSI_SIZE 4
- #define CLASSTWO_DCS "+FCS"
- #define CLASSTWO_DCS_SIZE 4
- #define CLASSTWO_NSS "+FNS"
- #define CLASSTWO_NSS_SIZE 4
- #define CLASSTWO_HNGUP "+FHS"
- #define CLASSTWO_HNGUP_SIZE 4
- #define CLASSTWO_CSI "+FCI"
- #define CLASSTWO_CSI_SIZE 4
- #define CLASSTWO_DIS "+FIS"
- #define CLASSTWO_DIS_SIZE 4
- #define CLASSTWO_NSF "+FNF"
- #define CLASSTWO_NSF_SIZE 4
- #define CLASSTWO_PTS "+FPS"
- #define CLASSTWO_PTS_SIZE 4
- #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+FKS"
- #define CLASSTWO_FK_SIZE 6
- #define CLASSTWO_SETID "AT+FLI="%s""
- #define CLASSTWO_SETRECV "AT+FCR=%d"
- #define CLASSTWO_SETBOR "AT+FBO=0"
- #define CLASSTWO_SETPARAMS "AT+FIS=%d,%d,%d,%d,%d,%d,0,%d"
- #define CLASSTWO_SENDET "AT+FET=%d"
- #define CLASSTWO_SETRPTING "AT+FNR=1,1,1,1"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CClassTwoPointZero::CClassTwoPointZero()
- {
- m_sEIAClass = "2.0";
- m_nScanTime = 0;
- }
- CClassTwoPointZero::~CClassTwoPointZero()
- {
- }
- void CClassTwoPointZero::OnConnect(void)
- {
- SetState( STATE_INIT );
- m_bGotOK = false;
- SendCommand( COMMAND_INIT );
- m_nLoopCtr = 0;
- }
- bool CClassTwoPointZero::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 CClassTwoPointZero::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 CClassTwoPointZero::OnReadLine(void)
- {
- //char szMsg[256];
- //wsprintf( szMsg, "CClassTwoPointZero::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 CClassTwoPointZero::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_0 );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_FCLASS_2_0:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SendCommand( COMMAND_QUERY_CLASS2_0_CAP );
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_QUERY_CLASS2_0_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 )
- {
- SetFlowControl();
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_FLOW_CONTROL:
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- SetHDLCReporting();
- }
- else
- {
- ErrorUnexpectedResponse();
- KillTimer( TIMER_COMMAND );
- OnDisconnectMsg();
- }
- break;
- case COMMAND_SET_HDLC_REPORTING:
- 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 CClassTwoPointZero::PhaseIdle(void)
- {
- if( IsRing() )
- {
- m_nRingCount = 1;
- SetState( STATE_RINGING );
- SignalEvent( EVENT_RING, m_nRingCount );
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase Ringing
- //////////////////////////////////////////////////////////////////////
- void CClassTwoPointZero::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 CClassTwoPointZero::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 );
- 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 CClassTwoPointZero::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();
- SetState( STATE_IDLE );
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Phase C - transmit/receive data
- //////////////////////////////////////////////////////////////////////
- void CClassTwoPointZero::PhaseC(void)
- {
- if( m_bReceiving )
- {
- if( strnicmp( m_szLineBuff, "CONNECT", 7 ) == 0 )
- {
- 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 )
- {
- 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 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 )
- {
- if( true /*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, 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_OK );
- KillTimer( TIMER_MAXPAGERETRIES );
- }
- }
- else
- {
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- }
- m_bLastPageGood = false;
- }
- 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 CClassTwoPointZero::PhaseD(void)
- {
- if( stricmp( m_szLineBuff, "OK" ) == 0 )
- {
- /*
- m_nLoopCtr = 0;
- 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;
- */ /*
- if( m_FaxFile.MorePages() )
- {
- DoWrite( CLASSTWO_DT, CLASSTWO_DT_SIZE, true );
- SetState( STATE_PHASE_C );
- if( m_FaxFile.ReadNextHeader() )
- {
- m_FaxFile.ReadPage( false, 0, 0, true );
- }
- }
- else
- {
- m_FaxFile.IncrementPageCount();
- m_bSuccessful = true;
- DoWrite( CLASSTWO_FK, CLASSTWO_FK_SIZE, true );
- SetState( STATE_PHASE_E, STATE_WAIT_FOR_FK_RESP );
- }
- }
- 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 CClassTwoPointZero::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 CClassTwoPointZero::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 CClassTwoPointZero::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 CClassTwoPointZero::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 CClassTwoPointZero::SetState( int nNewState, int nNewPhaseState )
- {
- m_nState = nNewState;
- m_nPhaseState = nNewPhaseState;
- if( nNewState == STATE_IDLE )
- {
- SignalEvent( EVENT_IDLE );
- }
- }
- void CClassTwoPointZero::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_E:
- // break;
- }
- }
- void CClassTwoPointZero::SetLocalID( void )
- {
- char szCmdBuff[256];
- wsprintf( szCmdBuff, CLASSTWO_SETID, m_sLocalCSID.c_str() );
- SendCommand( COMMAND_SET_LOCAL_ID, szCmdBuff );
- }
- void CClassTwoPointZero::SetRecv(void)
- {
- char szCmdBuff[256];
- wsprintf( szCmdBuff, CLASSTWO_SETRECV, m_bEnableReceive ? 1 : 0 );
- SendCommand( COMMAND_SET_RECV, szCmdBuff );
- }
- void CClassTwoPointZero::SetBitOrder(void)
- {
- SendCommand( COMMAND_SET_BIT_ORDER, CLASSTWO_SETBOR );
- }
- void CClassTwoPointZero::SetFlowControl(void)
- {
- SendCommand( COMMAND_SET_FLOW_CONTROL );
- }
- void CClassTwoPointZero::SetHDLCReporting(void)
- {
- SendCommand( COMMAND_SET_HDLC_REPORTING, CLASSTWO_SETRPTING );
- }
- void CClassTwoPointZero::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 ? 1 : 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 CClassTwoPointZero::OnDIS(void)
- {
- //OutputDebugString( "OnDISn" );
- 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 );
- }
- */
- SignalEvent( EVENT_RECV_DIS );
- }
- void CClassTwoPointZero::OnDCS(void)
- {
- //OutputDebugString( "OnDCSn" );
- 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 1: // 2D modified Read
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0x01 );
- break;
- case 2: // 2D uncompressed
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0 );
- break;
- case 3: // T.6
- m_FaxFile.SetImageCompression( 4 );
- m_FaxFile.SetT4Options( 0 );
- break;
- default: // 0 = 1D modified huffman
- m_FaxFile.SetImageCompression( 3 );
- m_FaxFile.SetT4Options( 0 );
- break;
- }
- m_FaxFile.SetImageLength( 0 );
- SignalEvent( EVENT_RECV_DCS );
- }
- 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, 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 CClassTwoPointZero::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 CClassTwoPointZero::OnNSF(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_NSF).c_str() );
- }
- void CClassTwoPointZero::OnNSS(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_NSS).c_str() );
- }
- // Page Status Report
- void CClassTwoPointZero::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
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MCF).c_str() );
- m_bLastPageGood = true;
- }
- 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 CClassTwoPointZero::OnFET(void)
- {
- int n;
- //OutputDebugString( "OnFETn" );
- ParseFaxParams( 1, &n );
- switch( n )
- {
- case 0:
- OnMPS();
- break;
- case 1:
- OnEOM();
- break;
- case 2:
- OnEOP();
- break;
- }
- }
- void CClassTwoPointZero::OnEOP(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOP).c_str() );
- m_bGotEOP = true;
- }
- void CClassTwoPointZero::OnEOM(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_EOM).c_str() );
- m_bGotEOM = true;
- }
- void CClassTwoPointZero::OnMPS(void)
- {
- SignalEventString( EVENT_INFO, (char*)LoadString(GEN_RECEIVED_MPS).c_str() );
- m_bGotMPS = true;
- }
- void CClassTwoPointZero::OnFHNG( void )
- {
- int n;
- //TODO: These are hexadecimal codes!
- //OutputDebugString( "OnFHNGn" );
- n = ParseFHSCode();
- //char szCode[32];
- //wsprintf( szCode, "==> %Xn", n );
- //OutputDebugString( szCode );
- switch( n )
- {
- case 0x00:
- m_bSuccessful = true;
- if( !m_bReceiving )
- {
- m_FaxFile.IncrementPageCount();
- }
- break;
- case 0x01:
- m_sLastError.assign( (char*)LoadString(GEN_CALL_ANSWERED_WO_FAX_HANDSHAKE).c_str() );
- break;
- case 0x02:
- m_sLastError.assign( (char*)LoadString(GEN_CALL_ABORTED_BY_USER).c_str() );
- break;
- case 0x03:
- m_sLastError.assign( (char*)LoadString(GEN_NO_LOOP_CURRENT).c_str() );
- break;
- case 0x04:
- m_sLastError.assign( (char*)LoadString(GEN_RINGBACK_DETECTED_BUT_NO_ANSWER).c_str() );
- break;
- case 0x05:
- m_sLastError.assign( (char*)LoadString(GEN_RINGBACK_DETECTED_CALL_ANSWERED_BUT_NO_CED_TONE).c_str() );
- break;
- case 0x10:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_A_ERROR).c_str() );
- break;
- case 0x11:
- m_sLastError.assign( (char*)LoadString(GEN_NO_ANSWER_OR_NO_DIS).c_str() );
- break;
- case 0x20:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_B_TRANSMIT_ERROR).c_str() );
- break;
- case 0x21:
- m_sLastError.assign( (char*)LoadString(GEN_REMOTE_CANNOT_RECEIVE_OR_SEND).c_str() );
- break;
- case 0x22:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 0x23:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_INVALID_COMMAND_RECEIVED).c_str() );
- break;
- case 0x24:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 0x25:
- m_sLastError.assign( (char*)LoadString(GEN_DCS_SENT_THREE_TIMES_WITHOUT_RESPONSE).c_str() );
- break;
- case 0x26:
- m_sLastError.assign( (char*)LoadString(GEN_DISDTC_RECEIVED_3_TIMES_DCS_NOT_RECOGNISED).c_str() );
- break;
- case 0x27:
- m_sLastError.assign( (char*)LoadString(GEN_FAILURE_TO_TRAIN_AT_2400_BPS).c_str() );
- break;
- case 0x28:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_TRANSMIT_INVALID_RESPONSE_RECEIVED).c_str() );
- break;
- case 0x40:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_C_TRANSMIT_ERROR).c_str() );
- break;
- case 0x41:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_IMAGE_FORMAT).c_str() );
- break;
- case 0x42:
- m_sLastError.assign( (char*)LoadString(GEN_IMAGE_CONVERSION_ERROR).c_str() );
- break;
- case 0x43:
- m_sLastError.assign( (char*)LoadString(GEN_DTE_TO_DCE_DATA_UNDERFLOW).c_str() );
- break;
- case 0x44:
- m_sLastError.assign( (char*)LoadString(GEN_UNRECOGNIZED_DLE_COMMAND).c_str() );
- break;
- case 0x45:
- m_sLastError.assign( (char*)LoadString(GEN_WRONG_LINE_LENGTH).c_str() );
- break;
- case 0x46:
- m_sLastError.assign( (char*)LoadString(GEN_WRONG_PAGE_LENGTH).c_str() );
- break;
- case 0x47:
- m_sLastError.assign( (char*)LoadString(GEN_WRONG_COMPRESSION_CODE).c_str() );
- break;
- case 0x50:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_D_TRANSMIT_ERROR).c_str() );
- break;
- case 0x51:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_TRANSMIT_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 0x52:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_MPS_REPEATED_3_TIMES).c_str() );
- break;
- case 0x53:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_MPS).c_str() );
- break;
- case 0x54:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_EOP_REPEATED_3_TIMES).c_str() );
- break;
- case 0x55:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_EOP).c_str() );
- break;
- case 0x56:
- m_sLastError.assign( (char*)LoadString(GEN_NO_RESPONSE_TO_EOM_REPEATED_3_TIMES).c_str() );
- break;
- case 0x57:
- m_sLastError.assign( (char*)LoadString(GEN_INVALID_RESPONSE_TO_EOM).c_str() );
- break;
- case 0x58:
- m_sLastError.assign( (char*)LoadString(GEN_UNABLE_TO_CONTINUE_AFTER_PIN_OR_PIP).c_str() );
- break;
- case 0x70:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_B_RECEIVE_ERROR).c_str() );
- break;
- case 0x71:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_RECEIVE_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 0x72:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_B_RECEIVE_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 0x73:
- m_sLastError.assign( (char*)LoadString(GEN_T30_T2_TIMEOUT).c_str() );
- break;
- case 0x74:
- m_sLastError.assign( (char*)LoadString(GEN_FAILURE_TO_RESUME_PHASE_B_AFTER_EOM).c_str() );
- break;
- case 0x90:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_C_RECEIVE_ERROR).c_str() );
- break;
- case 0x91:
- m_sLastError.assign( (char*)LoadString(GEN_MISSING_EOL_AFTER_5_SEC).c_str() );
- break;
- case 0x92:
- m_sLastError.assign( (char*)LoadString(GEN_CRC_OR_FRAME_ERROR_IN_ECM_MODE).c_str() );
- break;
- case 0x93:
- m_sLastError.assign( (char*)LoadString(GEN_MODEM_RECEIVE_BUFFER_OVERFLOWED).c_str() );
- break;
- case 0xA0:
- m_sLastError.assign( (char*)LoadString(GEN_UNSPECIFIED_PHASE_D_RECEIVE_ERROR).c_str() );
- break;
- case 0xA1:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_RECEIVE_RESPONSE_FRAME_ERROR).c_str() );
- break;
- case 0xA2:
- m_sLastError.assign( (char*)LoadString(GEN_PHASE_D_RECEIVE_COMMAND_FRAME_ERROR).c_str() );
- break;
- case 0xA3:
- 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, m_bReceiving ? STATE_WAIT_FOR_OK : STATE_WAIT_FOR_FK_RESP );
- }
- void CClassTwoPointZero::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 );
- }
- }
- void CClassTwoPointZero::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 );
- }
- else
- {
- m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
- }
- }
- else
- {
- m_FaxFile.WriteBuffer( m_szHDLCBuff, m_nHDLCBuffPtr );
- }
- }
- else
- {
- //OutputDebugString( "HDLC buffer overflow!n" );
- }
- }
- int CClassTwoPointZero::ParseFHSCode(void)
- {
- char szNumBuff[21];
- int j;
- int nCode = 0xA0;
- char* p = m_szLineBuff + 5; // Skip +XXXX
- if ( *p == ':' ) // skip the colon
- {
- p++;
- }
- // advance to first digit
- while( *p && (IsHexDigit(*p) == false) && (*p != ',') )
- {
- p++;
- }
- // check for end of string
- if( *p == ' ' )
- {
- return 0xA0;
- }
- j = 0;
- // advance to next comma
- while( *p && IsHexDigit(*p) && (j < 20) )
- {
- szNumBuff[j++] = *p++;
- }
- szNumBuff[j] = ' ';
- sscanf( szNumBuff, "%X", &nCode );
- return nCode;
- }
- void CClassTwoPointZero::OnTimer( UINT nID )
- {
- //OutputDebugString( "CClassTwoPointZero::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() );
- // SignalEvent( EVENT_ERROR );
- OnDisconnectMsg();
- }
- else
- {
- SendCommand( m_nLastCommand, (char*) m_LastCommandString.c_str() );
- }
- }
- break;
- }
- }
- }
- void CClassTwoPointZero::OnAbortFaxMsg(void)
- {
- Abort( true );
- }
- void CClassTwoPointZero::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][1] ? true : false;
- if( nModemCompression < m_nSendEncoding )
- {
- char szMsg[FAXAPI_MODEMMSG_INFOLEN];
- wsprintf( szMsg,(char*)LoadString(GEN_FORMAT_UNSUPPORTED_IN_CLASS_20).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 CClassTwoPointZero::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();
- DoHangup();
- m_dwActivityTimer = GetTickCount();
- }
- 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;
- }
- }