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

📄 hmp_test_cpp-c++.cpp

📁 列出了通过语音卡打电话和发传真的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		ip_cap[6].direction = IP_CAP_DIR_LCLTXRX;
		ip_cap[6].payload_type = 0;
		ip_cap[6].extra.data.max_bit_rate = 144;
		GC_PARM_BLKP parmblkp = NULL;
		for (int i=0; i<7; i++)
			gc_util_insert_parm_ref(&parmblkp, GCSET_CHAN_CAPABILITY, IPPARM_LOCAL_CAPABILITY, sizeof(IP_CAPABILITY), &ip_cap[i]);
		if (GCTGT_GCLIB_CRN == crn_or_chan)
			gc_SetUserInfo(GCTGT_GCLIB_CRN, crn, parmblkp, GC_SINGLECALL);
		else
			gc_SetUserInfo(GCTGT_GCLIB_CHAN, gc_dev, parmblkp, GC_SINGLECALL);
		gc_util_delete_parm_blk(parmblkp);
	}

	void set_alarm() {
		print("set_alarm()...");
		print_gc_error_info("gc_SetAlarmNotifyAll", gc_SetAlarmNotifyAll(ipm_dev, ALARM_SOURCE_ID_NETWORK_ID, ALARM_NOTIFY));
		print_gc_error_info("gc_SetAlarmParm", gc_SetAlarmParm(ipm_dev, ALARM_SOURCE_ID_NETWORK_ID, ParmSetID_qosthreshold_alarm, &alarm_parm_list, EV_SYNC));
	}

	void print_alarm_info(METAEVENT meta_evt) {
		long alarm_number = 0;
		char* alarm_name = NULL;
		unsigned long alarm_source_object_id = 0;
		char* alarm_source_object_name = NULL;
		gc_AlarmNumber(&meta_evt, &alarm_number); // Will be of type TYPE_LAN_DISCONNECT = 0x01 or TYPE_LAN_DISCONNECT + 0x10 (LAN connected).
		gc_AlarmName(&meta_evt, &alarm_name); // Will be "Lan Cable Disconnected" or "Lan cable connected".
		gc_AlarmSourceObjectID(&meta_evt, &alarm_source_object_id); // Will usually be 7.
		gc_AlarmSourceObjectName(&meta_evt, &alarm_source_object_name); // Will be IPCCLIBAsoId.
		print("alarm: %s(0x%lx) occurred on ASO %s(%d)", alarm_name, alarm_number, alarm_source_object_name, (int) alarm_source_object_id);
	}

	void close() {
		print("close()...");
		dx_close(vox_dev);
		fx_close(fax_dev);
		gc_Close(gc_dev);
	}

	void print(const char *format, ...) {
		char buf[1024] = "";
		SYSTEMTIME t;
		va_list argptr;
		va_start(argptr, format);
		_vsnprintf(buf, 1023, format, argptr);
		buf[1023] = '\0';
		va_end(argptr);		
		GetLocalTime(&t);
		printf("%02d:%02d:%02d.%04d CH %d: %s\n", t.wHour, t.wMinute, t.wSecond, t.wMilliseconds, id, buf);
	}
};

void enum_dev_information()
{
	int i = 0;
	int j = 0;
	int board_count = 0;
	int sub_dev_count = 0;
	int dsp_resource_count = 0;
	long handle = 0;
	long dev_handle = 0;
	char board_name[20] = "";
	char dev_name[20] = "";
	FEATURE_TABLE ft = {0};

	printf("enum_dev_information()...\n");

	sr_getboardcnt(DEV_CLASS_VOICE, &board_count);
	printf("  voice board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, "dxxxB%d", i);
		handle = dx_open(board_name, 0);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    voice board %s has %d sub-devs.\n", board_name, sub_dev_count);
		for (j=1; j<=sub_dev_count; j++) {
			sprintf(dev_name, "dxxxB%dC%d", i, j);
			dev_handle = dx_open(dev_name, 0);
			dx_getfeaturelist(dev_handle, &ft);
			printf("      %s %ssupport fax, %ssupport T38 fax, %ssupport CSP.\n", dev_name, 
				(ft.ft_fax & FT_FAX)?"":"NOT ",
				(ft.ft_fax & FT_FAX_T38UDP)?"":"NOT ", 
				(ft.ft_e2p_brd_cfg & FT_CSP)?"":"NOT ");
			dx_close(dev_handle);
		}
		dx_close(handle);
	}
	
	sr_getboardcnt(DEV_CLASS_DTI, &board_count);
	printf("  dti board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, "dtiB%d", i);
		handle = dt_open(board_name, 0);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    dti board %s has %d sub-devs.\n", board_name, sub_dev_count);
		dt_close(handle);
	}
	
	sr_getboardcnt(DEV_CLASS_MSI, &board_count);
	printf("  msi board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, "msiB%d", i);
		handle = ms_open(board_name, 0);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    msi board %s has %d sub-devs.\n", board_name, sub_dev_count);
		ms_close(handle);
	}

	sr_getboardcnt(DEV_CLASS_DCB, &board_count);
	printf("  dcb board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, "dcbB%d", i);
		handle = dcb_open(board_name, 0);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    dcb board %s has %d sub-devs(DSP).\n", board_name, sub_dev_count);
		for (j=1; j<=sub_dev_count; j++) {
			sprintf(dev_name, "%sD%d", board_name, j);
			dev_handle = dcb_open(dev_name, 0);
			dcb_dsprescount(dev_handle, &dsp_resource_count);
			printf("      DSP %s has %d conference resource.\n", dev_name, dsp_resource_count);
			dcb_close(dev_handle);
		}
		dcb_close(handle);
	}

	//	DEV_CLASS_SCX
	//	DEV_CLASS_AUDIO_IN	

	sr_getboardcnt(DEV_CLASS_IPT, &board_count);
	printf("  ipt board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, ":N_iptB%d:P_IP", i);
		gc_OpenEx(&handle, board_name, EV_SYNC, NULL);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    ipt board %s has %d sub-devs.\n", board_name, sub_dev_count);
		gc_Close(handle);
	}

	sr_getboardcnt("IPM", &board_count);
	printf("  ipm board count=%d.\n", board_count);
	for (i=1; i<=board_count; i++) {
		sprintf(board_name, ":M_ipmB%d", i);
		gc_OpenEx(&handle, board_name, EV_SYNC, NULL);
		sub_dev_count = ATDV_SUBDEVS(handle);
		printf("    ipm board %s has %d sub-devs.\n", board_name, sub_dev_count);
		gc_Close(handle);
	}
}

void enum_support_capabilities() 
{
	int count = 0;
	IPM_CAPABILITIES* caps = NULL;	
	printf("enum_support_capabilities()...\n");
	for (int index=0; index<MAX_CHANNELS; index++) {
		count = ipm_GetCapabilities(channls[index]->ipm_dev, CAPABILITY_CODERLIST, 0, NULL, EV_SYNC);
		caps = (IPM_CAPABILITIES*)malloc(sizeof(IPM_CAPABILITIES)*count);
		count = ipm_GetCapabilities(channls[index]->ipm_dev, CAPABILITY_CODERLIST, count, caps, EV_SYNC);
		channls[index]->print("support 1890 Coder: ");
		channls[index]->print("  [Type\tCoder\tFrSize\tFr/Pkt\tVAD]");
		for (int i=0; i<count; i++) 
			channls[index]->print("  [%d\t%d\t%d\t%d\t%d]", 
				caps[i].Coder.unCoderPayloadType, caps[i].Coder.eCoderType, caps[i].Coder.eFrameSize, 
				caps[i].Coder.unFramesPerPkt, caps[i].Coder.eVadEnable);
		free(caps);
	}
}

void authentication(const char* proxy_ip, const char* alias, const char* password, const char* realm)
{
	GC_PARM_BLKP gc_parm_blkp = NULL;
	IP_AUTHENTICATION auth;
	char identity[GC_ADDRSIZE] = "";
	printf("authentication()...\n");
	sprintf(identity, "sip:%s@%s", alias, proxy_ip);
	INIT_IP_AUTHENTICATION (&auth);
	auth.realm = (char *)realm;
	auth.identity = (char *)identity;
	auth.username = (char *)alias;
	auth.password = (char *)password;
	gc_util_insert_parm_ref(&gc_parm_blkp, IPSET_CONFIG, IPPARM_AUTHENTICATION_CONFIGURE, (unsigned char)(sizeof(IP_AUTHENTICATION)), &auth);
	gc_SetAuthenticationInfo(GCTGT_CCLIB_NETIF, board_dev, gc_parm_blkp);
	gc_util_delete_parm_blk(gc_parm_blkp);
}

void registration(const char* proxy_ip, const char* local_ip, const char* alias, const char* password, const char* realm)
{
	GC_PARM_BLKP gc_parm_blkp = NULL; 
	IP_REGISTER_ADDRESS register_address;
	unsigned long serviceID = 1;
	char contact[250] = "";

	if (!registered) {
		authentication(proxy_ip, alias, password, realm);

		printf("registration()...\n");

		gc_util_insert_parm_val(&gc_parm_blkp, GCSET_SERVREQ, PARM_REQTYPE, sizeof(unsigned char), IP_REQTYPE_REGISTRATION);
		gc_util_insert_parm_val(&gc_parm_blkp, GCSET_SERVREQ, PARM_ACK, sizeof(unsigned char), IP_REQTYPE_REGISTRATION);
		gc_util_insert_parm_val(&gc_parm_blkp, IPSET_PROTOCOL, IPPARM_PROTOCOL_BITMASK, sizeof(char), IP_PROTOCOL_SIP);
		gc_util_insert_parm_val(&gc_parm_blkp, IPSET_REG_INFO, IPPARM_OPERATION_REGISTER, sizeof(char), IP_REG_SET_INFO);
		
		memset((void*)&register_address, 0, sizeof(IP_REGISTER_ADDRESS));
		sprintf(register_address.reg_server, "%s", proxy_ip);// Request-URI
		sprintf(register_address.reg_client, "%s@%s", alias, proxy_ip);// To header field
		sprintf(contact, "sip:%s@%s:%d", alias, local_ip, HMP_SIP_PORT);// Contact header field
		register_address.time_to_live = 3600;
		register_address.max_hops = 30;

		gc_util_insert_parm_ref(&gc_parm_blkp, IPSET_REG_INFO, IPPARM_REG_ADDRESS, (unsigned char)sizeof(IP_REGISTER_ADDRESS), &register_address);
		gc_util_insert_parm_ref( &gc_parm_blkp, IPSET_LOCAL_ALIAS, IPPARM_ADDRESS_TRANSPARENT, (unsigned char)strlen(contact)+1, (void *)contact);
		gc_ReqService(GCTGT_CCLIB_NETIF, board_dev, &serviceID, gc_parm_blkp, NULL, EV_ASYNC);
		gc_util_delete_parm_blk(gc_parm_blkp);
		printf("  serviceID is 0x%x.\n", serviceID);

		registered = TRUE;
	}
}

void unregistration()
{
	GC_PARM_BLKP gc_parm_blkp = NULL;
	unsigned long serviceID = 1;

	if (registered) {
		printf("unregistration()...\n");
		gc_util_insert_parm_val(&gc_parm_blkp, IPSET_REG_INFO, IPPARM_OPERATION_DEREGISTER, sizeof(char), IP_REG_DELETE_ALL);	
		gc_util_insert_parm_val(&gc_parm_blkp, GCSET_SERVREQ, PARM_REQTYPE, sizeof(unsigned char), IP_REQTYPE_REGISTRATION);
		gc_util_insert_parm_val(&gc_parm_blkp, GCSET_SERVREQ, PARM_ACK, sizeof(unsigned char), IP_REQTYPE_REGISTRATION);
		gc_util_insert_parm_val(&gc_parm_blkp, IPSET_PROTOCOL, IPPARM_PROTOCOL_BITMASK, sizeof(char), IP_PROTOCOL_SIP);
		gc_ReqService(GCTGT_CCLIB_NETIF, board_dev, &serviceID, gc_parm_blkp, NULL, EV_ASYNC);
		gc_util_delete_parm_blk(gc_parm_blkp);
		printf("  serviceID is 0x%x.\n", serviceID);

		registered = FALSE;
	}	
}

int get_idle_channel_id(){
	for (unsigned index=0; index<MAX_CHANNELS; index++) {
		if (0 == channls[index]->crn)
			return index;
	}
	return -1;
}

void print_sys_status()
{
	int gc_status = 0;
	long vox_status = 0;
	long fax_status = 0;
	printf("print_sys_status()...\n");
	for (unsigned index=0; index<MAX_CHANNELS; index++) {
		if (0 == channls[index]->crn)
			gc_status = GCST_NULL;
		else 
			gc_GetCallState(channls[index]->crn, &gc_status);
		vox_status = ATDX_STATE(channls[index]->vox_dev);
		fax_status = ATFX_STATE(channls[index]->fax_dev);
		printf("  channel %d status: gc %sIDLE(0x%x), vox %sIDLE(0x%x), fax %sIDLE(0x%x).\n", index, 
			GCST_NULL==gc_status?"":"NOT ", gc_status,
			CS_IDLE==vox_status?"":"NOT ", vox_status,
			CS_IDLE==fax_status?"":"NOT ", fax_status);
	}
	printf("  %sregistered.\n", TRUE == registered?"":"NOT ");
}

void print_alarm_info(METAEVENT meta_evt)
{
	long alarm_number = 0;
	char* alarm_name = NULL;
	unsigned long alarm_source_object_id = 0;
	char* alarm_source_object_name = NULL;
	gc_AlarmNumber(&meta_evt, &alarm_number); // Will be of type TYPE_LAN_DISCONNECT = 0x01 or TYPE_LAN_DISCONNECT + 0x10 (LAN connected).
	gc_AlarmName(&meta_evt, &alarm_name); // Will be "Lan Cable Disconnected" or "Lan cable connected".
	gc_AlarmSourceObjectID(&meta_evt, &alarm_source_object_id); // Will usually be 7.
	gc_AlarmSourceObjectName(&meta_evt, &alarm_source_object_name); // Will be IPCCLIBAsoId.
	printf("  Alarm: %s(0x%lx) occurred on ASO %s(%d)\n", alarm_name, alarm_number, alarm_source_object_name, (int) alarm_source_object_id);
}

void global_call_start()
{
	GC_START_STRUCT	gclib_start;
	IPCCLIB_START_DATA cclib_start_data;
	IP_VIRTBOARD virt_boards[1];

	printf("global_call_start()...\n");
	
	memset(&cclib_start_data, 0, sizeof(IPCCLIB_START_DATA));
	memset(virt_boards, 0, sizeof(IP_VIRTBOARD));
	INIT_IPCCLIB_START_DATA(&cclib_start_data, 1, virt_boards);
	INIT_IP_VIRTBOARD(&virt_boards[0]);

	cclib_start_data.delimiter = ',';
	cclib_start_data.num_boards = 1;
	cclib_start_data.board_list = virt_boards;
	cclib_start_data.max_parm_data_size = 1024;				// set maximum SIP header length to 1k
	
	virt_boards[0].localIP.ip_ver = IPVER4;					// must be set to IPVER4
	virt_boards[0].localIP.u_ipaddr.ipv4 = IP_CFG_DEFAULT;	// or specify host NIC IP address
	virt_boards[0].h323_signaling_port = IP_CFG_DEFAULT;	// or application defined port for H.323
	virt_boards[0].sip_signaling_port = HMP_SIP_PORT;		// or application defined port for SIP
	virt_boards[0].sup_serv_mask = IP_SUP_SERV_CALL_XFER;	// Enable SIP Transfer Feature
	virt_boards[0].sip_msginfo_mask = IP_SIP_MSGINFO_ENABLE;// Enabling Access to SIP Header Information
//		| IP_SIP_MIME_ENABLE;								// Enabling SIP-T/MIME feature */
	virt_boards[0].reserved = NULL;							// must be set to NULL

	CCLIB_START_STRUCT cclib_start[]={{"GC_DM3CC_LIB", NULL}, {"GC_H3R_LIB", &cclib_start_data}, {"GC_IPM_LIB", NULL}};
	gclib_start.num_cclibs = 3;
	gclib_start.cclib_list = cclib_start;
	gc_Start(&gclib_start);
}

void pre_test()
{
	long request_id = 0;
	GC_PARM_BLKP gc_parm_blk_p = NULL;
	
	global_call_start();
	printf("global_call_start() done.\n");

	//enum_dev_information();

	gc_OpenEx(&board_dev, ":N_iptB1:P_IP", EV_SYNC, NULL);

	// Enable Alarm notification on the board handle with generic ASO ID
	gc_SetAlarmNotifyAll(board_dev, ALARM_SOURCE_ID_NETWORK_ID, ALARM_NOTIFY);
	iqti.unCount=2;
	iqti.QoSThresholdData[0].eQoSType = QOSTYPE_LOSTPACKETS;
	iqti.QoSThresholdData[0].unFaultThreshold = 20;
	iqti.QoSThresholdData[0].unDebounceOn = 10000;
	iqti.QoSThresholdData[0].unDebounceOff = 10000;
	iqti.QoSThresholdData[0].unTimeInterval = 1000;
	iqti.QoSThresholdData[0].unPercentSuccessThreshold = 60;
	iqti.QoSThresholdData[0].unPercentFailThreshold = 40;
	iqti.QoSThresholdData[1].eQoSType = QOSTYPE_JITTER;
	iqti.QoSThresholdData[1].unFaultThreshold = 60;
	iqti.QoSThresholdData[1].unDebounceOn = 20000;
	iqti.QoSThresholdData[1].unDebounceOff = 60000;
	iqti.QoSThresholdData[1].unTimeInterval = 5000;
	iqti.QoSThresholdData[1].unPercentSuccessThreshold = 60;
	iqti.QoSThresholdData[1].unPercentFailThreshold = 40;
	alarm_parm_list.n_parms = 1;
	alarm_parm_list.alarm_parm_fields[0].alarm_parm_data.pstruct = (void *) &iqti;
	gc_SetAlarmParm(board_dev, ALARM_SOURCE_ID_NETWORK_ID, ParmSetID_qosthreshold_alarm, &alarm_parm_list, EV_SYNC);

	if (FALSE == USING_MODIFY_MODE) {
		//setting T.38 fax server operating mode: IP MANUAL mode
		gc_util_insert_parm_val(&gc_parm_blk_p, IPSET_CONFIG, IPPARM_OPERATING_MODE, sizeof(long), IP_T38_MANUAL_MODE);
	} else {
		//access to SIP re-INVITE requests
		gc_util_insert_parm_val(&gc_parm_blk_p, IPSET_CONFIG, IPPARM_OPERATING_MODE, sizeof(long), IP_T38_MANUAL_MODIFY_MODE);
	}
	
	//Enabling and Disabling Unsolicited Notification Events
	gc_util_insert_parm_val(&gc_parm_blk_p, IPSET_EXTENSIONEVT_MSK, GCACT_ADDMSK, sizeof(long), 
		EXTENSIONEVT_DTMF_ALPHANUMERIC|EXTENSIONEVT_SIGNALING_STATUS|EXTENSIONEVT_STREAMING_STATUS|EXTENSIONEVT_T38_STATUS);
	gc_SetConfigData(GCTGT_CCLIB_NETIF, board_dev, gc_parm_blk_p, 0, GCUPDATE_IMMEDIATE, &request_id, EV_ASYNC);
	gc_util_delete_parm_blk(gc_parm_blk_p);

	for (int i=0; i<MAX_CHANNELS; i++) {
		channls[i] = new CHANNEL(i);
		channls[i]->open();
	}
}

void post_test()
{
	printf("post_test()...\n");
	unregistration();
	gc_Close(board_dev);
	for (int i=0; i<MAX_CHANNELS; i++) {
		channls[i]->close();
	}
	gc_Stop();
}

BOOL gets_quit_if_esc(char* output, unsigned size)
{
	/*char input = 0;
	unsigned index = 0;
	while (TRUE) {
		input = _getche();
		if (input == 13) {// input ENTER
			printf("\n");
			if (index <= size) output[index] = '\0';
			break;
		} else if (input == 27) {// input ESC
			printf("\n");
			if (index <= size) output[index] = '\0';
			return TRUE;
		} else if (input == 8) {// input BACKSAPCE ?
			if (index > 0) {
				output[index-1] = '\0';
				index = index - 2;
				printf("%c", 0);
				printf("\b");
			} else {
				output[index] = '\0';
			}
		} else {
			if (index < size) output[index] = input;
			else output[index] = '\0';
		}
		index++;
	}
	return FALSE;*/
	gets(output);
	return (0 == strnicmp(output, CLI_BACK, strlen(CLI_BACK)))?TRUE:FALSE;
}

⌨️ 快捷键说明

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