📄 tio.c
字号:
/****************************************************************************** SCT, Serial Communication Tracer ** CopyRight (C) Bruce (ZhaoFei), zhaofei@zflogic.com* http://www.zflogic.com ** All sources in the package are copyrighted under the the terms of GNU GPL****************************************************************************** * This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA** If you intend to use this pragram commercially on a regular basis you* must contact the author for an appropriate donation.* ***************************************************************************/#include "stdhdr.h"#include "util.h"#define TIO_L#include "tio.h"bool parse_frameset(devstat_t *dt,char *frameset) { char srate[30],sparity[30],swidth[30],sstop[30],*parv[4]; char tmpframe[100]; long rate; uchar width; int parc; if(strlen(frameset) > sizeof(tmpframe)){ printf("too long characters in framset\n"); return false; } strcpy(tmpframe,frameset); parseex(&parc,parv,tmpframe,4,','); if(parc<4) { printf("miss parameters in framset\n"); return false; } strcpy(srate,parv[0]); strcpy(sparity,parv[1]); strcpy(swidth,parv[2]); strcpy(sstop,parv[3]); rate=atol(srate); switch(rate){ case 110: dt->baudrate=B110;break; case 300: dt->baudrate= B300;break; case 600: dt->baudrate= B600;break; case 1200: dt->baudrate= B1200;break; case 2400: dt->baudrate= B2400;break; case 4800: dt->baudrate= B4800;break; case 9600: dt->baudrate= B9600;break;#ifdef COMPAT_WIN32 case 14400: dt->baudrate= B14400;break;#endif case 19200: dt->baudrate= B19200;break; case 38400: dt->baudrate= B38400;break; case 57600: dt->baudrate= B57600;break; case 115200: dt->baudrate= B115200;break;#ifdef COMPAT_WIN32 case 128000: dt->baudrate= B128000;break; case 256000: dt->baudrate= B256000;break;// case 230400: dt->baudrate= B230400;break;#endif default: printf("invalid rate as %d\n",rate); return false; } if(!strcmp(sparity,"n")){ dt->parity=0; } else if(!strcmp(sparity,"e")){ dt->parity=EVENPARITY; } else if(!strcmp(sparity,"o")){ dt->parity=ODDPARITY; } else { printf("invalid parity as %s\n",sparity); return false; } width=atoi(swidth); switch(width){ case 5: dt->databits=CS5; break; case 6: dt->databits=CS6; break; case 7: dt->databits=CS7; break; case 8: dt->databits=CS8; break; default:{ printf("invalid databits as %d",width); return false; } } if(!strcmp(sstop,"1")) dt->stopbits=0; else if(!strcmp(sstop,"2")) dt->stopbits=CSTOPB; else { printf("invalid stopbits as %s",sstop); return false; } return true;}int tio_block(int fd, bool block){ int val; if ( (val = fcntl(fd, F_GETFL, 0)) < 0) return -1; if (!block) val|=O_NONBLOCK; else val &=~O_NONBLOCK; if (fcntl(fd, F_SETFL, val) <0) return -1; return 0;}int tio_raw(int fd){ struct termios tios; if (tcgetattr(fd, &tios) < 0) return -1; tios.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); tios.c_iflag &= ~(BRKINT | ICRNL |INPCK | ISTRIP |IXON); tios.c_cflag &= ~(CSIZE | PARENB); //parity check off tios.c_cflag |= CS8; //set 8 bit char tios.c_oflag &= ~(OPOST); //output process off tios.c_cc[VMIN]= 1; tios.c_cc[VTIME] = 0; if(tcsetattr(fd, TCSANOW, &tios) < 0) return -1; return 0;}int tio_echo(int fd, bool echo){ struct termios tios; if (tcgetattr(fd, &tios) < 0) return -1; if (echo) tios.c_lflag |= ECHO; else tios.c_lflag &= ~ECHO; if(tcsetattr(fd, TCSANOW, &tios) < 0) return -1; return 0;}int tio_saveset(int fd, struct termios *save_tios){ if(tcgetattr(fd, save_tios) < 0) return -1; return 0; }int tio_reset(int fd, struct termios *save_tios){ if(tcsetattr(fd, TCSANOW, save_tios) < 0) return -1; return 0;}int tio_cr2nl(int fd, int direction){ struct termios tios; if(direction!=1 && direction!=0) return -1; if(tcgetattr(fd,&tios)<0) return -1; if(direction==1) tios.c_iflag |= ICRNL; else tios.c_oflag |= OCRNL; if(tcsetattr(fd,TCSANOW,&tios)<0) return -1; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -