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

📄 gc_basic_call_model.c

📁 dialogic 板卡globalcall 测试代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	} else {
		switch (value)
		{
			case GCCT_CAD :
				strcpy(str, "call connected - cadence break");
				break;

			case GCCT_LPC :
				strcpy(str, "call connected - loop current drop");
				break;

			case GCCT_PVD :
				strcpy(str, "call connected - voice detection");
				break;

			case GCCT_PAMD :
				strcpy(str, "call connected - answering machine");
				break;

			case GCCT_FAX :
				strcpy(str, "call connected - FAX machine");
				break;

			case GCCT_NA :
				strcpy(str, "call connected - call progress not applicable");
				break;
	
			default :
				strcpy(str, "call connected - unknown connect type");
				break;
		}
	}
	printandlog(pline->index, MISC, NULL, str); 

	pline->call_state = GCST_CONNECTED;
	pline->numb_calls++;							/* Increment the total calls on this device */
	out_calls++;									/* Increment the total outbound calls on all devices */
	outbound_application(pline);				/* call your application specific code here */
}

/****************************************************************
*			NAME: open_all_devices(void)
* DESCRIPTION: Routine calls the specific technology function, which
*					opens all the line devices. 
*		  INPUT: None
*		RETURNS: None - exits if error
*	  CAUTIONS: none
****************************************************************/
void open_all_devices(void)
{
	int	index;

	for (index = 0; index < num_devices; index++) { 
		open_device(index);
	}
}
/****************************************************************
*			NAME: open_devices(int index)
* DESCRIPTION: Routine calls the specific technology function, which
*					opens all specific line device. 
*		  INPUT: index - index into port data structure
*		RETURNS: None - exits if error
*	  CAUTIONS: Since multiple paths here, will init run-time fields of port data structure
****************************************************************/
void open_device(int index)
{
	/* reset run-time variables that might now be wrong */
	port[index].ldev = 0;
	port[index].crn = 0;
	port[index].index = index;
	port[index].call_state = GCST_NULL;
	port[index].blocked = YES;
	port[index].waitcall_active = NO;	
	port[index].dropcall_active = NO;	
	port[index].resetlinedev_active = NO;	
	port[index].resetlinedev_required_after_unblocked = NO;	
	port[index].dropcall_time = 0;


	if ((strcmp(port[index].protname, "isdn") == 0) ||
		(strcmp(port[index].protname, "ISDN") == 0)) {
		gc_demo_open_isdn_channel(index);
	} else if ((strstr(port[index].protname, "ss7") != NULL) ||
		(strstr(port[index].protname, "SS7") != NULL)) {
		gc_demo_open_ss7_channel(index);
	} else if ((strstr(port[index].protname, "_AN_") != NULL) ||
		(strstr(port[index].protname, "_an_") != NULL)) {
		gc_demo_open_analog_channel(index);
	} else {								/* assume everything else is E1 or T1 */
											/* if wrong, then gc_OpenEx() will fail */
		gc_demo_open_E1orT1_channel(index);
	}
}

