#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	const char *path = "/dev/ttyACM1";

	if (argc >= 2)
		path = argv[1];

	int fd = open(path, O_RDONLY | O_NOCTTY);
	if (fd < 0)
		return 1;

	struct termios tty;
	tcgetattr(fd, &tty);
	cfmakeraw(&tty);
	tty.c_cflag |= CLOCAL;
	tty.c_cflag &= ~(HUPCL | CRTSCTS);
	tcsetattr(fd, TCSANOW, &tty);

	uint8_t buf[4];
	int sofar = 0;

	while (1) {
		int n = read(fd, buf, sizeof(buf));
		if (n > 0) {
			fwrite(buf, n, 1, stdout);
		} else {
			return n < 0;
		}
	}
}
