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

📄 ansrmt.c

📁 Dialogic数字板卡示例程序
💻 C
📖 第 1 页 / 共 4 页
字号:
			if ( dt_settssigsim( tsdev, DTB_AON|DTB_BON ) == -1 ) 
			{
				disp_err( hwnd, index, tsdev );
				sprintf( tmpbuff[ index ], "Cannot set bits to %s on %s (%s)",
							"AON-BON", ATDV_NAMEP( tsdev ),	ATDV_ERRMSGP( tsdev ) );
				disp_msg( hwnd, tmpbuff[ index ] );
				return -1;
			}
		}	  
		break;

	case CT_NTE1:
	   
	   index = get_index( tsdev );
	   if ( state == DX_ONHOOK )
	   {
			if ( dt_settssigsim( tsdev, DTB_AON ) == -1 ) 
			{
				disp_err( hwnd, index, tsdev );
				sprintf( tmpbuff[ index ], "Cannot set bits to %s on %s (%s)",
							"AON",ATDV_NAMEP( tsdev ), ATDV_ERRMSGP( tsdev ) );
				disp_msg( hwnd, tmpbuff[ index ] );
				return -1;
			}
	   }
	   else
	   	   if ( dt_settssigsim( tsdev, DTB_AOFF ) == -1 )
		   {
			   disp_err( hwnd, index, tsdev );
			   sprintf( tmpbuff[ index ], "Cannot set bits to %s on %s (%s)",
							"AOFF", ATDV_NAMEP( tsdev ), ATDV_ERRMSGP( tsdev ) );
			   disp_msg( hwnd, tmpbuff[ index ] );
			   return -1;
			}
	   
	case CT_NTDM3:
		index = get_index( ldev );	  
		// Check whether the call has been established or not!
		if ( Dxinfo[ index ].crn < 0 )
			// We have not received OFFERED event so we have not get the CRN 
			// and then the value of CRN is now -1( the initial value )
			// so we need not do annything.
			break;

		if ( state == DX_ONHOOK )
		{
			sprintf( tmpbuff[ index ], "Channel %d is Dropping Call( CRN=%ld )",
					 index, Dxinfo[ index ].crn );
			disp_msg( hwnd, tmpbuff[ index ] );
			if ( gc_DropCall( Dxinfo[ index ].crn, GC_NORMAL_CLEARING, EV_SYNC ) != GC_SUCCESS ) 
			{
				print_GC_error( index, "gc_DropCall" );
				return -1;
			}
		
			sprintf( tmpbuff[ index ], "Channel %d is Releasing Call( CRN=%ld )",
					 index, Dxinfo[ index ].crn );
			disp_msg( hwnd, tmpbuff[ index ] );
			if ( gc_ReleaseCall( Dxinfo[ index ].crn ) != GC_SUCCESS ) 
			{
				print_GC_error( index, "gc_ReleaseCall" );
				return -1;
			}
			Dxinfo[ index ].crn = -1;						// Disable this crn!

		}
		else
		{
			sprintf( tmpbuff[ index ], "Channel %d is Accepting Call( CRN=%ld )",
					 index, Dxinfo[ index ].crn );
			disp_msg( hwnd, tmpbuff[ index ] );
			if ( gc_AcceptCall( Dxinfo[ index ].crn, 0, EV_SYNC ) < 0 )
			{
				print_GC_error( index, "gc_AcceptCall" );
				return -1;
			}
		
			sprintf( tmpbuff[ index ], "Channel %d is Answering Call( CRN=%ld )",
					 index, Dxinfo[ index ].crn );
			disp_msg( hwnd, tmpbuff[ index ] );
			if ( gc_AnswerCall( Dxinfo[ index ].crn, 0, EV_SYNC ) != GC_SUCCESS ) 
			{
				print_GC_error( index, "gc_AnswerCall" );
				return -1;
			}
		}
		break;
   }  
   
   return 0;
}
/***************************************************************************
 *        NAME: void InitDialogic(argc, argv)
 * DESCRIPTION: Entry Point to Application.
 *       INPUT: int argc;	- Argument Count.
 *		char *argv[];	- Array of Pointers to Arguments.
 *      OUTPUT: None.
 *     RETURNS: None.
 *    CAUTIONS: None.
 ***************************************************************************/
WINAPI InitDialogic( HWND *tempHwnd )
{
	int	thr_num;	/* Thread Number for Index */
	HANDLE hThread[ MAXCHANS ]; 
	DWORD IDThread[ MAXCHANS ];  

	hwnd = *tempHwnd;

	sysinit(); // initialize 

	/**
	**	Create the threads that will handle each Voice channel
	**/
    for ( thr_num = 0; thr_num < maxchans; thr_num++ )
    {
	    if ( !( hThread[ thr_num ] = CreateThread( NULL,	//no security attributes
				    0,					            //use default stack size
				    ( LPTHREAD_START_ROUTINE ) ThreadFunc,
				    ( LPVOID )thr_num,                //parameter to thread funciton
				    CREATE_SUSPENDED,	            //creation flag
				    &IDThread[ thr_num ] ) ) )         // returns thread ID
        {
	 		sprintf( tmpbuff[ get_index( thr_num ) ], "CreateThread failed %d ",GetLastError() );
	 		disp_msg( hwnd, tmpbuff[ thr_num ] );
	 		QUIT( 2 );
	    }
    }

    for ( thr_num = 0; thr_num < maxchans; thr_num++ )
    {
        hRingEvent[ thr_num ] = CreateEvent( NULL, FALSE, FALSE, NULL );
		ResumeThread( hThread[ thr_num ] );
    }
	  
	
	/**
	 ** Will wait for the threads to die
	 **/
	
	WaitForMultipleObjects ( maxchans, hThread, TRUE, INFINITE );
    ResetEvent( hExitEvent );
    
    // perform clean up and closing of Dialogic devices
    CloseDialogic();
    disp_clear( hwnd );

    // all threads spawn from within this one have died so lets close the handles
    for ( thr_num = 0; thr_num < maxchans; thr_num++ )
    {
        CloseHandle( hThread[ thr_num ] );      // close the thread handles
        CloseHandle( hRingEvent[ thr_num ] );    // close the event handles
    }
   	
    // do some window housekeeping
    EnableMenuItem( GetMenu( hwnd ), ID_ACTION_START, MF_ENABLED );
	disp_msg( hwnd, "Select Action/Start to begin or first select options" );

	return 0;
}
/****************************************************************
* 	FUNCTION : ThreadFunc()
*	PURPOSE : This funciton is the starting place of the Thread
*		it contains all the Dialogic stuff
*****************************************************************/
void WINAPI ThreadFunc( int index )
{		
	/*
     * If it is a digital network environment, enable a handler to catch
     * signaling transitions while a Dialogic function is in progress.
     * Also, disable idle on the timeslot, set it to signaling insertion
     * and set the signaling event mask.
     * For analog environment, just enable a cst handler
     */	
	if ( frontend == CT_NTANALOG ) 
	{        
        if ( sr_enbhdlr( Dxinfo[ index ].chdev, TDX_CST, cst_hdlr ) == -1 ) 
		{
	    	sprintf( tmpbuff[ index ], "Cannot set cst handler: %s" ,
		                     ATDV_ERRMSGP( SRL_DEVICE ) );
	    	disp_msg( hwnd, tmpbuff[ index ] );
	    	disp_err( hwnd, index, Dxinfo[ index ].chdev );
	    	return ;
        }

    }
    else 
		if ( frontend != CT_NTDM3 )
		{  // digital, enable the DTEV_SIG event
			if ( sr_enbhdlr( Dxinfo[ index ].tsdev, DTEV_SIG, sig_hdlr ) == -1 ) 
			{
	    		sprintf( tmpbuff[ index ], "Cannot set handler: %s" ,
		                     ATDV_ERRMSGP( SRL_DEVICE ) );
	    		disp_msg( hwnd, tmpbuff[ index ] );
	    		disp_err( hwnd, index, Dxinfo[ index ].tsdev );
	    		return ;
			}
    	    
			if ( dt_setidle( Dxinfo[ index ].tsdev, DTIS_DISABLE ) == -1 ) 
			{
				sprintf( tmpbuff[ index ], "Cannot disable IDLE for %s",
		                     ATDV_NAMEP( Dxinfo[ index ].tsdev ) );
	    		disp_msg( hwnd, tmpbuff[ index ] );
	    		disp_err( hwnd, index, Dxinfo[ index ].tsdev );
	    		return;
			}

			if ( dt_setsigmod( Dxinfo[ index ].tsdev, DTM_SIGINS ) == -1 ) 
			{
		    	sprintf( tmpbuff[ index ], "Cannot set SIGINS for %s",
		                     ATDV_NAMEP( Dxinfo[ index ].tsdev ) );
		    	disp_msg( hwnd, tmpbuff[ index ] );
				disp_err( hwnd, index, Dxinfo[ index ].tsdev );
	    		return;
	       	}
				
			/*
			 * Unblock E1 timeslot's signaling bits to ready state.
			*/
			if ( frontend == CT_NTE1 )
			{
			    if ( dt_settssigsim( Dxinfo[ index ].tsdev, 
				             DTB_DON | DTB_COFF | DTB_BOFF | DTB_AON ) == -1 ) 
				{
					sprintf( tmpbuff[ index ], "Cannot set bits to ready state on %s",
		                     ATDV_NAMEP( Dxinfo[ index ].tsdev ) );
					disp_msg( hwnd, tmpbuff[ index ] );
		    		disp_err( hwnd, index, Dxinfo[ index ].tsdev );
			   		return;
				}
			}

			if ( dt_setevtmsk( Dxinfo[ index ].tsdev, DTG_SIGEVT,
                                   DTMM_AOFF | DTMM_AON, DTA_SETMSK ) == -1 ) 
			{
	    		disp_msg( hwnd, "Unable to set DTI signaling event mask" );
		    	disp_err( hwnd, index, Dxinfo[ index ].tsdev );
		        return;
			}
		}
		else	//This is the DM3
		{
			if ( sr_enbhdlr( Dxinfo[ index ].ldev, EV_ANYEVT, gc_hdlr ) == -1 ) 
			{
	    		sprintf( tmpbuff[ index ], "Cannot set handler: %s" ,
		                     ATDV_ERRMSGP( SRL_DEVICE ) );
	    		disp_msg( hwnd, tmpbuff[ index ] );
	    		disp_err( hwnd, index, Dxinfo[ index ].tsdev );
	    		return ;
			}		
		}
		
	/*
     * Start the application by putting the channel to ON-HOOK state.
     */
   
	if ( set_hkstate( &Dxinfo[ index ], DX_ONHOOK ) == -1 ) 
	  	return;

	for ( ; ; ) 
	{
		Dxinfo[ index ].stop_cause = NONE;  // Clear the reason of being stopped
		disp_status( hwnd, index+1, "Ready to accept a call" );

		// Next function does the wait for call
		if ( WaitRing( &Dxinfo[ index ] ) == -1 ) 
			break;	// terminate thread


		sprintf( tmpbuff[ index ], "Incoming Call, Access code: %s", Dxinfo[ index ].ac_code);
		disp_status( hwnd, index+1, tmpbuff[ index ] );
		
		if ( set_hkstate( &Dxinfo[ index ], DX_OFFHOOK ) == -1)	
			break;
	
		/*
		 *This does the bulk of the processing for the current thread
		 */	
		if ( process( &Dxinfo[ index ] ) == -1 ) 
		{
			sprintf( tmpbuff[ index ], "Channel %d is Playing goodbye.vox...", index );
			disp_msg( hwnd, tmpbuff[ index ] );
			// If error occurs, try playing the goodbye prompt and hang up
			strcpy( Dxinfo[ index ].file_name, GOODBYE_VOX );
			play( &Dxinfo[ index ] );			
		}
   
		if ( set_hkstate( &Dxinfo[ index ], DX_ONHOOK ) == -1 )
			break;	
		sprintf( tmpbuff[ index ], "%d Call(s) have already made!", ++connected );
		disp_msg( hwnd, tmpbuff[ index ] );
	}
}
/***************************************************************************
 *        NAME: int process( *dx_info )
 * DESCRIPTION: Begin Initial Processing of the Event Received
 *       INPUT: DX_INFO *dx_info;	- Dxinfo structure pointer
 *      OUTPUT: None
 *     RETURNS: -1 on error
 *    CAUTIONS: None
 ***************************************************************************/
