Skip to content

Commit 6746fd5

Browse files
committed
Added JTermios OpenBSD Support
TestSuite - all test passed TwoPortSerialTest - did not tried
1 parent d3b6903 commit 6746fd5

File tree

3 files changed

+808
-0
lines changed

3 files changed

+808
-0
lines changed

c/c-openbsd.c

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
// This c.c is NOT part of PureJavaComm, however it can be useful
2+
// in porting JTermiosImpl to new platforms
3+
4+
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <errno.h>
8+
#include <sys/types.h>
9+
#include <sys/stat.h>
10+
#include <fcntl.h>
11+
#include <sys/ioctl.h>
12+
#include <termios.h>
13+
#include <sys/select.h>
14+
#include <poll.h>
15+
#include <sys/filio.h>
16+
17+
main(){
18+
printf("// sys/filio.h stuff\n");
19+
printf("FIONREAD = 0x%08X;\n",FIONREAD);
20+
21+
printf("// fcntl.h stuff\n");
22+
printf("O_RDWR = 0x%08X;\n",O_RDWR);
23+
printf("O_NONBLOCK= 0x%08X;\n",O_NONBLOCK);
24+
printf("O_NOCTTY = 0x%08X;\n",O_NOCTTY);
25+
printf("O_NDELAY = 0x%08X;\n",O_NDELAY);
26+
printf("O_CREAT = 0x%08X;\n",O_CREAT);
27+
printf("F_GETFL = 0x%08X;\n",F_GETFL);
28+
printf("F_SETFL = 0x%08X;\n",F_SETFL);
29+
30+
printf("// errno.h stuff\n");
31+
printf("EAGAIN = %d;\n",EAGAIN);
32+
printf("EBADF = %d;\n",EBADF);
33+
printf("EACCES= %d;\n",EINVAL);
34+
printf("EEXIST= %d;\n",EEXIST);
35+
printf("EINTR= %d;\n",EINTR);
36+
printf("EINVAL= %d;\n",EINVAL);
37+
printf("EIO= %d;\n",EIO);
38+
printf("EISDIR= %d;\n",EISDIR);
39+
printf("ELOOP= %d;\n",ELOOP);
40+
printf("EMFILE= %d;\n",EMFILE);
41+
printf("ENAMETOOLONG= %d;\n",ENAMETOOLONG);
42+
printf("ENFILE= %d;\n",ENFILE);
43+
printf("ENOENT= %d;\n",ENOENT);
44+
// printf("ENOSR= %d;\n",ENOSR);
45+
printf("ENOSPC= %d;\n",ENOSPC);
46+
printf("ENOTDIR= %d;\n",ENOTDIR);
47+
printf("ENXIO= %d;\n",ENXIO);
48+
printf("EOVERFLOW= %d;\n",EOVERFLOW);
49+
printf("EROFS= %d;\n",EROFS);
50+
printf("ENOTSUP= %d;\n",ENOTSUP);
51+
printf("EBUSY= %d;\n",EBUSY);
52+
53+
printf("// termios.h stuff\n");
54+
printf("TIOCM_RNG = 0x%08X;\n",TIOCM_RNG);
55+
printf("TIOCM_CAR = 0x%08X;\n",TIOCM_CAR);
56+
57+
printf("IGNBRK = 0x%08X;\n",IGNBRK);
58+
printf("BRKINT = 0x%08X;\n",BRKINT);
59+
printf("PARMRK = 0x%08X;\n",PARMRK);
60+
printf("INLCR = 0x%08X;\n",INLCR);
61+
printf("IGNCR = 0x%08X;\n",IGNCR);
62+
printf("ICRNL = 0x%08X;\n",ICRNL);
63+
printf("ECHONL = 0x%08X;\n",ECHONL);
64+
printf("IEXTEN = 0x%08X;\n",IEXTEN);
65+
66+
printf("CLOCAL = 0x%08X;\n",CLOCAL);
67+
printf("OPOST = 0x%08X;\n",OPOST);
68+
printf("VSTART = 0x%08X;\n",VSTART);
69+
printf("TCSANOW = 0x%08X;\n",TCSANOW);
70+
printf("VSTOP = 0x%08X;\n",VSTOP);
71+
printf("VMIN = 0x%08X;\n",VMIN);
72+
printf("VTIME = 0x%08X;\n",VTIME);
73+
printf("VEOF = 0x%08X;\n",VEOF);
74+
printf("TIOCMGET = 0x%08X;\n",TIOCMGET);
75+
printf("TIOCM_CTS = 0x%08X;\n",TIOCM_CTS);
76+
printf("TIOCM_DSR = 0x%08X;\n",TIOCM_DSR);
77+
printf("TIOCM_RI = 0x%08X;\n",TIOCM_RI);
78+
printf("TIOCM_CD = 0x%08X;\n",TIOCM_CD);
79+
printf("TIOCM_DTR = 0x%08X;\n",TIOCM_DTR);
80+
printf("TIOCM_RTS = 0x%08X;\n",TIOCM_RTS);
81+
printf("ICANON = 0x%08X;\n",ICANON);
82+
printf("ECHO = 0x%08X;\n", ECHO);
83+
printf("ECHOE = 0x%08X;\n", ECHOE);
84+
printf("ISIG = 0x%08X;\n",ISIG);
85+
printf("TIOCMSET= 0x%08X;\n",TIOCMSET);
86+
printf("IXON = 0x%08X;\n",IXON);
87+
printf("IXOFF = 0x%08X;\n",IXOFF);
88+
printf("IXANY = 0x%08X;\n",IXANY);
89+
// printf("CNEW_RTSCTS = 0x%08X;\n",CNEW_RTSCTS); // Not availabel on Mac OX X 10.6.6 atleast
90+
printf("CRTSCTS = 0x%08X;\n",CRTSCTS);
91+
printf("TCSADRAIN = 0x%08X;\n",TCSADRAIN);
92+
printf("INPCK = 0x%08X;\n",INPCK);
93+
printf("ISTRIP = 0x%08X;\n",ISTRIP);
94+
printf("CSIZE = 0x%08X;\n",CSIZE);
95+
printf("TCIFLUSH = 0x%08X;\n",TCIFLUSH);
96+
printf("TCOFLUSH = 0x%08X;\n",TCOFLUSH);
97+
printf("TCIOFLUSH = 0x%08X;\n",TCIOFLUSH);
98+
// printf("TIOCGSERIAL = 0x%08X;\n",TIOCGSERIAL);
99+
// printf("TIOCSSERIAL = 0x%08X;\n",TIOCSSERIAL);
100+
101+
// printf("ASYNC_SPD_MASK = 0x%08X;\n",ASYNC_SPD_MASK);
102+
// printf("ASYNC_SPD_CUST = 0x%08X;\n",ASYNC_SPD_CUST);
103+
104+
105+
106+
printf("CS5 = 0x%08X;\n",CS5);
107+
printf("CS6 = 0x%08X;\n",CS6);
108+
printf("CS7 = 0x%08X;\n",CS7);
109+
printf("CS8 = 0x%08X;\n",CS8);
110+
111+
printf("CSTOPB = 0x%08X;\n",CSTOPB);
112+
printf("CREAD = 0x%08X;\n",CREAD);
113+
printf("PARENB = 0x%08X;\n",PARENB);
114+
printf("PARODD = 0x%08X;\n",PARODD);
115+
116+
117+
printf("CCTS_OFLOW = 0x%08X;\n",CCTS_OFLOW);
118+
printf("CRTS_IFLOW = 0x%08X;\n",CRTS_IFLOW);
119+
// printf("CDTR_IFLOW = 0x%08X;\n",CDTR_IFLOW);
120+
// printf("CDSR_OFLOW = 0x%08X;\n",CDSR_OFLOW);
121+
// printf("CCAR_OFLOW = 0x%08X;\n",CCAR_OFLOW);
122+
123+
printf("B0 = %d;\n",B0);
124+
printf("B50 = %d;\n",B50);
125+
printf("B75 = %d;\n",B75);
126+
printf("B110 = %d;\n",B110);
127+
printf("B134 = %d;\n",B134);
128+
printf("B150 = %d;\n",B150);
129+
printf("B200 = %d;\n",B200);
130+
printf("B300 = %d;\n",B300);
131+
printf("B600 = %d;\n",B600);
132+
printf("B1200 = %d;\n",B600);
133+
printf("B1800 = %d;\n",B1800);
134+
printf("B2400 = %d;\n",B2400);
135+
printf("B4800 = %d;\n",B4800);
136+
printf("B9600 = %d;\n",B9600);
137+
printf("B19200 = %d;\n",B19200);
138+
printf("B38400 = %d;\n",B38400);
139+
printf("B7200 = %d;\n",B7200);
140+
printf("B14400 = %d;\n",B14400);
141+
printf("B28800 = %d;\n",B28800);
142+
printf("B57600 = %d;\n",B57600);
143+
printf("B76800 = %d;\n",B76800);
144+
printf("B115200 = %d;\n",B115200);
145+
printf("B230400 = %d;\n",B230400);
146+
// printf("B307200 = %d;\n",B307200);
147+
// printf("B460800 = %d;\n",B460800);
148+
// printf("B921600 = %d;\n",B921600);
149+
150+
printf("// poll.h stuff\n");
151+
printf("POLLIN = 0x%04X;\n",POLLIN);
152+
printf("POLLRDNORM = 0x%04X;\n",POLLRDNORM);
153+
printf("POLLRDBAND = 0x%04X;\n",POLLRDBAND);
154+
printf("POLLPRI = 0x%04X;\n",POLLPRI);
155+
printf("POLLOUT = 0x%04X;\n",POLLOUT);
156+
printf("POLLWRNORM = 0x%04X;\n",POLLWRNORM);
157+
printf("POLLWRBAND = 0x%04X;\n",POLLWRBAND);
158+
printf("POLLERR = 0x%04X;\n",POLLERR);
159+
printf("POLLNVAL = 0x%04X;\n",POLLNVAL);
160+
161+
162+
printf("// select.h stuff\n");
163+
printf("FD_SETSIZE = 0x%08X;\n",FD_SETSIZE);
164+
printf("__NFDBITS = 0x%08X;\n",__NFDBITS);
165+
166+
printf("// _misc\n");
167+
168+
struct termios t;
169+
printf("termios %d\n",sizeof(t));
170+
printf(".c_iflag %d\n",((char*)&t.c_iflag)-((char*)&t));
171+
printf(".c_oflag %d\n",((char*)&t.c_oflag)-((char*)&t));
172+
printf(".c_cflag %d\n",((char*)&t.c_cflag)-((char*)&t));
173+
printf(".c_lflag %d\n",((char*)&t.c_lflag)-((char*)&t));
174+
// printf(".c_line %d\n",((char*)&(t.c_line))-((char*)&t));
175+
printf(".c_cc[0] %d\n",((char*)&(t.c_cc[0]))-((char*)&t));
176+
printf(".c_cc[1] %d\n",((char*)&(t.c_cc[1]))-((char*)&t));
177+
printf(".c_cc[30] %d\n",((char*)&(t.c_cc[30]))-((char*)&t));
178+
printf(".c_cc[31] %d\n",((char*)&(t.c_cc[31]))-((char*)&t));
179+
printf(".c_ispeed %d\n",((char*)&t.c_ispeed)-((char*)&t));
180+
printf(".c_ospeed %d\n",((char*)&t.c_ospeed)-((char*)&t));
181+
182+
// struct serial_struct ss;
183+
// printf("serial_struct %d\n",sizeof(ss));
184+
// printf(".type %d\n",((char*)&ss.type)-((char*)&ss));
185+
// printf(".line %d\n",((char*)&ss.line)-((char*)&ss));
186+
// printf(".port %d\n",((char*)&ss.port)-((char*)&ss));
187+
// printf(".irq %d\n",((char*)&ss.irq)-((char*)&ss));
188+
// printf(".flags %d\n",((char*)&ss.flags)-((char*)&ss));
189+
// printf(".xmit_fifo_size %d\n",((char*)&ss.xmit_fifo_size)-((char*)&ss));
190+
// printf(".custom_divisor %d\n",((char*)&ss.custom_divisor)-((char*)&ss));
191+
// printf(".baud_base %d\n",((char*)&ss.baud_base)-((char*)&ss));
192+
// printf(".close_delay %d\n",((char*)&ss.close_delay)-((char*)&ss));
193+
// printf(".io_type %d\n",((char*)&ss.io_type)-((char*)&ss));
194+
// printf(".reserved_char %d\n",((char*)&ss.reserved_char)-((char*)&ss));
195+
// printf(".hub6 %d\n",((char*)&ss.hub6)-((char*)&ss));
196+
// printf(".closing_wait %d\n",((char*)&ss.closing_wait)-((char*)&ss));
197+
// printf(".closing_wait2 %d\n",((char*)&ss.closing_wait2)-((char*)&ss));
198+
// printf(".iomem_base %d\n",((char*)&ss.iomem_base)-((char*)&ss));
199+
// printf(".iomem_reg_shift %d\n",((char*)&ss.iomem_reg_shift)-((char*)&ss));
200+
// printf(".port_high %d\n",((char*)&ss.port_high)-((char*)&ss));
201+
// printf(".iomap_base %d\n",((char*)&ss.iomap_base)-((char*)&ss));
202+
203+
printf("timeval %d\n",sizeof(struct timeval));
204+
205+
fd_set fs;
206+
FD_ZERO(&fs);
207+
FD_SET(41,&fs);
208+
printf("sizeof(fd_set)=%d\n",sizeof(fs));
209+
int i;
210+
for (i=0; i<8; i++)
211+
printf("%08X ",fs.fds_bits[i]);
212+
213+
printf("\n");
214+
215+
int com;
216+
printf("open %d\n",com = open("/dev/tty.usbserial-FTOXM3NX", O_RDWR | O_NOCTTY | O_NDELAY));
217+
218+
struct termios opts;
219+
220+
printf("get %d\n",tcgetattr(com, &opts));
221+
printf("c_cflag %08X\n",opts.c_cflag);
222+
223+
opts.c_cflag |= CRTSCTS;
224+
printf("c_cflag %08X\n",opts.c_cflag);
225+
printf("set %d\n",tcsetattr(com,TCSANOW, &opts));
226+
227+
opts.c_cflag = 0;
228+
printf("get %d\n",tcgetattr(com, &opts));
229+
printf("c_cflag %08X\n",opts.c_cflag);
230+
231+
printf(" sizeof(speed_t) %d\n", sizeof(speed_t));
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
}

src/jtermios/JTermios.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ public void shutdown() {
322322
m_Termios = new jtermios.solaris.JTermiosImpl();
323323
} else if (Platform.isFreeBSD()) {
324324
m_Termios = new jtermios.freebsd.JTermiosImpl();
325+
} else if (Platform.isOpenBSD()) {
326+
m_Termios = new jtermios.openbsd.JTermiosImpl();
325327
} else {
326328
log(0, "JTermios has no support for OS %s\n", System.getProperty("os.name"));
327329
}

0 commit comments

Comments
 (0)