📄 ansrmt.c
字号:
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 getting digits!", index );
disp_msg( hwnd, tmpbuff[ index ] );
dx_info->stop_cause = NONE;
return 0;
}
break;
}
// Validate digits
if ( strcmp( dx_info->ac_code, dx_info->digbuf.dg_value ) == 0 )
{
/*
** Correct Digits Entered
*/
sprintf( dx_info->file_name, "message%d.pcm", index + 1 ); // To play message*.pcm
sprintf( tmpbuff[ index ], "Channel %d is playing the recorded file %s!",
index, dx_info->file_name );
disp_msg( hwnd, tmpbuff[ index ] );
if ( play( dx_info ) == -1 )
return -1;
}
else
{
sprintf( tmpbuff[ index ], "Channel %d is playing invalid.vox...", index );
disp_msg( hwnd, tmpbuff[ index ] );
// Invalid access code
strcpy( dx_info->file_name, INVALID_VOX );
if ( play( dx_info ) == -1 )
return -1;
}
} // Lets play goodbye and disconnect
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 ST_ONHOOK;
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/recording file!",
index );
disp_msg( hwnd, tmpbuff[ index ] );
dx_info->stop_cause = NONE;
return 0;
}
break;
}
sprintf( tmpbuff[ index ], "Channel %d is playing goodbbye.vox...!", index );
disp_msg( hwnd, tmpbuff[ index ] );
// Play the goodbye voice prompt and hang up
strcpy( dx_info->file_name, GOODBYE_VOX );
if ( play( dx_info ) == -1 )
return -1;
return 0;
}
/***************************************************************************
* NAME: int WaitRing( DX_INFO *dx_info, int timeout )
* DESCRIPTION:
* INPUT: DX_INFO *dx_info; - pointer to Dxinfo structure
* int timeout; - timeout
* OUTPUT: None
* RETURNS: 0 if okay, -1 if error
* CAUTIONS: None
***************************************************************************/
int WaitRing( DX_INFO *dx_info )
{
unsigned short index = get_index( dx_info->chdev );
HANDLE hEvents[] = { hExitEvent, hRingEvent[ index ] };
DWORD Ret;
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);
}
if ( frontend == CT_NTDM3 )
if ( gc_WaitCall( dx_info->ldev, NULL, NULL, 0, EV_ASYNC) < 0 )
{
print_GC_error( index, "gc_WaitCall" );
return -1;
}
/* Wait for two event objects. The first event object is the exit event
** while the second one is the ring received object. If the latter is
** signaled, then a ring event has come, otherwise the user has requested
** to terminate the thread, and we return a -1 to indicate so.
** This mechanism allows a clean termination of the thread which has proven
** better than a TerminateThread call.
*/
Ret = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
if (Ret == WAIT_OBJECT_0 )
return -1; // the user requested termination of the thread
return 0;
}
/******************************************************************************
* NAME: int cst_hdlr()
* DESCRIPTION: Signal handler to catch CST events generated by the vox
* devices
* INPUT: None.
* OUTPUT: None.
* RETURNS: 0
* CAUTIONS: None.
******************************************************************************/
long cst_hdlr( unsigned long event_handle )
{
int chdev = sr_getevtdev( event_handle );
DX_CST *cstp = ( DX_CST * )sr_getevtdatap( event_handle );
int index = get_index( chdev );
switch( cstp->cst_event )
{
case DE_RINGS:
// received rings, signal the event object
SetEvent(hRingEvent[index]);
return 0;
default:
// unexpected, ignore
return 0;
}
}
/******************************************************************************
* NAME: int sig_hdlr()
* DESCRIPTION: Signal handler to catch DTEV_SIG events generated by the dti
* timeslots.
* INPUT: None.
* OUTPUT: None.
* RETURNS: 0
* CAUTIONS: None.
******************************************************************************/
long sig_hdlr( unsigned long event_handle )
{
int tsdev = sr_getevtdev( event_handle );
int event = sr_getevttype( event_handle );
unsigned short *ev_datap = ( unsigned short * )sr_getevtdatap( event_handle );
unsigned short sig = ( unsigned short )( *ev_datap );
int index = get_index( tsdev );
short i;
if ( event != DTEV_SIG )
{
sprintf( tmpbuff[ index ], "Unknown Event 0x%lx Received on %s. Data = 0x%hx",
event, ATDV_NAMEP( tsdev ), sig );
disp_msg( hwnd, tmpbuff[ index ] );
disp_status( hwnd, index+1, "Unknown Event" );
return 0;
}
for ( i = 0; i < 4; i++ )
{
/*
* Check if bit in change mask (upper nibble - lower byte) is set or
* if this is a WINK (upper nibble - upper byte) event
*/
if ( !( sig & ( SIGEVTCHK << i ) ) )
continue;
switch ( sig & ( SIGBITCHK << i ) )
{
case DTMM_AON:
switch ( frontend )
{
case CT_NTT1:
/*
* Rings Received (Incoming Call)
*/
SetEvent( hRingEvent[ index ] );
return 0;
case CT_NTE1:
/*
* Caller hangup, set state to ONHOOK and set channel to ONHOOK
*/
set_hkstate( &Dxinfo[ index ], DX_ONHOOK );
return 0;
}
break;
case DTMM_AOFF:
switch ( frontend )
{
case CT_NTE1:
/*
* Rings Received (Incoming Call)
*/
SetEvent( hRingEvent[ index ] );
return 0;
case CT_NTT1:
/*
* Caller hangup, set state to ONHOOK and set channel to ONHOOK
*/
set_hkstate( &Dxinfo[ index ], DX_ONHOOK );
return 0;
}
break;
case DTMM_BOFF:
case DTMM_BON:
case DTMM_COFF:
case DTMM_CON:
case DTMM_DOFF:
case DTMM_DON:
case DTMM_WINK:
return 0;
default:
sprintf( tmpbuff[ index ], "Unknown DTEV_SIG Event 0x%hx Received on %s",
sig, ATDV_NAMEP( tsdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
}
}
return 0;
}
/******************************************************************************
* NAME: long gc_hdlr ()
* DESCRIPTION: GC events handler to catch DTEV_SIG events generated by the dti
* timeslots.
* INPUT: None.
* OUTPUT: None.
* RETURNS: 0
* CAUTIONS: None.
******************************************************************************/
long gc_hdlr( unsigned long temp )
{
METAEVENT metaevt;
int index;
if ( gc_GetMetaEvent( &metaevt ) < 0 )
{
print_GC_error( -1, "gc_GetMetaEvent" );
return 0;
}
index = get_index( metaevt.evtdev );
switch ( metaevt.evttype )
{
case GCEV_OFFERED:
if ( gc_GetCRN( &Dxinfo[ index ].crn, &metaevt ) < 0 )
{
print_GC_error( index, "gc_GetCRN" );
return 0;
}
sprintf( tmpbuff[ index ], "Channel %d received GCEV_OFFERED! CRN=%ld", index, Dxinfo[ index ].crn );
disp_msg( hwnd, tmpbuff[ index ] );
/*
* Rings Received (Incoming Call)
*/
SetEvent( hRingEvent[ index ] );
break;
case GCEV_DISCONNECTED:
sprintf( tmpbuff[ index ], "Channel %d received GCEV_DISCONNECTED!", index );
disp_msg( hwnd, tmpbuff[ index ] );
Dxinfo[ index ].stop_cause = DISCONNECT; // To indicate the call is disconnected
sprintf( tmpbuff[ index ], "Channel %d want to stopch()!", index );
disp_msg( hwnd, tmpbuff[ index ] );
// dx_stopch( Dxinfo[ index ].chdev, EV_ASYNC ); // May be some channel is playing, stop it
break;
case GCEV_UNBLOCKED:
sprintf( tmpbuff[ index ], "Channel %d received GCEV_UNBLOCKED!", index );
disp_msg( hwnd, tmpbuff[ index ] );
break;
default:
// unexpected, ignore
sprintf( tmpbuff[ index ], "Channel %d received unexpected event type=%ld!", index, metaevt.evttype );
disp_msg( hwnd, tmpbuff[ index ] );
return 0;
}
return 0;
}
/***************************************************************************
* NAME: int get_index( chtsdev )
* DESCRIPTION: Get the index into the Dxinfo[] for the channel or timeslot
* device descriptor, chtsdev.
* INPUT: int chtsdev; - Channel/Timeslot Device Descriptor
* OUTPUT: None.
* RETURNS: Returns the index into Dxinfo[]
* CAUTIONS: None.
***************************************************************************/
int get_index( long dev )
{
int index = 0;
while ( index < maxchans )
{
if ( Dxinfo[ index ].chdev == dev
|| Dxinfo[ index ].tsdev == dev
|| Dxinfo[ index ].ldev == dev )
return index ;
index++;
}
/*
* Not Found in the Array, print error and return -1
*/
sprintf( tmpbuff[ index ], "Unknown Device %d - ignored", dev );
disp_msg( hwnd, tmpbuff[ index ] );
return -1;
}
/***************************************************************************
* NAME: windexit( )
* DESCRIPTION: perform graceful exit
* INPUT: int level - exit code
* OUTPUT: None.
* RETURNS: None.
* CAUTIONS: None.
***************************************************************************/
void windexit( int level )
{
char szMsg[ 30 ];
sprintf( szMsg, "Exiting with code %d", level );
MessageBox( hwnd, szMsg, "Program Message ", MB_OK );
PostMessage( hwnd, WM_CLOSE, 0, 0L );
}
/***************************************************************************
* NAME: print_GC_error( )
* DESCRIPTION: display the GC error
* INPUT: int index--the index of devices, char *msg--the error cause
* OUTPUT: None.
* RETURNS: None.
* CAUTIONS: None.
***************************************************************************/
void print_GC_error( int index, char *msg )
{
int cclibid; /* cclib id for gc_ErrorValue(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -