?? dms100_drv.c
字號:
{ 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) { if (p > 2047) p = 0; szBuffer[p] = ch; ++p; szBuffer[p] = '\0';#ifdef DEBUG /* fprintf(lp,"%02x,%c\n",ch,ch); */ /* fflush(lp); */#endif } if (ch == '>' || ch == '?') { if (strstr(szBuffer, end_str1)) {#ifdef DEBUG fprintf(lp, "\nFinish 1\n"); fflush(lp);#endif retval = 0; break; } else if (end_str2) { if (strstr(szBuffer, end_str2)) {#ifdef DEBUG fprintf(lp, "\nFinish 2\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 if (strstr(szBuffer, abnormal_str)) { writeport(sock, "ABORT\r"); ret = -3; } 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_dms100_analysis(char *receive_str, TESTMSG * testmsg)Narrative: Get 12 test values from Received stirng from switch.Param: char *receive_str - socket id TESTMSG * testmsg - struct of test messageReturn: 0 OK. RESULT_OTHER No expected string.*********************************************************/int f_dms100_analysis(char *receive_str, TESTMSG * testmsg){ char temp_str[30]; char *p, *q, *r; p = (char *) strstr(receive_str, "TIP "); if (!p) return (RESULT_OTHER); else { memset(temp_str, 0, 30); strncpy(temp_str, p + 12, 12); f_dms100_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 + 24, 10); f_dms100_get_cap(testmsg->TestResult.TG_cap, temp_str);#ifdef DEBUG fprintf(lp, "TG_cap=%s\n", testmsg->TestResult.TG_cap); fflush(lp);#endif memset(temp_str, 0, 30); strncpy(temp_str, p + 34, 10); f_dms100_get_vol(testmsg->TestResult.TG_ACvol, temp_str);#ifdef DEBUG fprintf(lp, "TG_ACvol=%s\n", testmsg->TestResult.TG_ACvol); fflush(lp);#endif memset(temp_str, 0, 30); strncpy(temp_str, p + 44, 10); f_dms100_get_vol(testmsg->TestResult.TG2_DCvol, temp_str);#ifdef DEBUG fprintf(lp, "TG2_DCvol=%s\n", testmsg->TestResult.TG2_DCvol); fflush(lp);#endif } p = (char *) strstr(receive_str, "RNG "); if (!p) return (RESULT_OTHER); else { memset(temp_str, 0, 30); strncpy(temp_str, p + 12, 12); f_dms100_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 + 24, 10); f_dms100_get_cap(testmsg->TestResult.RG_cap, temp_str);#ifdef DEBUG fprintf(lp, "RG_cap=%s\n", testmsg->TestResult.RG_cap); fflush(lp);#endif memset(temp_str, 0, 30); strncpy(temp_str, p + 34, 10); f_dms100_get_vol(testmsg->TestResult.RG_ACvol, temp_str);#ifdef DEBUG fprintf(lp, "RG_ACvol=%s\n", testmsg->TestResult.RG_ACvol); fflush(lp);#endif memset(temp_str, 0, 30); strncpy(temp_str, p + 44, 10); f_dms100_get_vol(testmsg->TestResult.RG2_DCvol, temp_str);#ifdef DEBUG fprintf(lp, "RG2_DCvol=%s\n", testmsg->TestResult.RG2_DCvol); fflush(lp);#endif } p = (char *) strstr(receive_str, "TIP TO RNG "); if (!p) return (RESULT_OTHER); else { memset(temp_str, 0, 30); strncpy(temp_str, p + 12, 12); f_dms100_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 + 24, 10); f_dms100_get_cap(testmsg->TestResult.TR_cap, temp_str);#ifdef DEBUG fprintf(lp, "TR_cap=%s\n", testmsg->TestResult.TR_cap); fflush(lp);#endif/* memset(temp_str,0,30); strncpy(temp_str,p+34,10); f_dms100_get_vol(testmsg->TestResult.TR_ACvol,temp_str); #ifdef DEBUG fprintf(lp,"TR_ACvol=%s\n",testmsg->TestResult.TR_ACvol); fflush(lp); #endif memset(temp_str,0,30); strncpy(temp_str,p+44,10); f_dms100_get_vol(testmsg->TestResult.TR2_DCvol,temp_str); #ifdef DEBUG fprintf(lp,"TR2_DCvol=%s\n",testmsg->TestResult.TR2_DCvol); fflush(lp); #endif */ } return (0);}/*********************************************************Function:void f_dms100_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_dms100_get_res(char *result, char *val_str){ char temp_str[30]; char *p, *q; float val; float dw; dw = 1 / 1000; p = val_str; q = temp_str; while (*p) { if (*p != ' ') { *q = *p; ++q; if (*p == 'M' || *p == 'm') { dw = 1000; break; } else if (*p == 'K' || *p == 'k') { dw = 1; break; } if (*p == '\x0a' || *p == '\x0d') break; } ++p; } *q = '\0'; val = atof(temp_str) * dw; sprintf(result, "%9.3f", val);}/*********************************************************Function:void f_dms100_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_dms100_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 != ' ') { *q = *p; ++q; if (*p == 'V' || *p == 'v' || *p == '\x0a' || *p == '\x0d') { break; } } ++p; } *q = '\0'; val = atof(temp_str); sprintf(result, "%8.3f", val);}/*********************************************************Function:void f_dms100_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_dms100_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 != ' ') { *q = *p; ++q; if (*p == 'U' || *p == 'u' || *p == '\x0a' || *p == '\x0d') break; } ++p; } *q = '\0'; val = atof(temp_str); sprintf(result, "%8.3f", val);}/*********************************************************Function:static void send_break(int sock)Narrative: Send break signal to switch tty port.Param: int sock - socket idReturn: None.*********************************************************/static void send_break(int sock){ char telnet_brk[] = {255, 243}; poll(0, 0, 50); write(sock, &telnet_brk[0], 1); write(sock, &telnet_brk[1], 1);}/*********************************************************Function:static int f_dms100_is_lock(char *buffer)Narrative: Detect whether accessed line is locked by switch system.Param: char *buffer - a pointer to receive_strReturn: 0 OK. 1 No matching stirng.*********************************************************/static int f_dms100_is_lock(char *buffer){ char *p; char match_str[] = "CKT TYPE LEN DN STATE FAIL EqPEC "; p = (char *) strstr(buffer, match_str); if (p != NULL) { if (strncmp(p + strlen(match_str) + 4 + 61 + 41, "PLO", 3) == 0) /* STATE==PLO, Line was locked */ return 1; } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -