diff options
author | Rob Landley <rob@landley.net> | 2020-05-09 16:31:24 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-05-09 16:31:24 -0500 |
commit | 7573e325d3e9ed3d21fc8a93c464604c974ed76b (patch) | |
tree | a4fdb9834d68fc25d9449ba4d760ae6cac4d806b | |
parent | cecda30e855f541ce4f0694561ffa3a65938a3c4 (diff) | |
download | toybox-7573e325d3e9ed3d21fc8a93c464604c974ed76b.tar.gz |
Remove old scripts/minicom.sh and cleanup microcom.c a bit more.
Use s# instead of atoi, meantion -s default in help text, use toybuf instead
of stack buf, reuse i instead of declaring a separate ssize_t, FLAG() macro.
-rwxr-xr-x | scripts/minicom.sh | 18 | ||||
-rw-r--r-- | toys/net/microcom.c | 30 |
2 files changed, 12 insertions, 36 deletions
diff --git a/scripts/minicom.sh b/scripts/minicom.sh deleted file mode 100755 index f47d0966..00000000 --- a/scripts/minicom.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# If you want to use toybox netcat to talk to a serial port, use this. - -if [ ! -c "$1" ] -then - echo "usage: minicom.sh /dev/ttyS0" - exit 1 -fi - -SPEED="$2" -[ -z "$SPEED" ] && SPEED=115200 - -stty $SPEED -F "$1" -stty raw -echo -ctlecho -F "$1" -stty raw -echo # Need to do it on stdin, too. -./toybox netcat -f "$1" -stty cooked echo # Put stdin back. diff --git a/toys/net/microcom.c b/toys/net/microcom.c index 6f88ad4f..62b020f2 100644 --- a/toys/net/microcom.c +++ b/toys/net/microcom.c @@ -2,7 +2,7 @@ * * Copyright 2017 The Android Open Source Project. -USE_MICROCOM(NEWTOY(microcom, "<1>1s:X", TOYFLAG_USR|TOYFLAG_BIN)) +USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN)) config MICROCOM bool "microcom" @@ -12,7 +12,7 @@ config MICROCOM Simple serial console. - -s Set baud rate to SPEED + -s Set baud rate to SPEED (default 115200) -X Ignore ^@ (send break) and ^] (exit) */ @@ -20,7 +20,7 @@ config MICROCOM #include "toys.h" GLOBALS( - char *s; + long s; int fd; struct termios original_stdin_state, original_fd_state; @@ -36,10 +36,7 @@ static void restore_states(int i) void microcom_main(void) { struct pollfd fds[2]; - int i, speed; - - if (!TT.s) speed = 115200; - else speed = atoi(TT.s); + int i; // Open with O_NDELAY, but switch back to blocking for reads. TT.fd = xopen(*toys.optargs, O_RDWR | O_NOCTTY | O_NDELAY); @@ -47,36 +44,33 @@ void microcom_main(void) perror_exit_raw(*toys.optargs); // Set both input and output to raw mode. - xset_terminal(TT.fd, 1, speed, &TT.original_fd_state); + xset_terminal(TT.fd, 1, TT.s, &TT.original_fd_state); set_terminal(0, 1, 0, &TT.original_stdin_state); // ...and arrange to restore things, however we may exit. sigatexit(restore_states); fds[0].fd = TT.fd; - fds[0].events = POLLIN; fds[1].fd = 0; - fds[1].events = POLLIN; + fds[0].events = fds[1].events = POLLIN; while (poll(fds, 2, -1) > 0) { - char buf[BUFSIZ]; // Read from connection, write to stdout. if (fds[0].revents) { - ssize_t n = read(TT.fd, buf, sizeof(buf)); - if (n > 0) xwrite(0, buf, n); + if (0 < (i = read(TT.fd, toybuf, sizeof(toybuf)))) xwrite(0, toybuf, i); else break; } // Read from stdin, write to connection. if (fds[1].revents) { - if (read(0, buf, 1) != 1) break; - if (!(toys.optflags & FLAG_X)) { - if (!*buf) { + if (read(0, toybuf, 1) != 1) break; + if (!FLAG(X)) { + if (!*toybuf) { tcsendbreak(TT.fd, 0); continue; - } else if (*buf == (']'-'@')) break; + } else if (*toybuf == (']'-'@')) break; } - xwrite(TT.fd, buf, 1); + xwrite(TT.fd, toybuf, 1); } } } |