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

📄 f150_drv.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
字号:
#include <poll.h>#include <stdio.h>#include <stdlib.h>#include "simdrv.h"#include "simu112.h"#include "simufunc.h"#define MAX_FAIL_TIMES		4#define WAIT_TIME			60000#define RESULT_OTHER		-4#define RESULT_NULL			-5#define RESULT_BUSY			-6#define RESULT_TIMEOUT		-7#define ER_RAB_SHORT		1FILE *lp;static char str_wakeup[] ={'\5', '\0'};//static char str_pwd[]="ABCD;";static char str_tstcmd[] = "TES TER:SLN,DN=";int f_f150_send_wakeup(int port_fd);int f_f150_send_password(int port_fd, char *password);int f_f150_result_receive(int sock, char *szBuffer, char *end_str);int f_f150_test_process(int port_fd, char *phone_number, TESTMSG * testmsg);int f_f150_analysis(char *receive_str, TESTMSG * testmsg);//static char receive_str[2048];/*********************************************************Function:int f150_proc(int port_fd, char *phone_number, char *password, TESTMSG * testmsg)Narrative:	Called in simdrv.c. It is the main flow of f150_drv driver.Param:	int port_fd	- socket id	char *phone_number - char pointer to accessed telephone number string	char *password - char pointer to switch port password	TESTMSG * testmsg	- struct of test messageReturn: 0   OK or Null TelephoneNumber or Line Busy.	AM_UNREADY_ERROR	  	AM_NO_RESPONSE	AM_PORT_DOWN	AM_UNREADY_ERROR	AM_TIME_OUT*********************************************************/int f150_proc(int port_fd, char *phone_number, char *password, TESTMSG * testmsg){	int ret = 1;	int test_stat = 1;	int fail_count = 0;	struct tm *ctime;	time_t lt;#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	lp = backup_log("./f150_drv.log");	fprintf(lp, "\n>>> Start FETEX150 Test at %4d.%02d.%02d %02d:%02d:%02d <<<\n", ctime->tm_year > 90 ? ctime->tm_year + 1900 : ctime->tm_year + 2000, ctime->tm_mon + 1, ctime->tm_mday, ctime->tm_hour, ctime->tm_min, ctime->tm_sec);	fflush(lp);#endif	while (fail_count < MAX_FAIL_TIMES && ret)	{		ret = f_f150_send_wakeup(port_fd);		if (!ret)			ret = f_f150_send_password(port_fd, password);		++fail_count;	}	if (!ret)		ret = f_f150_test_process(port_fd, phone_number, testmsg);#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	fprintf(lp, "\n>>> Stop FETEX150 Test at %4d.%02d.%02d %02d:%02d:%02d <<<\n", ctime->tm_year > 90 ? ctime->tm_year + 1900 : ctime->tm_year + 2000, ctime->tm_mon + 1, ctime->tm_mday, ctime->tm_hour, ctime->tm_min, ctime->tm_sec);	fflush(lp);	fclose(lp);#endif	switch (ret)	{	case -1:		ret = AM_UNREADY_ERROR;		break;	case -2:		ret = AM_NO_RESPONSE;		break;	case -3:		ret = AM_PORT_DOWN;		break;	case RESULT_OTHER:		ret = AM_UNREADY_ERROR;		break;	case RESULT_NULL:		ret = 0;		strcpy(testmsg->TestResult.TestConclusion, "V08");		break;	case RESULT_BUSY:		ret = 0;		strcpy(testmsg->TestResult.TestConclusion, "V6");		break;	case RESULT_TIMEOUT:		ret = AM_TIME_OUT;		break;	}	return (ret);}/* end of f150_proc *//*********************************************************Function:int f150_conn_switch(int port_fd)Narrative:	Detect if interface to switch runs well by sending a wakeup signal or a command.Param:	int port_fd	- socket id Return:	0	OK.	-1	No fd ready when timeout.	-2	an error occur.*********************************************************/int f150_conn_switch(int port_fd){	int ret_val;	struct tm *ctime;	time_t lt;	char receive_str[2048];#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	lp = backup_log("./f150_drv.log");	fprintf(lp, "\n>>> Start FETEX150 Test at %4d.%02d.%02d %02d:%02d:%02d <<<\n", ctime->tm_year > 90 ? ctime->tm_year + 1900 : ctime->tm_year + 2000, ctime->tm_mon + 1, ctime->tm_mday, ctime->tm_hour, ctime->tm_min, ctime->tm_sec);	fflush(lp);#endif	receive_str[0] = 0;	if (!f_f150_send_wakeup(port_fd))		ret_val = 0;	else if (strlen(receive_str) == 0)		ret_val = -1;	else		ret_val = -2;#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	fprintf(lp, "\n>>> Stop FETEX150 Test at %4d.%02d.%02d %02d:%02d:%02d <<<\n", ctime->tm_year > 90 ? ctime->tm_year + 1900 : ctime->tm_year + 2000, ctime->tm_mon + 1, ctime->tm_mday, ctime->tm_hour, ctime->tm_min, ctime->tm_sec);	fflush(lp);	fclose(lp);#endif	return ret_val;}/*********************************************************Function:int f_f150_send_wakeup(int port_fd)Narrative:	Active switch port by sending wakeup signal.Param:	int port_fd	- socket idReturn:	0   OK.	-1	No expected string.	-2	No fd ready when timeout.	-3	An error occur when performing poll or read.********************************************************/int f_f150_send_wakeup(int port_fd){	int ret;	char receive_str[1024];	char resp_wakeup[] = "PASSWORD";	writeport1(port_fd, str_wakeup);	ret = f_f150_result_receive(port_fd, receive_str, resp_wakeup);	return (ret);}/*********************************************************Function:int f_f150_send_password(int port_fd, char *password)Narrative:	Send port password to login system.Param:	int port_fd	- socket id	char *password - a pointer to portpasswordReturn:	0   OK.	-1	No expected string.	-2	No fd ready when timeout.	-3	An error occur when performing poll or read.*********************************************************/int f_f150_send_password(int port_fd, char *password){	int ret;	char receive_str[1024];	char resp_pwd[] = "PORT=TYP";	f_trim_space(password);	strcat(password, ";");	sleep(1);	writeport1(port_fd, password);	ret = f_f150_result_receive(port_fd, receive_str, resp_pwd);	return (ret);}/*********************************************************Function:int f_f150_test_process(int port_fd, char *phone_number, TESTMSG * testmsg)Narrative:	Test 12 specialities of line.Param:	int port_fd	- socket id	phone_number - a pointer to telephone number	TESTMSG * testmsg	- struct of test messageReturn:	0   OK.	-1	Error occur when writing port.	-2	No fd ready when timeout.	-3	An error occur.*********************************************************/int f_f150_test_process(int port_fd, char *phone_number, TESTMSG * testmsg){	char test_str[50];	char receive_str[1024];	char resp_test[] = "END SUBSCRIBER LINE TEST";	int ret;	int i;	f_trim_space(phone_number);	sprintf(test_str, "%s%s;", str_tstcmd, phone_number);	sleep(1);	writeport1(port_fd, test_str);	ret = f_f150_result_receive(port_fd, receive_str, resp_test);	if (!ret)		ret = f_f150_analysis(receive_str, testmsg);	return (ret);}																/* end f_f150_test_process *//*********************************************************Function:int f_f150_result_receive(int sock, char *szBuffer, char *end_str1)Narrative:	Recieve responded string from switch after sending command.Param:	int sock - socket id	char *szBuffer - a pointer to receive_str	char *end_str1 - end lable1 of recieved stirngReturn:	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_f150_result_receive(int sock, char *szBuffer, char *end_str1){	int p;	int retval, ret, rc;	char ch;	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;				szBuffer[p] = '\0';				/* fprintf(lp,"%02x,%c\n",ch,ch); */			}			if (ch == '\x03')			{				if (strstr(szBuffer, end_str1) || strstr(szBuffer, "REJECTION (061)"))				{#ifdef DEBUG					fprintf(lp, "\nFinish\n");					fflush(lp);#endif					retval = 0;					break;				}			}		}	}#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");		fflush(lp);#endif		break;	case -1:#ifdef DEBUG		fprintf(lp, "Receive 0, exit\n");		fflush(lp);#endif		break;	case -2:#ifdef DEBUG		fprintf(lp, "Server no respone!\n");		fflush(lp);#endif		break;	case -3:#ifdef DEBUG		fprintf(lp, "\nServer port down!\n");		fflush(lp);#endif		break;	}	return (retval);}/*********************************************************Function:int f_f150_analysis(char *receive_str, TESTMSG * testmsg)Narrative:	Get 12 test values from Received stirng from switch.Param:	char *receive_str - an pointer to receive_str	TESTMSG * testmsg	- struct of test messageReturn:	0   OK.	RESULT_BUSY	Line busy.	RESULT_NULL	Ivalid telephone number.*********************************************************/int f_f150_analysis(char *receive_str, TESTMSG * testmsg){	char temp_str[30];	char *p, *q, *r, *temp;	int state, ret;	int r_ae, r_be, r_ab, c_ae, c_be, c_ab, v_ae, v_be, v_ab;	ret = 0;	state = 0;/* determine if the line is busy; */	if (strstr(receive_str, "BUSY"))	{		if (strstr(receive_str, "ERROR SUBSCRIBER LINE TEST"));		else		{			ret = RESULT_BUSY;				/* Line is busy */			return (ret);		}	}/* determine if the telephone number is null or man blocked,or line is resistance short; */	if (strstr(receive_str, "LOCK") || strstr(receive_str, "SPARE"))	{		if (strstr(receive_str, "LOCK-OUT"))			state = ER_RAB_SHORT;			/* T short to R; */		else		{			ret = RESULT_NULL;				/* Telephone number is null */			return (ret);		}	}/* determine if the telephone number is null; */	if (strstr(receive_str, "TES TER COMMAND REJECTION (061)"))	{		ret = RESULT_NULL;					/* Telephone number is null */		return (ret);	}/*   strcpy(testmsg->TestResult.TR2_DCres,"99999.0");   strcpy(testmsg->TestResult.TG2_DCres,"99999.0");   strcpy(testmsg->TestResult.RG2_DCres,"99999.0");   strcpy(testmsg->TestResult.TG2_DCvol,"0.0");   strcpy(testmsg->TestResult.RG2_DCvol,"0.0");   strcpy(testmsg->TestResult.TR_cap,"0.960");   strcpy(testmsg->TestResult.TG_cap,"0.241");   strcpy(testmsg->TestResult.RG_cap,"0.239"); */	strcpy(testmsg->TestResult.OutResult, "0");	if (strstr(receive_str, "ERROR SUBSCRIBER LINE TEST"))	{		p = (char *) strstr(receive_str, "R-AE:");		p += 5;		r_ae = *p - 48;		p += 6;		r_be = *p - 48;		p += 6;		r_ab = *p - 48;		p = (char *) strstr(receive_str, "C-AE:");		p += 5;		c_ae = *p - 48;		p += 6;		c_be = *p - 48;		p += 6;		c_ab = *p - 48;		p = (char *) strstr(receive_str, "V-AE:");		p += 5;		v_ae = *p - 48;		p += 6;		v_be = *p - 48;		p += 6;		v_ab = *p - 48;#ifdef DEBUG		fprintf(lp, "r_ab=%d,r_ae=%d,r_be=%d\n", r_ab, r_ae, r_be);		fprintf(lp, "c_ab=%d,c_ae=%d,c_be=%d\n", c_ab, c_ae, c_be);		fprintf(lp, "v_ab=%d,v_ae=%d,v_be=%d\n", v_ab, v_ae, v_be);		fflush(lp);#endif		if (r_ab == 1 && r_ae == 1 && r_be == 1)		{			if (v_ae == 1 || v_be == 1)				strcpy(testmsg->TestResult.OutResult, "12");	/* DCvol to T/R line; */			else if (c_ab = 1 || c_ae == 1 || c_be == 1)				strcpy(testmsg->TestResult.OutResult, "23");	/* T/R line to another T/R line; */			else			{				if (r_ab == 1)					state = ER_RAB_SHORT;	/* T short to R; */				if (r_ae == 1)					strcpy(testmsg->TestResult.OutResult, "24");	/* T short to GND; */				if (r_be == 1)					strcpy(testmsg->TestResult.OutResult, "24");	/* R short to GND; */			}		}		else if (r_ab == 0 && r_ae == 0 && r_be == 0)		{			if (c_ab = 1 || c_ae == 1 || c_be == 1)				strcpy(testmsg->TestResult.OutResult, "22");	/* line open; */		}		else		{			if (r_ab == 1)				state = ER_RAB_SHORT;		/* T short to R; */			if (r_ae == 1)				strcpy(testmsg->TestResult.OutResult, "24");	/* T short to GND; */			if (r_be == 1)				strcpy(testmsg->TestResult.OutResult, "24");	/* R short to GND; */		}	}#ifdef DEBUG	fprintf(lp, "state=%d\n", state);#endif	if (state == ER_RAB_SHORT)		strcpy(testmsg->TestResult.OutResult, "21");	/* T short to R; */	return (ret);}

⌨️ 快捷键说明

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