From 5d9373f24f1b519c030024b2f36277ba9713697c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 21 Jul 2010 14:41:04 +1000 Subject: [PATCH 3/3] Allow for custom baud rates. Signed-off-by: Peter Hutterer --- inputattach.c | 25 ++++++++++++++++++++++++- 1 files changed, 24 insertions(+), 1 deletions(-) diff --git a/inputattach.c b/inputattach.c index 0382954..6806fc8 100644 --- a/inputattach.c +++ b/inputattach.c @@ -506,7 +506,7 @@ static void show_help(void) struct input_types *type; puts(""); - puts("Usage: inputattach [--daemon] "); + puts("Usage: inputattach [--daemon] [--baud ] "); puts(""); puts("Modes:"); @@ -530,6 +530,7 @@ int main(int argc, char **argv) int i; char c; int retval; + int baud = -1; for (i = 1; i < argc; i++) { if (!strcasecmp(argv[i], "--help")) { @@ -540,6 +541,15 @@ int main(int argc, char **argv) } else if (need_device) { device = argv[i]; need_device = 0; + } else if (!strcasecmp(argv[i], "--baud")) { + if (argc <= i + 1) { + show_help(); + fprintf(stderr, + "inputattach: require baud rate\n"); + return EXIT_FAILURE; + } + + baud = atoi(argv[++i]); } else { if (type && type->name) { fprintf(stderr, @@ -580,6 +590,19 @@ int main(int argc, char **argv) return 1; } + switch(baud) { + case -1: break; + case 2400: type->speed = B2400; break; + case 4800: type->speed = B4800; break; + case 9600: type->speed = B9600; break; + case 19200: type->speed = B19200; break; + case 38400: type->speed = B38400; break; + default: + fprintf(stderr, "inputattach: invalid baud rate '%d'\n", + baud); + return EXIT_FAILURE; + } + setline(fd, type->flags, type->speed); if (type->flush) -- 1.7.2.3