+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <termios.h>
+
+#define BUFSIZE 16
+
+int open_serial_port(char *sdev) {
+
+ struct termios term;
+ int fd;
+
+ /* open serial device */
+
+ fd=open(sdev,O_RDWR);
+ if(fd<0) {
+ perror("tts open");
+ return fd;
+ }
+
+ /* configure the serial device */
+
+ tcgetattr(fd,&term);
+
+ // input/output baudrate
+
+ cfsetispeed(&term,B9600);
+ cfsetospeed(&term,B9600);
+
+ // control options -> 8n1
+
+ term.c_cflag&=~PARENB; // no parity
+ term.c_cflag&=~CSTOPB; // only 1 stop bit
+ term.c_cflag&=~CSIZE; // no bit mask for data bits
+ term.c_cflag|=CS8; // 8 data bits
+
+ // line options -> raw input
+
+ term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG);
+
+ // input options -> enable flow control
+
+ term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL);
+
+ // output options
+
+ term.c_oflag=0;
+
+ // more control options -> timeout / flow control
+
+ term.c_cc[VMIN]=0;
+ term.c_cc[VTIME]=40; // 4 second timeout
+ term.c_cc[VSTART]=0x11;
+ term.c_cc[VSTOP]=0x13;
+
+ tcsetattr(fd,TCSANOW,&term);
+
+ return fd;
+}
+
+int open_dump_file(char *file) {
+
+ int fd;
+
+ /* open dump file */
+
+ fd=open(file,O_WRONLY|O_CREAT);
+
+ if(fd<0)
+ perror("fw open");
+
+ return fd;
+}
+