diff frbl/test/main.c @ 323:cefa700d1b8f

frbl: beginning of frbl2test
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Mar 2020 22:05:01 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frbl/test/main.c	Thu Mar 05 22:05:01 2020 +0000
@@ -0,0 +1,59 @@
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <termios.h>
+#include <unistd.h>
+#include "srecreader.h"
+
+char *target_ttydev;
+int target_fd;
+int baudrate_code;
+struct termios target_termios;
+struct srecreader srimage;
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc != 4) {
+		fprintf(stderr, "usage: %s ttyport baud image.srec\n", argv[0]);
+		exit(1);
+	}
+	target_ttydev = argv[1];
+	if (!strcmp(argv[2], "115200"))
+		baudrate_code = B115200;
+	else if (!strcmp(argv[2], "230400"))
+		baudrate_code = B230400;
+	else {
+		fprintf(stderr,
+			"error: baud rate argument must be 115200 or 230400\n");
+		exit(1);
+	}
+	srimage.filename = argv[3];
+
+	target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK);
+	if (target_fd < 0) {
+		perror(target_ttydev);
+		exit(1);
+	}
+	ioctl(target_fd, TIOCEXCL);
+	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, baudrate_code);
+	cfsetospeed(&target_termios, baudrate_code);
+	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
+		perror("tcsetattr");
+		exit(1);
+	}
+	frbl_test_main();
+	tty_passthru();
+	exit(0);
+}