/* program: ECHOCOM.C use : echocom [/pn] [/bm] [/to] [/ep] where n is comport,may be 1 or 2 or 3 m is baudrate(2400-115200) o is 0(command mode) or 1(Bypass mode) p is 0(echo off) or 1(echo on) (1) must run on 7188 (2) default baudrate is 9600 , default port is COM3 (3) In bypass mode, any data key in will be direct send to comport (4) echo ON/OFF is used on bypass mode. function description: (1) echo any data on the 7188's COM1/2/3 to COM4. (2) data come from COM4(end with CR(0x0d)) will be send to COM1/2/3(data in will be buffered,until receive 0x0d, 7188 will send out the buffered data.(if checksum enable, will append checksum(2 bytes) after the data,before 0x0d.) (3) press 'q'(not 'Q') to quit. (4) press 's'(not 'S') to toggle checksum mode. so 'q' and 's' will not be send to comport. (5) default mode is checksum disable. (6) protocal is 1 start bit,8 data bit,none parity,1 stop bit. (7) when use COM2, echocom is the same as echo485 (8) press CTRL_A/B/C change to use COM1/2/3 (9) input "*bxxxx" to change baudrate,where the xxxx is baudrate. for example: *b115200 change baudrate to 115200 *b9600 change baudrate to 9600 [10/11/1999] Add show COM port,checksum,baudrate on 5-DigitLED position 1: 1/2/3 for COM1/2/3 position 2: 0/1 for checksum OFF/ON position 3-5: 115--> baudrate=115200 576--> baudrate=57600 384--> baudrate=38400 192--> baudrate=19200 096--> baudrate=9600 048--> baudrate=4800 024--> baudrate=2400 012--> baudrate=1200 006--> baudrate=600 003--> baudrate=300 [10/12/1999] Ver. 1.02 Add bypass mode, in bypass mode can set Echo ON/OFF *p0 --> end of bypass mode *p1 --> to bypass mode *e0 --> echo off *e1 --> echo on Only on [Command mode] can use *p,*e,*b command. Press CTRL_E to toggle between COMMAND mode and BYPASS mode [10/19/1999] use SetBaudrate1(),SetBaudrate2(),SetBaudrate3() to change baudrate. */ #include #include #include"..\lib\7188.h" unsigned no; unsigned char buf[80]; unsigned char OutBuf[80]; int idx=0; int outidx=0; int Bypass=0; int Echo=1; void ShowPort(int port) { Show5DigitLedWithDot(1,port); } void ShowChecksum(int checksum) { Show5DigitLedWithDot(2,checksum); } void ShowBaudrate(long baud) { int data; if(baud>100000) data=baud/1000; else data=baud/100; Show5DigitLed(5,data%10); data/=10; Show5DigitLed(4,data%10); data/=10; Show5DigitLed(3,data%10); } main(int argc,char *argv[]) { long baud=9600; int quit=0; int data; int i; int checksum=0; int port=3; int val; if(!Is7188()){ puts("\nechocom must run on 7188!"); return; } for(i=1;i COM1 */ if(port != 1){ RestoreCom(port); port=1; InstallCom(port,baud,8,0,1); printCom4("\n\rChange to COM1, Baud=%ld checksum=%d\n\r",baud,checksum); ShowPort(port); } } else if(data==2){ /* CTRL_B --> COM2 */ if(port != 2){ RestoreCom(port); port=2; InstallCom(port,baud,8,0,1); printCom4("\n\rChange to COM2, Baud=%ld checksum=%d\n\r",baud,checksum); ShowPort(port); } } else if(data==3){ /* CTRL_C --> COM3 */ if(port != 3){ RestoreCom(port); port=3; InstallCom(port,baud,8,0,1); printCom4("\n\rChange to COM3, Baud=%ld checksum=%d\n\r",baud,checksum); ShowPort(port); } } else if(data==5){ /* CTRL_E */ Bypass=!Bypass; printCom4("\n\rChange to %s mode\n\r",Bypass?"Bypass":"Command"); } else if(Bypass){ ToCom(port,data); if(Echo){ ToCom(4,data); } } else if(data=='q') quit=1; else if(data=='s'){ checksum=!checksum; ToComStr(4,"CheckSum="); ToCom(4,'0'+checksum); ToComStr(4,"\r\n"); ShowChecksum(checksum); } else if(data=='\b'){ if(outidx){ outidx--; ToCom(4,data); } } else { OutBuf[outidx++]=data; ToCom(4,data); if(data=='\r'){ unsigned char sum=0; ToCom(4,'\n'); outidx--; if(OutBuf[0]=='*'){ switch(OutBuf[1]){ case 'b': case 'B': {long b=atol(OutBuf+2); if(b>=300 && b<=115200){ /* RestoreCom(port); val=InstallCom(port,b,8,0,1); if(val==NoError){ baud=b; printCom4("COM%d baudrate change to %ld\n\r",port,baud); } else { InstallCom(port,baud,8,0,1); printCom4("Error=%d\n\r",val); } */ switch(port){ case 1: if(NoError==SetBaudrate1(b)) baud=b; break; case 2: if(NoError==SetBaudrate2(b)) baud=b; break; case 3: if(NoError==SetBaudrate2(b)) baud=b; break; } /* or use if(NeError==SetBaudrate(port,b)) baud=b; */ } ShowBaudrate(baud); outidx=0; } break; case 'e': case 'E': if(OutBuf[2]=='0' && Echo){ Echo=0; printCom4("Change to Echo OFF\n\r"); } else if(OutBuf[2]=='1' && !Echo){ Echo=1; printCom4("Change to Echo ON\n\r"); } break; case 'p': case 'P': if(OutBuf[2]=='0' && Bypass){ Bypass=0; printCom4("Change to Command mode\n\r"); } else if(OutBuf[2]=='1' && !Bypass){ Bypass=1; printCom4("Change to Bypass mode\n\r"); } break; } } else { Set485DirToTransmit(port); for(i=0;i>4]); ToCom(port,hex_to_ascii[sum&0xf]); } ToCom(port,'\r'); WaitTransmitOver(port); Set485DirToReceive(port); } outidx=0; } } } if(IsCom(port)){ data=ReadCom(port); /* printf("[%02X]",data); */ ToCom(4,data); if(data=='\r'&& !Bypass) ToCom(4,'\n'); buf[idx++]=data; if(data=='\r'){ idx=0; } else { if(idx>=79) idx=78; } } } RestoreCom(port); RestoreCom(4); }