/* 7000TOT.C for 7000 TimeOut count Test (USE COM2, RS-485) When use function ReceiveResponseFrom7000() need a parameter ltimeout, it means that the function check COM port input buffer for the response at max ltimeout times, if it check ltimeout times and has not get the response(do not get the 0x0d('\r')) it will return error code TimeOut. 7000TOT is use to determine the check times for 7000 modeules under the specified comunication baudrate. User need prepare a input file for the test, the format is as follow: baudrate=xxxx ;for example:9600 checksum=0 or 1 ;0:OFF, 1:ON addr=xx ;address number in HEX 00,01 - FF name=70xxD ;7060,7060D cmd=@01 ;test command count=xxxxx ;test count( 1-65534) The program will report the test result for max,min,average of check times. */ #include #include #include #include"..\lib\7188.h" FILE *infile; char buf[80]; char name[10]; unsigned count=100; int addr=1; char Cmd[20]; int checksum=0; long baudrate=9600; unsigned CheckTime; int SendCmdTo7000_2(unsigned char *cCmd, int iChksum) { unsigned char checksum=0; Set485DirToTransmit(2); /* change 485 direction to Transmit */ while (*cCmd) { ToCom2(*cCmd); if(iChksum) checksum+=*cCmd; cCmd++; } if(iChksum) { ToCom2(hex_to_ascii[checksum>>4]); ToCom2(hex_to_ascii[checksum&0xf]); } ToCom2(0x0d); /* send out 0x0D */ WaitTransmitOver2(); /* wait this character transmit over */ Set485DirToReceive(2); /* change 485 direction to Receive */ return NoError; } int ReceiveResponseFrom7000_2 (unsigned char *cCmd, long lTimeout, int iChksum) { int i; unsigned char c,checksum; long t; unsigned cnt; i=0; CheckTime=checksum=0; for(;;) { t=lTimeout; cnt=0; while(QueueIsEmpty==IsCom2()){ /* wait response */ cnt++; t--; if(!t) return TimeOut; /* time_out */ } if(cnt>CheckTime) CheckTime=cnt; c=ReadCom2(); /* receive next char */ if (c==0x0d){ /* receive 0x0d --> end of command */ cCmd[i]=0; break; } else { if(c){ cCmd[i]=c; /* store the command */ i++; /* next char */ if(iChksum) checksum+=c; } } } if (iChksum) { checksum-=cCmd[i-1]; checksum-=cCmd[i-2]; if(cCmd[i-1]!=hex_to_ascii[checksum&0x0f] || cCmd[i-2]!=hex_to_ascii[checksum>>4] ) return CheckSumError; cCmd[i-2]=0; /* when checksum is OK, remove the checksum */ } return NoError; } void main(int argc,char *argv[]) { unsigned maxcnt=0; unsigned mincnt=9999; unsigned average; unsigned long totalcount=0L; unsigned i; int ret; if(argc==1){ printf("command:7000tot in_file\n"); return; } infile=fopen(argv[1],"r"); if(!infile){ printf("cannot open in_file %s\n",argv[1]); return; } while(fgets(buf,79,infile)){ strupr(buf); if(!strncmp(buf,"BAUDRATE=",9)){ baudrate=atol(buf+9); } else if(!strncmp(buf,"CHECKSUM=",9)){ checksum=atoi(buf+9); } else if(!strncmp(buf,"ADDR=",5)){ addr=(ascii_to_hex(buf[5])<<4)+ascii_to_hex(buf[6]); } else if(!strncmp(buf,"NAME=",5)){ strncpy(name,buf+5,5); i=strlen(name); if(i && name[i-1]=='\n') name[i-1]=0; } else if(!strncmp(buf,"CMD=",4)){ strncpy(Cmd,buf+4,19); i=strlen(Cmd); if(i && Cmd[i-1]=='\n') Cmd[i-1]=0; } else if(!strncmp(buf,"COUNT=",6)){ count=atoi(buf+6); if(count==0) count=1; else if(count==65535) count--; } } fclose(infile); /* init system */ InitLib(); if(!Is7188()){ printf("7000TOT.EXE must run on 7188(D)/DOS\n"); return; } InstallCom2(baudrate,8,0,1); /* check if the module exist */ sprintf(buf,"$%02XM",addr); SendCmdTo7000_2(buf,checksum); ret=ReceiveResponseFrom7000_2(buf,10000,checksum); if(ret){ printf("Error on find module %s, error=%d\n",name,ret); } else { if(!strcmp(buf+3,name)){ printf("find %s at address %02X\n",name,addr); } else { printf("Cannot find %s, but find %s\n",name,buf+3); printf("Do you want continue the test ?(y/n)"); if(getch4()=='n') goto end; putch4('\n'); putch4('\r'); } } /* do test */ for(i=0;iCheckTime) mincnt=CheckTime; } printf("\rtest %d",i+1); } /* print result */ if(i){ printf("\nTest %s at baudrate %ld",name,baudrate); printf("\nMax check times=%u",maxcnt); printf("\nMin check times=%u",mincnt); printf("\nAverage check times=%u",(int)(totalcount/i)); } /* Test the count on ReceiveResponseFrom7000 */ printf("\nUse TimeOut=%u to test ReceiveResponseFrom7000()\n",maxcnt); for(i=0;i