📄 ansrmt.c
字号:
* If it is a digital network environment, disable idle on the timeslot,
* set it to signaling insertion and set the signaling event mask.
*/
if ( frontend != CT_NTANALOG && frontend != CT_NTDM3 )
{
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 );
QUIT( 2 );
}
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 );
QUIT( 2 );
}
/*
* 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 );
QUIT( 2 );
}
}
if ( dt_setevtmsk( Dxinfo[ index ].tsdev, DTG_SIGEVT,
DTMM_AOFF | DTMM_AON, DTA_SETMSK) == -1 )
{
sprintf( tmpbuff[ index ], "Unable to set DTI signaling event mask" );
disp_msg( hwnd, tmpbuff[ index ] );
QUIT( 2 );
}
}
}//for(;;)
/*
* Display number of channels being used
*/
sprintf( msg, "Using %d line%s", maxchans, maxchans > 1 ? "s." : "." );
disp_msg( hwnd, msg );
}
/***************************************************************************
* NAME: int play( *dx_info )
* DESCRIPTION: Set up IOTT and TPT's and Initiate the Play-Back
* INPUT: DX_INFO *dx_info; - Dxinfo structure pointer
* OUTPUT: Starts the play-back
* RETURNS: -1 = Error
* 0 = Success
* CAUTIONS: None
***************************************************************************/
int play( DX_INFO *dx_info )
{
DV_TPT tpt[ 2 ];
DX_IOTT iott;
int index, fd, ret = 0;
char *file = dx_info->file_name;
unsigned short mode = EV_SYNC;
index = get_index( dx_info->chdev );
fd = dx_fileopen( file, _O_RDONLY|_O_BINARY );
if ( fd == -1 )
{
sprintf( tmpbuff[ index ], "Cannot open %s, errno: %d", file, dx_fileerrno() );
disp_msg( hwnd, tmpbuff[ index ] );
return -1;
}
sprintf( tmpbuff[ index ], "Channel %d is playing File name=%s, File handle=%d",
index, file, fd );
disp_msg( hwnd, tmpbuff[ index ] );
dx_clrdigbuf( dx_info->chdev );
/*
* Clear and Set-Up the IOTT strcuture
*/
memset( &iott, 0, sizeof( DX_IOTT ) );
iott.io_type = IO_DEV | IO_EOT;
iott.io_fhandle = fd;
iott.io_offset = 0;
iott.io_length = -1;
/*
* Clear and then Set the DV_TPT structures
*/
tpt[ 0 ].tp_type = IO_CONT;
tpt[ 1 ].tp_type = IO_EOT;
dx_clrtpt( tpt, 2);
/* Terminate Play on Receiving any DTMF tone */
tpt[ 0 ].tp_type = IO_CONT;
tpt[ 0 ].tp_termno = DX_MAXDTMF;
tpt[ 0 ].tp_length = 1;
tpt[ 0 ].tp_flags = TF_MAXDTMF;
/* Terminate Play on Loop Current Drop */
tpt[ 1 ].tp_type = IO_EOT;
tpt[ 1 ].tp_termno = DX_LCOFF;
tpt[ 1 ].tp_length = 1;
tpt[ 1 ].tp_flags = TF_LCOFF;
/*
* Play VOX File on D/4x Channel, Normal Play Back
*/
// Let's detect the file type, PCM or ADPCM, for PCM it is specified to 8K sample rate
for ( ; *file; file++ )
if ( *file == '.' )
{
if ( !strcmp( file + 1, "pcm" ) || !strcmp( file + 1, "PCM" ) )
mode |= MD_PCM | PM_SR8;
break;
}
if ( dx_play( dx_info->chdev, &iott, tpt, mode ) == -1 )
{
disp_err( hwnd, index, dx_info->chdev );
sprintf( tmpbuff[ index ], "dx_play failed on %s: %s",
ATDV_NAMEP( dx_info->chdev ), ATDV_ERRMSGP( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
ret = -1;
}
sprintf( tmpbuff[ index ], "Channel %d is Terminated by %d while in playing!",
index, ATDX_TERMMSK( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
if ( ATDX_TERMMSK( dx_info->chdev ) == TM_USRSTOP )
{
// The reason of play stop may be user chooses STOP menu or received DISCONNECT event
sprintf( tmpbuff[ index ], "Channel %d is Terminated by user stopped while in playing, stop_cause=%d!",
index, dx_info->stop_cause );
disp_msg( hwnd, tmpbuff[ index ] );
if ( dx_info->stop_cause == USER_STOP )
{
// The reason is that user chooses STOP menu and then return as a failure!
dx_info->stop_cause = NONE;
ret = -1;
}
}
dx_fileclose( fd );
return ret;
}
/***************************************************************************
* NAME: int record( *dx_info )
* DESCRIPTION: Set up IOTT and TPT's and Initiate the record
* INPUT: DX_INFO *dx_info; - Dxinfo structure pointer
* OUTPUT: Starts the Recording
* RETURNS: -1 = Error
* 0 = Success
* CAUTIONS: None
***************************************************************************/
int record( DX_INFO *dx_info )
{
DV_TPT tpt[ 4 ];
DX_IOTT iott;
int index, fd, ret = 0;
unsigned short mode = EV_SYNC | MD_PCM | RM_SR8;
index = get_index( dx_info->chdev );
fd = dx_fileopen( dx_info->file_name, _O_RDWR | _O_TRUNC | _O_CREAT, 0666 );
if ( fd == -1 )
{
sprintf( tmpbuff[ index ], "Cannot create %s for recording", dx_info->file_name );
disp_msg( hwnd, tmpbuff[ index ] );
return -1;
}
sprintf( tmpbuff[ index ], "Channel %d is recording File name=%s, File handle=%d",
index, dx_info->file_name, fd );
disp_msg( hwnd, tmpbuff[ index ] );
/*
* Clear and Set-Up the IOTT strcuture
*/
memset( &iott, 0, sizeof( DX_IOTT ) );
iott.io_type = IO_DEV | IO_EOT;
iott.io_fhandle = fd;
iott.io_offset = 0;
iott.io_length = -1;
// Terminate Record on Receiving any DTMF tone
tpt[ 0 ].tp_type = IO_CONT;
tpt[ 0 ].tp_termno = DX_MAXDTMF;
tpt[ 0 ].tp_length = 1;
tpt[ 0 ].tp_flags = TF_MAXDTMF;
// Terminate Record on Loop Current Drop
tpt[ 1 ].tp_type = IO_CONT;
tpt[ 1 ].tp_termno = DX_LCOFF;
tpt[ 1 ].tp_length = 1;
tpt[ 1 ].tp_flags = TF_LCOFF;
// Terminate Record on 5 Seconds of Silence
tpt[ 2 ].tp_type = IO_CONT;
tpt[ 2 ].tp_termno = DX_MAXSIL;
tpt[ 2 ].tp_length = 50;
tpt[ 2 ].tp_flags = TF_MAXSIL;
// Terminate Record After 10 Seconds of Recording
tpt[ 3 ].tp_type = IO_EOT;
tpt[ 3 ].tp_termno = DX_MAXTIME;
tpt[ 3 ].tp_length = 100;
tpt[ 3 ].tp_flags = TF_MAXTIME;
// Record VOX File on D/4x Channel
if ( dx_rec( dx_info->chdev, &iott, tpt, mode ) == -1 )
{
disp_err( hwnd, index, dx_info->chdev );
sprintf( tmpbuff[ index ], "dx_rec failed on %s: %s",
ATDV_NAMEP( dx_info->chdev ), ATDV_ERRMSGP( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
ret = -1;
}
sprintf( tmpbuff[ index ], "Channel %d is Terminated by %d while in recording!",
index, ATDX_TERMMSK( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
if ( ATDX_TERMMSK( dx_info->chdev ) == TM_USRSTOP )
{
// The reason of play stop may be user chooses STOP menu or received DISCONNECT event
sprintf( tmpbuff[ index ], "Channel %d is Terminated by user stopped while in recording, stop_cause=%d!",
index, dx_info->stop_cause );
disp_msg( hwnd, tmpbuff[ index ] );
if ( dx_info->stop_cause == USER_STOP )
{
// The reason is that user chooses STOP menu and then return as a failure!
dx_info->stop_cause = NONE;
ret = -1;
}
}
dx_fileclose( fd );
return ret;
}
/***************************************************************************
* NAME: int get_digits( *dx_info )
* DESCRIPTION: Set up TPT's and Initiate get-digits function
* INPUT: DX_INFO *dx_info; - Dxinfo structure pointer
* OUTPUT: Starts to get the DTMF Digits
* RETURNS: -1 = Error
* 0 = Success
* CAUTIONS: None
***************************************************************************/
int get_digits( DX_INFO *dx_info )
{
int index;
DV_TPT tpt[ 3 ];
// return 0;
/*
* Clear and then Set the DV_TPT structures
*/
tpt[ 0 ].tp_type = IO_CONT;
tpt[ 1 ].tp_type = IO_CONT;
tpt[ 2 ].tp_type = IO_EOT;
dx_clrtpt( tpt, 3);
/* Terminate GetDigits on Receiving MAXDTMF Digits */
tpt[ 0 ].tp_type = IO_CONT;
tpt[ 0 ].tp_termno = DX_MAXDTMF;
tpt[ 0 ].tp_length = MAXDTMF;
tpt[ 0 ].tp_flags = TF_MAXDTMF;
/* Terminate GetDigits on Loop Current Drop */
tpt[ 1 ].tp_type = IO_CONT;
tpt[ 1 ].tp_termno = DX_LCOFF;
tpt[ 1 ].tp_length = 1;
tpt[ 1 ].tp_flags = TF_LCOFF;
/* Terminate GetDigits after 5 Seconds */
tpt[ 2 ].tp_type = IO_EOT;
tpt[ 2 ].tp_termno = DX_MAXTIME;
tpt[ 2 ].tp_length = 50;
tpt[ 2 ].tp_flags = TF_MAXTIME;
index = get_index( dx_info->chdev );
if ( dx_getdig( dx_info->chdev, tpt, &( dx_info->digbuf ), EV_SYNC ) == -1 )
{
disp_err( hwnd, index, dx_info->chdev );
sprintf( tmpbuff[ index ], "dx_getdig failed on %s: %s",
ATDV_NAMEP( dx_info->chdev ), ATDV_ERRMSGP( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
return -1;
}
sprintf( tmpbuff[ index ], "Channel %d is Terminated by %d while in getting digits!",
index, ATDX_TERMMSK( dx_info->chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
if (ATDX_TERMMSK(dx_info->chdev) == TM_USRSTOP)
{
sprintf( tmpbuff[ index ], "Channel %d is Terminated by user stopped while in getting digits, stop_cause=%d!",
index, dx_info->stop_cause );
disp_msg( hwnd, tmpbuff[ index ] );
if ( dx_info->stop_cause == USER_STOP )
{
dx_info->stop_cause = NONE;
// return as if a failure occurred
return -1;
}
}
return 0;
}
/***************************************************************************
* NAME: int set_hkstate( *dx_info, state )
* DESCRIPTION: Set the channel to the appropriate hook status
* INPUT: DX_INFO dx_info; - DX_INFO structure pointer
* int state; - State to set channel to
* OUTPUT: None.
* RETURNS: -1 = Error
* 0 = Success
* CAUTIONS: None.
***************************************************************************/
int set_hkstate(DX_INFO *dx_info , int state )
{
int chdev = dx_info->chdev;
int tsdev = dx_info->tsdev;
int ldev = dx_info->ldev;
int index;
/*
* Make sure you are in CS_IDLE state before setting the
* hook status
*/
if ( ATDX_STATE( chdev ) != CS_IDLE )
{
dx_stopch( chdev, EV_SYNC );
while ( ATDX_STATE( chdev ) != CS_IDLE );
}
switch ( frontend )
{
case CT_NTANALOG:
index = get_index( chdev );
if ( dx_sethook( chdev, (state == DX_ONHOOK) ? DX_ONHOOK : DX_OFFHOOK,
EV_SYNC ) == -1 )
{
disp_err( hwnd, index, chdev );
sprintf( tmpbuff[ index ], "Cannot set channel %s to %s-Hook (%s)",
ATDV_NAMEP( chdev ), (state == DX_ONHOOK) ? "On" : "Off",
ATDV_ERRMSGP( chdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
return( -1 );
}
break;
case CT_NTT1:
index = get_index( tsdev );
if (state == DX_ONHOOK)
{
if ( dt_settssigsim( tsdev, DTB_AOFF|DTB_BOFF ) == -1 )
{
disp_err( hwnd, index, tsdev );
sprintf( tmpbuff[ index ], "Cannot set bits to %s on %s (%s)",
"AOFF-BOFF", ATDV_NAMEP( tsdev ), ATDV_ERRMSGP( tsdev ) );
disp_msg( hwnd, tmpbuff[ index ] );
return -1;
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -