From 57769ec4371df6ceabacf11aa130c4e8f4eb0240 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 10 Sep 2013 14:09:09 +0200 Subject: [PATCH] Reducing timeout to 0.5 seconds --- Tools/com | Bin 0 -> 13632 bytes Tools/com.c | 191 +++++++++++++++++++++++++++++++++++++++++++ Tools/px_uploader.py | 2 +- 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100755 Tools/com create mode 100644 Tools/com.c diff --git a/Tools/com b/Tools/com new file mode 100755 index 0000000000000000000000000000000000000000..1d80d4aa5be7643c59635245881cd263a756d9b6 GIT binary patch literal 13632 zcmeHOdu&_P89$~8q@iFJ$_5*cyNH(d$t1! zT1E^t%EcI2h#;h)iI*5d6AOq!snn1@mLN0@HkgVAn*e32&AO3I8Dw2X_WPZ4uWP$4 z`)B`5x<@+S`CjKc-}%ntCf~h&^VnZLKSK!50wIP@6GHehSAh; zz5ix^^G)QI7EdX8Qi^t#V*tZw^>1%2RgwL*Ql34$fNuish|_JcVI<7{#Btqnd%p89 z8Hf+FBMRvXg(_GfhKfnUh$s3w;{{f^z1)S$UYD)m&`yUc+um{iXwT?2Ls2sZrE+^s z7b$ytZ3Cnk_d+?rzd$?@>k03)70T^ZU##p++j7#yrNlM_hS3+kvnL!hdcs{1Ntdq2 zG20&3oQ3ok6~i#QjjmWnuc@@k{nIZ|{_U}ikj7p+W#K*<#sV5fV?%30k(#FL$PG$1 zXj!;nQMlZ+>#Vh5ghNJrptmy;GNOstDec+arM+UmxSoqqonja}BSqWp1baSB`RCXp zU2gAO#~50}2z7jsf0}J?*zQBR*dFJLtz9UF5r~B2$2}~M->9bi%i29iJFzMlDMF5) z`z@PqyushN**UW{W$OT%rJjcrg?@P?rod9%D^dl(2bK@5v$v?R9ds2sw66vZn)~&9 z3f8E*XZc#tke>-w6Zt5#&r1I}>=M*dmF$&5Ty_%S+2CoYi%?hf#bc{NJ)Nt91EC;j zman4HkLMTu_Rl|ix$ddqCzek>fA2cqrQmTMqN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MRYpHhMl;n}Z0|>9 z^pj=ub7l04W%Qmhdc2J0n}y=>-Y%oxE2F2%=ugV%V`a2Q83$B_i^&CJI;$F$-@S7+ z&qC$92PToZI!u!@#dR(!bB|m%zH{WOk@Hbe>X`_yLj7OZ)bNW1BiIqcZ%2$S{CXtL z<7S*>TN`pC8zr0DDBaeuqz+}tRU>bN5{|ljBum{p_D!Mgh{Ek)-wV!-z*agZZvp50 etCL@H=AFY{IORZ`;|FtLXv&} literal 0 HcmV?d00001 diff --git a/Tools/com.c b/Tools/com.c new file mode 100644 index 0000000000..fa52dcb61e --- /dev/null +++ b/Tools/com.c @@ -0,0 +1,191 @@ +/* + * Building: cc -o com com.c + * Usage : ./com /dev/device [speed] + * Example : ./com /dev/ttyS0 [115200] + * Keys : Ctrl-A - exit, Ctrl-X - display control lines status + * Darcs : darcs get http://tinyserial.sf.net/ + * Homepage: http://tinyserial.sourceforge.net + * Version : 2009-03-05 + * + * Ivan Tikhonov, http://www.brokestream.com, kefeer@brokestream.com + * Patches by Jim Kou, Henry Nestler, Jon Miner, Alan Horstmann + * + */ + + +/* Copyright (C) 2007 Ivan Tikhonov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Ivan Tikhonov, kefeer@brokestream.com + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int transfer_byte(int from, int to, int is_control); + +typedef struct {char *name; int flag; } speed_spec; + + +void print_status(int fd) { + int status; + unsigned int arg; + status = ioctl(fd, TIOCMGET, &arg); + fprintf(stderr, "[STATUS]: "); + if(arg & TIOCM_RTS) fprintf(stderr, "RTS "); + if(arg & TIOCM_CTS) fprintf(stderr, "CTS "); + if(arg & TIOCM_DSR) fprintf(stderr, "DSR "); + if(arg & TIOCM_CAR) fprintf(stderr, "DCD "); + if(arg & TIOCM_DTR) fprintf(stderr, "DTR "); + if(arg & TIOCM_RNG) fprintf(stderr, "RI "); + fprintf(stderr, "\r\n"); +} + +int main(int argc, char *argv[]) +{ + int comfd; + struct termios oldtio, newtio; //place for old and new port settings for serial port + struct termios oldkey, newkey; //place tor old and new port settings for keyboard teletype + char *devicename = argv[1]; + int need_exit = 0; + speed_spec speeds[] = + { + {"1200", B1200}, + {"2400", B2400}, + {"4800", B4800}, + {"9600", B9600}, + {"19200", B19200}, + {"38400", B38400}, + {"57600", B57600}, + {"115200", B115200}, + {NULL, 0} + }; + int speed = B9600; + + if(argc < 2) { + fprintf(stderr, "example: %s /dev/ttyS0 [115200]\n", argv[0]); + exit(1); + } + + comfd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (comfd < 0) + { + perror(devicename); + exit(-1); + } + + if(argc > 2) { + speed_spec *s; + for(s = speeds; s->name; s++) { + if(strcmp(s->name, argv[2]) == 0) { + speed = s->flag; + fprintf(stderr, "setting speed %s\n", s->name); + break; + } + } + } + + fprintf(stderr, "C-a exit, C-x modem lines status\n"); + + tcgetattr(STDIN_FILENO,&oldkey); + newkey.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD; + newkey.c_iflag = IGNPAR; + newkey.c_oflag = 0; + newkey.c_lflag = 0; + newkey.c_cc[VMIN]=1; + newkey.c_cc[VTIME]=0; + tcflush(STDIN_FILENO, TCIFLUSH); + tcsetattr(STDIN_FILENO,TCSANOW,&newkey); + + + tcgetattr(comfd,&oldtio); // save current port settings + newtio.c_cflag = speed | CS8 | CLOCAL | CREAD; + newtio.c_iflag = IGNPAR; + newtio.c_oflag = 0; + newtio.c_lflag = 0; + newtio.c_cc[VMIN]=1; + newtio.c_cc[VTIME]=0; + tcflush(comfd, TCIFLUSH); + tcsetattr(comfd,TCSANOW,&newtio); + + print_status(comfd); + + while(!need_exit) { + fd_set fds; + int ret; + + FD_ZERO(&fds); + FD_SET(STDIN_FILENO, &fds); + FD_SET(comfd, &fds); + + + ret = select(comfd+1, &fds, NULL, NULL, NULL); + if(ret == -1) { + perror("select"); + } else if (ret > 0) { + if(FD_ISSET(STDIN_FILENO, &fds)) { + need_exit = transfer_byte(STDIN_FILENO, comfd, 1); + } + if(FD_ISSET(comfd, &fds)) { + need_exit = transfer_byte(comfd, STDIN_FILENO, 0); + } + } + } + + tcsetattr(comfd,TCSANOW,&oldtio); + tcsetattr(STDIN_FILENO,TCSANOW,&oldkey); + close(comfd); + + return 0; +} + + +int transfer_byte(int from, int to, int is_control) { + char c; + int ret; + do { + ret = read(from, &c, 1); + } while (ret < 0 && errno == EINTR); + if(ret == 1) { + if(is_control) { + if(c == '\x01') { // C-a + return -1; + } else if(c == '\x18') { // C-x + print_status(to); + return 0; + } + } + while(write(to, &c, 1) == -1) { + if(errno!=EAGAIN && errno!=EINTR) { perror("write failed"); break; } + } + } else { + fprintf(stderr, "\nnothing to read. probably port disconnected.\n"); + return -2; + } + return 0; +} + diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py index cab3c2fd0e..52d089360a 100755 --- a/Tools/px_uploader.py +++ b/Tools/px_uploader.py @@ -436,7 +436,7 @@ while True: print("attempting reboot on %s..." % port) up.send_reboot() # wait for the reboot, without we might run into Serial I/O Error 5 - time.sleep(1.5) + time.sleep(0.5) continue try: