📄 5ess_drv.c
字号:
if (rc < 0) { retval = -3; break; } if (rc == 0) { retval = -1; break; } if (ch != 0) { szBuffer[p] = ch; ++p; /* fprintf(lp,"%02x,%c\n",ch,ch); */ } if (ch == 0x0d && p > 3) { szBuffer[p] = '\0'; if (strstr(szBuffer, finish_str)) {#ifdef DEBUG fprintf(lp, "\nFinish\n");#endif retval = 0; break; } else if (strstr(szBuffer, fail_str)) {#ifdef DEBUG fprintf(lp, "\nFail\n");#endif retval = RESULT_OTHER; break; } } } } szBuffer[p] = '\0';#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");#endif break; case -1:#ifdef DEBUG fprintf(lp, "Receive 0, exit\n");#endif break; case -2:#ifdef DEBUG fprintf(lp, "Server no respone!\n");#endif break; case -3:#ifdef DEBUG fprintf(lp, "\nServer port down!\n");#endif break; } return (retval);}/*********************************************************Function:int result_receive_op_rslt(int sock, char *szBuffer)Narrative: Recieve responded string after send 'op-rslt' command.Param: int sock - socket id char *szBuffer - a pointer to array receive_strReturn: 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. RESULT_OTHER Fail for other reason.*********************************************************/int result_receive_op_rslt(int sock, char *szBuffer){ int p; int retval, ret, rc; char ch; char finish_str[] = "OP OFRSLT"; char busy_str[] = "TESTPOSITION IS BUSY"; char fail_str[] = "COULD NOT INTERPRET INPUT"; 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; /* fprintf(lp,"%02x,%c\n",ch,ch); */ } if (ch == 0x0d && p > 3) { szBuffer[p] = '\0'; if (strstr(szBuffer, finish_str)) {#ifdef DEBUG fprintf(lp, "\nFinish\n");#endif retval = 0; break; } else if (strstr(szBuffer, fail_str)) {#ifdef DEBUG fprintf(lp, "\nFail\n");#endif retval = RESULT_OTHER; break; } else if (strstr(szBuffer, busy_str)) {#ifdef DEBUG fprintf(lp, "\nBusy\n");#endif retval = RESULT_BUSY; break; } } } } szBuffer[p] = '\0';#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");#endif break; case -1:#ifdef DEBUG fprintf(lp, "Receive 0, exit\n");#endif break; case -2:#ifdef DEBUG fprintf(lp, "Server no respone!\n");#endif break; case -3:#ifdef DEBUG fprintf(lp, "\nServer port down!\n");#endif break; } return (retval);}/* FOREIGN VOLTAGE INSULATION RESISTANCE CAPACITANCE (VOLTS) (MOHMS) (UF) --------------- --------------------- ----------- AC A-E 0 V A-E 14.6 M A-E 0.11 uF < AC B-E 0 V B-E 16.0 M B-E 0.16 uF AC A-B 0 V A.B-E 7.63 M A-B 5.38 uF DC A-E + 0.0 V A-B 1.57 M OPN NOT RUN DC B-E + 0.0 V A-BATT 3.14 M DC A-B + 0.0 V B-BATT 9.98 M A.B-BATT 2.40 M *//*********************************************************Function:int f_5ess_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_5ess_analysis(char *receive_str, TESTMSG * testmsg){ char temp_str[30]; char *p, *q, *r; if (strlen(receive_str) < 600) return (RESULT_OTHER); p = (char *) strstr(receive_str, "AC A-E"); if (!p) return (RESULT_OTHER); else { /* ag_ACvoltage */ memset(temp_str, 0, 30); strncpy(temp_str, p + 6, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_vol(testmsg->TestResult.TG_ACvol, temp_str);#ifdef DEBUG fprintf(lp, "TG_ACvol=%s\n", testmsg->TestResult.TG_ACvol);#endif /* ag_resistance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 32, 15); temp_str[15] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_res(testmsg->TestResult.TG2_DCres, temp_str);#ifdef DEBUG fprintf(lp, "TG2_DCres=%s\n", testmsg->TestResult.TG2_DCres);#endif /* ag_capacitance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 57, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_cap(testmsg->TestResult.TG_cap, temp_str);#ifdef DEBUG fprintf(lp, "TG_cap=%s\n", testmsg->TestResult.TG_cap);#endif } p = (char *) strstr(receive_str, "AC B-E"); if (!p) return (RESULT_OTHER); else { /* bg_ACvoltage */ memset(temp_str, 0, 30); strncpy(temp_str, p + 6, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_vol(testmsg->TestResult.RG_ACvol, temp_str);#ifdef DEBUG fprintf(lp, "RG_ACvol=%s\n", testmsg->TestResult.RG_ACvol);#endif /* bg_resistance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 32, 15); temp_str[15] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_res(testmsg->TestResult.RG2_DCres, temp_str);#ifdef DEBUG fprintf(lp, "RG2_DCres=%s\n", testmsg->TestResult.RG2_DCres);#endif /* bg_capacitance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 57, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_cap(testmsg->TestResult.RG_cap, temp_str);#ifdef DEBUG fprintf(lp, "RG_cap=%s\n", testmsg->TestResult.RG_cap);#endif } p = (char *) strstr(receive_str, "AC A-B"); if (!p) return (RESULT_OTHER); else { /* ab_ACvoltage */ /* memset(temp_str,0,30); strncpy(temp_str,p+6,10); temp_str[10]='\0'; fprintf(lp,"temp_str=%s\n",temp_str); f_5ess_get_vol(testmsg->TestResult.TR_ACvol,temp_str); fprintf(lp,"TR_ACvol=%s\n",testmsg->TestResult.TR_ACvol); */ /* ab_capacitance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 57, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_cap(testmsg->TestResult.TR_cap, temp_str);#ifdef DEBUG fprintf(lp, "TR_cap=%s\n", testmsg->TestResult.TR_cap);#endif } p = (char *) strstr(receive_str, "DC A-E"); if (!p) return (RESULT_OTHER); else { /* ag_DCvoltage */ memset(temp_str, 0, 30); strncpy(temp_str, p + 6, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_vol(testmsg->TestResult.TG2_DCvol, temp_str);#ifdef DEBUG fprintf(lp, "TG2_DCvol=%s\n", testmsg->TestResult.TG2_DCvol);#endif /* ab_resistance */ memset(temp_str, 0, 30); strncpy(temp_str, p + 32, 15); temp_str[15] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_res(testmsg->TestResult.TR2_DCres, temp_str);#ifdef DEBUG fprintf(lp, "TR2_DCres=%s\n", testmsg->TestResult.TR2_DCres);#endif } p = (char *) strstr(receive_str, "DC B-E"); if (!p) return (RESULT_OTHER); else { /* bg_DCvoltage */ memset(temp_str, 0, 30); strncpy(temp_str, p + 6, 10); temp_str[10] = '\0';#ifdef DEBUG fprintf(lp, "temp_str=%s\n", temp_str);#endif f_5ess_get_vol(testmsg->TestResult.RG2_DCvol, temp_str);#ifdef DEBUG fprintf(lp, "RG2_DCvol=%s\n", testmsg->TestResult.RG2_DCvol);#endif } p = (char *) strstr(receive_str, "DC A-B"); if (!p) return (RESULT_OTHER); else { /* ab_DCvoltage */ /* memset(temp_str,0,30); strncpy(temp_str,p+6,10); temp_str[10]='\0'; fprintf(lp,"temp_str=%s\n",temp_str); f_5ess_get_vol(testmsg->TestResult.TR2_DCvol,temp_str); fprintf(lp,"TR2_DCvol=%s\n",testmsg->TestResult.TR2_DCvol); */ } return (0);}/*********************************************************Function:void f_5ess_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_5ess_get_res(char *result, char *val_str){ char temp_str[30]; char *p, *q; float val; int dw; dw = 1; p = val_str; q = temp_str; while (*p) { if (*p != ' ') { *q = *p; ++q; if (*p == 'M') { dw = 1000; break; } else if (*p == 'k') { dw = 1; break; } } ++p; } *q = '\0'; val = atof(temp_str) * dw; sprintf(result, "%9.3f", val);}/*********************************************************Function:void f_5ess_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_5ess_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') { break; } } ++p; } *q = '\0'; val = atof(temp_str); sprintf(result, "%8.3f", val);}/*********************************************************Function:void f_5ess_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_5ess_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') break; else if (*p == 'E') break; } ++p; } *q = '\0'; val = atof(temp_str); sprintf(result, "%8.3f", val);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -