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

📄 pansr.cpp

📁 基于dialogic语音卡的IVR系统源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		disp_msg( tmpbuff );
		return -1;
    }

	dx_clrdigbuf( dxinfo[ channum ].chdev );
	
	//
	// Clear and Set-Up the IOTT strcuture
	//
	memset( dxinfo[ channum ].iott, 0, 45*sizeof( DX_IOTT ) );

	dxinfo[ channum ].iott[ 0 ].io_type = IO_DEV | IO_EOT;
	dxinfo[ channum ].iott[ 0 ].io_fhandle = dxinfo[ channum ].msg_fd;
	dxinfo[ channum ].iott[ 0 ].io_length = -1;

	//
    // Clear and then Set the DV_TPT structures
    //
	dxinfo[ channum ].tpt[ 0 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 1 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 2 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 3 ].tp_type = IO_EOT;
	dx_clrtpt( dxinfo[ channum ].tpt, 4);

	/* Terminate Record on Receiving any DTMF tone */
	dxinfo[ channum ].tpt[ 0 ].tp_termno = DX_MAXDTMF;
	dxinfo[ channum ].tpt[ 0 ].tp_length = 1;
	dxinfo[ channum ].tpt[ 0 ].tp_flags = TF_MAXDTMF;

	/* Terminate Record on Loop Current Drop */
	dxinfo[ channum ].tpt[ 1 ].tp_termno = DX_LCOFF;
	dxinfo[ channum ].tpt[ 1 ].tp_length = 1;
	dxinfo[ channum ].tpt[ 1 ].tp_flags = TF_LCOFF;

	/* Terminate Record on 5 Seconds of Silence */
	dxinfo[ channum ].tpt[ 2 ].tp_termno = DX_MAXSIL;
	dxinfo[ channum ].tpt[ 2 ].tp_length = 50;
	dxinfo[ channum ].tpt[ 2 ].tp_flags = TF_MAXSIL;

	/* Terminate Record After Maxtime Seconds of Recording */
	dxinfo[ channum ].tpt[ 3 ].tp_termno = DX_MAXTIME;
	dxinfo[ channum ].tpt[ 3 ].tp_length = 10*maxtime;
	dxinfo[ channum ].tpt[ 3 ].tp_flags = TF_MAXTIME;

	/* Record VOX File on D/4x Channel */
	return( dx_rec( dxinfo[ channum ].chdev, dxinfo[ channum ].iott,
			dxinfo[ channum ].tpt, RM_TONE | EV_ASYNC| MD_PCM | RM_ALAW | PM_SR8 ) );
}

/***************************************************************************
 *        NAME: int set_hkstate( channum, state )
 * DESCRIPTION: Set the channel to the appropriate hook status
 *       INPUT: int channum;	- Index into dxinfo structure
 *              int state;		- State to set channel to
 *      OUTPUT: None.
 *     RETURNS: -1 = Error
 *               0 = Success
 *    CAUTIONS: None.
 ***************************************************************************/
int set_hkstate( int channum, int state )
{
	int chdev = dxinfo[ channum ].chdev;
	int tsdev = dxinfo[ channum ].tsdev;

	if (!chdev) return -1;

	// Make sure you are in CS_IDLE state before setting hook status
    
	if ( ATDX_STATE( chdev ) != CS_IDLE ) 
	{
		dx_stopch( chdev, EV_ASYNC );
		while ( ATDX_STATE( chdev ) != CS_IDLE );
	}

	switch ( frontend ) 
	{
		case CT_NTANALOG:
			if ( dx_sethook( chdev, (state == DX_ONHOOK) ? DX_ONHOOK : DX_OFFHOOK,
				EV_ASYNC ) == -1 ) 
			{
				disp_err( channum, chdev, dxinfo[ channum ].state );
				sprintf( tmpbuff, "Cannot set channel %s to %s-Hook (%s)",
					ATDV_NAMEP( chdev ), (state == DX_ONHOOK) ? "On" : "Off",
					ATDV_ERRMSGP( chdev ) );
				disp_msg( tmpbuff );
				return( -1 );
			}
			break;

		case CT_NTT1:
			if (!tsdev) return -1;
			if ( dt_settssigsim( tsdev, (state == DX_ONHOOK) ? DTB_AOFF | DTB_BOFF :
				DTB_AON | DTB_BON ) == -1 ) 
			{
				disp_err( channum, tsdev, dxinfo[ channum ].state );
				sprintf( tmpbuff, "Cannot set bits to %s on %s (%s)",
					(state == DX_ONHOOK) ? "AOFF-BOFF" : "AON-BON", ATDV_NAMEP( tsdev ),
					ATDV_ERRMSGP( tsdev ) );
				disp_msg( tmpbuff );
				return( -1 );
			}
			break;

		case CT_NTE1:
			if (!tsdev) return -1;
			if ( dt_settssig( tsdev, (state == DX_ONHOOK) ? DTB_AON | DTB_BOFF:	
				DTB_BBIT,DTA_ADDMSK) == -1 ) 
			{
				disp_err( channum, tsdev, dxinfo[ channum ].state );
				sprintf( tmpbuff, "Cannot set bits to %s on %s (%s)",
					(state == DX_ONHOOK) ? "AON-BOFF" : "AOFF",ATDV_NAMEP( tsdev ), 
					ATDV_ERRMSGP( tsdev ) );
				disp_msg( tmpbuff );
				return( -1 );
			}
			break;
	}

	if ( state == DX_ONHOOK ) 
	{
		if ( dx_clrdigbuf( chdev ) == -1 ) 
		{
			sprintf( tmpbuff, "Cannot clear DTMF Buffer for %s",
				ATDV_NAMEP( chdev ) );
			disp_msg( tmpbuff );
			disp_err(channum, chdev, dxinfo[ channum ].state);
			return -1;
		}
		dxinfo[ channum ].state = ST_WTRING ;
		if (dxinfo[channum].msg_fd > 0 )
		{
			dx_fileclose(dxinfo[channum].msg_fd);
			dxinfo[channum].msg_fd = 0;
		}
	}

	if (frontend != CT_NTANALOG) 
	{
		switch ( state ) 
		{
			case DX_ONHOOK:
				dxinfo[ channum ].state = ST_WTRING;
				disp_status( channum, "Ready1         " );
				if (dxinfo[channum].msg_fd > 0 )
				{
					dx_fileclose(dxinfo[channum].msg_fd);
					dxinfo[channum].msg_fd = 0;
				}
				break;

			case DX_OFFHOOK:
				if(dx_enbtone(dxinfo[channum].chdev,TONEALL,DM_TONEON|DM_TONEOFF) ==-1)
				{
					disp_msg("Unable tp enable tone detection");
					return -1;
				}
				dxinfo[ channum ].state = ST_GETR2MF;
				strcpy( dxinfo[channum].anis_buf, "" );
				break;
		}
	}

	return( 0 );
}

/***************************************************************************
 *        NAME: int curr_state( channum, event )
 * DESCRIPTION: Complete Processing of the Current State
 *      		Identify the Next State to be Entered
 *       INPUT: int channum;	- Index into dxinfo structure
 *         		int event;	- Event being processed
 *      OUTPUT: None
 *     RETURNS: Next Channel State
 *    CAUTIONS: None
 ***************************************************************************/
int curr_state( int channum, int event )
{
	int  m_state = dxinfo[ channum ].state ;

	switch ( dxinfo[ channum ].state )
	{
		case ST_WTRING:
			
			if( dxinfo[ channum ].service == CMD_ONHOOK )
			{
				WriteReplyQueue( channum, event );
				break;
			}
			switch (event)
			{
				case TDX_SETHOOK:
					return ST_WTRING;
				case TDX_CST: 
					return ST_OFFHOOK;
			}
			break;
		
		case ST_ERROR: 
			return ST_ONHOOK;

		case ST_OFFHOOK:
		default: 
			m_state = WriteReplyQueue( channum, event );
			break;
	}
	return m_state;
}

/***************************************************************************
 *        NAME: int process( channum, event )
 * DESCRIPTION: Begin Initial Processing of the Event Received
 *       INPUT: int channum;	- Index into dxinfo structure
 *		int event;	- Event being processed
 *      OUTPUT: None
 *     RETURNS: New Channel State
 *    CAUTIONS: None
 ***************************************************************************/
int process( int channum, int event )
{
	DX_CST	 *cstp;
    int     signal;
    int     chdev = dxinfo[channum].chdev;
	
	//for debug
	Viewevent( channum, event );
    
	//* Switch according to the event received.
    /*
	if( event & DT_GC ) 
		vProcessCallEvents( channum, SRLevent );
	else
		vProcessVoxEvents( channum, SRLevent );
	*/

	switch ( event ) 
	{
		case TDX_PLAYTONE:
			return( curr_state( channum, event ) );

		case TDX_CST:
			cstp = (DX_CST *) sr_getevtdatap();
			switch ( cstp->cst_event ) 
			{
				case DE_RINGS:
					//* Rings Received (Incoming Call)
					if ( dxinfo[ channum ].state == ST_WTRING ) 
					{
						return( ST_OFFHOOK );
					}
					break;

				case DE_LCON:
					Sleep(1);
					break;
				case DE_LCOFF:
					Sleep(1);
					break;

				case DE_TONEON:
   			    
			        signal = cstp->cst_data;
					if( frontend == CT_NTANALOG && signal == TID_1 )
					{
						//set_hkstate( channum, DX_ONHOOK );
						WriteReplyQueue( channum, TDX_ERROR );
						return( ST_ONHOOK );
					}
					//cn_r2_mfc( channum, signal );
					break;

				default:
					break;
			}				
			break;

		case TFX_FAXSEND:
		case TFX_FAXRECV:
		case TFX_FAXERROR:
			FaxClose( channum );
			return( curr_state( channum, event ) );

		case TDX_DIAL:
		case TDX_CALLP:
			return( curr_state( channum, event ) );


		case TDX_TXDATA:	//Transmit FSK data Completed
			if( dxinfo[channum].msg_buf != NULL )
			{
				MyFreeMem(dxinfo[channum].msg_buf);
				dxinfo[channum].msg_buf = NULL;
			}
			//* If drop in loop current, set state to ON-HOOK
			
			switch ( frontend ) 
			{
				case CT_NTANALOG:        //signal of the analog line
					if ( ATDX_TERMMSK( dxinfo[ channum ].chdev ) & TM_LCOFF ) 
					{
						return( ST_ONHOOK );
					}
					break;
				default: break;
			} 
			return(curr_state( channum, event ) );

		case TDX_USER:		// User event Completed
		case TDX_PLAY:		// Play Completed	
		case TDX_RECORD:	// Record Completed
		case TDX_GETDIG:	// Get Digits Completed	

			// if playing or recording a file, close it

			if (dxinfo[channum].msg_fd)
			{
				dx_fileclose(dxinfo[channum].msg_fd);
				dxinfo[ channum ].msg_fd = 0;
			}
			
			if( dxinfo[channum].msg_buf != NULL )
			{
				delete dxinfo[channum].msg_buf;
				dxinfo[channum].msg_buf = NULL;
			}
			
			//* If drop in loop current, set state to ON-HOOK
			
			switch ( frontend ) 
			{
				case CT_NTANALOG:        //signal of the analog line
					if ( ATDX_TERMMSK( dxinfo[ channum ].chdev ) & TM_LCOFF ) 
					{
						return( ST_ONHOOK );
					}
					break;
				default: break;
			} 
			return(curr_state( channum, event ) );

			// falls through

		case TDX_SETHOOK:	/* Set-Hook Complete	*/
			return( curr_state( channum, event ) );

		case MSEV_SIGEVT:		/* MSI signalling event */

			signal = *(int *)sr_getevtdatap();
			switch( signal )
			{
			case MSMM_OFFHOOK:
				//AfxMessageBox("MSI Offhk");
				MSIBegin( channum );
				break;

			case MSMM_ONHOOK:
				//AfxMessageBox("MSI Onhook");
				MSIStop( channum );
				break;
			}
			return( curr_state( channum, event ) );


		case MSEV_RING:
			
			signal = *(int *)sr_getevtdatap();
			switch( signal )
			{
			case MSMM_RNGOFFHK:
				//AfxMessageBox("Ring Offhk!");
			case E_MSBADRNGSTA:
				//AfxMessageBox("Ring OK");
				MSIBegin( channum );
				break;

			case MSMM_RNGSTOP:
				//AfxMessageBox("Ring Stop!");
			case MSMM_TERM:
				//AfxMessageBox("RING Term!");
				MSIStop( channum );
				break;
			}
			return( curr_state( channum, event ) );
		
		case MSEV_NORING:

			signal = *(int *)sr_getevtdatap();
			switch( signal )
			{
			case MSMM_RNGOFFHK:
				AfxMessageBox("NORing Offhk!");
			case E_MSBADRNGSTA:
				AfxMessageBox("NORing OK");
				MSIBegin( channum );
				break;

			case MSMM_RNGSTOP:
				AfxMessageBox("NORing Stop!");
			case MSMM_TERM:
				AfxMessageBox("NORING Term!");
				MSIStop( channum );
				break;
			}
			return( curr_state( channum, event ) );

		case MSEV_ERREVT:
			MSIStop( channum );
			return( curr_state( channum, event ) );

		default:
			
			//* Unexpected or Error Termination Event
			/*	Display Debug infomations  */
			sprintf( tmpbuff, "Unknown Event %d, State = %d",
				event, dxinfo[ channum ].state );
			disp_msg( tmpbuff );
			disp_err(channum, dxinfo[ channum ].chdev, dxinfo[ channum ].state);			
			return( curr_state( channum, event ) );
	}

	return( dxinfo[ channum ].state );
}


/***************************************************************************
 *        NAME: int next_state( channum )
 * DESCRIPTION: Begin the Next State, Initiate the Functions
 *       INPUT: int channum;	- Index into dxinfo structure
 *      OUTPUT: None
 *     RETURNS: Pass/Fail Status
 *    CAUTIONS: None
 ***************************************************************************/
int next_state( int channum )
{       
	int errcode = 0;

	switch ( dxinfo[ channum ].state ) 
	{
		case ST_WTRING:
			disp_status( channum, "Ready to accept a call" );
			break;

⌨️ 快捷键说明

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