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

📄 gatepstn.c

📁 dialogic voip 测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************************************

* 

* $ProjectName: X:/SIPROJ/VOIP/HOST/WIN_NT/DEMOS/Samples.rel5/Dm3/Iplink/project.pj $

* $ProjectRevision: 1.5 $

* $Label$

* $Revision: 1.9 $ - $Date: 2001/12/02 10:34:28 $

* 

**********************************************************************************************/



#define  _GATEPSTN_C               





/* The IPT H files are needed in this order: */

#include <libdbg.h>

#include "gatepstn.h"             

#include "gatestrc.h"             

#include "gatevars.h"

#include "gatedefs.h"

#include "incfile.h"

#include <stdlib.h>







/*****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

****************************************************************/

unsigned int pstnGetVOXChannels()			

{

	int       boardNum = 0;

	unsigned int    channel = 1; 

	unsigned int    channelNum = 0;

	unsigned int    networkChannel = 0;

	unsigned int    voiceChannel = 0;

	unsigned short    index;

    unsigned int   NumChannlesOnBoard = 0;

	int       boardH;

	char      brdname[64]; 

	

        

	if ( frontEnd == GATE_LEGACY_ANALOG ) {

		if (PDLsr_getboardcnt(&boardNum,"",2) == -1)

			printf("%s"," ***** Error: PDLsr_getboardcnt failed to get analog boards *****\n");		   

		else{

			printf("\n<<Number of VOICE boards found: %d >>\n",boardNum);

		 

			for ( index = 1; index <= boardNum; index++) {

				sprintf(brdname, "dxxxB%d",index);

				if ((boardH = dx_open(brdname, 0)) < 0){

					printf("%s"," ***** Error: dx_open failed to get analog board handle *****\n");

				}

				else{

					

					/* Find Num channels per board */

					NumChannlesOnBoard = ATDV_SUBDEVS(boardH);

						

					/* Add the num channels on the board to total PSTN channels */

					channelNum += NumChannlesOnBoard;

						

					channel = 1;

					while (channel <= NumChannlesOnBoard){

					    	Session[channelNum - NumChannlesOnBoard + channel].pstnParams.BoardNum = index;

                            Session[channelNum - NumChannlesOnBoard + channel].pstnParams.ChanNum = channel;

					        channel++;

					}

					

					if(dx_close(boardH) <0){

						printf("%s"," ***** Error: failed to call dx_close*****\n");

					}

				} 

			}

		}

	}

	else {

		if (PDLsr_getboardcnt(&boardNum,"",3) == -1)

			printf("%s"," ***** Error: PDLsr_getboardcnt failed to get digital boards *****\n");

		else{

				printf("\n<<Number of DTI boards found: %d >>\n",boardNum);



			for ( index = 1; index <= boardNum; index++) {

				sprintf(brdname, "dtiB%d",index);

				if ((boardH = dt_open(brdname, 0)) < 0)

					printf("%s"," ***** Error: dt_open failed to get digital board handle *****\n");

		        else{

						

						/* Find Num channels per board */

						NumChannlesOnBoard = ATDV_SUBDEVS(boardH);

						

						/* Add the num channels on the board to total PSTN channels */

						networkChannel += NumChannlesOnBoard;

						

						channel = 1;

						while (channel <= NumChannlesOnBoard){

					    	Session[networkChannel - NumChannlesOnBoard + channel].pstnParams.BoardNum = index;

                            Session[networkChannel - NumChannlesOnBoard + channel].pstnParams.ChanNum = channel;

					        channel++;

						}



					if(dt_close(boardH) <0){ 

						printf("%s"," ***** Error: failed to call dt_close *****\n");

					}

				}

			}

		}

		boardNum = 0;

        if (PDLsr_getboardcnt(&boardNum,"",2) == -1)

			printf("%s"," ***** Error: PDLsr_getboardcnt failed to get voice boards *****\n");		   

		else{

			printf("\n<<Number of VOICE boards found: %d >>\n",boardNum);

		 

			for ( index = 1; index <= boardNum; index++) {

				sprintf(brdname, "dxxxB%d",index);

				if ((boardH = dx_open(brdname, 0)) < 0){

					printf("%s"," ***** Error: dx_open failed to get voice board handle *****\n");

				}

				else{

					

					/* Find Num channels per board */

					NumChannlesOnBoard = ATDV_SUBDEVS(boardH);

						

					/* Add the num channels on the board to total PSTN channels */

					voiceChannel += NumChannlesOnBoard;

						

					channel = 1;

					while (channel <= NumChannlesOnBoard){

					    	Session[voiceChannel - NumChannlesOnBoard + channel].voiceParams.BoardNum = index;

                            Session[voiceChannel - NumChannlesOnBoard + channel].voiceParams.ChanNum = channel;

					        channel++;

					}

					

					if(dx_close(boardH) <0){

						printf("%s"," ***** Error: failed to call dx_close*****\n");

					}

				} 

			}

		}

		

       channelNum = (networkChannel <= voiceChannel) ? networkChannel : voiceChannel; 

	}

	PSTNNumOfBoards = boardNum;

	return((unsigned int) (channelNum));



} /* Function pstnGetVOXChannels */







