📄 gatepstn.c
字号:
/**********************************************************************************************
*
* $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"
// add for dx_fileopen RDONLY and BINARY
#include <fcntl.h>
// add for function nr_scroute
#include "sctools.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));
//}
// Modified by xuzq 98.5.12 中国邮电标准挂机信号!!
if(dx_bldstcad(DisconnectToneID,500,200,55,40,55,40,2) == -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
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -