*
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
*
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
*/
+//config:config MICROCOM
+//config: bool "microcom (5.6 kb)"
+//config: default y
+//config: help
+//config: The poor man's minicom utility for chatting with serial port devices.
+
+//applet:IF_MICROCOM(APPLET(microcom, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_MICROCOM) += microcom.o
+
+//usage:#define microcom_trivial_usage
+//usage: "[-d DELAY] [-t TIMEOUT] [-s SPEED] [-X] TTY"
+//usage:#define microcom_full_usage "\n\n"
+//usage: "Copy bytes for stdin to TTY and from TTY to stdout\n"
+//usage: "\n -d Wait up to DELAY ms for TTY output before sending every"
+//usage: "\n next byte to it"
+//usage: "\n -t Exit if both stdin and TTY are silent for TIMEOUT ms"
+//usage: "\n -s Set serial line to SPEED"
+//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin"
+
#include "libbb.h"
+#include "common_bufsiz.h"
// set raw tty mode
static void xget1(int fd, struct termios *t, struct termios *oldt)
{
+//TODO: use set_termios_to_raw()
tcgetattr(fd, oldt);
*t = *oldt;
cfmakeraw(t);
unsigned opts;
// fetch options
- opt_complementary = "=1:s+:d+:t+"; // exactly one arg, numeric options
- opts = getopt32(argv, "Xs:d:t:", &speed, &delay, &timeout);
+ opt_complementary = "=1";
+ opts = getopt32(argv, "Xs:+d:+t:+", &speed, &delay, &timeout);
// argc -= optind;
argv += optind;
if (sfd < 0) {
// device already locked -> bail out
if (errno == EEXIST)
- bb_perror_msg_and_die("can't create %s", device_lock_file);
+ bb_perror_msg_and_die("can't create '%s'", device_lock_file);
// can't create lock -> don't care
if (ENABLE_FEATURE_CLEAN_UP)
free(device_lock_file);
bb_got_signal = 0;
nfd = 2;
- while (!bb_got_signal && safe_poll(pfd, nfd, timeout) > 0) {
+ // Not safe_poll: we want to exit on signal
+ while (!bb_got_signal && poll(pfd, nfd, timeout) > 0) {
if (nfd > 1 && pfd[1].revents) {
char c;
// read from stdin -> write to device
skip_write: ;
}
if (pfd[0].revents) {
-#define iobuf bb_common_bufsiz1
ssize_t len;
+#define iobuf bb_common_bufsiz1
+ setup_common_bufsiz();
// read from device -> write to stdout
- len = safe_read(sfd, iobuf, sizeof(iobuf));
+ len = safe_read(sfd, iobuf, COMMON_BUFSIZE);
if (len > 0)
full_write(STDOUT_FILENO, iobuf, len);
else {