changeset 40:8f505d413815

serial: full baud/spenh argument parsing implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Mar 2021 20:23:24 +0000
parents 61a8ac93764f
children 5ee00413b8af
files serial/Makefile serial/atrmain.c serial/baud_parse.c
diffstat 3 files changed, 57 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/serial/Makefile	Sat Mar 20 20:03:29 2021 +0000
+++ b/serial/Makefile	Sat Mar 20 20:23:24 2021 +0000
@@ -6,7 +6,7 @@
 
 INSTBIN=${INSTALL_PREFIX}/bin
 
-ATR_OBJS=	atrmain.o collect_atr.o invtable.o serport.o
+ATR_OBJS=	atrmain.o baud_parse.o collect_atr.o invtable.o serport.o
 
 all:	${PROGS}
 
--- a/serial/atrmain.c	Sat Mar 20 20:03:29 2021 +0000
+++ b/serial/atrmain.c	Sat Mar 20 20:23:24 2021 +0000
@@ -5,6 +5,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+extern unsigned baud_base;
+
 main(argc, argv)
 	char **argv;
 {
@@ -15,7 +17,8 @@
 		exit(1);
 	}
 	open_serial_port(argv[1]);
-	set_serial_params(atoi(argv[2]));
+	parse_baud_spenh_arg(argv[2]);
+	set_serial_params(baud_base);
 	set_serial_nonblock(0);
 	serial_card_reset();
 	rc = collect_atr();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serial/baud_parse.c	Sat Mar 20 20:23:24 2021 +0000
@@ -0,0 +1,52 @@
+/*
+ * This module handles the parsing of the baud rate and speed enhancement
+ * command line argument.
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+unsigned baud_base, baud_spenh, spenh_host_max;
+
+void
+parse_baud_spenh_arg(arg)
+	char *arg;
+{
+	char *cp;
+
+	if (!isdigit(*arg)) {
+inv:		fprintf(stderr,
+			"error: invalid baud/spenh selection argument \"%s\"\n",
+			arg);
+		exit(1);
+	}
+	baud_base = strtoul(arg, &cp, 10);
+	if (!*cp)
+		return;
+	if (*cp++ != ',')
+		goto inv;
+	if (!isdigit(*cp))
+		goto inv;
+	baud_spenh = strtoul(cp, &cp, 10);
+	if (!*cp) {
+		spenh_host_max = 1;
+		return;
+	}
+	if (*cp++ != ',')
+		goto inv;
+	if (!isdigit(*cp) || cp[1])
+		goto inv;
+	spenh_host_max = *cp - '0';
+	switch (spenh_host_max) {
+	case 1:
+	case 2:
+	case 4:
+	case 8:
+		break;
+	default:
+		fprintf(stderr,
+	"error: speed enhancement multiplier can only be 1, 2, 4 or 8\n");
+		exit(1);
+	}
+}