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

📄 s1240_drv.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
📖 第 1 页 / 共 2 页
字号:
   #endif    memset(temp_str,0,30);   strncpy(temp_str,p+36,20);   f_s1240_get_vol(testmsg->TestResult.TR_ACvol,temp_str);   #ifdef DEBUG   fprintf(lp,"TR_ACvol=%s\n",testmsg->TestResult.TR_ACvol);   fflush(lp);   #endif    } */		/* get AG DCVol and ACVol */		p = strstr(q, "A-GND");		if (p != NULL)		{			memset(temp_str, 0, 30);			strncpy(temp_str, p + 12, 20);			f_s1240_get_vol(testmsg->TestResult.TG2_DCvol, temp_str);#ifdef DEBUG			fprintf(lp, "TG2_DCvol=%s\n", testmsg->TestResult.TG2_DCvol);			fflush(lp);#endif			memset(temp_str, 0, 30);			strncpy(temp_str, p + 33, 20);			f_s1240_get_vol(testmsg->TestResult.TG_ACvol, temp_str);#ifdef DEBUG			fprintf(lp, "TG_ACvol=%s\n", testmsg->TestResult.TG_ACvol);			fflush(lp);#endif		}		/* get BG DCVol and ACVol */		p = strstr(q, "B-GND");		if (p != NULL)		{			memset(temp_str, 0, 30);			strncpy(temp_str, p + 12, 20);			f_s1240_get_vol(testmsg->TestResult.RG2_DCvol, temp_str);#ifdef DEBUG			fprintf(lp, "RG2_DCvol=%s\n", testmsg->TestResult.RG2_DCvol);			fflush(lp);#endif			memset(temp_str, 0, 30);			strncpy(temp_str, p + 33, 20);			f_s1240_get_vol(testmsg->TestResult.RG_ACvol, temp_str);#ifdef DEBUG			fprintf(lp, "RG_ACvol=%s\n", testmsg->TestResult.RG_ACvol);			fflush(lp);#endif		}		q = strstr(receive_str, "RES                 CAP");		if (q == NULL)			return (RESULT_OTHER);		/* get AG RES and CAP */		p = strstr(q, "A-GND");		if (p != NULL)		{			memset(temp_str, 0, 30);			strncpy(temp_str, p + 12, 20);			f_s1240_get_res(testmsg->TestResult.TG2_DCres, temp_str);#ifdef DEBUG			fprintf(lp, "TG2_DCres=%s\n", testmsg->TestResult.TG2_DCres);			fflush(lp);#endif			memset(temp_str, 0, 30);			strncpy(temp_str, p + 33, 20);			f_s1240_get_cap(testmsg->TestResult.TG_cap, temp_str);#ifdef DEBUG			fprintf(lp, "TG_cap=%s\n", testmsg->TestResult.TG_cap);			fflush(lp);#endif		}		/* get BG RES and CAP */		p = strstr(q, "B-GND");		if (p != NULL)		{			memset(temp_str, 0, 30);			strncpy(temp_str, p + 12, 20);			f_s1240_get_res(testmsg->TestResult.RG2_DCres, temp_str);#ifdef DEBUG			fprintf(lp, "RG2_DCres=%s\n", testmsg->TestResult.RG2_DCres);			fflush(lp);#endif			memset(temp_str, 0, 30);			strncpy(temp_str, p + 33, 20);			f_s1240_get_cap(testmsg->TestResult.RG_cap, temp_str);#ifdef DEBUG			fprintf(lp, "RG_cap=%s\n", testmsg->TestResult.RG_cap);			fflush(lp);#endif		}		/* get AB RES and CAP */		p = strstr(q, "A-B");		if (p != NULL)		{			memset(temp_str, 0, 30);			strncpy(temp_str, p + 12, 20);			f_s1240_get_res(testmsg->TestResult.TR2_DCres, temp_str);#ifdef DEBUG			fprintf(lp, "TR2_DCres=%s\n", testmsg->TestResult.TR2_DCres);			fflush(lp);#endif			memset(temp_str, 0, 30);			strncpy(temp_str, p + 33, 20);			f_s1240_get_cap(testmsg->TestResult.TR_cap, temp_str);#ifdef DEBUG			fprintf(lp, "TR_cap=%s\n", testmsg->TestResult.TR_cap);			fflush(lp);#endif		}	}	return (0);}/*********************************************************Function:void f_s1240_get_res(char *result, char *val_str)Narrative:	Get value of resistance from received string from switch.Param:	char *result - value of resistance	char *val_str - received string from switchReturn:	None.*********************************************************/void f_s1240_get_res(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	float dw;	dw = 1;	p = val_str;	q = temp_str;	while (*p)	{		if (*p == ',')		{			*q = '.';			++q;		}		else if (isdigit(*p) || *p == '+' || *p == '-')		{			*q = *p;			++q;		}		if (*p == 'M' || *p == 'm')		{			dw = 1000;			break;		}		else if (*p == 'K' || *p == 'k')		{			dw = 1;			break;		}		else if (*p == 'O' || *p == 'o')		{			dw = 0.001;			break;		}		else if (*p == '\x0a' || *p == '\x0d')			break;		++p;	}	*q = '\0';	val = atof(temp_str) * dw;	sprintf(result, "%9.3f", val);}/*********************************************************Function:void f_s1240_get_vol(char *result, char *val_str)Narrative:	Get value of voltage from received string from switch.Param:	char *result - value of voltage	char *val_str - received string from switchReturn:	None.*********************************************************/void f_s1240_get_vol(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	float dw;	p = val_str;	q = temp_str;	dw = 1;	while (*p)	{		if (*p == ',')		{			*q = '.';			++q;		}		else if (isdigit(*p) || *p == '+' || *p == '-')		{			*q = *p;			++q;		}		if (*p == 'M' || *p == 'm')		{			dw = 0.001;			break;		}		else if (*p == 'V' || *p == 'v')		{			dw = 1;			break;		}		else if (*p == '\x0a' || *p == '\x0d')			break;		++p;	}	*q = '\0';	val = atof(temp_str) * dw;	sprintf(result, "%8.3f", val);}/*********************************************************Function:void f_s1240_get_cap(char *result, char *val_str)Narrative:	Get value of capacitance from received string from switch.Param:	char *result - value of capacitance	char *val_str - received string from switchReturn:	None.*********************************************************/void f_s1240_get_cap(char *result, char *val_str){	char temp_str[30];	char *p, *q;	float val;	float dw;	p = val_str;	q = temp_str;	dw = 1;	while (*p)	{		if (*p == ',')		{			*q = '.';			++q;		}		else if (isdigit(*p) || *p == '+' || *p == '-')		{			*q = *p;			++q;		}		if (*p == 'U' || *p == 'u')		{			dw = 1;			break;		}		else if (*p == 'N' || *p == 'n')		{			dw = 0.001;			break;		}		else if (*p == 'F' || *p == 'F')		{			dw = 1000000.0;			break;		}		else if (*p == '\x0a' || *p == '\x0d')			break;		++p;	}	*q = '\0';	val = atof(temp_str) * dw;	sprintf(result, "%8.3f", val);}/*********************************************************Function:static void send_break(int port_fd)Narrative:	Send break signal to switch iog port.Param:	int port_fd - socket idReturn:	None.*********************************************************/static void send_break(int sock){	char telnet_brk[] =	{255, 243};	write(sock, &telnet_brk[0], 1);	poll(0, 0, 50);	write(sock, &telnet_brk[1], 1);}/*********************************************************Function:int f_s1240_makepassword(char *password)Narrative:	Generate accessing string of password.Param:	char *password - a pointer to portpasswordReturn:	int value.*********************************************************/int f_s1240_makepassword(char *password){	strcat(password, ";");}/*********************************************************Function:int f_s1240_send_ctrlX(int port_fd)Narrative:	Send signal of ^X to reset command state.Param:	int port_fd	- socket idReturn:	Int value.*********************************************************/int f_s1240_send_ctrlX(int port_fd){	char test_str[5];#ifdef DEBUG	fprintf(lp, "Send ^X\n");	fflush(lp);#endif	sprintf(test_str, "%c", 0x18);	writeport(port_fd, test_str);	f_s1240_result_receive(port_fd, receive_str, NULL, NULL, 500);}/*********************************************************Function:int f_s1240_make518_7x_cmd(char *test_str, char *phone_number)Narrative:	Generate accessing string of 518 test command.Param:	char *test_str - a pointer to accessing string	char *phone_number - a pointer to telenumberReturn:	0	OK.*********************************************************/int f_s1240_make518_7x_cmd(char *test_str, char *phone_number){	sprintf(test_str, "518:DN=K'%s,TSEGMENT=11,VAL;\n", phone_number);	return 0;}/*********************************************************Function:int f_s1240_make518_5x_cmd(char *test_str, char *phone_number)Narrative:	Generate accessing string of 518 test command.Param:	char *test_str - a pointer to accessing string	char *phone_number - a pointer to telenumberReturn:	0	OK.*********************************************************/int f_s1240_make518_5x_cmd(char *test_str, char *phone_number){	sprintf(test_str, "518:DN=K'%s,EXEC=2;\n", phone_number);	return 0;}/*********************************************************Function:int s1240_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 s1240_conn_switch(int port_fd){	int ret;	int ret_val;	struct tm *ctime;	time_t lt;#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	lp = backup_log("./s1240_drv.log");	fprintf(lp, "\n>>> Start s1240 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	ret_val = 0;	send_break(port_fd);	receive_str[0] = 0;	ret = f_s1240_result_receive(port_fd, receive_str, NULL, NULL, 2000);	if (strstr(receive_str, "PASSWORD <") != NULL)		ret_val = 0;	else if (strlen(receive_str) == 0)		ret_val = -1;	else		ret_val = -2;	f_s1240_send_ctrlX(port_fd);#ifdef DEBUG	lt = time(NULL);	ctime = localtime(&lt);	fprintf(lp, "\n>>> Stop s1240 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;}/* example of s1240J (7x) report   PASSWORD <   JINGAN            1999-06-14  16:17:58  MO   001  0005/000C/0011   <518:DN=K'5551234,TSEGMENT=11,VAL;   SEQ=0597.990614 9002   COM=0518   JOB SUBMITTED   9000   RESULT FOLLOWS   JINGAN            1999-06-14  16:18:16  MO   001  0005/000C/0011   SEQ=0597+990614 04243  C7C04A   TESTING   REQ MANUAL TEST                                              SUCCESSFUL   -----------------------------------------------------------------------   NA      = H'8112      NBR = 11         DN = 5551234   DEVTYPE = ALCB   SBLTYPE = SLIF   TSEGMENT = 11                NBRLOOPS = 1                SEGMENT PASSED   MEASURED VALUES :   POT DC              POT AC   A-B           -   7,50  MVOLT            22,00  MVOLT   A-GND         -   1,00  MVOLT            40,00  MVOLT   B-GND         -   5,50  MVOLT            70,50  MVOLT   RES                 CAP   A-GND         >   5,00  MOHM            173,81  NFAR   B-GND         >   5,00  MOHM            176,85  NFAR   A-B           >   5,00  MOHM          >   1,12  UFAR   REF TO DIAL INPUT SEQ = 597   REPORT FOLLOWS       NO = 04243   JINGAN            1999-06-14  16:18:16  MO   001  0005/000C/0011   SEQ=0597.990614 00527  C7C04A   SUBSCRIBER LINE TEST   COMMAND ENTERED: EXE-REQ-MT                                 SUCCESSFUL   ----------------------------------------------------------------------   GLOBAL  OUTWARD  TEST (11)   UNIT UNDER TEST:   EN    = H'8112  &  11   DN    = 5551234   SUBSCRIBER TYPE =  ANALOGUE   TEST COMMENTS:   RESULT= TEST OK,         ENVIRONMENT      DIS-ESTABLISHED   LAST REPORT          NO = 00527 *//* example of s1240E (5x) report   PASSWORD <^W         DONG_SHAN         1998-04-17  17:04:19  FR   <518:DN=K'8728393,EXEC=2;   SEQ=1460.980417 9002   COM=0518   JOB SUBMITTED   9000   RESULT FOLLOWS   ^B   DONG_SHAN         1998-04-17  17:04:40  FR         SEQ=1460.980417 0154   TESTING   REQ MANUAL TEST                                          NOT SUCCESSFUL   -----------------------------------------------------------------------   EXCH    = 0        NA = H'1603      NBR = 242        DN = 8728393    POT DC              POT AC                             A-B             000,000 VOLT        000,000 VOLT        A-GND           000,000 VOLT        000,000 VOLT        B-GND           000,000 VOLT        000,000 VOLT        RES                 CAP                              A-B             007,650 MOHM    !   012,237 NFAR  !     A-GND         > 010,000 MOHM        005,656 NFAR        B-GND         > 010,000 MOHM        005,656 NFAR        LAST REPORT          NO = 0154   ^C */

⌨️ 快捷键说明

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