* Change baudrate to 115200.

* Switch from use of select to blocking reads.

* Print non ascii bytes as hex.
This commit is contained in:
bg- 2006-12-27 14:19:22 +00:00
parent 7f5c1fde0f
commit 79899c69c1

View file

@ -26,11 +26,12 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: scat.c,v 1.1 2006/08/02 14:41:30 bg- Exp $ * $Id: scat.c,v 1.2 2006/12/27 14:19:22 bg- Exp $
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
@ -54,7 +55,8 @@
#define SLIP_ESC_END 0334 #define SLIP_ESC_END 0334
#define SLIP_ESC_ESC 0335 #define SLIP_ESC_ESC 0335
#define BAUDRATE B57600 #define BAUDRATE B115200
//#define BAUDRATE B57600
//#define BAUDRATE B38400 //#define BAUDRATE B38400
//#define BAUDRATE B19200 //#define BAUDRATE B19200
@ -71,9 +73,9 @@ stty_telos(int fd)
cfmakeraw(&tty); cfmakeraw(&tty);
/* Nonblocking read. */ /* Blocking read. */
tty.c_cc[VTIME] = 0; tty.c_cc[VTIME] = 0;
tty.c_cc[VMIN] = 0; tty.c_cc[VMIN] = 1;
tty.c_cflag &= ~CRTSCTS; tty.c_cflag &= ~CRTSCTS;
tty.c_cflag &= ~HUPCL; tty.c_cflag &= ~HUPCL;
tty.c_cflag &= ~CLOCAL; tty.c_cflag &= ~CLOCAL;
@ -83,16 +85,11 @@ stty_telos(int fd)
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr"); if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
#if 1
/* Nonblocking read and write. */
/* if(fcntl(fd, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); */
tty.c_cflag |= CLOCAL; tty.c_cflag |= CLOCAL;
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr"); if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
i = TIOCM_DTR; i = TIOCM_DTR;
if(ioctl(fd, TIOCMBIS, &i) == -1) err(1, "ioctl"); if(ioctl(fd, TIOCMBIS, &i) == -1) err(1, "ioctl");
#endif
usleep(10*1000); /* Wait for hardware 10ms. */ usleep(10*1000); /* Wait for hardware 10ms. */
@ -113,26 +110,31 @@ main(int argc, char **argv)
err(1, "usage: scat device-file"); err(1, "usage: scat device-file");
siodev = argv[1]; siodev = argv[1];
slipfd = open(siodev, O_RDWR | O_NONBLOCK); slipfd = open(siodev, O_RDWR);
if (slipfd == -1) err(1, "can't open '%s'", siodev); if (slipfd == -1) err(1, "can't open '%s'", siodev);
stty_telos(slipfd); stty_telos(slipfd);
inslip = fdopen(slipfd, "r"); inslip = fdopen(slipfd, "r");
if(inslip == NULL) err(1, "main: fdopen"); if(inslip == NULL) err(1, "main: fdopen");
do { while (1) {
fd_set rset; int c = getc(inslip);
while (c == SLIP_END)
FD_ZERO(&rset); c = getc(inslip);
FD_SET(slipfd, &rset); do {
if (c == SLIP_ESC) {
ret = select(slipfd + 1, &rset, NULL, NULL, NULL); c = getc(inslip);
if (FD_ISSET(slipfd, &rset)) { if (c == SLIP_ESC_ESC)
while ((c = getc(inslip)) != -1) c = SLIP_ESC;
if (c != SLIP_END) else if (c == SLIP_ESC_END)
putchar(c); c = SLIP_END;
} }
clearerr(inslip); if (isprint(c) || c == '\n' || c == '\t' || c == '\r')
} while (1); putchar(c);
else
printf("%02x ", c);
c = getc(inslip);
} while (c != SLIP_END);
}
return 0; return 0;
} }