/*****FUNCTION***************************************************

*        NAME : pstnOpenFrontEnd

* DESCRIPTION : Initialize front end

*       INPUT : None

*      OUTPUT : None

*     RETURNS : success or fail

*    CAUTIONS : None

****************************************************************/

int pstnOpenFrontEnd()

{



    unsigned int      index;

    unsigned int      chan;

	int       brd;

    unsigned int      chanVoice;

	int       brdVoice;

    char      devname[50];

    SC_TSINFO tsInfo;

    unsigned long	 tsArray[1];

    char      errmsg[MSGLENGTH];

    long      errCode;



    int       oldBoard =1;



    tsInfo.sc_tsarrayp = tsArray;

    tsInfo.sc_numts = 1;

	switch(frontEnd) {



		case GATE_LEGACY_ANALOG:



			    /* For every channel  */

            for ( index = 1; index <= gateChannels; index++) {

								    

                gateTRACE(index,_logLevel,Session[index].LogFile, (Session[index].LogFile,"\t   Start pstnOpenFrontEnd function on channel %d\n",index));

				brd = Session[index].pstnParams.BoardNum;

                chan = Session[index].pstnParams.ChanNum;



				sprintf(devname, ":P_%s:V_dxxxB%dC%d", pstnProtocol, brd, chan);

				if (gc_OpenEx(&(Session[index].pstnParams.linedev), devname, 0,(void *)&Session[index])<0) {

					printGCError("gc_OpenEx",index,Session[index].LogFile,_logLevel);

					return FUNCFAIL;

				}





				if (gc_LoadDxParm(Session[index].pstnParams.linedev,VCP_FILE,errmsg,MSGLENGTH)!=0){

					printGCError("gc_ErrorValue",index,Session[index].LogFile,_logLevel);

					return FUNCFAIL;

				}





				if (gc_GetVoiceH(Session[index].pstnParams.linedev, &Session[index].pstnParams.VoiceH)<0){

                    printGCError("gc_GetVoiceH",index ,Session[index].LogFile,_logLevel);

				    return FUNCFAIL;

				}



				/*Get the TX timeslot of the pstn phone device and store it in the

   	               demo Session structure. */

				if (ag_getxmitslot(Session[index].pstnParams.VoiceH, &tsInfo) == -1) {

					 errCode = ATDV_LASTERR(Session[index].pstnParams.VoiceH);

                     gateFATAL(index,_logLevel,Session[index].LogFile,(Session[index].LogFile,"\tError (%ld) getting TX Tslot for channel %d\n",errCode,

                     Session[index].pstnParams.VoiceH));

				}else {

     		         Session[index].pstnParams.TxTSlot = (unsigned short)tsArray[0];

				}

   				gateTRACE(index,_logLevel,Session[index].LogFile, (Session[index].LogFile,"\t   End of pstnOpenFrontEnd function on channel %d\n",index));



			} /* end for index */



            break; /* end GATE_LEGACY_ANALOG case */





	    case GATE_T1:

        case GATE_E1:



			/* For every network timeslot..	 */

			for (index = 1; index <= gateChannels; index++)  {



				gateTRACE(index,_logLevel,Session[index].LogFile, (Session[index].LogFile,"\t   Start pstnOpenFrontEnd function on channel %d\n",index));

			   	brd = Session[index].pstnParams.BoardNum;

                chan = Session[index].pstnParams.ChanNum;



               

                brdVoice = Session[index].voiceParams.BoardNum;

                chanVoice = Session[index].voiceParams.ChanNum;

                   		

                sprintf(devname, ":N_dtiB%dT%d:P_%s:V_dxxxB%dC%d", brd, chan, pstnProtocol, brdVoice, chanVoice);

			/* Attempt to open a timeslot device */

				if (gc_OpenEx(&(Session[index].pstnParams.linedev), devname, 0, (void *)&Session[index])<0) {

                    printGCError("gc_OpenEx",index,Session[index].LogFile,_logLevel); 

				    return FUNCFAIL;

				}

	

				if (gc_GetNetworkH(Session[index].pstnParams.linedev, &Session[index].pstnParams.NetwH)<0){

                    printGCError("gc_GetNetworkH",index,Session[index].LogFile,_logLevel); 

				    return FUNCFAIL;

				}

                if (gc_GetVoiceH(Session[index].pstnParams.linedev, &Session[index].pstnParams.VoiceH)<0){

                    printGCError("gc_GetVoiceH",index ,Session[index].LogFile,_logLevel);

				    return FUNCFAIL;

				}

					 

				

				/*Get the TX timeslot of the R4 phone device and store it in the

   	                demo Session structure. */

				if ( dt_getxmitslot(Session[index].pstnParams.NetwH,&tsInfo) == -1){

				    gateFATAL(index,_logLevel,Session[index].LogFile,(Session[index].LogFile,"\tError dx_getxmitslot on channel %d\n",index));

					return FUNCFAIL;

				}else {

     		        Session[index].pstnParams.TxTSlot = (unsigned short)tsArray[0];

				}



				gateTRACE(index,_logLevel,Session[index].LogFile, (Session[index].LogFile,"\t   End of pstnOpenFrontEnd function on channel %d\n",index));

⌨️ 快捷键说明

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