3 * Murray Jensen <Murray.Jensen@csiro.au>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #if defined(__sun__) || \
31 defined(__OpenBSD__) || \
32 defined(__FreeBSD__) || \
33 defined(__NetBSD__) || \
35 static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, { 0 } };
37 static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, 0 };
40 static struct speedmap {
44 { "50", B50 }, { "75", B75 }, { "110", B110 },
45 { "134", B134 }, { "150", B150 }, { "200", B200 },
46 { "300", B300 }, { "600", B600 }, { "1200", B1200 },
47 { "1800", B1800 }, { "2400", B2400 }, { "4800", B4800 },
48 { "9600", B9600 }, { "19200", B19200 }, { "38400", B38400 },
53 { "115200", B115200 },
55 { "153600", B153600 },
57 { "230400", B230400 },
59 { "307200", B307200 },
65 static int nspeeds = sizeof speedmap / sizeof speedmap[0];
70 struct speedmap *smp = speedmap, *esmp = &speedmap[nspeeds];
73 if (strcmp(str, smp->str) == 0)
81 serialopen(char *device, speed_t speed)
85 if (cfsetospeed(&tios, speed) < 0)
88 if ((fd = open(device, O_RDWR)) < 0)
91 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
100 serialreadchar(int fd, int timeout)
113 /* this is a fucking horrible quick hack - fix this */
115 if ((n = select(fd + 1, &fds, 0, 0, &tv)) < 0)
119 return SERIAL_TIMEOUT;
121 if ((n = read(fd, &ch, 1)) < 0)
131 serialwrite(int fd, char *buf, int len)
136 n = write(fd, buf, len);