13 #if defined(__FreeBSD_kernel__)
14 /* Not patching the code directly, used once, in a "|" context */
18 #include <sys/types.h>
20 #include <sys/ioctl.h>
29 int Sample(int fd, int bits);
31 int main(int argc, char *argv[]) {
38 printf("Usage: %s <tty> <baud>\n", argv[0]);
42 switch(atoi(argv[2])) {
43 case 1200: baud = B1200; break;
44 case 2400: baud = B2400; break;
45 case 4800: baud = B4800; break;
46 case 9600: baud = B9600; break;
47 case 19200: baud = B19200; break;
48 case 38400: baud = B38400; break;
49 case 115200: baud = B115200; break;
51 printf("%s: Baud rate %s not supported.\n", argv[0], argv[2]);
55 if ((TTY_fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
56 fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
60 res = tcgetattr(TTY_fd, &tt);
61 res = cfsetospeed(&tt, baud);
63 #if !defined(__FreeBSD_kernel__)
64 tt.c_oflag &= (~(TABDLY | ONLCR));
66 res = tcsetattr(TTY_fd, TCSANOW, &tt);
69 for (i = 0; i < 100; i++) {
70 n1 = Sample(TTY_fd, 200);
73 if (i % 20 == 19) printf("\n");
76 printf("Mean of first 100 REG200 trials = %f\n", (double)mean / 100.0);
79 for (i = 100; i < 200; i++) {
80 n1 = Sample(TTY_fd, i);
81 printf("%3d: %3d\n", i, n1);
86 static int oldbits = 0;
87 static int bitsleft = 0;
88 int Sample(int fd, int bits) {
95 sum += (oldbits & 0x01);
101 n1 = read(fd, &c1, 1);
102 } while (n1 == 0 || (n1 == -1 && errno == EAGAIN));
104 /* Fatal error occurred, die now? */
110 printf("Sampled %c%c%c%c%c%c%c%c\n",
111 ((oldbits & 0x80)?'1':'0'),
112 ((oldbits & 0x40)?'1':'0'),
113 ((oldbits & 0x20)?'1':'0'),
114 ((oldbits & 0x10)?'1':'0'),
115 ((oldbits & 0x08)?'1':'0'),
116 ((oldbits & 0x04)?'1':'0'),
117 ((oldbits & 0x02)?'1':'0'),
118 ((oldbits & 0x01)?'1':'0'));