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

📄 neax_rsu_drv.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
📖 第 1 页 / 共 3 页
字号:
_exit_neax1:#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	fprintf(lp, "Now stat: %d,ret=%d\n", stat, ret);	fprintf(lp, "\n>>> Stop Neax-61 (RSU) Test at %4d.%02d.%02d %02d:%02d:%02d <<<\n", ctime->tm_year + 1900, ctime->tm_mon + 1, ctime->tm_mday, ctime->tm_hour, ctime->tm_min, ctime->tm_sec);	fflush(lp);#endif	switch (ret)	{	case -1:		ret = AM_UNREADY_ERROR;		break;	case -2:		ret = AM_UNREADY_ERROR;		break;	case -3:		ret = AM_PORT_DOWN;		break;	case -4:		ret = AM_UNREADY_ERROR;		break;	case -5:		ret = 0;		strcpy(testmsg->TestResult.TestConclusion, "V08");		break;	case -6:		ret = 0;		strcpy(testmsg->TestResult.TestConclusion, "V6");		break;	case -7:		ret = AM_TIME_OUT;		break;	}	if (stat == STAT_FINISH)	{		/* f_show_msg(testmsg); */		return (0);									/* finish */	}	else	{		return (ret);	}}/* end of neax_proc *//*********************************************************Function:char *f_nec_rsu_make_access_str(char *phone_number)Narrative:	Generate accessing string of telephone number to switch.Param:	char *phone_number - Telephone number of accessed line.Return:	String of telephone number		*********************************************************/char *f_nec_rsu_make_access_str(char *phone_number){	char *p, *q;	static char str_return[50];	p = phone_number;	q = str_return;	for (; *p != '\0'; ++p)	{		if (*p == '0')			*p += 0x0a;		*q = '\x40';		*(q + 1) = '\x20' + *p;		*(q + 2) = '\x0d';		q += 3;	}	*q = '\0';	return (str_return);}/*********************************************************Function:int f_nec_rsu_send_wakeup1(int port_fd, int *stat)Narrative:	Active switch port by sending wakeup1 signal.Param:	int port_fd	- socket id	int *stat - a pointer to test stateReturn:	0   OK.	-1	No expected string.	-2	No fd ready when timeout.	-3	An error occur when performing poll or read.*********************************************************/int f_nec_rsu_send_wakeup1(int port_fd, int *stat){	struct pollfd pollfdsp[1];	char ch, str[256];	int p, rc, ret;	pollfdsp[0].fd = port_fd;	pollfdsp[0].events = POLLIN;	pollfdsp[0].revents = 0;	/* send Wakeup1 string to switch port */	if (do_wakeup1_flag)	{#ifdef DEBUG		fprintf(lp, "Send WakeUp1\n");		fflush(lp);#endif		writeport(port_fd, str_wakeup1);		do_wakeup1_flag = 0;		poll(0, 0, 10);	}	*stat = STAT_WAKEUP2;	return (0);/*   p=0;   while (1){   ret=poll(pollfdsp,1,10000);   if (ret<0)   return(-3);   if (ret==0)   return(-2);   if (pollfdsp[0].revents & POLLIN){   rc=read(port_fd,&ch,1);   if (rc<=0)   return(-3);   if (ch=='\0')   continue;   #ifdef DEBUG   fprintf(lp,"%02X,%c\n",ch,ch);   #endif    if (ch==str_wakeup1_resp[p])   {   ++p;   if (p==strlen(str_wakeup1_resp))   {   poll(0,0,10);   *stat=STAT_WAKEUP2;   #ifdef DEBUG   fprintf(lp,"\nsend Wakeup1 string OK!\n");   fflush(lp);   #endif    return (0);   }   }   else   p=0;   }   } */}/* end of f_nec_rsu_send_wakeup1 *//*********************************************************Function:int f_nec_rsu_send_wakeup2(int port_fd, int *stat, int *char_cnt)Narrative:	Active switch port by sending wakeup2 signal.Param:	int port_fd	- socket id	int *stat - a pointer to test state	int *char_cnt - a pointer to character number recievedReturn:	0   OK.	-1	No expected string.	-2	No fd ready when timeout.	-3	An error occur when performing poll or read.*********************************************************/int f_nec_rsu_send_wakeup2(int port_fd, int *stat, int *char_cnt){	struct pollfd pollfdsp[1];	char ch, str[256];	int p, rc, ret;	pollfdsp[0].fd = port_fd;	pollfdsp[0].events = POLLIN;	pollfdsp[0].revents = 0;	*char_cnt = 0;	/* send Wakeup2 string to switch port */	writeport(port_fd, str_release1);	poll(0, 0, 50);	writeport(port_fd, str_wakeup2);	p = 0;	while (1)	{		ret = poll(pollfdsp, 1, 2000);		if (ret < 0)			return (-3);		if (ret == 0)			return (-2);		if (pollfdsp[0].revents & POLLIN)		{			rc = read(port_fd, &ch, 1);			if (rc <= 0)				return (-3);			++*char_cnt;							/* count received char number */			if (ch == '\0')				continue;/*   #ifdef DEBUG   fprintf(lp,"%02X,%c\n",(unsigned char)ch,ch);   #endif  */			if (ch == str_wakeup2_resp[p])			{				++p;				if (p == strlen(str_wakeup2_resp))				{					poll(0, 0, 10);					*stat = STAT_ACCESS;#ifdef DEBUG					fprintf(lp, "\nsend Wakeup2 string OK!\n");					fflush(lp);#endif					return (0);				}			}			else				p = 0;		}	}}/* end of f_nec_rsu_send_wakeup2 *//*********************************************************Function:int f_nec_rsu_access(int port_fd, char *phone_number, int *stat)Narrative:	Access line.Param:	int port_fd	- socket id	char *phone_number - Telephone number of accessed line	int *stat - a pointer to test stateReturn:	0   OK.	1	Line busy.	2	Line busy.	3	Line busy.	-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_nec_rsu_access(int port_fd, char *phone_number, int *stat){	struct pollfd pollfdsp[1];	char ch, str[2048];	int p, q, r, rc, ret;	int i;	int result;										/* 0 - Access OK  1 - Line Busy  2 - Lock Out  3 - Channel Busy */	char str_begin[] =	{0x43, 0x40, 0x0d, 0x00};	char str_end[] =	{0x40, 0x5f, 0x0d, 0x00};	char str_channel_busy[] =	{0x42, 0x43, 0x0d, 0x00};	char str_access_ok[] =	{0x40, 0x51, 0x0d, 0x40, 0x55, 0x0d, 0x40, 0x53, 0x0d, 0x00};	char str_access_not_ok[] =	{0x40, 0x51, 0x0d, 0x40, 0x56, 0x0d, 0x40, 0x53, 0x0d, 0x00};	char str_access_line_busy[] =	{0x40, 0x58, 0x0d, 0x40, 0x55, 0x0d, 0x40, 0x59, 0x0d, 0x40, 0x51, 0x0d, 0x40, 0x5f, 0x0d, 0x00};	char str_access_lock_out[] =	{0x40, 0x58, 0x0d, 0x40, 0x54, 0x0d, 0x40, 0x59, 0x0d, 0x40, 0x51, 0x0d, 0x40, 0x5f, 0x0d, 0x00};	char str_access_lock_out1[] =	{0x40, 0x51, 0x0D, 0x40, 0x51, 0x0D, 0x40, 0x58, 0x0D, 0x40, 0x52, 0x0D, 0x40, 0x5F, 0x0D, 0x00};	pollfdsp[0].fd = port_fd;	pollfdsp[0].events = POLLIN;	pollfdsp[0].revents = 0;#ifdef DEBUG	fprintf(lp, "\nphone number: %s\n", phone_number);	fflush(lp);#endif	/* send Access string to switch port */	writeport(port_fd, f_nec_rsu_make_access_str(phone_number));	result = 0;	p = 0;	q = 0;	r = 0;	while (1)	{		ret = poll(pollfdsp, 1, 8000);		if (ret < 0)			return (-3);		if (ret == 0)			return (-2);		if (pollfdsp[0].revents & POLLIN)		{			rc = read(port_fd, &ch, 1);			if (rc <= 0)				return (-3);			if (ch == '\0')				continue;/*   #ifdef DEBUG   fprintf(lp,"%02X,%c\n",(unsigned char)ch,ch);   fflush(lp);   #endif  */			str[r] = ch;			++r;			if (r >= 2048)				r = 0;			if (ch == str_channel_busy[p])			{				++p;				if (p == strlen(str_channel_busy))				{					poll(0, 0, 10);					result = 3;						/* result=3  Channel Busy */					/*result=0;             /* Test anyway, Channel Busy */					break;				}			}			else				p = 0;			if (ch == str_end[q])			{				++q;				if (q == strlen(str_end))				{					poll(0, 0, 10);					str[r] = '\0';#ifdef DEBUG					fprintf(lp, "\naccess response string: ");					for (i = 0; i < strlen(str); ++i)						fprintf(lp, "%02X,", (unsigned char) str[i]);					fprintf(lp, "\n");					fflush(lp);#endif					result = -1;					if (strstr(str, str_access_ok) != NULL)					{						result = 0;						break;					}					else					{						if (strstr(str, str_access_not_ok) != NULL)						{							if (strstr(str, str_access_line_busy) != NULL)							{								result = 1;								break;							}							else if (strstr(str, str_access_lock_out) != NULL || strstr(str, str_access_lock_out1) != NULL)							{								/* result=2;          *//* Lock Out */								result = 0;			/* Test anyway, Lock Out */								break;							}						}					}					break;				}			}			else				q = 0;		}	}	str[r] = '\0';#ifdef DEBUG	fprintf(lp, "\nsend Access string OK!\n");	fflush(lp);#endif	if (result == 0)	{#ifdef DEBUG		fprintf(lp, "\nAccess line OK!\n");#endif		*stat = STAT_ACCESS_STATE;	}	else if (result == 1 || result == 2 || result == 3)	{#ifdef DEBUG		fprintf(lp, "Line busy!\n");#endif	}	return (result);}/*********************************************************Function:int f_nec_rsu_access_state(int port_fd, int *stat)Narrative:	Send access state command to switch.Param:	int port_fd	- socket id	int *stat - a pointer to test stateReturn:	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_nec_rsu_access_state(int port_fd, int *stat){	struct pollfd pollfdsp[1];	char ch;	int p, q, rc, ret;	int result;										/* 1 - off hook   2 - on hook */	char str_off_hook[] =	{0x42, 0x60, 0x0d, 0x00};	char str_on_hook[] =	{0x42, 0x61, 0x0d, 0x00};	pollfdsp[0].fd = port_fd;	pollfdsp[0].events = POLLIN;	pollfdsp[0].revents = 0;	/* send Access State string to switch port */	writeport(port_fd, str_access_state);	p = 0;	q = 0;	while (1)	{		ret = poll(pollfdsp, 1, 5000);		if (ret < 0)			return (-3);		if (ret == 0)			return (-2);		if (pollfdsp[0].revents & POLLIN)		{			rc = read(port_fd, &ch, 1);			if (rc <= 0)				return (-3);			if (ch == '\0')				continue;/*   #ifdef DEBUG   fprintf(lp,"%02X,%c\n",(unsigned char)ch,ch);   fflush(lp);   #endif  */

⌨️ 快捷键说明

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