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

📄 simdrv.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
📖 第 1 页 / 共 2 页
字号:
				case AM_COMMAND_ERROR:					writelog(logfp, "AM_COMMAND_ERROR");					strcpy(testMsg.Error, NOTEXEC);					break;				case AM_PARAMETER_ERROR:					writelog(logfp, "AM_PARAMETER_ERROR");					strcpy(testMsg.Error, NOTEXEC);					break;				case AM_MESSAGE_ERROR:					writelog(logfp, "AM_MESSAGE_ERROR");					strcpy(testMsg.Error, NOTEXEC);					break;				case AM_UNREADY_ERROR:					writelog(logfp, "AM_UNREADY_ERROR");					strcpy(testMsg.Error, NOTEXEC);					break;					/* The next errors is for Access Net */				case AM_ANET_ERR1:					writelog(logfp, "AM_ANET_ERR1");					strcpy(testMsg.Error, ANET_ERR1);					break;				case AM_ANET_ERR2:					writelog(logfp, "AM_ANET_ERR2");					strcpy(testMsg.Error, ANET_ERR2);					break;				case AM_ANET_ERR3:					writelog(logfp, "AM_ANET_ERR3");					strcpy(testMsg.Error, ANET_ERR3);					break;				case AM_ANET_ERR4:					writelog(logfp, "AM_ANET_ERR4");					strcpy(testMsg.Error, ANET_ERR4);					break;				case AM_ANET_ERR5:					writelog(logfp, "AM_ANET_ERR5");					strcpy(testMsg.Error, ANET_ERR5);					break;				case AM_ANET_ERR6:					writelog(logfp, "AM_ANET_ERR6");					strcpy(testMsg.Error, ANET_ERR6);					break;				case AM_ANET_ERR7:					writelog(logfp, "AM_ANET_ERR7");					strcpy(testMsg.Error, ANET_ERR7);					break;				case AM_ANET_ERR8:					writelog(logfp, "AM_ANET_ERR8");					strcpy(testMsg.Error, ANET_ERR8);					break;				case AM_ANET_ERR9:					writelog(logfp, "AM_ANET_ERR9");					strcpy(testMsg.Error, ANET_ERR9);					break;				case AM_ANET_ERR10:					writelog(logfp, "AM_ANET_ERR10");					strcpy(testMsg.Error, ANET_ERR10);					break;				default:					writelog(logfp, "AM_UNKNOWN_ERROR");					break;				}												/* end of switch (cmdret) */				break;			case TST_QUERY:				if ((sock = conntcp(testReqMsg.TSAddress, testReqMsg.TSPortNo)) < 0)				{					writelog(logfp, "TST_QUERY: terminal server not alive");					strcpy(testMsg.TestResult.TestConclusion, TS_DRV);					break;				}				if (testReqMsg.TestPortType == 'D')				{					ret = connect_modem(sock, testReqMsg.DialNumber);					if (ret == -1)					{						writelog(logfp, "TST_QUERY: ts_modem connect error");						strcpy(testMsg.TestResult.TestConclusion, TS_MODEM);						break;					}					if (ret == -2)					{						writelog(logfp, "TST_QUERY: modem_modem connect error");						strcpy(testMsg.TestResult.TestConclusion, MODEM_MODEM);						break;					}					ret = conn_switch(sock, testReqMsg.SwitchType, testReqMsg.TeleNumber, testReqMsg.PortPassword);					write(sock, "+++ath\r\n", 8);					if (ret == -1)					{						writelog(logfp, "TST_QUERY: modem_exchange connect error");						strcpy(testMsg.TestResult.TestConclusion, EXCH_MODEM);						break;					}					else if (ret == -2)					{						writelog(logfp, "TST_QUERY: Switch can not be activated");						strcpy(testMsg.TestResult.TestConclusion, EXCH_FAIL);						break;					}					else if (ret == -3)					{						writelog(logfp, "UNKNOWN EXCHANGE TYPE");						strcpy(testMsg.Error, NOFOUND);						break;					}				}				else				{					ret = conn_switch(sock, testReqMsg.SwitchType, testReqMsg.TeleNumber, testReqMsg.PortPassword);					if (ret == -1)					{						writelog(logfp, "TST_QUERY: TS_exchange connect error");						strcpy(testMsg.TestResult.TestConclusion, TS_EXCH);						break;					}					else if (ret == -2)					{						writelog(logfp, "TST_QUERY: Switch can not be activated");						strcpy(testMsg.TestResult.TestConclusion, EXCH_FAIL);						break;					}					else if (ret == -3)					{						writelog(logfp, "UNKNOWN EXCHANGE TYPE");						strcpy(testMsg.Error, NOFOUND);						break;					}				}				writelog(logfp, "TST_QUERY: test ok");				strcpy(testMsg.TestResult.TestConclusion, "ok");				break;			case CONN_TACC_POTS:				if (testReqMsg.SwitchType == HW_AN || testReqMsg.SwitchType == ZX_AN						|| testReqMsg.SwitchType == UT_AN || testReqMsg.SwitchType == BE_AN						|| testReqMsg.SwitchType == XMZ_AN || testReqMsg.SwitchType == FST_AN						|| testReqMsg.SwitchType == LX_AN || testReqMsg.SwitchType == NEC_AN)				{					strcpy(testMsg.TestResult.TestConclusion, "ok");					writelog(logfp, "CONN-TACC-POTS: OK!");				}				else					strcpy(testMsg.Error, NOACCESSERR);				break;			case DISC_TACC:				strcpy(testMsg.TestResult.TestConclusion, "ok");				writelog(logfp, "DISC-TACC: OK!");				break;			default:				strcpy(testMsg.Error, INSERR);				break;			}													/* end of switch (testReqMsg.CommandType) */			return_msg(&testMsg);			close(sock);			exit(0);		}														/* end of if (fork()==0) */		else			/* the parent process */		{			writelog(logfp, "Parent Process!");			AddPidNode(pid);					/* Add pid into PidList for checking */		}	}															/* end of for (;;) */}/* end of main */void writelog(int logfp, char *fmt,...){	char buf[2048];	va_list ptr;	va_start(ptr, fmt);	vsprintf(buf, fmt, ptr);	va_end(ptr);	strcat(buf, "\n");	write(logfp, buf, strlen(buf));}/* end of log */void check_log(){	struct stat logstat;	char tmpbuf[256];	/* check logfile len */	if (fstat(logfp, &logstat) != -1)	{		if (logstat.st_size >= 1024 * 1024)		{			close(logfp);			remove(LOGOLD);			rename(LOGFILE, LOGOLD);			logfp = open(LOGFILE, O_WRONLY | O_CREAT, 0644);		}	}}/* end of check_log */void return_msg(TESTMSG * testMsg){	char buf[2048];	int wc;	wc = write(1, testMsg, TESTMSGSIZE);	sprintf(buf, "wc=%d\n", wc);	writelog(logfp, buf);	sprintf(buf, "return TESTMSG : CommandType=%d\n\			CorrelationTag=%s\n\			Error=%s\n\			TestConclusion=%s\n\			A-Bres=%s\n\			A-Gres=%s\n\			B-Gres=%s\n\			A-Gdc=%s\n\			B-Gdc=%s\n\			A-Gac=%s\n\			B-Gac=%s\n\			A-Bcap=%s\n\			A-Gcap=%s\n\			B-Gcap=%s\n\			EndFlag=%c",					testMsg->CommandType,					testMsg->CorrelationTag,					testMsg->Error,					testMsg->TestResult.TestConclusion,					testMsg->TestResult.TR2_DCres,					testMsg->TestResult.TG2_DCres,					testMsg->TestResult.RG2_DCres,					testMsg->TestResult.TG2_DCvol,					testMsg->TestResult.RG2_DCvol,					testMsg->TestResult.TG_ACvol,					testMsg->TestResult.RG_ACvol,					testMsg->TestResult.TR_cap,					testMsg->TestResult.TG_cap,					testMsg->TestResult.RG_cap,					testMsg->EndFlag);	writelog(logfp, buf);}/* end of return_msg *//*********************************************************Function:int conn_switch(int sock, int SwitchType, char *telephone, char *password)Narrative:	This function return the status of STSC testing pathParam:	int sock - socket id	int SwitchType - switch type 	char *telephone - char pointer to accessed telephone number string	char *password - char pointer to switch port password or EWSD dial number 	int *err- error.Return:  0   OK	-1   Can not connect Switch, or Switch no response	-2   Connect Switch OK, but wake up fail**********************************************************/int conn_switch(int sock, int SwitchType, char *telephone, char *password){	switch (SwitchType)	{	case NEAX61:		return (neax_conn_switch(sock));		break;	case NEAX_RSU:		return (neax_rsu_conn_switch(sock));		break;	case S1240E:	case S1240J:		return (s1240_conn_switch(sock));		break;	case DMS10:		return (dms10_conn_switch(sock, password));		break;	case HW_AN:	case ZX_AN:	case UT_AN:	case BE_AN:	case XMZ_AN:	case LX_AN:	case FST_AN:	case NEC_AN:		return (anet_conn_switch(sock, testReqMsg.CommandType, testReqMsg.TeleNumber, testReqMsg.V5EN, testReqMsg.OffHook, testReqMsg.Num, testReqMsg.Loop, testReqMsg.Channel, testReqMsg.UseGrade, testReqMsg.Grade, testReqMsg.TSN, &testMsg));		break;	case S5ESS:		return (att_5ess_conn_switch(sock));		break;	case DMS100:		return (dms100_conn_switch(sock));		break;	case CC08:		return (cc08_conn_switch(sock, testReqMsg.TeleNumber, &testMsg));		break;	case SP30:	case SP30CN:		return (sp30_conn_switch(sock));		break;	case EWSD:		return (ewsd_conn_switch(sock, password));		break;	case F150:		return (f150_conn_switch(sock));		break;	case AXE10:	default:		return -3;		break;	}}/* end of conn_switch *//*********************************************************Function:void timeout(int sig)Narrative:	This function deal with the alarm signal, when received this signal,	do function longjmp.Param:	int sig	- signalReturn:  none**********************************************************/void timeout(int sig){	signal(sig, SIG_IGN);	signal(SIGALRM, timeout);	longjmp(env, 0);}void f_set_result(TESTMSG * testMsg){	strcpy(testMsg->TestResult.RG2_DCvol, "0.300");	/*dr5:b-ground voltage */	strcpy(testMsg->TestResult.TG2_DCvol, "-0.200");		/*dr4:a-ground voltage */	strcpy(testMsg->TestResult.RG_ACvol, "0");		/*af2:b-ground AC voltage */	strcpy(testMsg->TestResult.TG_ACvol, "0");	/*af1:a-ground AC voltage */	strcpy(testMsg->TestResult.TR_cap, "0.680");	/*ac4:a-b capacity */	strcpy(testMsg->TestResult.RG_cap, "0.02");	/*ac6:b-ground capacity */	strcpy(testMsg->TestResult.TG_cap, "0.08");	/*ac5:a-ground capacity */	strcpy(testMsg->TestResult.TR2_DCres, "9999.999");	/*dr1:a-b resistant */	strcpy(testMsg->TestResult.RG2_DCres, "9999.999");		/*dr3:b-ground resistant */	strcpy(testMsg->TestResult.TG2_DCres, "9999.999");		/*dr2:a-ground resistant */}/*********************************************************Function: void DeletePidNode(CHILDPIDNODE * prevnode, CHILDPIDNODE * node)Narrative:	This function delete one node of PidList.Param:	CHILDPIDNODE * prevnode - the point of previous node	CHILDPIDNODE * node - the point of current nodeReturn:  none**********************************************************/void DeletePidNode(CHILDPIDNODE * prevnode, CHILDPIDNODE * node){	if (prevnode != PidList)	{		prevnode->Next = node->Next;	}	else	{		PidList = node->Next;	}	free(node);}/*********************************************************Function: void AddPidNode(int pid)Narrative:	This function add one node to PidList.Param:	int pid - process idReturn:  none**********************************************************/void AddPidNode(int pid){	CHILDPIDNODE *node, *newnode;	newnode = (CHILDPIDNODE *) malloc(sizeof(CHILDPIDNODE));	newnode->pid = pid;	newnode->Next = NULL;	if (PidList == NULL)		PidList = newnode;	else	{		node = PidList;		while (node->Next != NULL)			node = node->Next;		node->Next = newnode;	}}/*********************************************************Function: void CheckChildDied()Narrative:	This function handle the signal when child died.Param:	noneReturn:  none**********************************************************/void CheckChildDied(){	CHILDPIDNODE *node, *prevnode;	int rtn, stat;	ChildDiedFlag = 0;	prevnode = PidList;	node = PidList;	while (node != NULL)	{		if (node->pid > 0)		{			rtn = waitpid(node->pid, &stat, WNOHANG);			writelog(logfp, "CheckChildDied()::node pid=%d,stat=%d,rtn=%d", node->pid, stat, rtn);			/* if ((stat!= 0) && (rtn > 0)) */			if (rtn > 0 || (rtn < 0 && stat == 0))			{				node->pid = 0;				DeletePidNode(prevnode, node);				node = prevnode->Next;			}			else			{				prevnode = node;				node = node->Next;			}		}		else		{			DeletePidNode(prevnode, node);			node = prevnode->Next;		}	}}/*********************************************************Function: int f_simdrv_receive(int sock, char *szBuffer, int *len, int max_len, int wait_time)Narrative:	This function receive characters from the socket.Param:	int sock	- socket id	char *szBuffer	- buffer for receive	int *len	- received length	int max_len	- the max length 	int wait_time	- wait time , millisecondsReturn:  0 - receive ok	-1 - socket error	-2 - time out	-3 - port down**********************************************************/int f_simdrv_receive(int sock, char *szBuffer, int *len, int max_len, int wait_time){	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)	{		if (p >= max_len)			p = 0;		ret = poll(pollfdsp, 1, wait_time);		if (ret < 0)		{			writelog(logfp, "f_simdrv_receive()111::poll=%d,errno=%d\n", retval, errno);			if (errno != EAGAIN && errno != EFAULT && errno != EINTR && errno != EINVAL && errno != EWOULDBLOCK)				retval = -3;			else				retval = 0;			break;		}		else if (ret == 0)		{			retval = -2;			break;		}		if (pollfdsp[0].revents & POLLIN)		{			rc = read(sock, &ch, 1);			if (rc < 0)			{				writelog(logfp, "f_simdrv_receive()222::read=%d,errno=%d\n", retval, errno);				if (errno != EAGAIN && errno != EFAULT && errno != EINTR && errno != EINVAL && errno != EWOULDBLOCK)					retval = -3;				else					retval = 0;				break;			}			if (rc == 0)			{				retval = -1;				break;			}			szBuffer[p] = ch;			++p;			if (ch == ';')			{				szBuffer[p] = '\0';				break;			}		}	}	szBuffer[p] = '\0';	*len = p;	switch (retval)	{	case 0:		writelog(logfp, "Server Replied:p=%d\n", p);		/* writelog(logfp,"\nReceive OK!\n"); */		break;	case -1:		/* writelog(logfp,"Receive 0, exit\n"); */		break;	case -2:		/* writelog(logfp,"Server no respone!\n"); */		retval = 0;		break;	case -3:		/* writelog(logfp,"\nServer port down!\n"); */		break;	}	return (retval);}/*********************************************************Function: int CheckIdle()Narrative:	This function check simdrv's idle timeParam:	noneReturn: 1 - simdrv's idle time is longer than MaxIdleSeconds	0 - otherwise**********************************************************/int CheckIdle(){	time_t t;	t = time(NULL);	if (t - IdleStart > MaxIdleSeconds)		return 1;	else		return 0;}/*********************************************************Function: static void sig_child_died(int sig)Narrative:	child process died  functionParam:	int sig - signal numberReturn: none	0 - otherwise**********************************************************/static void sig_child_died(int sig){	sig = sig;	ChildDiedFlag = 1;}

⌨️ 快捷键说明

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