📄 gatepstn.bak.txt
字号:
/**********************************************************************************************
*
* $ProjectName: X:\SIPROJ\VOIP\HOST\WIN_NT\DEMOS\VOIPGATE\PROJECT.PJ $
* $ProjectRevision: 1.5 $
* $Label$
* $Revision: 1.10 $ - $Date: 1997/08/17 10:58:28 $
*
**********************************************************************************************/
#define _GATEPSTN_C
/* The IPT H files are needed in this order: */
#include "GateDbg.h"
#include "PstnFP.h"
#include "GateStrc.h"
#include "GateVars.h"
///////////////////////////////////////////////////////
/// ///
/// DEFINITION OF GLOBAL FUNCTIONS ///
/// ///
///////////////////////////////////////////////////////
/*****FUNCTION***************************************************
* NAME : pstnGetVOXChannels
* DESCRIPTION : Gets the number of VOX channels available
* in the system
* INPUT : None
* OUTPUT : None
* RETURNS : Number of Voice channels
* CAUTIONS : None
****************************************************************/
USHORT pstnGetVOXChannels()
{
int boardNum = 0;
if ( frontEnd == GATE_LEGACY_ANALOG ) {
if(sr_getboardcnt(DEV_CLASS_VOICE,&boardNum) == -1) {
printf("Unable to get number of VOX boards.\n");
}
return((USHORT) (boardNum * VOX_CH));
}
else {
if(sr_getboardcnt(DEV_CLASS_DTI,&boardNum) == -1) {
printf("Unable to get number of DTI boards.\n");
}
return((USHORT) (boardNum * numtslots));
}
} /* Function pstnGetVOXChannels */
/*****FUNCTION***************************************************
* NAME : pstnOpenFrontEnd
* DESCRIPTION : Initialize front end
* INPUT : USHORT numTSC - Number of channels
* OUTPUT : None
* RETURNS : success or fail
* CAUTIONS : None
****************************************************************/
BOOL pstnOpenFrontEnd(USHORT numTSC)
{
USHORT index;
int brd;
int chan;
char devname[20];
SC_TSINFO tsInfo;
ULONG tsArray[1];
LONG errCode;
/* Tone detection variables for cadence for disconnect detection */
UINT unF1=620,
unF2=480,
unDev1=200,
unDev2=200,
unOnT=30,
unOffT=20,
unOnTDev=10,
unOffTDev=10,
unRepCt =3;
tsInfo.sc_tsarrayp = tsArray;
tsInfo.sc_numts = 1;
for(index = 1; index <= MAX_PSTN_DEVICES; index++) {
deviceToChannel[index] = 0;
}
switch(frontEnd) {
case GATE_LEGACY_ANALOG:
// For every channel
for ( index = 1; index <= numTSC; index++) {
brd = index/VOX_CH + 1;
chan = index%VOX_CH;
if (chan == 0) {
chan = VOX_CH;
brd--;
}
// Create channel device name
sprintf(devname, "dxxxB%dC%d",brd,chan);
// Attempt to open a timeslot device
if ((Session[index].PstnInfo.phoneDevice = dx_open(devname, 0)) == -1) {
gateFATAL(index,(Session[index].LogFile,"dx_open() failed for device \"%s\": errno = 0x%X\n",devname, errno));
return DM3FAIL;
}
deviceToChannel[Session[index].PstnInfo.phoneDevice] = index;
pstnSetLine((USHORT)index,PSTN_ONHOOK);
// Set the events to capture using Call Transition Status (CST)
if (dx_setevtmsk(Session[index].PstnInfo.phoneDevice,
DM_RINGS|DM_LCOFF) == -1 ) {
gateFATAL(index,(Session[index].LogFile,"Error setting event mask for channel %d\n",
Session[index].PstnInfo.phoneDevice));
return(DM3FAIL);
}
/* Set number of rings */
if (dx_setrings(Session[index].PstnInfo.phoneDevice,
numRings) == -1) {
gateFATAL(index,(Session[index].LogFile,"Error setting rings channel %d\n",
Session[index].PstnInfo.phoneDevice));
return(DM3FAIL);
}
// IMPORTANT! Set up tone detection for phone disconnect
// Set cadence for the PBX being used.
/* First delete old tones */
if(dx_deltones(Session[index].PstnInfo.phoneDevice)==-1) {
gateFATAL(index,(Session[index].LogFile,"\tError disabling old tones for channel %d\n",
Session[index].PstnInfo.phoneDevice));
return(DM3FAIL);
}
if(dx_blddtcad(DisconnectToneID,unF1,unDev1,unF2,unDev2,
unOnT,unOnTDev,unOffT,unOffTDev,unRepCt) == -1) {
gateFATAL(index,(Session[index].LogFile,"\tError setting tone cadence for channel %d\n",
Session[index].PstnInfo.phoneDevice));
}
// Set tone detection
if (dx_addtone(Session[index].PstnInfo.phoneDevice,NULL,0) == -1) {
errCode = ATDV_LASTERR(Session[index].PstnInfo.phoneDevice);
gateFATAL(index,(Session[index].LogFile,"\tError (%ld) setting tone detection for channel %d\n",errCode,
Session[index].PstnInfo.phoneDevice));
}
// End of add tone detection
// Get the TX timeslot of the R4 phone device and store it in the
// Demo structure.
if (ag_getxmitslot(Session[index].PstnInfo.phoneDevice, &tsInfo) == -1) {
errCode = ATDV_LASTERR(Session[index].PstnInfo.phoneDevice);
gateFATAL(index,(Session[index].LogFile,"\tError (%ld) getting TX Tslot for channel %d\n",errCode,
Session[index].PstnInfo.phoneDevice));
}
else {
Session[index].PstnInfo.pstnTxTSlot = (USHORT)tsArray[0];
}
} /* end for index */
break; // end GATE_LEGACY_ANALOG case
case GATE_LEGACY_T1:
case GATE_LEGACY_E1:
// For every network timeslot..
for (index = 1; index <= numTSC; index++) {
/*
* Open all devices and make sure they are not already listening
* to the SCbus by explicitly doing an unlisten. At application
* startup, the state of the device channels with relation to how
* they are routed to the SCbus is unknown.
*/
// Create timeslot (network) device name
brd = index/numtslots + 1;
chan = index%numtslots;
if ( chan == 0 ) {
chan = numtslots;
brd--;
}
sprintf(devname, "dtiB%dT%d", brd, chan);
// Attempt to open a timeslot device
if ((Session[index].PstnInfo.phoneDevice = dt_open(devname, 0)) == -1) {
gateFATAL(index,(Session[index].LogFile,"dt_open() failed for device \"%s\": errno = 0x%X\n",
devname, errno));
return DM3FAIL;
}
deviceToChannel[Session[index].PstnInfo.phoneDevice] = index;
if (dt_unlisten(Session[index].PstnInfo.phoneDevice) == -1) {
gateFATAL(index,(Session[index].LogFile,"dt_unlisten() failed for device \"%s\": errno = 0x%X\n",
devname, errno));
return DM3FAIL;
}
/*
* Set the event mask to DISABLE unsolicited of ALL events
* for which the application might get notification.
*/
if ( dt_setevtmsk(Session[index].PstnInfo.phoneDevice, DTG_SIGEVT,
DTMM_AON|DTMM_AOFF|DTMM_BON|DTMM_BOFF, DTA_SUBMSK) == -1 ) {
gateFATAL(index,(Session[index].LogFile,"dt_setevtmsk for disabling all events failed for device \"%d\": errno = 0x%X\n",
Session[index].PstnInfo.phoneDevice, errno));
return DM3FAIL;
}
/* Set the signalling mode to signal insertion */
if (dt_setsigmod(Session[index].PstnInfo.phoneDevice,
DTM_SIGINS) == -1) {
gateFATAL(index,(Session[index].LogFile,"dt_setsigmod failed for device \"%d\": errno = 0x%X\n",
Session[index].PstnInfo.phoneDevice, errno));
return DM3FAIL;
}
/*
* Make sure that the board is sending cleared signaling bits.
* The current signaling may be in an indetermined state. Be
* sure to present A & B low to the CO.
*/
if(frontEnd == GATE_LEGACY_T1) {
errCode = dt_settssigsim(Session[index].PstnInfo.phoneDevice,
DTB_AOFF|DTB_BOFF);
if (errCode == -1) {
gateFATAL(index,(Session[index].LogFile,"dt_settssigsim failed for device \"%d\": errno = 0x%X\n",
Session[index].PstnInfo.phoneDevice, errno));
return DM3FAIL;
}
}
/*
* Set the event mask to indicate for which unsolicited events the
* application needs notification. Prepare to receive all events by
* by ENABLing all the signalling events.
*/
if ( dt_setevtmsk(Session[index].PstnInfo.phoneDevice, DTG_SIGEVT,
DTMM_AON|DTMM_AOFF, DTA_SETMSK) == -1 ) {
gateFATAL(index,(Session[index].LogFile,"dt_setevtmsk (AON) failed for device \"%d\": errno = 0x%X\n",
Session[index].PstnInfo.phoneDevice, errno));
return DM3FAIL;
}
// Get the TX timeslot of the R4 phone device and store it in the
// demo Session structure.
if (dt_getxmitslot(Session[index].PstnInfo.phoneDevice,
&tsInfo) == -1) {
errCode = ATDV_LASTERR(Session[index].PstnInfo.phoneDevice);
gateFATAL(index,(Session[index].LogFile,"\tError (%ld) getting TX Tslot for channel %d\n",errCode,
Session[index].PstnInfo.phoneDevice));
}
else {
Session[index].PstnInfo.pstnTxTSlot = (USHORT)tsArray[0];
}
} // for index i = 1,.. till all channels.
break;
default:
printf("Default telephone card not set.\n");
break;
} /* end switch on front end type */
return(DM3SUCCESS);
} /* Function pstnOpenFrontEnd */
/*****FUNCTION***************************************************
* NAME : pstnState
* DESCRIPTION : Checks pstn state
* INPUT : USHORT channel - Channel to set hook
* OUTPUT : None
* RETURNS : TRUE - channel is off hook
* FALSE - channel is on hook
* CAUTIONS : None
****************************************************************/
BOOL pstnState(USHORT channel)
{
long tsBits;
int aState;
tsBits = ATDT_TSSGBIT(Session[channel].PstnInfo.phoneDevice);
if(tsBits == AT_FAILURE) {
gateERROR(channel,(Session[channel].LogFile,"Getting PSTN state failed.\n"));
}
aState = tsBits & DTSG_RCVA;
if( (frontEnd == GATE_LEGACY_T1) && aState) {
gateTRACE(channel,(Session[channel].LogFile,"channel %d off hook.\n",channel));
return TRUE; // A bit on is T1 - Off hook
}
if( (frontEnd == GATE_LEGACY_T1) && !aState) {
gateTRACE(channel,(Session[channel].LogFile,"channel %d on hook.\n",channel));
return FALSE; // A bit off is T1 - On hook
}
if( (frontEnd == GATE_LEGACY_E1) && aState) {
gateTRACE(channel,(Session[channel].LogFile,"channel %d on hook.\n",channel));
return FALSE; // A bit on is E1 - On hook
}
if( (frontEnd == GATE_LEGACY_E1) && !aState) {
gateTRACE(channel,(Session[channel].LogFile,"channel %d off hook.\n",channel));
return TRUE; // A bit off is E1 - Off hook
}
}
/*****FUNCTION***************************************************
* NAME : pstnSetLine
* DESCRIPTION : Sets phone line on hook or off hook
* INPUT : USHORT channel - Channel to set hook
* USHORT on - On hook or off hook
* OUTPUT : None
* RETURNS : Success or fail
* CAUTIONS : None
****************************************************************/
BOOL pstnSetLine(USHORT channel, USHORT on)
{
if ( frontEnd == GATE_LEGACY_ANALOG ) {
if (dx_sethook(channel,on,EV_SYNC) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"dx_sethook failed on channel %s\n",ATDV_NAMEP(channel) ));
gateFATAL(channel,(Session[channel].LogFile,"\tError making call on device\n"));
return(DM3FAIL);
}
}
else {
if (dt_settssigsim(channel, on) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"dt_settssigsim failed on channel %s\n",ATDV_NAMEP(channel) ));
gateFATAL(channel,(Session[channel].LogFile,"\tError making call on device\n"));
return(DM3FAIL);
}
}
return (DM3SUCCESS);
} /* Function pstnSetLine */
/*****FUNCTION***************************************************
* NAME : pstnGetDigits
* DESCRIPTION : Gets phone number to dial,
* in case of Analog front-end
* INPUT : channel, the event device
* OUTPUT : none
* RETURNS : none
* CAUTIONS : none
****************************************************************/
BOOL pstnGetDigits(USHORT channel)
{
DV_TPT digtpt;
DV_DIGIT digit;
int numofdigits;
if (dx_clrdigbuf(channel) == -1) {
gateERROR(channel,(Session[channel].LogFile,"\tDigit Buffer not cleared on %s\n",ATDV_NAMEP(channel)));
}
// Set up digit TPT structure for collecting digits.
dx_clrtpt(&digtpt,1);
digtpt.tp_type = IO_EOT;
digtpt.tp_termno = DX_DIGMASK;
digtpt.tp_length = DM_P;
digtpt.tp_flags = TF_DIGMASK;
digtpt.tp_data = 0;
gateTRACE(channel, (Session[channel].LogFile,"%s: Getting analog phone digits\n",
ATDV_NAMEP(channel)));
// Get remote phone number to dial
gateTRACE(channel, (Session[channel].LogFile,"Enter number to dial, ending with \"#\" key\n"));
if ( dx_getdig(channel,&digtpt,&digit,EV_SYNC) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"dx_getdig failed on channel %s\n",ATDV_NAMEP(channel) ));
gateFATAL(channel,(Session[channel].LogFile,"\tError getting digits on device\n"));
return(DM3FAIL);
}
// Fill in the digits received into Session structure for sending
// them to the remote side to dial out.
numofdigits = strlen(digit.dg_value) - 1;
ZeroMemory(&(Session[channel].ConfigFileParm.phoneList),
sizeof(Session[channel].ConfigFileParm.phoneList));
Session[channel].ConfigFileParm.phoneList[0] = '\0';
strncpy(Session[channel].ConfigFileParm.phoneList,digit.dg_value,numofdigits);
return (DM3SUCCESS);
} /* Function pstnGetDigits */
/*****FUNCTION***************************************************
* NAME : pstnDial
* DESCRIPTION : Dials using the D/xxx card
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -