annotate calypso/caltest.c @ 6:0a21a7ffe144

calypso: caltest front end put together
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 05:26:58 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <sys/file.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <sys/ioctl.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <termios.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <unistd.h>
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 int target_fd;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 open_serial_port(ttyport)
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char *ttyport;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 if (target_fd < 0) {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 perror(ttyport);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 exit(1);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 }
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ioctl(target_fd, TIOCEXCL);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return 0;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 set_termios()
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct termios target_termios;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 target_termios.c_iflag = IGNBRK;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 target_termios.c_oflag = 0;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 target_termios.c_lflag = 0;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 target_termios.c_cc[VMIN] = 1;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 target_termios.c_cc[VTIME] = 0;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 cfsetispeed(&target_termios, B115200);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cfsetospeed(&target_termios, B115200);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 perror("tcsetattr");
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return 0;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 main(argc, argv)
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char **argv;
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char c_arg[16];
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (argc != 3) {
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr, "usage: %s ttyport second-prog\n", argv[0]);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 open_serial_port(argv[1]);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 set_termios();
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 sprintf(c_arg, "-C%d", target_fd);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 execl(argv[2], argv[2], c_arg, (char *) 0);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 perror(argv[2]);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 exit(1);
0a21a7ffe144 calypso: caltest front end put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }