#include "uart.h" #include FILE *stream; #define TIMEOUT 100000L int iComPort,iChksum,iTotal53, iTotal43, iTotal17, iTotal12, iDebug; int iTest53, iTest43, iTest17, iTest12; long int lBaudRate; float ok_count[256],err_count[256]; char address[256][2]; /* ---- main ------------------------------------------------------------- */ main() { char cChar; load_test_dat(); iComPort=1; iChksum=0; lBaudRate=115200L; OPEN_COM(iComPort,lBaudRate); /* default */ for(;;) { printf("\n************** Diagnostic Program *******************"); show_status(); printf("\n* 0 : init (for all module) *"); printf("\n* 1 : search (1200 to 115200)(for all module) *"); printf("\n* 2 : send command (for all module) *"); printf("\n* 3 : I-7053 performance test *"); printf("\n* 4 : I-7043 performance test *"); printf("\n* 5 : I-7017 performance test *"); printf("\n* 6 : I-7012 performance test *"); printf("\n* Q : quit *"); printf("\n*************** Press Keyword ***********************"); printf("\n"); cChar=getche(); switch (cChar) { case '0': init(); break; case '1': search(); break; case '2': send_command(); break; case '3': test_7053(); break; case '4': test_7043(); break; case '5': test_7017(); break; case '6': test_7012(); break; case 'q': case 'Q': goto ret_label; default : printf(" --> Error Keyword"); break; } } ret_label: printf("\n************** Diagnostic Program *******************"); } /* ---- load test.dat ---------------------------------------------------- */ load_test_dat() { FILE *stream; stream=fopen("test.dat","r"); fscanf(stream,"%d %d",&iTotal53,&iTest53); fscanf(stream,"%d %d",&iTotal43,&iTest43); fscanf(stream,"%d %d",&iTotal17,&iTest17); fscanf(stream,"%d %d",&iTotal12,&iTest12); fscanf(stream,"%d",&iDebug); fclose(stream); printf("\nTotal modules of I-7053 = %d , test=%d",iTotal53,iTest53); printf("\nTotal modules of I-7043 = %d , test=%d",iTotal43,iTest43); printf("\nTotal modules of I-7017 = %d , test=%d",iTotal17,iTest17); printf("\nTotal modules of I-7012 = %d , test=%d",iTotal12,iTest12); if (iDebug==0) printf("\nHigh speed test mode"); else printf("\nLow speed test mode"); } /* ---- show status ------------------------------------------------------ */ show_status() { printf("\n* STATUS : COM=%d,",iComPort); printf("Baud_Rate=%5ld,",lBaudRate); if (iChksum==0) printf("Checksum=DISABLE *"); else printf("Checksum=ENABLE *"); printf("\n*---------------------------------------------------*"); } /* ---- function 0 ------------------------------------------------------- */ init() { int iRet,iPort; printf(" --> (0):init\n"); printf("port (1/2/3/4)="); scanf("%d",&iPort); printf("baud rate(1200/2400/4800/9600/19200/38400/57600/115200)="); scanf("%ld",&lBaudRate); printf("chksum (0=DISABLE,others=ENABLE)="); scanf("%d",&iChksum); iRet=OPEN_COM(iPort,lBaudRate); if (iRet==0) {printf("--> OK"); iComPort=iPort;} else if (iRet==1) printf("--> port error"); else if (iRet==2) printf("--> baudrate error"); } /* ---- function 1 ------------------------------------------------------- */ char cCmd1[100],cCmd2[100],cCmd3[100]; search() { int i,iD1,iD2,iRet,j; long BaudRate; char cFlag; printf(" Search address=00 to FF, baudrate=1200 to 115200, press any key to stop\n"); cCmd1[0]='$'; strcpy(cCmd3,"Test Command"); for(;;) for (i=0; i<256; i++) /* search from adress_00 to adress_FF */ { printf("\n---------------------------------------------\n"); for (j=3; j<=10; j++) /* search from BaudRate_1200 to BaudRate_115200 */ { switch (j) { case 3 : BaudRate=1200L; break; case 4 : BaudRate=2400L; break; case 5 : BaudRate=4800L; break; case 6 : BaudRate=9600L; break; case 7 : BaudRate=19200L; break; case 8 : BaudRate=38400L; break; case 9 : BaudRate=57600L; break; case 10: BaudRate=115200L; break; } /* OPEN_COM(iComPort,BaudRate); */ iRet=OPEN_COM(iComPort,BaudRate); if (iRet!=0) printf(" Open Error, iComPort=%d, BaudRate=%ld iRet=%d",iComPort,BaudRate,iRet); SEND_CMD(iComPort,cCmd3,TIMEOUT,0); /* RS-232 settling time delay */ RECEIVE_CMD(iComPort,cCmd2,TIMEOUT,0); /* chksum disable */ iD1=i/16; iD2=i%16; cCmd1[1]=get_ascii(iD1); cCmd1[2]=get_ascii(iD2); cCmd1[3]='2'; cCmd1[4]=0; /* $AA2 --> read status */ cFlag=0; /* ------------------- checksum DISABLE ----------------------------------- */ SEND_CMD(iComPort,cCmd1,TIMEOUT,0); /* chksum disable */ iRet=RECEIVE_CMD(iComPort, cCmd2, TIMEOUT,0); /* chksum disable */ if (iRet==0) { cFlag=1; /* find module in chksum DISABLE */ cCmd1[3]='M'; cCmd1[4]=0; /* $AAM --> read module name */ SEND_CMD(iComPort,cCmd1,TIMEOUT,0); /* chksum disable */ iRet=RECEIVE_CMD(iComPort, cCmd2, TIMEOUT,0);/* chksum disable */ if (iRet==0) { printf("\nFind %c%c%c%c --> Address=%d, Chksum DISABLE, speed=%ld ", cCmd2[3],cCmd2[4],cCmd2[5],cCmd2[6],i,BaudRate); } } /* ------------------- checksum ENABLE ----------------------------------- */ cCmd1[3]='2'; cCmd1[4]=0; /* $AA2 --> read status */ SEND_CMD(iComPort,cCmd1,TIMEOUT,1); /* chksum enable */ iRet=RECEIVE_CMD(iComPort, cCmd2, TIMEOUT,1); /* chksum enable */ if (iRet==0) { cFlag=1; /* find module in chksum ENABLE */ cCmd1[3]='M'; cCmd1[4]=0; /* $AAM --> read module name */ SEND_CMD(iComPort,cCmd1,TIMEOUT,1); /* chksum enable */ iRet=RECEIVE_CMD(iComPort, cCmd2, TIMEOUT,1);/* chksum enable */ if (iRet==0) { printf("\nFind %c%c%c%c --> Address=%d, Chksum ENSABLE, speed=%ld ", cCmd2[3],cCmd2[4],cCmd2[5],cCmd2[6],i,BaudRate); } } if (cFlag==0) printf("[%ld,%x]",BaudRate,i); if (kbhit()!=0) {getch(); goto ret_label;} } } ret_label: OPEN_COM(iComPort,lBaudRate); /* default */ } /* ----------------------------------------------------------------------- */ get_ascii(int iHex) { if (iHex<10) return(iHex+'0'); else return('A'+iHex-10); } /* ---- function 2 ------------------------------------------------------- */ send_command() { char cCmd1[50],cCmd2[50]; int iRet; printf(" --> (2):send_command\n"); printf("cmd="); scanf("%s",cCmd1); SEND_CMD(iComPort,cCmd1,TIMEOUT,iChksum); iRet=RECEIVE_CMD(iComPort, cCmd2, TIMEOUT,iChksum); printf("Port=%d, chksum=%d, Send=%s\n",iComPort,iChksum,cCmd1); if (iRet==0) printf("Receive=%s",cCmd2); else if (iRet==1) printf("Receive=com value error (must 1/2/3/4)"); else if (iRet==2) printf("Receive=Timeout"); else if (iRet==3) printf("Receive=chksum error"); } /* ---- function 3 -------------------------------------------------------- */ test_7053() { int total,i,j,h,l,iRet; clock_t start,end; float ok,err,tt; cCmd1[0]='@'; cCmd1[3]=0; ok=err=0; for (i=0; i<256; i++) { h=i/10; l=i%10; if (h<=9) address[i][0]=h+'0'; else address[i][0]=h-10+'A'; if (l<=9) address[i][1]=l+'0'; else address[i][1]=l-10+'A'; } start=clock(); for (j=0;j receive=%s",cCmd2); delay(10000); } if (iRet==0) ok++; else err++; } if (kbhit()!=0) {getch(); return;} } end=clock(); printf("\nok=%f, err=%f",ok,err); tt=(end-start)/CLK_TCK; printf("\nThe time=%f",tt); printf("\nPerformance=%f samples/second",(float)(iTotal53*iTest53)*16.0/tt); } /* ---- function 4 -------------------------------------------------------- */ test_7043() { } /* ---- function 5 -------------------------------------------------------- */ test_7017() { int total,i,j,h,l,iRet; clock_t start,end; float ok,err,tt; cCmd1[0]='$'; cCmd1[3]='A'; cCmd1[4]=0; ok=err=0; for (i=0; i<256; i++) { h=i/10; l=i%10; if (h<=9) address[i][0]=h+'0'; else address[i][0]=h-10+'A'; if (l<=9) address[i][1]=l+'0'; else address[i][1]=l-10+'A'; } start=clock(); for (j=0; j receive=%s",cCmd2); delay(1000); } } if (kbhit()!=0) {getch(); return;} } end=clock(); printf("\nok=%f, err=%f",ok,err); tt=(end-start)/CLK_TCK; printf("\nThe time=%f",tt); printf("\nPerformance=%f samples/second",(float)(iTotal17*iTest17)*8.0/tt); } /* ---------------- */ find_hex(char str[]) { int i,j; char hex[8][5]; j=1; for (i=0; i<8; i++) { hex[i][4]=0; hex[i][0]=str[j]; j++; hex[i][1]=str[j]; j++; hex[i][2]=str[j]; j++; hex[i][3]=str[j]; j++; } /* for (i=0; i<8; i++) printf(" %s",&(hex[i][0])); */ } /* ---- function 6 -------------------------------------------------------- */ test_7012() { int total,i,j,h,l,iRet,len; clock_t start,end; float ok,err,tt; cCmd1[0]='#'; cCmd1[3]=0; ok=err=0; for (i=0; i<256; i++) { h=i/10; l=i%10; if (h<=9) address[i][0]=h+'0'; else address[i][0]=h-10+'A'; if (l<=9) address[i][1]=l+'0'; else address[i][1]=l-10+'A'; } strcpy(cCmd1,"#01"); iRet=0; start=clock(); for (j=0; j receive=%s",cCmd2); delay(1000); } if (iRet==0) ok++; else err++; } if (kbhit()!=0) {getch(); return;} } end=clock(); printf("\nok=%f, err=%f",ok,err); tt=(end-start)/CLK_TCK; printf("\nThe time=%f",tt); printf("\nPerformance=%f samples/second",(float)(iTotal12*iTest12)/tt); }