#include "uart.h" FILE *stream; #define TIMEOUT 60000L int iComPort,iChksum; long int lBaudRate; float ok_count[256],err_count[256]; /* ---- main ------------------------------------------------------------- */ main() { char cChar; iComPort=2; 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 binary command (for all module) *"); printf("\n* 3 : demo (0, 23, 678) (for all module) *"); printf("\n* 4 : demo 782N *"); printf("\n* 5 : RS-485 network testing (for all module) *"); 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': demo(); break; case '4': demo4(); break; case '5': test_485(); break; case 'q': case 'Q': goto ret_label; default : printf(" --> Error Keyword"); break; } } ret_label: printf("\n************** Diagnostic Program *******************"); } /* ---- 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,Len,i,j; printf(" --> (2):send Hex command\n"); printf("Len="); scanf("%d",&Len); for (i=0; i ",j); for (i=0; i (3):demo, command=$012,$01M,$01F"); printf("\nTest 0"); cCmd[0]=0; SEND_CMD(iComPort,cCmd,TIMEOUT,1); RECEIVE_CMD(iComPort, cCmd, TIMEOUT,&j); printf(" --> Len=%d --> ",j); for (i=0; i Len=%d --> ",j); for (i=0; i Len=%d --> ",j); for (i=0; i (4):demo, command=$012,$01M,$01F"); printf("\nTest 0"); cCmd[0]=':'; cCmd[1]='0'; cCmd[2]='1'; cCmd[3]=0; SEND_CMD(iComPort,cCmd,TIMEOUT,4); RECEIVE_CMD(iComPort, cCmd, TIMEOUT,&j); printf(" --> Len=%d --> ",j); for (i=0; i Len=%d --> ",j); for (i=0; i Len=%d --> ",j); for (i=0; i (4):host watchdog test, for 7021, Address=03"); strcpy(cCmd,"#0305.000"); SEND_CMD(iComPort,cCmd,TIMEOUT,0); iRet=RECEIVE_CMD(iComPort, cCmd, TIMEOUT,0); if ((iRet==0) & (cCmd[0]=='>')) printf("\nStep1 : DA=5.0 Volt"); else {printf("\ntest error"); return;} strcpy(cCmd,"~03310A"); SEND_CMD(iComPort,cCmd,TIMEOUT,0); iRet=RECEIVE_CMD(iComPort, cCmd, TIMEOUT,0); if ((iRet==0) & (cCmd[0]=='!')) printf("\nStep2 : enable host watchdog OK"); else {printf("\ntest error"); return;} printf("\nStep3 : HOST continuously reflesh watchdog timer (normal condition)"); printf("\n (press any key to simulate host failure)"); for(;;) { strcpy(cCmd,"~**"); SEND_CMD(iComPort,cCmd,TIMEOUT,0); iRet=RECEIVE_CMD(iComPort, cCmd, TIMEOUT,0); if (kbhit()!=0) {getch(); break;} } printf("\nStep4 : HOST is failure now (simulation)"); printf("\n --> host watchdog will active"); printf("\n --> D/A will go to safe state"); printf("\n --> module LED will flash"); printf("\n (press any key to continue)"); getch(); strcpy(cCmd,"~031"); SEND_CMD(iComPort,cCmd,TIMEOUT,0); iRet=RECEIVE_CMD(iComPort, cCmd, TIMEOUT,0); if (iRet==0) { printf("\nStep5 : clear module status"); printf("\n --> module LED will not flash"); } else {printf("\ntest error"); return;} } /* ---- function 5 -------------------------------------------------------- */ test_485() { int i,j,k,num,ComPort,checksum,iRet; long BaudRate; char str1[80],str2[80],str3[80]; float ok,err; ok=err=0.0; for(;;) { stream=fopen("test.dat","r"); fscanf(stream,"%d",&num); for (k=0; k