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

📄 gatepstn.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	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_ASYNC) == -1) { //98.6.10 由同步方式改为异步方式
          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 : pstnPlayVox
* DESCRIPTION : play the vox file to the specified channel
*               
*       INPUT : channel, handle of the vox file
*      OUTPUT : none
*     RETURNS : none
*    CAUTIONS : none
*    WRITTEN by XUZQ 98.5.19
****************************************************************/
BOOL pstnPlayVox(USHORT channel)
{
	
/* use fuction dx_playvox 总是有系统错误!*/
/*	USHORT chdev;   //通道句柄 
	DV_TPT tpt;  //结束参数表

	// 得到通道句柄
    chdev=channel;


	// 得到一个按键就停止播放vox文件 
    tpt.tp_type   = IO_EOT;
    tpt.tp_termno = DX_MAXDTMF;
    tpt.tp_length = 1;
    tpt.tp_flags  = TF_MAXDTMF;

    // 开始播放
    if (dx_playvox(chdev,&tpt,"intro.VOX",NULL,EV_SYNC) == -1) {
          gateFATAL(channel,(Session[channel].LogFile,"%s: 播放声音文件时遇到错误!",ATDV_ERRMSGP(channel)));
		  }
     return(DM3FAIL);


	gateTRACE(channel,(Session[channel].LogFile,"%s:播放声音文件成功!",ATDV_NAMEP(channel)));

	return(DM3SUCCESS); */

/* use function dx_playiotdata 经过测试成功!*/  
	
   int chdev;
   DX_IOTT iott;
   DV_TPT  tpt;

   chdev=Session[channel].PstnInfo.phoneDevice;   
    /* route the VOX to LSI */
   //if (nr_scroute(chdev,SC_LSI,chdev,SC_VOX,SC_FULLDUP)==-1) {
   //    gateFATAL(channel,(Session[channel].LogFile,"channel %d: 连接模拟和话音通道时遇到错误!",channel));
	//   return(DM3FAIL);
   //}
    
   // set up DX_IOTT 
   iott.io_type = IO_DEV|IO_EOT;
   iott.io_bufp = 0;
   iott.io_offset = 0;
   iott.io_length = -1;  // play till end of file

   if((iott.io_fhandle = dx_fileopen("intro.vox", O_RDONLY|O_BINARY)) == -1)  {
	   gateFATAL(channel,(Session[channel].LogFile,"channel %d: 打开播放声音文件时遇到错误!",channel));
	   return(DM3FAIL);
	      }
   // set up DV_TPT 
   
   tpt.tp_type   = IO_EOT;          // only entry in the table 
   tpt.tp_termno = DX_MAXDTMF;      // Maximum digits 
   tpt.tp_length = 1;               // terminate on one digits 
   tpt.tp_flags  = TF_MAXDTMF;      // Use the default flags 

   // Now play the file 
    if (dx_play(chdev,&iott,&tpt,EV_SYNC) == -1) {
	   gateFATAL(channel,(Session[channel].LogFile,"channel %d: 播放声音文件时遇到错误!",channel));
       return(DM3FAIL);
   }
      
    if (dx_fileclose(iott.io_fhandle) == -1) {
       gateFATAL(channel,(Session[channel].LogFile,"channel %d: 关闭声音文件时遇到错误!",channel));
	   return(DM3FAIL);
   }
       return(DM3SUCCESS);
} /* Function pstnPlayVox */



/*****FUNCTION***************************************************
*        NAME : pstnDial
* DESCRIPTION : Dials using the D/xxx card
*       INPUT : USHORT channel   -  Channel to make the dialing on 
*               PCHAR dialString -  Extention to dial to
*      OUTPUT : 
*      MODIFIED BY XUZQ 98.6.11
*     RETURNS : TRUE - success, FALSE - fail
*    CAUTIONS : None
****************************************************************/
BOOL pstnDial(USHORT channel, PCHAR dialString)
{
   int rc;
    DX_CAP capp;

	  // Clear DX_CAP structure
      dx_clrcap(&capp);
	  capp.ca_nbrdna = 8;

   /* Dialing */
   rc = dx_dial(Session[channel].PstnInfo.phoneDevice,dialString,&capp,DX_CALLP|EV_ASYNC);

   if(rc < 0) {
      gateFATAL(channel,(Session[channel].LogFile,"\tError dialing in pstnDial(..) on channel %d\n", channel));
      return(DM3FAIL);
   } 

   return (DM3SUCCESS);

} /* Function pstnDial */


/*****FUNCTION***************************************************
*        NAME : pstnCloseFrontEnd
* DESCRIPTION : Closes front end hardware
*       INPUT : USHORT channel   -  Channel to close
*      OUTPUT : None
*     RETURNS : TRUE - success, FALSE - fail
*    CAUTIONS : None
****************************************************************/
BOOL pstnCloseFrontEnd(USHORT channel)
{

   USHORT index;

   if ( channel == ALL_CHANNELS ) {
      for (index = 1; index <= gateChannels; index++) {
         if (closePstnChannel(index) == DM3FAIL) 
            return(DM3FAIL);
      } 
   }
   else {   /* Closes a specific channel */
      if (closePstnChannel(channel) == DM3FAIL) {
         return(DM3FAIL);
      }
   }

   return (DM3SUCCESS);

} /* Function pstnCloseFrontEnd */

/*****FUNCTION***************************************************
*        NAME : pstnGetXMitSlot
* DESCRIPTION : Get transmit timeslot for given channel
*       INPUT : USHORT channel   -  Channel to get its transmit TS 
*               UINT *timeslot   -  Time slot
*      OUTPUT : UINT *timeslot   -  Time slot the channel transmit on
*     RETURNS : TRUE - success
*    CAUTIONS : None
****************************************************************/
BOOL pstnGetXMitSlot(USHORT channel, UINT *pTimeslot)

{
   *pTimeslot = Session[channel].PstnInfo.pstnTxTSlot;
   return(DM3SUCCESS);

} /* Function pstnGetXMitSlot */


/*****FUNCTION***************************************************
*        NAME : pstnListen
* DESCRIPTION : Listen to a given timeslot
*       INPUT : USHORT channel  
*               UINT timeslot    -  Time slot to listen to
*      OUTPUT : None
*     RETURNS : TRUE - success, FALSE - fail
*    CAUTIONS : None
****************************************************************/
BOOL pstnListen(USHORT channel, UINT timeslot)

{
   int         rc; 
   SC_TSINFO   tsInfo;
   ULONG       tsArray[1];


   /* Set the timeslot */
   tsArray[0] = timeslot;

   /* Set SC structure to point to timeslot */
   tsInfo.sc_tsarrayp = tsArray;
   tsInfo.sc_numts = 1;
   
   // switch on front end
   switch(frontEnd) {

     case GATE_LEGACY_ANALOG:
      
         // Listen
         if ( (rc = ag_listen(Session[channel].PstnInfo.phoneDevice,
                              &tsInfo)) == -1) {
            gateFATAL(channel,(Session[channel].LogFile,"\tError in ag_listen on channel %d\n",channel));
         }
         
         gateTRACE(channel, (Session[channel].LogFile,"\t ag_listen on channel %d\n",channel));
   
         break;

     case GATE_LEGACY_T1:
     case GATE_LEGACY_E1:
      
         if ( (rc = dt_listen(Session[channel].PstnInfo.phoneDevice,
                              &tsInfo)) == -1) {         // error
            gateFATAL(channel,(Session[channel].LogFile,"\tError in dt_listen on channel %d\n",channel));
         }
         
         gateTRACE(channel, (Session[channel].LogFile,"\t dt_listen on channel %d\n",channel));
   
         break;

     default:
         break;

   } /* end switch(frontEnd) */


   return(DM3SUCCESS);

} /* Function pstnListen */


/*****FUNCTION***************************************************
*        NAME : pstnUnListen
* DESCRIPTION : UnListen on a given channel, and relisten to default

⌨️ 快捷键说明

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