--- /dev/null
+*.d
+*.o
+*~
+log-plotter
+version.h
+.*
+!.gitignore
\ No newline at end of file
--- /dev/null
+CC=gcc
+LD=ld
+CFLAGS=-Wall -O2 -g -fPIC
+
+LOG-PLOTTER_OBJS = baud.o main.o
+
+ALL_OBJS = $(LOG-PLOTTER_OBJS)
+ALL_DEBS = $(patsubst %.o,.%.o.d,$(ALL_OBJS))
+
+ifeq ($(V),1)
+ Q =
+ QUIET_CC =
+ QUIET_LINK =
+else
+ Q = @
+ QUIET_CC = @echo " CC " $@;
+ QUIET_LINK = @echo " LINK " $@;
+endif
+
+default: log-plotter
+
+log-plotter: $(LOG-PLOTTER_OBJS)
+ $(QUIET_LINK)$(CC) -o log-plotter $(LOG-PLOTTER_OBJS)
+
+clean:
+ rm -vf log-plotter *~ *.o .*.d .version version.h .compiler_check*
+
+%.o: %.c .compiler_check
+ $(QUIET_CC)$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@
+ $(Q)cp .$@.d .$@.P; \
+ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
+ -e '/^$$/ d' -e 's/$$/ :/' < .$@.d >> .$@.P; \
+ mv .$@.P .$@.d
+
+version.h .compiler_check: FORCE
+ $(Q)./mkcompile_h "$(CC) $(CFLAGS)"
+
+FORCE:
+
+
+TAGS:
+ @echo -e "\tTAGS\t"
+ @etags *.[ch]
+
+.PHONY: all clean TAGS
+
+-include $(ALL_DEBS)
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <linux/termios.h>
+#include <unistd.h>
+
+/*
+ * HACK: declare the ioctl function by hand...
+ *
+ * We cannot include <sys/ioctl.h> as it will eventually include
+ * <termios.h>, which will conflict with <linux/temios.h>. As we
+ * really need the latter one AND the ioctl, just declare it by hand
+ * here so that we get to use it...
+ */
+int ioctl(int d, int request, ...);
+
+/**
+ * Open a serial device and adjust the baud rate to give (arbitrary)
+ * baud rate. The actual baud rate is stored back to the @baud
+ * variable. This might differ from the requested one as the
+ * underlying hardware may not support all possible baud
+ * rates.
+ *
+ * Returns the file descriptor that was opened.
+ */
+int open_at_baud(const char *device, int *baud)
+{
+ struct termios2 tios;
+ int fd;
+
+ fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
+
+ if (fd == -1) {
+ fprintf(stderr, "error opening %s: %m", device);
+ return fd;
+ }
+
+ if (ioctl(fd, TCGETS2, &tios)) {
+ perror("TCGETS2");
+ goto err;
+ }
+
+ tios.c_cflag &= ~CBAUD;
+ tios.c_cflag |= BOTHER;
+ tios.c_ispeed = *baud;
+ tios.c_ospeed = *baud;
+
+ if (ioctl(fd, TCSETS2, &tios)) {
+ perror("TCSETS2");
+ goto err;
+ }
+
+ if (ioctl(fd, TCGETS2, &tios)) {
+ perror("TCGETS2");
+ goto err;
+ }
+
+ *baud = tios.c_ospeed;
+
+ return fd;
+err:
+ close(fd);
+
+ return -1;
+}
--- /dev/null
+#ifndef _BAUD_H
+#define _BAUD_H
+
+int open_at_baud(const char *device, int *baud);
+
+#endif
--- /dev/null
+#include <stdio.h>
+#include <unistd.h>
+
+#include "baud.h"
+
+int main(int argc, char *argv[])
+{
+ int fd, baud, ret;
+ char *device;
+ char buf[256];
+
+ if (argc < 2) {
+ printf("Usage: %s SERIAL_DEVICE\n", argv[0]);
+ return 1;
+ }
+
+ baud = 128000;
+ device = argv[1];
+
+ fd = open_at_baud(device, &baud);
+ if (fd < 0)
+ return 1;
+
+ if (baud != 128000) {
+ printf("Failed to set baudrate to 128000, only got %d\n", baud);
+ close(fd);
+ return 1;
+ }
+
+ while (1) {
+ ret = read(fd, buf, sizeof(buf));
+ if (read < 0) {
+ perror("read");
+ break;
+ }
+
+ if (read == 0)
+ break;
+
+ ret = write(1, buf, ret);
+ if (read < 0) {
+ perror("write");
+ break;
+ }
+ }
+
+ close(fd);
+ return 0;
+}
--- /dev/null
+#!/bin/sh
+
+VERSION_TMP=.version
+VERSION_TARGET=version.h
+
+VERSION_STR=$(git show | grep ^commit | sed -e s.commit\ .. | cut -b -10)
+
+COMPILER_STR="$1"
+COMPILER_STR_TARGET=.compiler_check
+COMPILER_STR_TMP=$COMPILER_CHECK.tmp
+
+echo > $VERSION_TMP
+echo "#ifndef _VERSION_H_" >> $VERSION_TMP
+echo "#define _VERSION_H_" >> $VERSION_TMP
+echo >> $VERSION_TMP
+echo "/* Autogenerated version.h file */" >> $VERSION_TMP
+echo >> $VERSION_TMP
+echo "#define LOG-PLOTTER_VERSION \"$VERSION_STR\"" >> $VERSION_TMP
+echo >> $VERSION_TMP
+echo "#endif" >> $VERSION_TMP
+
+if [ -f $VERSION_TARGET ] ; then
+ cmp -s $VERSION_TMP $VERSION_TARGET || cp $VERSION_TMP $VERSION_TARGET
+else
+ cp $VERSION_TMP $VERSION_TARGET
+fi
+
+echo $COMPILER_STR > $COMPILER_STR_TMP
+
+if [ -f $COMPILER_STR_TARGET ] ; then
+ cmp -s $COMPILER_STR_TMP $COMPILER_STR_TARGET || \
+ cp $COMPILER_STR_TMP $COMPILER_STR_TARGET
+else
+ cp $COMPILER_STR_TMP $COMPILER_STR_TARGET
+fi
+