diff fluid-mnf/serial.c @ 348:37b5f94de802

fluid-mnf: sensible target tty specification
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 06:41:44 +0000
parents 2bd27d940023
children 49fe64a5e207
line wrap: on
line diff
--- a/fluid-mnf/serial.c	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/serial.c	Fri Mar 13 06:41:44 2020 +0000
@@ -45,8 +45,6 @@
 static int target_fd;
 static struct termios2 target_termios;
 
-static const char port_name_prefix[] = "/dev/ttyUSB";
-
 static void fill_termios(int bps)
 {
 	int termios_baud_code;
@@ -89,12 +87,19 @@
 	target_termios.c_ospeed = bps;
 }
 
-int serial_init(int uart, int bps, char *flowcontrol)
+int serial_init(char *ttyport, int bps)
 {
-	char ttyport[32];
 	static int zero = 0;
 
-	sprintf(ttyport, "%s%d", port_name_prefix, uart);
+	if (!ttyport) {
+		ttyport = getenv("FLUID_PORT");
+		if (!ttyport) {
+			fprintf(stderr,
+"fluid-mnf error: target tty port must be specified with -p or FLUID_PORT=\n");
+			exit(-E_BADARG);
+		}
+	}
+
 	target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
 	if (target_fd < 0)
 		return E_OS + E_UART_INIT;