From 4ed6c4a3a8407469a9a379c68c194bec62346704 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 25 Aug 2013 10:10:55 -0400 Subject: [PATCH] Add hw/sw flow control options to passthru. --- passthru.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- redirector.c | 2 +- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/passthru.c b/passthru.c index b134f1f..25493ed 100644 --- a/passthru.c +++ b/passthru.c @@ -59,9 +59,8 @@ static void dump_config(char *prefix, struct sob_config *cfg) void printhelp() { fprintf(stderr, " Serial to Serial forwarder and sniffer\n\n"); - fprintf(stderr, "\t-d -s \n"); - fprintf(stderr, "\t-D -S \n"); - + fprintf(stderr, "\t-d -s [ -x | -r ]\n"); + fprintf(stderr, "\t-D -S [ -X | -R ]\n"); fprintf(stderr, "commsparams: -\n"); fprintf(stderr, "\n"); } @@ -79,6 +78,8 @@ int main (int argc, char **argv) int hw_flow = 0; int sw_flow = 0; + int hw_flow2 = 0; + int sw_flow2 = 0; char *ser_dev1 = NULL; char *ser_dev2 = NULL; @@ -99,7 +100,7 @@ int main (int argc, char **argv) /* Parse command line */ while(1) { int c; - c = getopt(argc, argv, "hd:s:D:S:"); + c = getopt(argc, argv, "hd:s:D:S:xrXR"); if (c == -1) break; switch (c) { case 'h': @@ -117,6 +118,19 @@ int main (int argc, char **argv) case 'S': comm_params2 = optarg; break; + case 'x': + sw_flow = 1; + break; + case 'r': + hw_flow = 1; + break; + case 'X': + sw_flow2 = 1; + break; + case 'R': + hw_flow2 = 1; + break; + default: fprintf(stderr, "getopt returned bogus option '%c'\n", c); return 1; @@ -129,6 +143,32 @@ int main (int argc, char **argv) return 2; } + if (hw_flow && sw_flow) { + fprintf(stderr, "ERROR: can't use both hardware and software flow control.\n\n"); + printhelp(); + return 10; + } + + if (hw_flow2 && sw_flow2) { + fprintf(stderr, "ERROR: can't use both hardware and software flow control.\n\n"); + printhelp(); + return 10; + } + + if (hw_flow) + sob_cfg1.flow = 'H'; + else if (sw_flow) + sob_cfg1.flow = 'S'; + else + sob_cfg1.flow = 'N'; + + if (hw_flow2) + sob_cfg2.flow = 'H'; + else if (sw_flow2) + sob_cfg2.flow = 'S'; + else + sob_cfg2.flow = 'N'; + /* Parse serial parameters #1 */ i = sscanf(comm_params1, "%d-%d%c%d", &sob_cfg1.baud, &sob_cfg1.databits, &sob_cfg1.parity, &sob_cfg1.stopbits); @@ -197,7 +237,7 @@ int main (int argc, char **argv) /* Set serial Parameters #2*/ i = setserial(&ser_cfg2, ser_fd2, sob_cfg2.baud, sob_cfg2.databits, sob_cfg2.parity, sob_cfg2.stopbits, - hw_flow, sw_flow, modem_lines); + hw_flow2, sw_flow2, modem_lines); if (i > 0) { printhelp(); return 7; diff --git a/redirector.c b/redirector.c index d67f5c8..f425aff 100644 --- a/redirector.c +++ b/redirector.c @@ -276,7 +276,7 @@ int main (int argc, char **argv) } if (hw_flow) - sob_cfg.flow = 'H'; + sob_cfg.flow = 'H'; else if (sw_flow) sob_cfg.flow = 'S'; else