diff calypso/caltest.c @ 6:0a21a7ffe144

calypso: caltest front end put together
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 05:26:58 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calypso/caltest.c	Sun Mar 14 05:26:58 2021 +0000
@@ -0,0 +1,57 @@
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int target_fd;
+
+open_serial_port(ttyport)
+	char *ttyport;
+{
+	target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
+	if (target_fd < 0) {
+		perror(ttyport);
+		exit(1);
+	}
+	ioctl(target_fd, TIOCEXCL);
+	return 0;
+}
+
+set_termios()
+{
+	struct termios target_termios;
+
+	target_termios.c_iflag = IGNBRK;
+	target_termios.c_oflag = 0;
+	target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
+	target_termios.c_lflag = 0;
+	target_termios.c_cc[VMIN] = 1;
+	target_termios.c_cc[VTIME] = 0;
+	cfsetispeed(&target_termios, B115200);
+	cfsetospeed(&target_termios, B115200);
+	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
+		perror("tcsetattr");
+		exit(1);
+	}
+	return 0;
+}
+
+main(argc, argv)
+	char **argv;
+{
+	char c_arg[16];
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s ttyport second-prog\n", argv[0]);
+		exit(1);
+	}
+	open_serial_port(argv[1]);
+	set_termios();
+	sprintf(c_arg, "-C%d", target_fd);
+	execl(argv[2], argv[2], c_arg, (char *) 0);
+	perror(argv[2]);
+	exit(1);
+}