1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* BSD serial port control features not found in POSIX
* including modem line control and hardware flow control
*/
static struct flagmap lines[] = {
{"cts", TIOCM_CTS},
{"dsr", TIOCM_DSR},
{"ring", TIOCM_RI},
{"dcd", TIOCM_CD},
{"dtr", TIOCM_DTR},
{"rts", TIOCM_RTS},
{0, -1}
};
static void
resxtra(int port, struct termios *ts)
{
int fd = eia[port].fd;
USED(ts);
if(eia[port].dtr)
ioctl(fd, TIOCM_DTR, eia[port].dtr);
if(eia[port].rts)
ioctl(fd, TIOCM_RTS, eia[port].rts);
if(eia[port].cts)
ioctl(fd, TIOCM_CTS, eia[port].cts);
}
static char *
rdxtra(int port, struct termios *ts, char *str)
{
int fd = eia[port].fd;
int line;
// struct flagmap *lp;
char *s = str;
USED(ts);
if(ioctl(fd, TIOCMGET, &line) < 0)
oserror();
// for(lp = lines; lp->str; lp++)
// if(line&lp->flag)
// s += sprint(s, " %s", lp->str);
return s;
}
static char *
wrxtra(int port, struct termios *ts, char *cmd)
{
int fd = eia[port].fd;
int n, r, flag, iocmd, *l;
USED(ts);
switch(*cmd) {
case 'D':
case 'd':
flag = TIOCM_DTR;
l = &eia[port].dtr;
break;
case 'R':
case 'r':
flag = TIOCM_RTS;
l = &eia[port].rts;
break;
case 'M':
case 'm':
flag = TIOCM_CTS;
l = &eia[port].cts;
break;
default:
return nil;
}
n = atoi(cmd+1);
if(n)
iocmd = TIOCMBIS;
else
iocmd = TIOCMBIC;
osenter();
r = ioctl(fd, iocmd, &flag);
osleave();
if(r < 0)
oserror();
eia[port].restore = 1;
*l = iocmd;
return nil;
}
|