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

📄 anet_drv.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
📖 第 1 页 / 共 2 页
字号:
   fflush(lp);   #endif    }   return(ret); */}/* end f_anet_test_process *//*********************************************************Function:int f_anet_result_receive(int sock, char *szBuffer, int times, int wait_time)Narrative:	Recieve responded string after send command.Param:	int sock - socket id	char *szBuffer - point to array receive_str	int times - count times	int wait_time - poll system call waiting timeReturn:	0   OK.	-1	an error of hangup occur when reading.	-2	No fd ready when timeout.	-3	an error occur when performing poll or read.*********************************************************/int f_anet_result_receive(int sock, char *szBuffer, int times, int wait_time){	int p;	int retval, ret, rc;	char ch;	int recv_counter = 0;	struct pollfd pollfdsp[1];	pollfdsp[0].fd = sock;	pollfdsp[0].events = POLLIN;	pollfdsp[0].revents = 0;	retval = 0;	p = 0;	szBuffer[p] = '\0';	while (1)	{		ret = poll(pollfdsp, 1, wait_time);		if (ret < 0)		{			retval = -3;			break;		}		else if (ret == 0)		{			retval = -2;			break;		}		if (pollfdsp[0].revents & POLLIN)		{			rc = read(sock, &ch, 1);			if (rc < 0)			{				retval = -3;				break;			}			if (rc == 0)			{				retval = -1;				break;			}			if (ch != 0)			{				szBuffer[p] = ch;				++p;				/* fprintf(lp,"%02x,%c\n",ch,ch); */			}			if (ch == ';')			{				szBuffer[p] = '\0';				++recv_counter;				if (recv_counter >= times)				{#ifdef DEBUG					fprintf(lp, "\nFinish\n");#endif					break;				}			}		}	}	szBuffer[p] = '\0';#ifdef DEBUG	fprintf(lp, "Server Replied:p=%d\n%s\n", p, szBuffer);	fflush(lp);#endif	switch (retval)	{	case 0:#ifdef DEBUG		fprintf(lp, "\nReceive OK!\n");#endif		break;	case -1:#ifdef DEBUG		fprintf(lp, "Receive 0, exit\n");#endif		break;	case -2:#ifdef DEBUG		fprintf(lp, "Server no respone!\n");#endif		retval = 0;		break;	case -3:#ifdef DEBUG		fprintf(lp, "\nServer port down!\n");#endif		break;	}	return (retval);}/*********************************************************Function:int f_anet_analysis(char *receive_str, TESTMSG * testmsg)Narrative:	Get test values from Received string from switch.Param:	char *receive_str - a pointer to receive_str	TESTMSG * testmsg - struct of test messageReturn:	0   OK.	RESULT_OTHER	No expected string.	RESULT_BUSY	Line busy.	RESULT_NULL	Ivalid telephone number.*********************************************************/int f_anet_analysis(char *receive_str, TESTMSG * testmsg){	char temp_str[30];	char *p, *q, *r;	char state;	int ret;	ret = 0;	p = (char *) strstr(receive_str, " RESULT=");	if (p != NULL)	{		state = p[7];		switch (state)		{		case '1':		case '2':		case '4':			ret = RESULT_BUSY;			return (ret);		case '3':			ret = RESULT_NULL;			return (ret);		case '0':		default:			ret = 0;			break;		}		p += 8;		f_anet_get_result(p, testmsg->TestResult.OutResult);	}	else if ((p = (char *) strstr(receive_str, " OUTRESULT=")) != NULL)	{		p += 11;		f_anet_get_result(p, testmsg->TestResult.OutResult);		if ((p = (char *) strstr(receive_str, " DIALTONERESULT=")) != NULL)		{			p += 16;			f_anet_get_result(p, testmsg->TestResult.DialToneResult);		}		if ((p = (char *) strstr(receive_str, " FEEDVOLRESULT=")) != NULL)		{			p += 15;			f_anet_get_result(p, testmsg->TestResult.FeedVolResult);		}		if ((p = (char *) strstr(receive_str, " LOOPRINGRESULT=")) != NULL)		{			p += 16;			f_anet_get_result(p, testmsg->TestResult.LoopRingResult);		}		if ((p = (char *) strstr(receive_str, " VBATVALUE=")) != NULL)		{			p += 11;			f_anet_get_result(p, testmsg->TestResult.VBatValue);		}		if ((p = (char *) strstr(receive_str, " ILOOPVALUE=")) != NULL)		{			p += 12;			f_anet_get_result(p, testmsg->TestResult.ILoopValue);		}	}	else		return (RESULT_OTHER);	/* get AB Res */	p = (char *) strstr(receive_str, "ABINS=");	if (p)		f_anet_get_res(testmsg->TestResult.TR2_DCres, p + 6);	/* get AG Res */	p = (char *) strstr(receive_str, "AGINS=");	if (p)		f_anet_get_res(testmsg->TestResult.TG2_DCres, p + 6);	/* get BG Res */	p = (char *) strstr(receive_str, "BGINS=");	if (p)		f_anet_get_res(testmsg->TestResult.RG2_DCres, p + 6);	/* get AB DCVol  -- skip */	/*	   p = (char*)strstr(receive_str,"ABDCVOL=");	   if (p)	   f_anet_get_vol(testmsg->TestResult.TR2_DCres,p+8);	 */	/* get AG DCVol */	p = (char *) strstr(receive_str, "AGDCVOL=");	if (p)		f_anet_get_vol(testmsg->TestResult.TG2_DCvol, p + 8);	/* get BG DCVol */	p = (char *) strstr(receive_str, "BGDCVOL=");	if (p)		f_anet_get_vol(testmsg->TestResult.RG2_DCvol, p + 8);	/* get AG ACVol */	p = (char *) strstr(receive_str, "AGACVOL=");	if (p)		f_anet_get_vol(testmsg->TestResult.TG_ACvol, p + 8);	/* get BG ACVol */	p = (char *) strstr(receive_str, "BGACVOL=");	if (p)		f_anet_get_vol(testmsg->TestResult.RG_ACvol, p + 8);	/* get AB Cap */	p = (char *) strstr(receive_str, "ABCAPAC=");	if (p)		f_anet_get_cap(testmsg->TestResult.TR_cap, p + 8);	/* get AG Cap */	p = (char *) strstr(receive_str, "AGCAPAC=");	if (p)		f_anet_get_cap(testmsg->TestResult.TG_cap, p + 8);	/* get BG Cap */	p = (char *) strstr(receive_str, "BGCAPAC=");	if (p)		f_anet_get_cap(testmsg->TestResult.RG_cap, p + 8);	/* get loop current */	p = (char *) strstr(receive_str, "ABDCCUR=");	if (p)		f_anet_get_vol(testmsg->TestResult.LoopCur, p + 8);	/* get loop resistance */	p = (char *) strstr(receive_str, "ABLOOPRES=");	if (p)		f_anet_get_vol(testmsg->TestResult.LoopRes, p + 10);	/* get AB Impedance */	p = (char *) strstr(receive_str, "ABIMPED=");	if (p)		f_anet_get_vol(testmsg->TestResult.TR_imped, p + 8);	/* get AG Impedance */	p = (char *) strstr(receive_str, "AGIMPED=");	if (p)		f_anet_get_vol(testmsg->TestResult.TG_imped, p + 8);	/* get BG Impedance */	p = (char *) strstr(receive_str, "BGIMPED=");	if (p)		f_anet_get_vol(testmsg->TestResult.RG_imped, p + 8);	return (0);}/*********************************************************Function:void f_anet_get_res(char *result, char *val_str)Narrative:	Get value of resistance from received string from switch.Param:	char *result - a pointer to value of resistance	char *val_str - a pointer to received string from switchReturn:	None.*********************************************************/void f_anet_get_res(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	p = val_str;	q = temp_str;	while (*p)	{		if (*p == ' ' || *p == ';')		{			break;		}		else		{			*q = *p;			++q;		}		++p;	}	*q = '\0';	if (temp_str[0] != '\0')	{		val = atof(temp_str);		sprintf(result, "%9.3f", val);	}	else	{		result[0] = '\0';	}}/*********************************************************Function:void f_anet_get_vol(char *result, char *val_str)Narrative:	Get value of voltage from received string from switch.Param:	char *result - a pointer to value of voltage	char *val_str - a pointer to received string from switchReturn:	None.*********************************************************/void f_anet_get_vol(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	p = val_str;	q = temp_str;	while (*p)	{		if (*p == ' ' || *p == ';')		{			break;		}		else		{			*q = *p;			++q;		}		++p;	}	*q = '\0';	if (temp_str[0] != '\0')	{		val = atof(temp_str);		sprintf(result, "%8.3f", val);	}	else	{		result[0] = '\0';	}}/*********************************************************Function:void f_anet_get_cap(char *result, char *val_str)Narrative:	Get value of capacitance from received string from switch.Param:	char *result - a pointer to value of capacitance	char *val_str - a pointer to received string from switchReturn:	None.*********************************************************/void f_anet_get_cap(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	p = val_str;	q = temp_str;	while (*p)	{		if (*p == ' ' || *p == ';')		{			break;		}		else		{			*q = *p;			++q;		}		++p;	}	*q = '\0';	if (temp_str[0] != '\0')	{		val = atof(temp_str) / 1000;		sprintf(result, "%8.3f", val);	}	else	{		result[0] = '\0';	}}/*********************************************************Function:int f_anet_get_result(char *str, char *result)Narrative:	Get other values except 12 specialities.Param:	char *str - a pointer to recieved string from switch	char *result - a pointer to test value Return:	0	OK.*********************************************************/int f_anet_get_result(char *str, char *result){	char *p;	int i;	int ret;	i = 0;	p = str;	while (*p != '\0' && *p != ';' && *p != ' ' && i < 20)	{		result[i] = *p;		++p;		++i;	}	result[i] = '\0';	ret = 0;	return (ret);}/*********************************************************Function:int f_anet_get_code(char *str)Narrative:	Get code from received string from switch.Param:	char *str - a pointer to recieved string from switchReturn:	Int value of code.*********************************************************/int f_anet_get_code(char *str){	char *p;	int i;	char temp[10];	p = str;	temp[0] = 0;	i = 0;	while (*p != '\0' && *p != ';' && *p != ' ' && i < 10)	{		temp[i] = *p;		++p;		++i;	}	temp[i] = 0;	return (atoi(temp));}/*********************************************************Function:int f_anet_get_DIGIT(char *src, char *dst)Narrative:	Get digit value from received string from switch.Param:	char *src - a pointer to recieved stirng	char *dst - a pointer to trimed stringReturn:	-1	No expected stirng.*********************************************************/int f_anet_get_DIGIT(char *src, char *dst){	char *p, *q;	char *orgchar;	char temp[21];	p = src;	*dst = 0;	if (strchr(p, ';') == NULL)		return -1;	if ((q = (char *) strstr(p, "RESULT=")) == NULL)		return -1;	f_anet_get_result(q + 7, temp);	sprintf(dst, "RESULT=%s DIGIT=", temp);	while ((orgchar = (char *) strchr(p, ';')) != NULL)	{		*orgchar = 0;		q = (char *) strstr(p, "DIGIT=");		if (q != NULL)		{			f_anet_get_result(q + 6, temp);			strcat(dst, temp);		}		*orgchar = ';';		p = orgchar + 1;	}}/*   aci1=(-7392.510),aci2=(-7184.600),aci3=(-2862.650),   acr1=99999.999,acr2=99999.999,acr3=99999.999 *//*   INVOKEID=56 DIGTEST DN=2611491 STARTTIME=19990407113515 STOPTIME=19990407113521:   STATE=0 RESULT=0 DIGIT=2;INVOKEID=56 DIGTEST DN=2611491 STARTTIME=19990407113515   STOPTIME=19990407113522:STATE=0 RESULT=0 DIGIT=5;INVOKEID=56 DIGTEST DN=2611491   STARTTIME=19990407113515 STOPTIME=19990407113522:STATE=0 RESULT=0 DIGIT=2;INVOK   EID=56 DIGTEST DN=2611491 STARTTIME=19990407113515 STOPTIME=19990407113523:STATE   =0 RESULT=0 DIGIT=1;INVOKEID=56 DIGTEST DN=2611491 STARTTIME=19990407113515 STOP   TIME=19990407113524:STATE=0 RESULT=0 DIGIT=A; */

⌨️ 快捷键说明

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