int process( DX_INFO *dx_info )
{
	int index = get_index( dx_info->chdev );

	// Play the introduction prompt
	sprintf( tmpbuff[ index ], "Channel %d is Playing intro.vox...", index );
	disp_msg( hwnd, tmpbuff[ index ] );

	strcpy( dx_info->file_name, INTRO_VOX );	// To play intro.vox
	if ( play( dx_info ) == -1 ) 
	{
		sprintf( tmpbuff[ index ], "Channel %d is Terminated by user stopped while playing intro.vox!", index );
		disp_msg( hwnd, tmpbuff[ index ] );
		return -1;
	}
	
	switch ( frontend ) 
	{
	case CT_NTANALOG:
		// if caller disconnected, then hang up
        if ( ATDX_TERMMSK( dx_info->chdev ) & TM_LCOFF ) 
	    	return 0;
        break;

    case CT_NTT1:
	    // if RCVA bit is OFF, the hang up
        if ( ( ATDT_TSSGBIT( dx_info->tsdev ) & DTSG_RCVA ) == 0 ) 
		    return 0;
        break;

    case CT_NTE1:
	    // if RCVA is ON, then hang up
        if ( ( ATDT_TSSGBIT( dx_info->tsdev ) & DTSG_RCVA ) != 0 ) 
            return 0; 
        break;

	case CT_NTDM3:
		// if caller disconnected, then hang up
		if ( dx_info->stop_cause == DISCONNECT )
		{
			sprintf( tmpbuff[ index ], "Channel %d is Terminated by DISCONNECT while playing intro.vox!", index );
			disp_msg( hwnd, tmpbuff[ index ] );
			dx_info->stop_cause = NONE;
			return 0;
		}
		break;
    }  

	// If reached end of data, perform recording of message	
	if ( ATDX_TERMMSK( dx_info->chdev ) & TM_EOD )  
	{
		sprintf( tmpbuff[ index ], "Channel %d played end of intro.vox!", index );
		disp_msg( hwnd, tmpbuff[ index ] );
    	if ( dx_clrdigbuf( dx_info->chdev ) == -1 ) 
		{
	 		sprintf( tmpbuff[ index ], "Cannot clear DTMF Buffer for %s", ATDV_NAMEP( dx_info->chdev ) );
	 		disp_msg( hwnd, tmpbuff[ index ] );
	 		disp_err( hwnd, index, dx_info->chdev );
     		return -1;
      	}

		sprintf( dx_info->file_name, "message%d.pcm", index + 1 );  // To record message*.pcm
		sprintf( tmpbuff[ index ], "Channel %d is recording to file %s!", 
					index, dx_info->file_name );
		disp_msg( hwnd, tmpbuff[ index ] );
		
      	if ( record( dx_info ) == -1 )
			return -1;
	}
	else 
	{
		/* Caller entered access code, therefore we need to check
		** whether it is correct or not and proceed.
		*/
		sprintf( tmpbuff[ index ], "Channel %d is Terminated by %d, stop_cause=%d!", 
					index, ATDX_TERMMSK( dx_info->chdev ), dx_info->stop_cause );
		disp_msg( hwnd, tmpbuff[ index ] );
		sprintf( tmpbuff[ index ], "Channel %d is getting digits!", index );
		disp_msg( hwnd, tmpbuff[ index ] );
    	if ( get_digits( dx_info ) == -1 )
			return -1;

	  	switch ( frontend ) 
		{
      	case CT_NTANALOG:
	    	// if caller disconnected, then hang up
        	if ( ATDX_TERMMSK( dx_info->chdev ) & TM_LCOFF ) 

⌨️ 快捷键说明

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