/* charge - a simple tool to enble the built in charger in Mobile Action USB data cables Copyright (C) 2006 Martin Leopold 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 */ #include #include #include #include #include #include #include #include struct termios oldkey, newkey; //place for old and new port settings for keyboard teletype int read_fd(int fd, unsigned char *bufstart, unsigned int bufs) { fd_set rfds; struct timeval timeout; unsigned char * bufptr; unsigned int n; FD_ZERO(&rfds); FD_SET(fd, &rfds); timeout.tv_sec = 3; timeout.tv_usec = 0; n = select(fd+1, &rfds, NULL, NULL, &timeout); if (n < 0) { perror("select failed"); return(errno); } else if (n == 0) { perror("TIMEOUT"); return(-1); } bufptr = bufstart; while ((n = read(fd, bufptr, bufstart + bufs - bufptr - 1)) > 0) { bufptr += n; } (*bufptr) = (char) 0; printf("Read %i bytes: %s ", bufptr-bufstart, bufptr); for(n=0 ; n