Debian Codegraph @

src/I2CImp.c

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /*-------------------------------------------------------------------------
2 | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
3 | RXTX is a native interface to serial ports in java.
4 | Copyright 1997-2007 by Trent Jarvi [email protected] and others who
5 | actually wrote it. See individual source files for more information.
6 |
7 | A copy of the LGPL v 2.1 may be found at
8 | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is
9 | here for your convenience.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation; either
14 | version 2.1 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | An executable that contains no derivative of any portion of RXTX, but
22 | is designed to work with RXTX by being dynamically linked with it,
23 | is considered a "work that uses the Library" subject to the terms and
24 | conditions of the GNU Lesser General Public License.
25 |
26 | The following has been added to the RXTX License to remove
27 | any confusion about linking to RXTX. We want to allow in part what
28 | section 5, paragraph 2 of the LGPL does not permit in the special
29 | case of linking over a controlled interface. The intent is to add a
30 | Java Specification Request or standards body defined interface in the
31 | future as another exception but one is not currently available.
32 |
33 | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
34 |
35 | As a special exception, the copyright holders of RXTX give you
36 | permission to link RXTX with independent modules that communicate with
37 | RXTX solely through the Sun Microsytems CommAPI interface version 2,
38 | regardless of the license terms of these independent modules, and to copy
39 | and distribute the resulting combined work under terms of your choice,
40 | provided that every copy of the combined work is accompanied by a complete
41 | copy of the source code of RXTX (the version of RXTX used to produce the
42 | combined work), being distributed under the terms of the GNU Lesser General
43 | Public License plus this exception. An independent module is a
44 | module which is not derived from or based on RXTX.
45 |
46 | Note that people who make modified versions of RXTX are not obligated
47 | to grant this special exception for their modified versions; it is
48 | their choice whether to do so. The GNU Lesser General Public License
49 | gives permission to release a modified version without this exception; this
50 | exception also makes it possible to release a modified version which
51 | carries forward this exception.
52 |
53 | You should have received a copy of the GNU Lesser General Public
54 | License along with this library; if not, write to the Free
55 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 | All trademarks belong to their respective owners.
57 --------------------------------------------------------------------------*/
58 #if defined(__MWERKS__) /* dima */
59 #include "I2C.h" /* dima */
60 #else /* dima */
61 #include "config.h"
62 #include "gnu_io_I2C.h"
63 #endif /* dima */
64 #include <time.h>
65 #include <unistd.h>
66 #include <stdio.h>
67 #include <string.h>
68 #include <stdlib.h>
69 #include <errno.h>
70 #ifndef WIN32
71 #include <sys/ioctl.h>
72 #include <sys/param.h>
73 #include <sys/utsname.h>
74 #ifdef HAVE_TERMIOS_H
75 # include <termios.h>
76 #endif
77 #ifdef HAVE_SYS_SIGNAL_H
78 # include <sys/signal.h>
79 #endif
80 #else
81 # include <win32termios.h>
82 #endif
83 #include <sys/types.h>
84 #include <sys/stat.h>
85 #include <sys/time.h>
86 #ifdef HAVE_SYS_FCNTL_H
87 # include <sys/fcntl.h>
88 #endif
89 #ifdef HAVE_SYS_FILE_H
90 # include <sys/file.h>
91 #endif
92
93 #if defined(__linux__)
94 # include <linux/types.h> /* fix for linux-2.3.4? kernels */
95 # include <linux/serial.h>
96 # include <linux/version.h>
97 #endif
98
99 extern int errno;
100 #include "I2CImp.h"
101 /* #define DEBUG_TIMEOUT */
102
103 /*----------------------------------------------------------
104 I2CPort.Initialize
105
106 accept: none
107 perform: Initialize the native library
108 return: none
109 ----------------------------------------------------------*/
110 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_Initialize(
111 JNIEnv *env,
112 jclass jclazz
113 )
114 {
115 #ifndef WIN32
116 struct utsname name;
117 /* This bit of code checks to see if there is a signal handler installed
118 for SIGIO, and installs SIG_IGN if there is not. This is necessary
119 for the native threads jdk, but we don't want to do it with green
120 threads, because it slows things down. Go figure. */
121
122 /* POSIX signal handling functions */
•123 #if !defined(__FreeBSD_kernel___)
124 struct sigaction handler;
125 sigaction( SIGIO, NULL, &handler );
126 if( !handler.sa_handler ) signal( SIGIO, SIG_IGN );
•127 #endif /* !__FreeBSD_kernel__ */
128 #if defined(__linux__)
129 /* Lets let people who upgraded kernels know they may have problems */
•130 /*
131 if (uname (&name) == -1)
132 {
133 fprintf(stderr,"RXTX WARNING: cannot get system name\n");
134 return;
135 }
136 if(strcmp(name.release,UTS_RELEASE)!=0)
137 {
138 fprintf(stderr, "\n\n\nRXTX WARNING: This library was compiled to run with OS release %s and you are currently running OS release %s. In some cases this can be a problem. Try recompiling RXTX if you notice strange behavior. If you just compiled RXTX make sure /usr/include/linux is a symbolic link to the include files that came with the kernel source and not an older copy.\n\n\npress enter to continue\n",UTS_RELEASE,name.release);
139 getchar();
140 }
•141 */
142 #endif /* __linux__ */
143 #endif /* WIN32 */
144 }
145
146
147 /*----------------------------------------------------------
148 I2CPort.open
149
150 accept: The device to open. ie "/dev/ttyS0"
151 perform: open the device, set the termios struct to sane settings and
152 return the filedescriptor
153 return: fd
154 exceptions: IOExcepiton
155 comments: Very often people complain about not being able to get past
156 this function and it turns out to be permissions on the
157 device file or bios has the device disabled.
158 ----------------------------------------------------------*/
159 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_open(
160 JNIEnv *env,
161 jobject jobj,
162 jstring jstr
163 )
164 {
165 struct termios ttyset;
166 int fd;
167 const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 );
168
169 do {
170 fd=open (filename, O_RDWR | O_NOCTTY | O_NONBLOCK );
171 } while (fd < 0 && errno==EINTR);
172 (*env)->ReleaseStringUTFChars( env, jstr, NULL );
173 if( fd < 0 ) goto fail;
174
175 if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
176 ttyset.c_iflag = INPCK;
177 ttyset.c_lflag = 0;
178 ttyset.c_oflag = 0;
179 ttyset.c_cflag = CREAD | CS8 | CLOCAL;
180 ttyset.c_cc[ VMIN ] = 0;
181 ttyset.c_cc[ VTIME ] = 0;
182
•183 #ifdef __FreeBSD_kernel__
184 if( cfsetspeed( &ttyset, B9600 ) < 0 ) goto fail;
185 #else
186 if( cfsetispeed( &ttyset, B9600 ) < 0 ) goto fail;
187 if( cfsetospeed( &ttyset, B9600 ) < 0 ) goto fail;
188 #endif
189 if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail;
190
191 #ifndef WIN32
192 fcntl( fd, F_SETOWN, getpid() );
193 fcntl( fd, F_SETFL, FASYNC );
194 #endif /* WIN32 */
195
196 return (jint)fd;
197
198 fail:
199 throw_java_exception( env, IO_EXCEPTION, "open", strerror( errno ) );
200 return -1;
201 }
202
203 /*----------------------------------------------------------
204 I2CPort.nativeClose
205
206 accept: none
207 perform: get the fd from the java end and close it
208 return: none
209 exceptions: none
210 ----------------------------------------------------------*/
211 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_nativeClose( JNIEnv *env,
212 jobject jobj )
213 {
214 int result;
215 int fd = get_java_var( env, jobj,"fd","I" );
216
217 do {
218 result=close (fd);
219 } while (result < 0 && errno==EINTR);
220 return;
221 }
222
223 /*----------------------------------------------------------
224 I2CPort.nativeSetI2CPortParams
225
226 accept: speed, data bits, stop bits, parity
227 perform: set the i2c port parameters
228 return: void
229 exceptions: UnsupportedCommOperationException
230 ----------------------------------------------------------*/
231 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_nativeSetI2CPortParams(
232 JNIEnv *env, jobject jobj, jint speed, jint dataBits, jint stopBits,
233 jint parity )
234 {
235 struct termios ttyset;
236 int fd = get_java_var( env, jobj,"fd","I" );
237 int cspeed = translate_speed( env, speed );
238 if( !cspeed ) return;
239 if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
240 if( !translate_data_bits( env, (int *)&(ttyset.c_cflag), dataBits ) ) return; /* dima darwin defime c_cflag as unsigned long */
241 if( !translate_stop_bits( env, (int *)&(ttyset.c_cflag), stopBits ) ) return; /* dima darwin defime c_cflag as unsigned long */
242 if( !translate_parity( env, (int *)&(ttyset.c_cflag), parity ) ) return;/* dima darwin defime c_cflag as unsigned long */
•243 #ifdef __FreeBSD_kernel__
244 if( cfsetspeed( &ttyset, cspeed ) < 0 ) goto fail;
245 #else
246 if( cfsetispeed( &ttyset, cspeed ) < 0 ) goto fail;
247 if( cfsetospeed( &ttyset, cspeed ) < 0 ) goto fail;
248 #endif
249 if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail;
250 /* dump_termios("set",*ttyset); */
251 return;
252
253 fail:
254 throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
255 "nativeSetI2CPortParams", strerror( errno ) );
256 }
257
258 /*----------------------------------------------------------
259 translate_speed
260
261 accept: speed in bits-per-second
262 perform: convert bits-per-second to a speed_t constant
263 return: speed_t constant
264 exceptions: UnsupportedCommOperationException
265 comments: Only the lowest level code should know about
266 the magic constants.
267 ----------------------------------------------------------*/
268 int translate_speed( JNIEnv *env, jint speed )
269 {
270 switch( speed ) {
271 case 0: return B0;
272 case 50: return B50;
273 case 75: return B75;
274 case 110: return B110;
275 case 134: return B134;
276 case 150: return B150;
277 case 200: return B200;
278 case 300: return B300;
279 case 600: return B600;
280 case 1200: return B1200;
281 case 1800: return B1800;
282 case 2400: return B2400;
283 case 4800: return B4800;
284 case 9600: return B9600;
285 case 19200: return B19200;
286 case 38400: return B38400;
287 case 57600: return B57600;
288 case 115200: return B115200;
289 case 230400: return B230400;
290 #ifdef B460800
291 case 460800: return B460800;
292 #endif
293 }
294
295 throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
296 "translate_speed", "speed" );
297 return 0;
298 }
299
300 /*----------------------------------------------------------
301 translate_data_bits
302
303 accept: gnu.io.I2CPort.DATABITS_* constant
304 perform: set proper termios c_cflag bits
305 return: 1 if successful
306 0 if an exception is thrown
307 exceptions: UnsupportedCommOperationException
308 ----------------------------------------------------------*/
309 int translate_data_bits( JNIEnv *env, int *cflag, jint dataBits )
310 {
311 int temp = (*cflag) & ~CSIZE;
312
313 switch( dataBits ) {
314 case DATABITS_5:
315 (*cflag) = temp | CS5;
316 return 1;
317 case DATABITS_6:
318 (*cflag) = temp | CS6;
319 return 1;
320 case DATABITS_7:
321 (*cflag) = temp | CS7;
322 return 1;
323 case DATABITS_8:
324 (*cflag) = temp | CS8;
325 return 1;
326 }
327
328 throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
329 "translate_data_bits", "data bits" );
330 return 0;
331 }
332
333 /*----------------------------------------------------------
334 translate_stop_bits
335
336 accept: gnu.io.I2CPort.STOPBITS_* constant
337 perform: set proper termios c_cflag bits
338 return: 1 if successful
339 0 if an exception is thrown
340 exceptions: UnsupportedCommOperationException
341 comments: If you specify 5 data bits and 2 stop bits, the port will
342 allegedly use 1.5 stop bits. Does anyone care?
343 ----------------------------------------------------------*/
344 int translate_stop_bits( JNIEnv *env, int *cflag, jint stopBits )
345 {
346 switch( stopBits ) {
347 case STOPBITS_1:
348 (*cflag) &= ~CSTOPB;
349 return 1;
350 case STOPBITS_2:
351 (*cflag) |= CSTOPB;
352 return 1;
353 }
354
355 throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
356 "translate_stop_bits", "stop bits" );
357 return 0;
358 }
359
360 /*----------------------------------------------------------
361 translate_parity
362
363 accept: gnu.io.I2CPort.PARITY_* constant
364 perform: set proper termios c_cflag bits
365 return: 1 if successful
366 0 if an exception is thrown
367 exceptions: UnsupportedCommOperationException
368 comments: The CMSPAR bit should be used for 'mark' and 'space' parity,
369 but it's not in glibc's includes. Oh well, rarely used anyway.
370 ----------------------------------------------------------*/
371 int translate_parity( JNIEnv *env, int *cflag, jint parity )
372 {
373 (*cflag) &= ~(PARENB | PARODD);
374 switch( parity ) {
375 case PARITY_NONE:
376 return 1;
377 #ifdef CMSPAR
378 case PARITY_EVEN:
379 (*cflag) |= PARENB;
380 return 1;
381 case PARITY_ODD:
382 (*cflag) |= PARENB | PARODD;
383 return 1;
384 case PARITY_MARK:
385 (*cflag) |= PARENB | PARODD | CMSPAR;
386 return 1;
387 case PARITY_SPACE:
388 (*cflag) |= PARENB | CMSPAR;
389 return 1;
390 #else
391 case PARITY_EVEN:
392 (*cflag) |= PARENB;
393 return 1;
394 case PARITY_ODD:
395 (*cflag) |= PARENB | PARODD;
396 return 1;
397 #endif
398 }
399
400 throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
401 "translate_parity", "parity" );
402 return 0;
403 }
404
405
406 /*----------------------------------------------------------
407 I2CPort.writeByte
408
409 accept: byte to write (passed as int)
410 perform: write a single byte to the port
411 return: none
412 exceptions: IOException
413 ----------------------------------------------------------*/
414 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_writeByte( JNIEnv *env,
415 jobject jobj, jint ji )
416 {
417 unsigned char byte = (unsigned char)ji;
418 int fd = get_java_var( env, jobj,"fd","I" );
419 int result;
420
421 do {
422 result=write (fd, &byte, sizeof(unsigned char));
423 } while (result < 0 && errno==EINTR);
424 if(result >= 0)
425 return;
426 throw_java_exception( env, IO_EXCEPTION, "writeByte",
427 strerror( errno ) );
428 }
429
430
431 /*----------------------------------------------------------
432 I2CPort.writeArray
433
434 accept: jbarray: bytes used for writing
435 offset: offset in array to start writing
436 count: Number of bytes to write
437 perform: write length bytes of jbarray
438 return: none
439 exceptions: IOException
440 ----------------------------------------------------------*/
441 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_writeArray( JNIEnv *env,
442 jobject jobj, jbyteArray jbarray, jint offset, jint count )
443 {
444 int fd = get_java_var( env, jobj,"fd","I" );
445 int result=0,total=0,i;
446
447 unsigned char *bytes = (unsigned char *)malloc( count );
448
449 jbyte *body = (*env)->GetByteArrayElements( env, jbarray, 0 );
450 for( i = 0; i < count; i++ ) bytes[ i ] = body[ i + offset ];
451 (*env)->ReleaseByteArrayElements( env, jbarray, body, 0 );
452 do {
453 result=write (fd, bytes + total + offset, count - total); /* dima */
454 if(result >0){
455 total += result;
456 }
457 } while ((total<count)||(result < 0 && errno==EINTR));
458 free( bytes );
459 if( result < 0 ) throw_java_exception( env, IO_EXCEPTION,
460 "writeArray", strerror( errno ) );
461 }
462
463
464 /*----------------------------------------------------------
465 I2CPort.drain
466
467 accept: none
468 perform: wait until all data is transmitted
469 return: none
470 exceptions: IOException
471 comments: java.io.OutputStream.flush() is equivalent to tcdrain,
472 not tcflush, which throws away unsent bytes
473
474 count logic added to avoid infinite loops when EINTR is
475 true... Thread.yeild() was suggested.
476 ----------------------------------------------------------*/
477 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_drain( JNIEnv *env,
478 jobject jobj )
479 {
480 int fd = get_java_var( env, jobj,"fd","I" );
481 int result, count=0;
482
483 do {
484 result=tcdrain (fd);
485 count++;
486 } while (result && errno==EINTR && count <5);
487
488 if( result ) throw_java_exception( env, IO_EXCEPTION, "drain",
489 strerror( errno ) );
490 }
491
492 /*----------------------------------------------------------
493 I2CPort.sendBreak
494
495 accept: duration in milliseconds.
496 perform: send break for actual time. not less than 0.25 seconds.
497 exceptions: none
498 comments: not very precise
499 ----------------------------------------------------------*/
500 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_sendBreak( JNIEnv *env,
501 jobject jobj, jint duration )
502 {
503 int fd = get_java_var( env, jobj,"fd","I" );
504 tcsendbreak( fd, (int)( duration / 250 ) );
505 }
506
507
508 /*----------------------------------------------------------
509 I2CPort.NativegetReceiveTimeout
510
511 accept: none
512 perform: get termios.c_cc[VTIME]
513 return: VTIME
514 comments: see NativeEnableReceiveTimeoutThreshold
515 ----------------------------------------------------------*/
516 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_NativegetReceiveTimeout(
517 JNIEnv *env,
518 jobject jobj
519 )
520 {
521 int fd = get_java_var( env, jobj,"fd","I" );
522 struct termios ttyset;
523
524 if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
525 return(ttyset.c_cc[ VTIME ] * 100);
526 fail:
527 throw_java_exception( env, IO_EXCEPTION, "getReceiveTimeout", strerror( errno ) );
528 return -1;
529 }
530
531 /*----------------------------------------------------------
532 I2CPort.NativeisReceiveTimeoutEnabled
533
534 accept: none
535 perform: determine if VTIME is none 0
536 return: JNI_TRUE if VTIME > 0 else JNI_FALSE
537 comments: see NativeEnableReceiveTimeoutThreshold
538 ----------------------------------------------------------*/
539 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_NativeisReceiveTimeoutEnabled(
540 JNIEnv *env,
541 jobject jobj
542 )
543 {
544 int fd = get_java_var( env, jobj,"fd","I" );
545 struct termios ttyset;
546
547 if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
548 return(ttyset.c_cc[ VTIME ] > 0 ? JNI_TRUE:JNI_FALSE);
549 fail:
550 throw_java_exception( env, IO_EXCEPTION, "isReceiveTimeoutEnabled", strerror( errno ) );
551 return JNI_FALSE;
552 }
553
554 /*----------------------------------------------------------
555 I2CPort.isDSR
556
557 accept: none
558 perform: check status of DSR
559 return: true if TIOCM_DSR is set
560 false if TIOCM_DSR is not set
561 exceptions: none
562 comments: DSR stands for Data Set Ready
563 ----------------------------------------------------------*/
564 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isDSR( JNIEnv *env,
565 jobject jobj )
566 {
567 unsigned int result = 0;
568 int fd = get_java_var( env, jobj,"fd","I" );
569
570 ioctl( fd, TIOCMGET, &result );
571 if( result & TIOCM_DSR ) return JNI_TRUE;
572 else return JNI_FALSE;
573 }
574
575 /*----------------------------------------------------------
576 I2CPort.isCD
577
578 accept: none
579 perform: check status of CD
580 return: true if TIOCM_CD is set
581 false if TIOCM_CD is not set
582 exceptions: none
583 comments: CD stands for Carrier Detect
584 The following comment has been made...
585 "well, it works, there might ofcourse be a bug, but making DCD
586 permanently on fixed it for me so I don't care"
587
588 ----------------------------------------------------------*/
589 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isCD( JNIEnv *env,
590 jobject jobj )
591 {
592 unsigned int result = 0;
593 int fd = get_java_var( env, jobj,"fd","I" );
594
595 ioctl( fd, TIOCMGET, &result );
596 if( result & TIOCM_CD ) return JNI_TRUE;
597 else return JNI_FALSE;
598 }
599
600 /*----------------------------------------------------------
601 I2CPort.isCTS
602
603 accept: none
604 perform: check status of CTS
605 return: true if TIOCM_CTS is set
606 false if TIOCM_CTS is not set
607 exceptions: none
608 comments: CTS stands for Clear To Send.
609 ----------------------------------------------------------*/
610 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isCTS( JNIEnv *env,
611 jobject jobj )
612 {
613 unsigned int result = 0;
614 int fd = get_java_var( env, jobj,"fd","I" );
615
616 ioctl( fd, TIOCMGET, &result );
617 if( result & TIOCM_CTS ) return JNI_TRUE;
618 else return JNI_FALSE;
619 }
620
621 /*----------------------------------------------------------
622 I2CPort.isRI
623
624 accept: none
625 perform: check status of RI
626 return: true if TIOCM_RI is set
627 false if TIOCM_RI is not set
628 exceptions: none
629 comments: RI stands for Ring Indicator
630 ----------------------------------------------------------*/
631 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isRI( JNIEnv *env,
632 jobject jobj )
633 {
634 unsigned int result = 0;
635 int fd = get_java_var( env, jobj,"fd","I" );
636
637 ioctl( fd, TIOCMGET, &result );
638 if( result & TIOCM_RI ) return JNI_TRUE;
639 else return JNI_FALSE;
640 }
641
642 /*----------------------------------------------------------
643 I2CPort.isRTS
644
645 accept: none
646 perform: check status of RTS
647 return: true if TIOCM_RTS is set
648 false if TIOCM_RTS is not set
649 exceptions: none
650 comments: tcgetattr with c_cflag CRTS_IFLOW
651 ----------------------------------------------------------*/
652 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isRTS( JNIEnv *env,
653 jobject jobj )
654 {
655 unsigned int result = 0;
656 int fd = get_java_var( env, jobj,"fd","I" );
657
658 ioctl( fd, TIOCMGET, &result );
659 if( result & TIOCM_RTS ) return JNI_TRUE;
660 else return JNI_FALSE;
661 }
662
663 /*----------------------------------------------------------
664 I2CPort.setRTS
665
666 accept: state flag to set/unset.
667 perform: depends on the state flag
668 if true TIOCM_RTS is set
669 if false TIOCM_RTS is unset
670 return: none
671 exceptions: none
672 comments: tcsetattr with c_cflag CRTS_IFLOW
673 ----------------------------------------------------------*/
674 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setRTS( JNIEnv *env,
675 jobject jobj, jboolean state )
676 {
677 unsigned int result = 0;
678 int fd = get_java_var( env, jobj,"fd","I" );
679
680 ioctl( fd, TIOCMGET, &result );
681 if( state == JNI_TRUE ) result |= TIOCM_RTS;
682 else result &= ~TIOCM_RTS;
683 ioctl( fd, TIOCMSET, &result );
684 return;
685 }
686
687 /*----------------------------------------------------------
688 I2CPort.setDSR
689
690 accept: state flag to set/unset.
691 perform: depends on the state flag
692 if true TIOCM_DSR is set
693 if false TIOCM_DSR is unset
694 return: none
695 exceptions: none
696 comments: tcsetattr with c_cflag CRTS_IFLOW
697 ----------------------------------------------------------*/
698 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setDSR( JNIEnv *env,
699 jobject jobj, jboolean state )
700 {
701 unsigned int result = 0;
702 int fd = get_java_var( env, jobj,"fd","I" );
703
704 ioctl( fd, TIOCMGET, &result );
705 if( state == JNI_TRUE ) result |= TIOCM_DSR;
706 else result &= ~TIOCM_DSR;
707 ioctl( fd, TIOCMSET, &result );
708 return;
709 }
710
711 /*----------------------------------------------------------
712 I2CPort.isDTR
713
714 accept: none
715 perform: check status of DTR
716 return: true if TIOCM_DTR is set
717 false if TIOCM_DTR is not set
718 exceptions: none
719 comments: DTR stands for Data Terminal Ready
720 ----------------------------------------------------------*/
721 JNIEXPORT jboolean JNICALL Java_gnu_io_I2CPort_isDTR( JNIEnv *env,
722 jobject jobj )
723 {
724 unsigned int result = 0;
725 int fd = get_java_var( env, jobj,"fd","I" );
726
727 ioctl( fd, TIOCMGET, &result );
728 if( result & TIOCM_DTR ) return JNI_TRUE;
729 else return JNI_FALSE;
730 }
731
732 /*----------------------------------------------------------
733 I2CPort.setDTR
734
735 accept: new DTR state
736 perform: if state is true, TIOCM_DTR is set
737 if state is false, TIOCM_DTR is unset
738 return: none
739 exceptions: none
740 comments: DTR stands for Data Terminal Ready
741 ----------------------------------------------------------*/
742 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setDTR( JNIEnv *env,
743 jobject jobj, jboolean state )
744 {
745 unsigned int result = 0;
746 int fd = get_java_var( env, jobj,"fd","I" );
747
748 ioctl( fd, TIOCMGET, &result );
749 if( state == JNI_TRUE ) result |= TIOCM_DTR;
750 else result &= ~TIOCM_DTR;
751 ioctl( fd, TIOCMSET, &result );
752 return;
753 }
754
755 /*----------------------------------------------------------
756 read_byte_array
757
758 accept: int fd file descriptor to read from
759 unsigned char *buffer buffer to read data into
760 int length number of bytes to read
761 int timeout milliseconds to wait before returning
762 perform: read bytes from the port into a buffer
763 return: status of read
764 -1 fail (IOException)
765 0 timeout
766 >0 number of bytes read
767 comments: According to the Communications API spec, a receive threshold
768 of 1 is the same as having the threshold disabled.
769
770 The nuts and bolts are documented in
771 NativeEnableReceiveTimeoutThreshold()
772 ----------------------------------------------------------*/
773 int read_byte_array( int fd, unsigned char *buffer, int length, int timeout )
774 {
775 int ret, left, bytes = 0;
776 fd_set rfds;
777 struct timeval sleep;
778 struct timeval *psleep=&sleep;
779
780 left = length;
781 FD_ZERO( &rfds );
782 FD_SET( fd, &rfds );
783 if( timeout != 0 )
784 {
785 sleep.tv_sec = timeout / 1000;
786 sleep.tv_usec = 1000 * ( timeout % 1000 );
787 }
788 while( bytes < length )
789 {
790 /* FIXME: In Linux, select updates the timeout automatically, so
791 other OSes will need to update it manually if they want to have
792 the same behavior. For those OSes, timeouts will occur after no
793 data AT ALL is received for the timeout duration. No big deal. */
794 do {
795 if( timeout == 0 ) psleep = NULL;
796 ret=select( fd + 1, &rfds, NULL, NULL, psleep );
797 } while (ret < 0 && errno==EINTR);
798 if( ret == 0 ) break;
799 if( ret < 0 ) return -1;
800 ret = read( fd, buffer + bytes, left );
801 if( ret == 0 ) break;
802 if( ret < 0 ) return -1;
803 bytes += ret;
804 left -= ret;
805 }
806 return bytes;
807 }
808
809 /*----------------------------------------------------------
810 NativeEnableReceiveTimeoutThreshold
811 accept: int threshold, int vtime,int buffer
812 perform: Set c_cc->VMIN to threshold and c_cc=>VTIME to vtime
813 return: void
814 exceptions: IOException
815 comments: This is actually all handled in read with select in
816 canonical input mode.
817 ----------------------------------------------------------*/
818
819 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_NativeEnableReceiveTimeoutThreshold(JNIEnv *env, jobject jobj, jint vtime, jint threshold, jint buffer)
820 {
821 int fd = get_java_var( env, jobj,"fd","I" );
822 struct termios ttyset;
823
824 if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
825 ttyset.c_cc[ VMIN ] = threshold;
826 ttyset.c_cc[ VTIME ] = vtime/100;
827 if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail;
828
829 return;
830 fail:
831 throw_java_exception( env, IO_EXCEPTION, "TimeoutThreshold", strerror( errno ) );
832 return;
833 }
834
835 /*----------------------------------------------------------
836 I2CPort.readByte
837
838 accept: none
839 perform: Read a single byte from the port
840 return: The byte read
841 exceptions: IOException
842 ----------------------------------------------------------*/
843 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_readByte( JNIEnv *env,
844 jobject jobj )
845 {
846 int bytes;
847 unsigned char buffer[ 1 ];
848 int fd = get_java_var( env, jobj,"fd","I" );
849 int timeout = get_java_var( env, jobj, "timeout", "I" );
850
851 bytes = read_byte_array( fd, buffer, 1, timeout );
852 if( bytes < 0 ) {
853 throw_java_exception( env, IO_EXCEPTION, "readByte",
854 strerror( errno ) );
855 return -1;
856 }
857 return (bytes ? (jint)buffer[ 0 ] : -1);
858 }
859
860 /*----------------------------------------------------------
861 I2CPort.readArray
862
863 accept: offset (offset to start storing data in the jbarray) and
864 Length (bytes to read)
865 perform: read bytes from the port into a byte array
866 return: bytes read on success
867 0 on read timeout
868 exceptions: IOException
869 comments: throws ArrayIndexOutOfBoundsException if asked to
870 read more than SSIZE_MAX bytes
871 ----------------------------------------------------------*/
872 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_readArray( JNIEnv *env,
873 jobject jobj, jbyteArray jbarray, jint offset, jint length )
874 {
875 int bytes;
876 jbyte *body;
877 unsigned char *buffer;
878 int fd = get_java_var( env, jobj, "fd", "I" );
879 int timeout = get_java_var( env, jobj, "timeout", "I" );
880
881 if( (size_t) length > SSIZE_MAX || length < 0 ) {
882 throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS,
883 "readArray", "Invalid length" );
884 return -1;
885 }
886
887 buffer = (unsigned char *)malloc( sizeof( unsigned char ) * length );
888 if( buffer == 0 ) {
889 throw_java_exception( env, OUT_OF_MEMORY, "readArray",
890 "Unable to allocate buffer" );
891 return -1;
892 }
893
894 bytes = read_byte_array( fd, buffer, length, timeout );
895 if( bytes < 0 ) {
896 free( buffer );
897 throw_java_exception( env, IO_EXCEPTION, "readArray",
898 strerror( errno ) );
899 return -1;
900 }
901 body = (*env)->GetByteArrayElements( env, jbarray, 0 );
902 memcpy(body + offset, buffer, bytes);
903 (*env)->ReleaseByteArrayElements( env, jbarray, body, 0 );
904 free( buffer );
905 return (bytes ? bytes : -1);
906 }
907
908 /*----------------------------------------------------------
909 I2CPort.nativeavailable
910
911 accept: none
912 perform: find out the number of bytes available for reading
913 return: available bytes
914 -1 on error
915 exceptions: none
916 ----------------------------------------------------------*/
917 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_nativeavailable( JNIEnv *env,
918 jobject jobj )
919 {
920 int fd = get_java_var( env, jobj,"fd","I" );
921 int result;
922
923 if( ioctl( fd, FIONREAD, &result ) )
924 {
925 throw_java_exception( env, IO_EXCEPTION, "nativeavailable", strerror( errno ) );
926 return -1;
927 }
928 else return (jint)result;
929
930 }
931
932 /*----------------------------------------------------------
933 I2CPort.setflowcontrol
934
935 accept: flowmode
936 FLOWCONTROL_NONE none
937 FLOWCONTROL_RTSCTS_IN hardware flow control
938 FLOWCONTROL_RTSCTS_OUT ""
939 FLOWCONTROL_XONXOFF_IN input software flow control
940 FLOWCONTROL_XONXOFF_OUT output software flow control
941 perform: set flow control to flowmode
942 return: none
943 exceptions: IOException
944 comments: there is no differentiation between input and output hardware
945 flow control
946 ----------------------------------------------------------*/
947 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setflowcontrol( JNIEnv *env,
948 jobject jobj, jint flowmode )
949 {
950 struct termios ttyset;
951 int fd = get_java_var( env, jobj,"fd","I" );
952
953 if( tcgetattr( fd, &ttyset ) ) goto fail;
954
955 if ( flowmode & ( FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT ) )
956 ttyset.c_cflag |= HARDWARE_FLOW_CONTROL;
957 else ttyset.c_cflag &= ~HARDWARE_FLOW_CONTROL;
958
959 ttyset.c_iflag &= ~IXANY;
960
961 if ( flowmode & FLOWCONTROL_XONXOFF_IN )
962 ttyset.c_iflag |= IXOFF;
963 else ttyset.c_iflag &= ~IXOFF;
964
965 if ( flowmode & FLOWCONTROL_XONXOFF_OUT )
966 ttyset.c_iflag |= IXON;
967 else ttyset.c_iflag &= ~IXON;
968
969 if( tcsetattr( fd, TCSANOW, &ttyset ) ) goto fail;
970 return;
971 fail:
972 throw_java_exception( env, IO_EXCEPTION, "setHWFC",
973 strerror( errno ) );
974 return;
975 }
976
977 /*----------------------------------------------------------
978 I2CPort.eventLoop
979
980 accept: none
981 perform: periodically check for I2CPortEvents
982 return: none
983 exceptions: none
984 comments: FIXME This is probably wrong on bsd.
985 ----------------------------------------------------------*/
986 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_eventLoop( JNIEnv *env,
987 jobject jobj )
988 {
989 int fd, ret, change;
990 fd_set rfds;
991 struct timeval tv_sleep;
992 unsigned int mflags;
993 #if defined(TIOCGICOUNT)
994 struct serial_icounter_struct sis, osis;
995 #endif /* TIOCGICOUNT */
996 unsigned int omflags;
997
998 jmethodID method, interrupt;
999 jboolean interrupted = 0;
1000 jclass jclazz, jthread;
1001 jclazz = (*env)->GetObjectClass( env, jobj );
1002 fd = get_java_var(env, jobj, "fd", "I");
1003 method = (*env)->GetMethodID( env, jclazz, "sendEvent", "(IZ)V" );
1004 jthread = (*env)->FindClass( env, "java/lang/Thread" );
1005 interrupt = (*env)->GetStaticMethodID( env, jthread, "interrupted", "()Z" );
1006
1007 /* Some multiport i2c cards do not implement TIOCGICOUNT ... */
1008 #if defined(TIOCGICOUNT)
1009 if( ioctl( fd, TIOCGICOUNT, &osis ) < 0 ) {
1010 fprintf( stderr, "Port does not support TIOCGICOUNT events\n" );
1011 return;
1012 }
1013 #else
1014 fprintf( stderr, "Port does not support all Hardware events\n" );
1015 #endif /* TIOCGICOUNT */
1016
1017 if( ioctl( fd, TIOCMGET, &omflags) <0 ) {
1018 fprintf( stderr, "Port does not support events\n" );
1019 return;
1020 }
1021
1022 FD_ZERO( &rfds );
1023 while( !interrupted ) {
1024 FD_SET( fd, &rfds );
1025 /* Check every 1 second, or on receive data */
1026 tv_sleep.tv_sec = 1;
1027 tv_sleep.tv_usec = 0;
1028 do {
1029 ret=select( fd + 1, &rfds, NULL, NULL, &tv_sleep );
1030 } while (ret < 0 && errno==EINTR);
1031 if( ret < 0 ) {
1032 fprintf( stderr, "select() Failed\n" );
1033 break;
1034 }
1035
1036 #if defined TIOCSERGETLSR
1037 if( ioctl( fd, TIOCSERGETLSR, &change ) ) {
1038 fprintf( stderr, "TIOCSERGETLSR Failed\n" );
1039 break;
1040 }
1041 else if( change ) {
1042 (*env)->CallVoidMethod( env, jobj, method,
1043 (jint)SPE_OUTPUT_BUFFER_EMPTY, JNI_TRUE );
1044 }
1045 #endif /* TIOCSERGETLSR */
1046 #if defined(TIOCGICOUNT)
1047 /* wait for RNG, DSR, CD or CTS but not DataAvailable
1048 * The drawback here is it never times out so if someone
1049 * reads there will be no chance to try again.
1050 * This may make sense if the program does not want to
1051 * be notified of data available or errors.
1052 * ret=ioctl(fd,TIOCMIWAIT);
1053 */
1054 if( ioctl( fd, TIOCGICOUNT, &sis ) ) {
1055 fprintf( stderr, "TIOCGICOUNT Failed\n" );
1056 break;
1057 }
1058 while( sis.frame != osis.frame ) {
1059 (*env)->CallVoidMethod( env, jobj, method, (jint)SPE_FE, JNI_TRUE );
1060 osis.frame++;
1061 }
1062 while( sis.overrun != osis.overrun ) {
1063 (*env)->CallVoidMethod( env, jobj, method, (jint)SPE_OE, JNI_TRUE );
1064 osis.overrun++;
1065 }
1066 while( sis.parity != osis.parity ) {
1067 (*env)->CallVoidMethod( env, jobj, method, (jint)SPE_PE, JNI_TRUE );
1068 osis.parity++;
1069 }
1070 while( sis.brk != osis.brk ) {
1071 (*env)->CallVoidMethod( env, jobj, method, (jint)SPE_BI, JNI_TRUE );
1072 osis.brk++;
1073 }
1074 osis = sis;
1075 #endif /* TIOCGICOUNT */
1076 if( ioctl( fd, TIOCMGET, &mflags ) ) {
1077 fprintf( stderr, "TIOCMGET Failed\n" );
1078 break;
1079 }
1080 interrupted = (*env)->CallStaticBooleanMethod( env, jthread, interrupt );
1081 /* A Portable implementation */
1082 change = (mflags&TIOCM_CTS) - (omflags&TIOCM_CTS);
1083 if( change ) {
1084 fprintf(stderr, "Sending SPE_CTS\n");
1085 (*env)->CallVoidMethod( env, jobj, method,
1086 (jint)SPE_CTS, JNI_TRUE );
1087 }
1088 change = (mflags&TIOCM_DSR) - (omflags&TIOCM_DSR);
1089 if( change ) {
1090 fprintf(stderr, "Sending SPE_DSR\n");
1091 (*env)->CallVoidMethod( env, jobj, method,
1092 (jint)SPE_DSR, JNI_TRUE );
1093 }
1094 change = (mflags&TIOCM_RNG) - (omflags&TIOCM_RNG);
1095 if( change ) {
1096 fprintf(stderr, "Sending SPE_RI\n");
1097 (*env)->CallVoidMethod( env, jobj, method,
1098 (jint)SPE_RI, JNI_TRUE );
1099 }
1100 change = (mflags&TIOCM_CD) - (omflags&TIOCM_CD);
1101 if( change ) {
1102 fprintf(stderr, "Sending SPE_CD\n");
1103 (*env)->CallVoidMethod( env, jobj, method,
1104 (jint)SPE_CD, JNI_TRUE );
1105 }
1106 omflags = mflags;
1107 if( ioctl( fd, FIONREAD, &change ) ) {
1108 fprintf( stderr, "FIONREAD Failed\n" );
1109 }
1110 else if( change ) {
1111 (*env)->CallVoidMethod( env, jobj, method,
1112 (jint)SPE_DATA_AVAILABLE, JNI_TRUE );
1113 usleep(1000); /* select wont block */
1114 }
1115 }
1116 return;
1117 }
1118
1119 /*----------------------------------------------------------
1120 send_modem_events
1121
1122 accept: int event I2CPortEvent constant
1123 int change Number of times this event happened
1124 int state current state: 0 is false, nonzero is true
1125 perform: Send the necessary events
1126 return: none
1127 exceptions: none
1128 comments: Since the interrupt counters tell us how many times the
1129 state has changed, we can send a I2CPortEvent for each
1130 interrupt (change) that has occured. If we don't do this,
1131 we'll miss a whole bunch of events.
1132 ----------------------------------------------------------*/
1133 void send_modem_events( JNIEnv *env, jobject jobj, jmethodID method,
1134 int event, int change, int state )
1135 {
1136 int i, s;
1137 jboolean flag;
1138 if( state ) s = 1;
1139 else s = 0;
1140
1141 for( i = 0; i < change; i++ ) {
1142 if( ( change + s + i ) % 2 ) flag = JNI_FALSE;
1143 else flag = JNI_TRUE;
1144 (*env)->CallVoidMethod( env, jobj, method, (jint)event, flag );
1145 }
1146 }
1147
1148 /*----------------------------------------------------------
1149 get_java_fd
1150
1151 accept: env (keyhole to java)
1152 jobj (java I2CPort object)
1153 return: the fd field from the java object
1154 exceptions: none
1155 comments:
1156 ----------------------------------------------------------*/
1157 int get_java_var( JNIEnv *env, jobject jobj, char *id, char *type )
1158 {
1159 int result = 0;
1160 jclass jclazz = (*env)->GetObjectClass( env, jobj );
1161 jfieldID jfd = (*env)->GetFieldID( env, jclazz, id, type );
1162 if( !jfd ) {
1163 (*env)->ExceptionDescribe( env );
1164 (*env)->ExceptionClear( env );
1165 return result;
1166 }
1167 result = (int)( (*env)->GetIntField( env, jobj, jfd ) );
1168 /* ct7 & gel * Added DeleteLocalRef */
1169 (*env)->DeleteLocalRef( env, jclazz );
1170 return result;
1171 }
1172
1173 /*----------------------------------------------------------
1174 throw_java_exception
1175
1176 accept: env (keyhole to java)
1177 *exc (exception class name)
1178 *foo (function name)
1179 *msg (error message)
1180 perform: Throw a new java exception
1181 return: none
1182 exceptions: haha!
1183 comments:
1184 ----------------------------------------------------------*/
1185 void throw_java_exception( JNIEnv *env, char *exc, char *foo, char *msg )
1186 {
1187 char buf[ 60 ];
1188 jclass clazz = (*env)->FindClass( env, exc );
1189 if( !clazz ) {
1190 (*env)->ExceptionDescribe( env );
1191 (*env)->ExceptionClear( env );
1192 return;
1193 }
1194 #if defined(_GNU_SOURCE)
1195 snprintf( buf, 60, "%s in %s", msg, foo );
1196 #else
1197 sprintf( buf,"%s in %s", msg, foo );
1198 #endif /* _GNU_SOURCE */
1199 (*env)->ThrowNew( env, clazz, buf );
1200 /* ct7 * Added DeleteLocalRef */
1201 (*env)->DeleteLocalRef( env, clazz );
1202 }
1203
1204 JNIEXPORT jboolean JNICALL Java_gnu_io_RXTXCommDriver_IsDeviceGood(JNIEnv *env,
1205 jobject jobj, jstring tty_name){
1206
1207 jboolean result;
1208 static struct stat mystat;
1209 char teststring[256];
1210 int fd,i;
1211 const char *name = (*env)->GetStringUTFChars(env, tty_name, 0);
1212
1213 #if defined(__linux__)
1214 if(!strcmp(name,"tty0")|| !strcmp(name,"ttyd")||
1215 !strcmp(name,"ttyq")|| !strcmp(name,"ttym")||
1216 !strcmp(name,"ttyf")|| !strcmp(name,"cuaa")
1217 )
1218 {
1219 #ifdef DEBUG
1220 fprintf(stderr,"DEBUG: Ignoring Port %s\*\n",name);
1221 #endif
1222 return(JNI_FALSE);
1223 }
1224 #endif
•1225 #if defined(__FreeBSD_kernel__)
1226 if(!strcmp(name,"tty0")|| !strcmp(name,"ttyd")||
1227 !strcmp(name,"ttyq")|| !strcmp(name,"ttym")||
1228 !strcmp(name,"ttyf")|| !strcmp(name,"ttyS")||
1229 !strcmp(name,"ttyI")|| !strcmp(name,"ttyW")||
1230 !strcmp(name,"ttyC")|| !strcmp(name,"ttyR")
1231 )
1232 {
1233 #ifdef DEBUG
1234 fprintf(stderr,"DEBUG: Ignoring Port %s*\n",name);
1235 #endif
1236 return(JNI_FALSE);
1237 }
1238 #endif
1239 #if defined(__NetBSD__)
1240 if( !strcmp(name,"ttyd")||
1241 !strcmp(name,"ttyq")|| !strcmp(name,"ttym")||
1242 !strcmp(name,"ttyf")|| !strcmp(name,"ttyS")||
1243 !strcmp(name,"ttyI")|| !strcmp(name,"ttyW")||
1244 !strcmp(name,"ttyq")|| !strcmp(name,"ttym")||
1245 !strcmp(name,"ttyf")|| !strcmp(name,"cuaa")||
1246 !strcmp(name,"ttyC")|| !strcmp(name,"ttyR")||
1247 !strcmp(name,"ttyM")
1248 )
1249 {
1250 #ifdef DEBUG
1251 fprintf(stderr,"DEBUG: Ignoring Port %s*\n",name);
1252 #endif
1253 return(JNI_FALSE);
1254 }
1255 #endif
1256 for(i=0;i<64;i++){
1257 sprintf(teststring,"/dev/%s%i",name, i);
1258 stat(teststring,&mystat);
1259 if(S_ISCHR(mystat.st_mode)){
1260 fd=open(teststring,O_RDONLY|O_NONBLOCK);
1261 if (fd>0){
1262 close(fd);
1263 result=JNI_TRUE;
1264 break;
1265 }
1266 result=JNI_FALSE;
1267 }
1268 else result=JNI_FALSE;
1269 }
1270 sprintf(teststring,"/dev/%s",name);
1271 stat(teststring,&mystat);
1272 if(S_ISCHR(mystat.st_mode)){
1273 fd=open(teststring,O_RDONLY|O_NONBLOCK);
1274 if (fd>0){
1275 close(fd);
1276 result=JNI_TRUE;
1277 }
1278 }
1279 (*env)->ReleaseStringUTFChars(env, tty_name, name);
1280 return(result);
1281 }
1282 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setInputBufferSize(JNIEnv *env, jobject jobj, jint size )
1283 {
1284 #ifdef DEBUG
1285 fprintf(stderr,"setInputBufferSize is not implemented\n");
1286 #endif
1287 }
1288 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_getInputBufferSize(JNIEnv *env, jobject jobj)
1289 {
1290 #ifdef DEBUG
1291 fprintf(stderr,"getInputBufferSize is not implemented\n");
1292 #endif
1293 return(1);
1294 }
1295 JNIEXPORT void JNICALL Java_gnu_io_I2CPort_setOutputBufferSize(JNIEnv *env, jobject jobj, jint size )
1296 {
1297 #ifdef DEBUG
1298 fprintf(stderr,"setOutputBufferSize is not implemented\n");
1299 #endif
1300 }
1301 JNIEXPORT jint JNICALL Java_gnu_io_I2CPort_getOutputBufferSize(JNIEnv *env, jobject jobj)
1302 {
1303 #ifdef DEBUG
1304 fprintf(stderr,"getOutputBufferSize is not implemented\n");
1305 #endif
1306 return(1);
1307 }
1308
1309 void dump_termios(char *foo,struct termios *ttyset)
1310 {
1311 int i;
1312
1313 fprintf(stderr,"%s %o\n",foo,ttyset->c_iflag);
1314 fprintf(stderr,"%s %o\n",foo,ttyset->c_lflag);
1315 fprintf(stderr,"%s %o\n",foo,ttyset->c_oflag);
1316 fprintf(stderr,"%s %o\n",foo,ttyset->c_cflag);
1317 for(i=0;i<NCCS;i++)
1318 {
1319 fprintf(stderr,"%s %o ",foo,ttyset->c_cc[i]);
1320 }
1321 fprintf(stderr,"\n");
1322 }