/****************************************************************
*			NAME: gc_demo_makecall(index)
* DESCRIPTION: Routine calls the gc_Makecall() function if not blocked and there is not a call active
*		  INPUT: index into port[] for this channel
*		RETURNS: exits with exitdemo() if not successful
*	  CAUTIONS: none
****************************************************************/
void gc_demo_makecall(int index)
{
	char					str[MAX_STRING_SIZE];
	struct channel		*pline;
	GC_MAKECALL_BLK	*makecallblkp;				/* Variable for MAKECALL block */		

	pline = &port[index];
	if (pline->blocked == YES) {
		return;											/* cannot make a call until unblocked */
	}

	if (pline->makecall_active == YES) {
		printandlog(index, MISC, NULL, "Trying to make a call while makecall is already active\n");
		return;
	}

	/* if the makecall block has been initialized, use it */
	/* else use NULL for the makecall block pointer */
	makecallblkp = (pline->makecallblk.gclib != NULL) ? &pline->makecallblk : NULL;

	if (gc_MakeCall(pline->ldev, &pline->crn, pline->destination_num, makecallblkp, pline->makecall_timeout, EV_ASYNC) != GC_SUCCESS) {
		sprintf(str, "gc_MakeCall(linedev=%ld, numberstr=%s, mode=EV_ASYNC) Failed", pline->ldev, pline->destination_num);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	pline->makecall_active = YES;					/* indicate there is a call active */
	sprintf(str, "gc_MakeCall(linedev=%ld, numberstr=%s, mode=EV_ASYNC) Success", pline->ldev, pline->destination_num);
	printandlog(index, GC_APICALL, NULL, str);
} /* End of Function */

/****************************************************************
*			NAME: gc_demo_open_isdn_channel(index)
* DESCRIPTION: initialize a port used by an ISDN protocol
*		  INPUT: index into port[] for this channel
*		RETURNS: exits with exitdemo() if not successful
*	  CAUTIONS: none
****************************************************************/
void gc_demo_open_isdn_channel(int index)
{
	char						str[MAX_STRING_SIZE];
	GCLIB_MAKECALL_BLK	*gclib_makecallp;
	GC_PARM_BLKP			parmblkp = NULL;


	printandlog(index, MISC, NULL, "ISDN device being opened");

	/* initialize the flag blocked to YES */
	port[index].blocked = YES; 
	port[index].techtype = ISDN;
	port[index].call_state = GCST_NULL;
	port[index].makecall_timeout = 0;							/* timeout parameter is ignored for ISDN */

	/* initializes the GC_PARM_BLK with the respective set_id, parm_id and the value */
	/*To set the bearer channel transfer mode information */
	gc_util_insert_parm_val(&parmblkp, GCIS_SET_BEARERCHNL, GCIS_PARM_TRANSFERMODE, 
		sizeof(int), ISDN_ITM_CIRCUIT);

	/*To set the bearer channel transfer rate information */
	gc_util_insert_parm_val(&parmblkp, GCIS_SET_BEARERCHNL, GCIS_PARM_TRANSFERRATE, 
		sizeof(int), BEAR_RATE_64KBPS);

	/*To set Layer 1 protocol to use on bearer channel */
	gc_util_insert_parm_val(&parmblkp, GCSET_CHAN_CAPABILITY, GCPARM_TYPE, 
		sizeof(int), GCCAPTYPE_AUDIO);

	/*To set Layer 1 protocol to use on bearer channel */
	gc_util_insert_parm_val(&parmblkp, GCSET_CHAN_CAPABILITY, GCPARM_CAPABILITY, 
		sizeof(int), GCCAP_AUDIO_g711Alaw64k);

	/*To set User rate to use on bearer channel (layer 1 rate)*/
	gc_util_insert_parm_val(&parmblkp, GCSET_CHAN_CAPABILITY, GCPARM_RATE, 
		sizeof(int), GCCAPRATE_DEFAULT);

	/*To support the specific feature or service requested from the network */
	gc_util_insert_parm_val(&parmblkp, GCIS_SET_FACILITY, GCIS_PARM_FACILITY_CODINGVALUE, 
		sizeof(int), 0x03);

	/*To support the specific feature or service requested from the network */
	gc_util_insert_parm_val(&parmblkp, GCIS_SET_FACILITY, GCIS_PARM_FACILITY_FEATURESERVICE, 
		sizeof(int), ISDN_SERVICE);
		
	/* Note: gclib_makecallp is not freed since a "permanent" data */
	/* structure. Assume program exit will free the resource			*/
	gclib_makecallp = (GCLIB_MAKECALL_BLKP)
		malloc(sizeof(GCLIB_MAKECALL_BLK) + parmblkp->parm_data_size);
	if (gclib_makecallp == NULL) {
		printandlog(ALL_DEVICES, MISC, NULL, "Could not allocate memory\n");
		exitdemo(1);
	}
	port[index].makecallblk.cclib = NULL;
	port[index].makecallblk.gclib = gclib_makecallp;

  /* Set the extra data in the makecall block */
  gclib_makecallp->ext_datap = parmblkp;

	/* Set the called number plan to ISDN type  */
	gclib_makecallp->destination.address_plan = GCADDRPLAN_ISDN;

	/* Set the called number plan to ISDN type  */
	gclib_makecallp->destination.address_type = GCADDRTYPE_NAT;
	strcpy(gclib_makecallp->destination.sub_address, "456");
	gclib_makecallp->destination.sub_address_plan = 0;
	gclib_makecallp->destination.sub_address_type = GCSUBADDR_OSI;
		
	strcpy(gclib_makecallp->origination.address, "7654321");

	/* Set the calling number plan to ISDN type	*/
	gclib_makecallp->origination.address_plan = GCADDRPLAN_ISDN;

	/* Set the calling number plan to ISDN type	*/
	gclib_makecallp->origination.address_type = GCADDRTYPE_NAT;
	strcpy(gclib_makecallp->origination.sub_address, "456");
	gclib_makecallp->origination.sub_address_plan = 0;
	gclib_makecallp->origination.sub_address_type = GCSUBADDR_OSI;
	
	gclib_makecallp->call_info.address_info = GCADDRINFO_ENBLOC;
	
	/* Open the line device */
	if (gc_OpenEx(&port[index].ldev, port[index].devname, EV_SYNC, (void *)&port[index]) != GC_SUCCESS) {
		sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Failed", port[index].devname);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Success", port[index].devname);
	printandlog(index, GC_APICALL, NULL, str);

	/* Due to implementation, must wait until get GCEV_UNBLOCKED before issueing the reset linedevice */
	port[index].resetlinedev_required_after_unblocked = YES;
} /* End of Function */

/****************************************************************
*			NAME: gc_demo_open_analog_channel(index)
* DESCRIPTION: initialize a port used by an ANAPI protocol
*		  INPUT: index into port[] for this channel
*		RETURNS: exits with exitdemo() if not successful
*	  CAUTIONS: none
****************************************************************/
void gc_demo_open_analog_channel(int index)
{
	char		str[MAX_STRING_SIZE], msgbuffer[MAX_STRING_SIZE];


	printandlog(index, MISC, NULL, "Analog device being opened");

	/* initialize the flag blocked to YES */
	port[index].blocked = YES; 
	port[index].techtype = ANALOG;
	port[index].call_state = GCST_NULL;
	port[index].makecall_timeout = 60;
	
	if (gc_OpenEx(&port[index].ldev, port[index].devname, EV_SYNC, (void *)&port[index]) != GC_SUCCESS) {
		sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Failed", port[index].devname);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	
	sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Success", port[index].devname);
	printandlog(index, GC_APICALL, NULL, str);

	if ((gc_LoadDxParm(port[index].ldev,"dxchan.vcp", msgbuffer, MAX_STRING_SIZE)) !=0) {
		sprintf(str, "gc_LoadDxParm(linedev=%ld) Failed)%s)", port[index].ldev, msgbuffer);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	sprintf(str, "gc_LoadDxParm(linedev=%ld) Success)", port[index].ldev);
	printandlog(index, MISC, NULL, str);

	/* Some implementations do not reset (i.e. go on-hook) if line is off-hook at open time */
	if (gc_ResetLineDev(port[index].ldev, EV_ASYNC) != GC_SUCCESS) {
		sprintf(str, "gc_ResetLineDev(linedev=%ld, EV_ASYNC) Failed", port[index].ldev);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}

	port[index].resetlinedev_active = YES;
	sprintf(str, "gc_ResetLineDev(linedev=%ld, EV_ASYNC) Success", port[index].ldev);
	printandlog(index, GC_APICALL, NULL, str);
} /* End of Function */

/****************************************************************
*			NAME: gc_demo_open_E1orT1_channel(index)
* DESCRIPTION: initialize a port used by an E1 or T1 protocol
*		  INPUT: index into port[] for this channel
*		RETURNS: exits with exitdemo if not successful
*	  CAUTIONS: none
****************************************************************/
void gc_demo_open_E1orT1_channel(int index) 
{
	char		str[MAX_STRING_SIZE]; 

	printandlog(index, MISC, NULL, "E1 or T1 device being opened");

	/* initialize the flag blocked to YES */
	port[index].blocked = YES; 
	port[index].techtype = E1ORT1;
	port[index].call_state = GCST_NULL;
	port[index].makecall_timeout = 60;							/* Use 1 minute */
	
	if (gc_OpenEx(&port[index].ldev, port[index].devname, EV_SYNC, (void *)&port[index]) != GC_SUCCESS) {
		sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Failed", port[index].devname);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	
	sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Success", port[index].devname);
	printandlog(index, GC_APICALL, NULL, str);

	set_calling_num(&port[index], "7654321");

} /* End of function */

/****************************************************************
*			NAME: gc_demo_open_ss7_channel(index)
* DESCRIPTION: initialize a port used by an SS7 protocol
*		  INPUT: index into port[] for this channel
*		RETURNS: exits with exitdemo if not successful
*	  CAUTIONS: none
****************************************************************/
void gc_demo_open_ss7_channel(int index)
{
	char		str[MAX_STRING_SIZE];
	

	printandlog(index, MISC, NULL, "SS7 device being opened");

	/* initialize the flag blocked to YES */
	port[index].blocked = YES; 
	port[index].techtype = SS7;
	port[index].call_state = GCST_NULL;
	port[index].makecall_timeout = 60;							/* timeout is supported, try 1 minute */
	
	/* 
	NOTE:
	The SS7 MakeCallBlock is not initialized currently, as Gc_MakeCallBlk->cclib is set to 
	Null to use default values. For Live Testing, initialize the SS7MakeCallBlock and set 
	its address to Gc_MakeCallBlk->cclib field.
	*/
	if (gc_OpenEx(&port[index].ldev, port[index].devname, EV_SYNC, (void *)&port[index]) != GC_SUCCESS) {
		sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Failed", port[index].devname);
		printandlog(index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	
	sprintf(str, "gc_OpenEx(devicename=%s, mode=EV_SYNC) Success", port[index].devname);
	printandlog(index, GC_APICALL, NULL, str);

	set_calling_num(&port[index], "7654321");
} /* End of function */ 

⌨️ 快捷键说明

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