| 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 |
#ifdef __STRICT_ANSI__ |
| 64 |
#undef __STRICT_ANSI__ |
| 65 |
#endif |
| 66 |
#if defined(__MWERKS__) |
| 67 |
#include "Raw.h" |
| 68 |
#else |
| 69 |
#include "config.h" |
| 70 |
#include "gnu_io_Raw.h" |
| 71 |
#endif |
| 72 |
#include <time.h> |
| 73 |
#include <unistd.h> |
| 74 |
#include <stdio.h> |
| 75 |
#include <string.h> |
| 76 |
#include <stdlib.h> |
| 77 |
#include <errno.h> |
| 78 |
#include <sys/ioctl.h> |
| 79 |
#include <sys/param.h> |
| 80 |
#include <sys/utsname.h> |
| 81 |
#ifdef HAVE_TERMIOS_H |
| 82 |
# include <termios.h> |
| 83 |
#endif |
| 84 |
#ifdef HAVE_SYS_SIGNAL_H |
| 85 |
# include <sys/signal.h> |
| 86 |
#endif |
| 87 |
#include <sys/types.h> |
| 88 |
#include <sys/stat.h> |
| 89 |
#include <sys/time.h> |
| 90 |
#ifdef HAVE_SYS_FCNTL_H |
| 91 |
# include <sys/fcntl.h> |
| 92 |
#endif |
| 93 |
#ifdef HAVE_SYS_FILE_H |
| 94 |
# include <sys/file.h> |
| 95 |
#endif |
| 96 |
|
| 97 |
#if defined(__linux__) |
| 98 |
# include <linux/types.h> |
| 99 |
# include <linux/serial.h> |
| 100 |
# include <linux/version.h> |
| 101 |
#endif |
| •102 |
#ifdef HAVE_SYS_IO_H |
| 103 |
# include <sys/io.h> |
| 104 |
#endif |
| 105 |
|
| 106 |
extern int errno; |
| 107 |
#include "I2CImp.h" |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_open( |
| 123 |
JNIEnv *env, |
| 124 |
jobject jobj, |
| 125 |
jint ciAddress |
| 126 |
) |
| 127 |
{ |
| 128 |
if(ioperm(ciAddress, 3, 1)) |
| 129 |
goto fail; |
| 130 |
return (0); |
| 131 |
fail: |
| 132 |
throw_java_exception( env, IO_EXCEPTION, "open", strerror( errno ) ); |
| 133 |
return -1; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_nativeClose( JNIEnv *env, |
| 145 |
jobject jobj ) |
| 146 |
{ |
| 147 |
int ciAddress = get_java_var( env, jobj,"ciAddress","I" ); |
| 148 |
|
| 149 |
if(ioperm(ciAddress, 3, 0)) |
| 150 |
goto fail; |
| 151 |
return(0); |
| 152 |
fail: |
| 153 |
throw_java_exception( env, IO_EXCEPTION, "close", "failed" ); |
| 154 |
return -1; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
JNIEXPORT jint JNICALL Java_Bus_read8 |
| 166 |
(JNIEnv * env, jobject poObj, jint piPort) |
| 167 |
{ |
| 168 |
return (jint) inb((unsigned) piPort); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
JNIEXPORT void JNICALL Java_Bus_write8 |
| 180 |
(JNIEnv * env, jobject poObj, jint piData, jint piPort) |
| 181 |
{ |
| 182 |
outb((unsigned char) piData ,(unsigned) piPort); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
JNIEXPORT jint JNICALL Java_Bus_read16 |
| 194 |
(JNIEnv * env, jobject poObj, jint piPort) |
| 195 |
{ |
| 196 |
return (jint) inw((unsigned) piPort); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
JNIEXPORT void JNICALL Java_Bus_write16 |
| 207 |
(JNIEnv * env, jobject poObj, jint piPort, jint piData) |
| 208 |
{ |
| 209 |
outb((unsigned short) piData ,(unsigned) piPort); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
JNIEXPORT jint JNICALL Java_Bus_read32 |
| 221 |
(JNIEnv * env, jobject poObj, jint piPort) |
| 222 |
{ |
| 223 |
return (jint) inl((unsigned) piPort); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
JNIEXPORT void JNICALL Java_Bus_write32 |
| 237 |
(JNIEnv * env, jobject poObj, jint piPort, jint piData) |
| 238 |
{ |
| 239 |
outl((unsigned) piData ,(unsigned) piPort); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_Initialize( |
| 254 |
JNIEnv *env, |
| 255 |
jclass jclazz |
| 256 |
) |
| 257 |
{ |
| 258 |
#ifndef WIN32 |
| 259 |
struct utsname name; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| •266 |
#if !defined(__FreeBSD_kernel___) |
| 267 |
struct sigaction handler; |
| 268 |
sigaction( SIGIO, NULL, &handler ); |
| 269 |
if( !handler.sa_handler ) signal( SIGIO, SIG_IGN ); |
| •270 |
#endif |
| 271 |
#if defined(__linux__) |
| 272 |
|
| •273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| •284 |
|
| 285 |
#endif |
| 286 |
#endif |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_nativeSetRawPortParams( |
| 299 |
JNIEnv *env, jobject jobj, jint speed, jint dataBits, jint stopBits, |
| 300 |
jint parity ) |
| 301 |
{ |
| 302 |
struct termios ttyset; |
| 303 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 304 |
int cspeed = translate_speed( env, speed ); |
| 305 |
if( !cspeed ) return; |
| 306 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
| 307 |
if( !translate_data_bits( env, (int *)&(ttyset.c_cflag), dataBits ) ) return; |
| 308 |
if( !translate_stop_bits( env, (int *)&(ttyset.c_cflag), stopBits ) ) return; |
| 309 |
if( !translate_parity( env, (int *)&(ttyset.c_cflag), parity ) ) return; |
| •310 |
#ifdef __FreeBSD_kernel__ |
| 311 |
if( cfsetspeed( &ttyset, cspeed ) < 0 ) goto fail; |
| 312 |
#else |
| 313 |
if( cfsetispeed( &ttyset, cspeed ) < 0 ) goto fail; |
| 314 |
if( cfsetospeed( &ttyset, cspeed ) < 0 ) goto fail; |
| 315 |
#endif |
| 316 |
if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail; |
| 317 |
|
| 318 |
return; |
| 319 |
|
| 320 |
fail: |
| 321 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
| 322 |
"nativeSetRawPortParams", strerror( errno ) ); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
int translate_speed( JNIEnv *env, jint speed ) |
| 336 |
{ |
| 337 |
switch( speed ) { |
| 338 |
case 0: return B0; |
| 339 |
case 50: return B50; |
| 340 |
case 75: return B75; |
| 341 |
case 110: return B110; |
| 342 |
case 134: return B134; |
| 343 |
case 150: return B150; |
| 344 |
case 200: return B200; |
| 345 |
case 300: return B300; |
| 346 |
case 600: return B600; |
| 347 |
case 1200: return B1200; |
| 348 |
case 1800: return B1800; |
| 349 |
case 2400: return B2400; |
| 350 |
case 4800: return B4800; |
| 351 |
case 9600: return B9600; |
| 352 |
case 19200: return B19200; |
| 353 |
case 38400: return B38400; |
| 354 |
case 57600: return B57600; |
| 355 |
case 115200: return B115200; |
| 356 |
case 230400: return B230400; |
| 357 |
#ifdef B460800 |
| 358 |
case 460800: return B460800; |
| 359 |
#endif |
| 360 |
} |
| 361 |
|
| 362 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
| 363 |
"translate_speed", "speed" ); |
| 364 |
return 0; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
int translate_data_bits( JNIEnv *env, int *cflag, jint dataBits ) |
| 377 |
{ |
| 378 |
int temp = (*cflag) & ~CSIZE; |
| 379 |
|
| 380 |
switch( dataBits ) { |
| 381 |
case DATABITS_5: |
| 382 |
(*cflag) = temp | CS5; |
| 383 |
return 1; |
| 384 |
case DATABITS_6: |
| 385 |
(*cflag) = temp | CS6; |
| 386 |
return 1; |
| 387 |
case DATABITS_7: |
| 388 |
(*cflag) = temp | CS7; |
| 389 |
return 1; |
| 390 |
case DATABITS_8: |
| 391 |
(*cflag) = temp | CS8; |
| 392 |
return 1; |
| 393 |
} |
| 394 |
|
| 395 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
| 396 |
"translate_data_bits", "data bits" ); |
| 397 |
return 0; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
int translate_stop_bits( JNIEnv *env, int *cflag, jint stopBits ) |
| 412 |
{ |
| 413 |
switch( stopBits ) { |
| 414 |
case STOPBITS_1: |
| 415 |
(*cflag) &= ~CSTOPB; |
| 416 |
return 1; |
| 417 |
case STOPBITS_2: |
| 418 |
(*cflag) |= CSTOPB; |
| 419 |
return 1; |
| 420 |
} |
| 421 |
|
| 422 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
| 423 |
"translate_stop_bits", "stop bits" ); |
| 424 |
return 0; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
int translate_parity( JNIEnv *env, int *cflag, jint parity ) |
| 439 |
{ |
| 440 |
(*cflag) &= ~(PARENB | PARODD); |
| 441 |
switch( parity ) { |
| 442 |
case PARITY_NONE: |
| 443 |
return 1; |
| 444 |
#ifdef CMSPAR |
| 445 |
case PARITY_EVEN: |
| 446 |
(*cflag) |= PARENB; |
| 447 |
return 1; |
| 448 |
case PARITY_ODD: |
| 449 |
(*cflag) |= PARENB | PARODD; |
| 450 |
return 1; |
| 451 |
case PARITY_MARK: |
| 452 |
(*cflag) |= PARENB | PARODD | CMSPAR; |
| 453 |
return 1; |
| 454 |
case PARITY_SPACE: |
| 455 |
(*cflag) |= PARENB | CMSPAR; |
| 456 |
return 1; |
| 457 |
#else |
| 458 |
case PARITY_EVEN: |
| 459 |
(*cflag) |= PARENB; |
| 460 |
return 1; |
| 461 |
case PARITY_ODD: |
| 462 |
(*cflag) |= PARENB | PARODD; |
| 463 |
return 1; |
| 464 |
#endif |
| 465 |
} |
| 466 |
|
| 467 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
| 468 |
"translate_parity", "parity" ); |
| 469 |
return 0; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_writeByte( JNIEnv *env, |
| 482 |
jobject jobj, jint ji ) |
| 483 |
{ |
| 484 |
unsigned char byte = (unsigned char)ji; |
| 485 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 486 |
int result; |
| 487 |
|
| 488 |
do { |
| 489 |
result=write (fd, &byte, sizeof(unsigned char)); |
| 490 |
} while (result < 0 && errno==EINTR); |
| 491 |
if(result >= 0) |
| 492 |
return; |
| 493 |
throw_java_exception( env, IO_EXCEPTION, "writeByte", |
| 494 |
strerror( errno ) ); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_writeArray( JNIEnv *env, |
| 509 |
jobject jobj, jbyteArray jbarray, jint offset, jint count ) |
| 510 |
{ |
| 511 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 512 |
int result=0,total=0,i; |
| 513 |
|
| 514 |
unsigned char *bytes = (unsigned char *)malloc( count ); |
| 515 |
|
| 516 |
jbyte *body = (*env)->GetByteArrayElements( env, jbarray, 0 ); |
| 517 |
for( i = 0; i < count; i++ ) bytes[ i ] = body[ i + offset ]; |
| 518 |
(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 ); |
| 519 |
do { |
| 520 |
result=write (fd, bytes + total, count - total); |
| 521 |
if(result >0){ |
| 522 |
total += result; |
| 523 |
} |
| 524 |
} while ((total<count)||(result < 0 && errno==EINTR)); |
| 525 |
free( bytes ); |
| 526 |
if( result < 0 ) throw_java_exception( env, IO_EXCEPTION, |
| 527 |
"writeArray", strerror( errno ) ); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_drain( JNIEnv *env, |
| 545 |
jobject jobj ) |
| 546 |
{ |
| 547 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 548 |
int result, count=0; |
| 549 |
|
| 550 |
do { |
| 551 |
result=tcdrain (fd); |
| 552 |
count++; |
| 553 |
} while (result && errno==EINTR && count <5); |
| 554 |
|
| 555 |
if( result ) throw_java_exception( env, IO_EXCEPTION, "drain", |
| 556 |
strerror( errno ) ); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_sendBreak( JNIEnv *env, |
| 568 |
jobject jobj, jint duration ) |
| 569 |
{ |
| 570 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 571 |
tcsendbreak( fd, (int)( duration / 250 ) ); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_NativegetReceiveTimeout( |
| 584 |
JNIEnv *env, |
| 585 |
jobject jobj |
| 586 |
) |
| 587 |
{ |
| 588 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 589 |
struct termios ttyset; |
| 590 |
|
| 591 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
| 592 |
return(ttyset.c_cc[ VTIME ] * 100); |
| 593 |
fail: |
| 594 |
throw_java_exception( env, IO_EXCEPTION, "getReceiveTimeout", strerror( errno ) ); |
| 595 |
return -1; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_NativeisReceiveTimeoutEnabled( |
| 607 |
JNIEnv *env, |
| 608 |
jobject jobj |
| 609 |
) |
| 610 |
{ |
| 611 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 612 |
struct termios ttyset; |
| 613 |
|
| 614 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
| 615 |
return(ttyset.c_cc[ VTIME ] > 0 ? JNI_TRUE:JNI_FALSE); |
| 616 |
fail: |
| 617 |
throw_java_exception( env, IO_EXCEPTION, "isReceiveTimeoutEnabled", strerror( errno ) ); |
| 618 |
return JNI_FALSE; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isDSR( 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_DSR ) return JNI_TRUE; |
| 639 |
else return JNI_FALSE; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isCD( JNIEnv *env, |
| 657 |
jobject jobj ) |
| 658 |
{ |
| 659 |
unsigned int result = 0; |
| 660 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 661 |
|
| 662 |
ioctl( fd, TIOCMGET, &result ); |
| 663 |
if( result & TIOCM_CD ) return JNI_TRUE; |
| 664 |
else return JNI_FALSE; |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isCTS( JNIEnv *env, |
| 678 |
jobject jobj ) |
| 679 |
{ |
| 680 |
unsigned int result = 0; |
| 681 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 682 |
|
| 683 |
ioctl( fd, TIOCMGET, &result ); |
| 684 |
if( result & TIOCM_CTS ) return JNI_TRUE; |
| 685 |
else return JNI_FALSE; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isRI( JNIEnv *env, |
| 699 |
jobject jobj ) |
| 700 |
{ |
| 701 |
unsigned int result = 0; |
| 702 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 703 |
|
| 704 |
ioctl( fd, TIOCMGET, &result ); |
| 705 |
if( result & TIOCM_RI ) return JNI_TRUE; |
| 706 |
else return JNI_FALSE; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isRTS( JNIEnv *env, |
| 720 |
jobject jobj ) |
| 721 |
{ |
| 722 |
unsigned int result = 0; |
| 723 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 724 |
|
| 725 |
ioctl( fd, TIOCMGET, &result ); |
| 726 |
if( result & TIOCM_RTS ) return JNI_TRUE; |
| 727 |
else return JNI_FALSE; |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setRTS( JNIEnv *env, |
| 742 |
jobject jobj, jboolean state ) |
| 743 |
{ |
| 744 |
unsigned int result = 0; |
| 745 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 746 |
|
| 747 |
ioctl( fd, TIOCMGET, &result ); |
| 748 |
if( state == JNI_TRUE ) result |= TIOCM_RTS; |
| 749 |
else result &= ~TIOCM_RTS; |
| 750 |
ioctl( fd, TIOCMSET, &result ); |
| 751 |
return; |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setDSR( JNIEnv *env, |
| 766 |
jobject jobj, jboolean state ) |
| 767 |
{ |
| 768 |
unsigned int result = 0; |
| 769 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 770 |
|
| 771 |
ioctl( fd, TIOCMGET, &result ); |
| 772 |
if( state == JNI_TRUE ) result |= TIOCM_DSR; |
| 773 |
else result &= ~TIOCM_DSR; |
| 774 |
ioctl( fd, TIOCMSET, &result ); |
| 775 |
return; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RawPort_isDTR( JNIEnv *env, |
| 789 |
jobject jobj ) |
| 790 |
{ |
| 791 |
unsigned int result = 0; |
| 792 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 793 |
|
| 794 |
ioctl( fd, TIOCMGET, &result ); |
| 795 |
if( result & TIOCM_DTR ) return JNI_TRUE; |
| 796 |
else return JNI_FALSE; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setDTR( JNIEnv *env, |
| 810 |
jobject jobj, jboolean state ) |
| 811 |
{ |
| 812 |
unsigned int result = 0; |
| 813 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 814 |
|
| 815 |
ioctl( fd, TIOCMGET, &result ); |
| 816 |
if( state == JNI_TRUE ) result |= TIOCM_DTR; |
| 817 |
else result &= ~TIOCM_DTR; |
| 818 |
ioctl( fd, TIOCMSET, &result ); |
| 819 |
return; |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
int read_byte_array( int fd, unsigned char *buffer, int length, int timeout ) |
| 841 |
{ |
| 842 |
int ret, left, bytes = 0; |
| 843 |
fd_set rfds; |
| 844 |
struct timeval sleep; |
| 845 |
struct timeval *psleep=&sleep; |
| 846 |
|
| 847 |
left = length; |
| 848 |
FD_ZERO( &rfds ); |
| 849 |
FD_SET( fd, &rfds ); |
| 850 |
if( timeout != 0 ) |
| 851 |
{ |
| 852 |
sleep.tv_sec = timeout / 1000; |
| 853 |
sleep.tv_usec = 1000 * ( timeout % 1000 ); |
| 854 |
} |
| 855 |
while( bytes < length ) |
| 856 |
{ |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
do { |
| 862 |
if( timeout == 0 ) psleep = NULL; |
| 863 |
ret=select( fd + 1, &rfds, NULL, NULL, psleep ); |
| 864 |
} while (ret < 0 && errno==EINTR); |
| 865 |
if( ret == 0 ) break; |
| 866 |
if( ret < 0 ) return -1; |
| 867 |
ret = read( fd, buffer + bytes, left ); |
| 868 |
if( ret == 0 ) break; |
| 869 |
if( ret < 0 ) return -1; |
| 870 |
bytes += ret; |
| 871 |
left -= ret; |
| 872 |
} |
| 873 |
return bytes; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_NativeEnableReceiveTimeoutThreshold(JNIEnv *env, jobject jobj, jint vtime, jint threshold, jint buffer) |
| 887 |
{ |
| 888 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 889 |
struct termios ttyset; |
| 890 |
|
| 891 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
| 892 |
ttyset.c_cc[ VMIN ] = threshold; |
| 893 |
ttyset.c_cc[ VTIME ] = vtime/100; |
| 894 |
if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail; |
| 895 |
|
| 896 |
return; |
| 897 |
fail: |
| 898 |
throw_java_exception( env, IO_EXCEPTION, "TimeoutThreshold", strerror( errno ) ); |
| 899 |
return; |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_readByte( JNIEnv *env, |
| 911 |
jobject jobj ) |
| 912 |
{ |
| 913 |
int bytes; |
| 914 |
unsigned char buffer[ 1 ]; |
| 915 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 916 |
int timeout = get_java_var( env, jobj, "timeout", "I" ); |
| 917 |
|
| 918 |
bytes = read_byte_array( fd, buffer, 1, timeout ); |
| 919 |
if( bytes < 0 ) { |
| 920 |
throw_java_exception( env, IO_EXCEPTION, "readByte", |
| 921 |
strerror( errno ) ); |
| 922 |
return -1; |
| 923 |
} |
| 924 |
return (bytes ? (jint)buffer[ 0 ] : -1); |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_readArray( JNIEnv *env, |
| 940 |
jobject jobj, jbyteArray jbarray, jint offset, jint length ) |
| 941 |
{ |
| 942 |
int bytes; |
| 943 |
jbyte *body; |
| 944 |
unsigned char *buffer; |
| 945 |
int fd = get_java_var( env, jobj, "fd", "I" ); |
| 946 |
int timeout = get_java_var( env, jobj, "timeout", "I" ); |
| 947 |
|
| 948 |
if( (size_t) length > SSIZE_MAX || (size_t) length < 0 ) { |
| 949 |
throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS, |
| 950 |
"readArray", "Invalid length" ); |
| 951 |
return -1; |
| 952 |
} |
| 953 |
|
| 954 |
buffer = (unsigned char *)malloc( sizeof( unsigned char ) * length ); |
| 955 |
if( buffer == 0 ) { |
| 956 |
throw_java_exception( env, OUT_OF_MEMORY, "readArray", |
| 957 |
"Unable to allocate buffer" ); |
| 958 |
return -1; |
| 959 |
} |
| 960 |
|
| 961 |
bytes = read_byte_array( fd, buffer, length, timeout ); |
| 962 |
if( bytes < 0 ) { |
| 963 |
free( buffer ); |
| 964 |
throw_java_exception( env, IO_EXCEPTION, "readArray", |
| 965 |
strerror( errno ) ); |
| 966 |
return -1; |
| 967 |
} |
| 968 |
body = (*env)->GetByteArrayElements( env, jbarray, 0 ); |
| 969 |
memcpy(body + offset, buffer, bytes); |
| 970 |
(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 ); |
| 971 |
free( buffer ); |
| 972 |
return (bytes ? bytes : -1); |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_nativeavailable( JNIEnv *env, |
| 985 |
jobject jobj ) |
| 986 |
{ |
| 987 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 988 |
int result; |
| 989 |
|
| 990 |
if( ioctl( fd, FIONREAD, &result ) ) |
| 991 |
{ |
| 992 |
throw_java_exception( env, IO_EXCEPTION, "nativeavailable", strerror( errno ) ); |
| 993 |
return -1; |
| 994 |
} |
| 995 |
else return (jint)result; |
| 996 |
|
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setflowcontrol( JNIEnv *env, |
| 1015 |
jobject jobj, jint flowmode ) |
| 1016 |
{ |
| 1017 |
struct termios ttyset; |
| 1018 |
int fd = get_java_var( env, jobj,"fd","I" ); |
| 1019 |
|
| 1020 |
if( tcgetattr( fd, &ttyset ) ) goto fail; |
| 1021 |
|
| 1022 |
if ( flowmode & ( FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT ) ) |
| 1023 |
ttyset.c_cflag |= HARDWARE_FLOW_CONTROL; |
| 1024 |
else ttyset.c_cflag &= ~HARDWARE_FLOW_CONTROL; |
| 1025 |
|
| 1026 |
ttyset.c_iflag &= ~IXANY; |
| 1027 |
|
| 1028 |
if ( flowmode & FLOWCONTROL_XONXOFF_IN ) |
| 1029 |
ttyset.c_iflag |= IXOFF; |
| 1030 |
else ttyset.c_iflag &= ~IXOFF; |
| 1031 |
|
| 1032 |
if ( flowmode & FLOWCONTROL_XONXOFF_OUT ) |
| 1033 |
ttyset.c_iflag |= IXON; |
| 1034 |
else ttyset.c_iflag &= ~IXON; |
| 1035 |
|
| 1036 |
if( tcsetattr( fd, TCSANOW, &ttyset ) ) goto fail; |
| 1037 |
return; |
| 1038 |
fail: |
| 1039 |
throw_java_exception( env, IO_EXCEPTION, "setHWFC", |
| 1040 |
strerror( errno ) ); |
| 1041 |
return; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_eventLoop( JNIEnv *env, |
| 1054 |
jobject jobj ) |
| 1055 |
{ |
| 1056 |
int fd, ret, change; |
| 1057 |
fd_set rfds; |
| 1058 |
struct timeval tv_sleep; |
| 1059 |
unsigned int mflags; |
| 1060 |
#if defined(TIOCGICOUNT) |
| 1061 |
struct serial_icounter_struct sis, osis; |
| 1062 |
#endif |
| 1063 |
unsigned int omflags; |
| 1064 |
|
| 1065 |
jmethodID method, interrupt; |
| 1066 |
jboolean interrupted = 0; |
| 1067 |
jclass jclazz, jthread; |
| 1068 |
jclazz = (*env)->GetObjectClass( env, jobj ); |
| 1069 |
fd = get_java_var(env, jobj, "fd", "I"); |
| 1070 |
method = (*env)->GetMethodID( env, jclazz, "sendEvent", "(IZ)V" ); |
| 1071 |
jthread = (*env)->FindClass( env, "java/lang/Thread" ); |
| 1072 |
interrupt = (*env)->GetStaticMethodID( env, jthread, "interrupted", "()Z" ); |
| 1073 |
|
| 1074 |
|
| 1075 |
#if defined(TIOCGICOUNT) |
| 1076 |
if( ioctl( fd, TIOCGICOUNT, &osis ) < 0 ) { |
| 1077 |
fprintf( stderr, "Port does not support TIOCGICOUNT events\n" ); |
| 1078 |
return; |
| 1079 |
} |
| 1080 |
#else |
| 1081 |
fprintf( stderr, "Port does not support all Hardware events\n" ); |
| 1082 |
#endif |
| 1083 |
|
| 1084 |
if( ioctl( fd, TIOCMGET, &omflags) <0 ) { |
| 1085 |
fprintf( stderr, "Port does not support events\n" ); |
| 1086 |
return; |
| 1087 |
} |
| 1088 |
|
| 1089 |
FD_ZERO( &rfds ); |
| 1090 |
while( !interrupted ) { |
| 1091 |
FD_SET( fd, &rfds ); |
| 1092 |
|
| 1093 |
tv_sleep.tv_sec = 1; |
| 1094 |
tv_sleep.tv_usec = 0; |
| 1095 |
do { |
| 1096 |
ret=select( fd + 1, &rfds, NULL, NULL, &tv_sleep ); |
| 1097 |
} while (ret < 0 && errno==EINTR); |
| 1098 |
if( ret < 0 ) { |
| 1099 |
fprintf( stderr, "select() Failed\n" ); |
| 1100 |
break; |
| 1101 |
} |
| 1102 |
|
| 1103 |
#if defined TIOCSERGETLSR |
| 1104 |
if( ioctl( fd, TIOCSERGETLSR, &change ) ) { |
| 1105 |
fprintf( stderr, "TIOCSERGETLSR Failed\n" ); |
| 1106 |
break; |
| 1107 |
} |
| 1108 |
else if( change ) { |
| 1109 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1110 |
(jint)SPE_OUTPUT_BUFFER_EMPTY, JNI_TRUE ); |
| 1111 |
} |
| 1112 |
#endif |
| 1113 |
#if defined(TIOCGICOUNT) |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
if( ioctl( fd, TIOCGICOUNT, &sis ) ) { |
| 1122 |
fprintf( stderr, "TIOCGICOUNT Failed\n" ); |
| 1123 |
break; |
| 1124 |
} |
| 1125 |
while( sis.frame != osis.frame ) { |
| 1126 |
(*env)->CallVoidMethod( env, jobj, method, (jint)SPE_FE, JNI_TRUE ); |
| 1127 |
osis.frame++; |
| 1128 |
} |
| 1129 |
while( sis.overrun != osis.overrun ) { |
| 1130 |
(*env)->CallVoidMethod( env, jobj, method, (jint)SPE_OE, JNI_TRUE ); |
| 1131 |
osis.overrun++; |
| 1132 |
} |
| 1133 |
while( sis.parity != osis.parity ) { |
| 1134 |
(*env)->CallVoidMethod( env, jobj, method, (jint)SPE_PE, JNI_TRUE ); |
| 1135 |
osis.parity++; |
| 1136 |
} |
| 1137 |
while( sis.brk != osis.brk ) { |
| 1138 |
(*env)->CallVoidMethod( env, jobj, method, (jint)SPE_BI, JNI_TRUE ); |
| 1139 |
osis.brk++; |
| 1140 |
} |
| 1141 |
osis = sis; |
| 1142 |
#endif |
| 1143 |
if( ioctl( fd, TIOCMGET, &mflags ) ) { |
| 1144 |
fprintf( stderr, "TIOCMGET Failed\n" ); |
| 1145 |
break; |
| 1146 |
} |
| 1147 |
interrupted = (*env)->CallStaticBooleanMethod( env, jthread, interrupt ); |
| 1148 |
|
| 1149 |
change = (mflags&TIOCM_CTS) - (omflags&TIOCM_CTS); |
| 1150 |
if( change ) { |
| 1151 |
fprintf(stderr, "Sending SPE_CTS\n"); |
| 1152 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1153 |
(jint)SPE_CTS, JNI_TRUE ); |
| 1154 |
} |
| 1155 |
change = (mflags&TIOCM_DSR) - (omflags&TIOCM_DSR); |
| 1156 |
if( change ) { |
| 1157 |
fprintf(stderr, "Sending SPE_DSR\n"); |
| 1158 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1159 |
(jint)SPE_DSR, JNI_TRUE ); |
| 1160 |
} |
| 1161 |
change = (mflags&TIOCM_RNG) - (omflags&TIOCM_RNG); |
| 1162 |
if( change ) { |
| 1163 |
fprintf(stderr, "Sending SPE_RI\n"); |
| 1164 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1165 |
(jint)SPE_RI, JNI_TRUE ); |
| 1166 |
} |
| 1167 |
change = (mflags&TIOCM_CD) - (omflags&TIOCM_CD); |
| 1168 |
if( change ) { |
| 1169 |
fprintf(stderr, "Sending SPE_CD\n"); |
| 1170 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1171 |
(jint)SPE_CD, JNI_TRUE ); |
| 1172 |
} |
| 1173 |
omflags = mflags; |
| 1174 |
if( ioctl( fd, FIONREAD, &change ) ) { |
| 1175 |
fprintf( stderr, "FIONREAD Failed\n" ); |
| 1176 |
} |
| 1177 |
else if( change ) { |
| 1178 |
(*env)->CallVoidMethod( env, jobj, method, |
| 1179 |
(jint)SPE_DATA_AVAILABLE, JNI_TRUE ); |
| 1180 |
usleep(1000); |
| 1181 |
} |
| 1182 |
} |
| 1183 |
return; |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
void send_modem_events( JNIEnv *env, jobject jobj, jmethodID method, |
| 1201 |
int event, int change, int state ) |
| 1202 |
{ |
| 1203 |
int i, s; |
| 1204 |
jboolean flag; |
| 1205 |
if( state ) s = 1; |
| 1206 |
else s = 0; |
| 1207 |
|
| 1208 |
for( i = 0; i < change; i++ ) { |
| 1209 |
if( ( change + s + i ) % 2 ) flag = JNI_FALSE; |
| 1210 |
else flag = JNI_TRUE; |
| 1211 |
(*env)->CallVoidMethod( env, jobj, method, (jint)event, flag ); |
| 1212 |
} |
| 1213 |
} |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
int get_java_var( JNIEnv *env, jobject jobj, char *id, char *type ) |
| 1225 |
{ |
| 1226 |
int result = 0; |
| 1227 |
jclass jclazz = (*env)->GetObjectClass( env, jobj ); |
| 1228 |
jfieldID jfd = (*env)->GetFieldID( env, jclazz, id, type ); |
| 1229 |
if( !jfd ) { |
| 1230 |
(*env)->ExceptionDescribe( env ); |
| 1231 |
(*env)->ExceptionClear( env ); |
| 1232 |
return result; |
| 1233 |
} |
| 1234 |
result = (int)( (*env)->GetIntField( env, jobj, jfd ) ); |
| 1235 |
|
| 1236 |
(*env)->DeleteLocalRef( env, jclazz ); |
| 1237 |
return result; |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
void throw_java_exception( JNIEnv *env, char *exc, char *foo, char *msg ) |
| 1253 |
{ |
| 1254 |
char buf[ 60 ]; |
| 1255 |
jclass clazz = (*env)->FindClass( env, exc ); |
| 1256 |
if( !clazz ) { |
| 1257 |
(*env)->ExceptionDescribe( env ); |
| 1258 |
(*env)->ExceptionClear( env ); |
| 1259 |
return; |
| 1260 |
} |
| 1261 |
#if defined(_GNU_SOURCE) |
| 1262 |
snprintf( buf, 60, "%s in %s", msg, foo ); |
| 1263 |
#else |
| 1264 |
sprintf( buf,"%s in %s", msg, foo ); |
| 1265 |
#endif |
| 1266 |
(*env)->ThrowNew( env, clazz, buf ); |
| 1267 |
|
| 1268 |
(*env)->DeleteLocalRef( env, clazz ); |
| 1269 |
} |
| 1270 |
|
| 1271 |
JNIEXPORT jboolean JNICALL Java_gnu_io_RXTXCommDriver_IsDeviceGood(JNIEnv *env, |
| 1272 |
jobject jobj, jstring tty_name){ |
| 1273 |
|
| 1274 |
jboolean result; |
| 1275 |
static struct stat mystat; |
| 1276 |
char teststring[256]; |
| 1277 |
int fd,i; |
| 1278 |
const char *name = (*env)->GetStringUTFChars(env, tty_name, 0); |
| 1279 |
|
| 1280 |
#if defined(__linux__) |
| 1281 |
if(!strcmp(name,"tty0")|| !strcmp(name,"ttyd")|| |
| 1282 |
!strcmp(name,"ttyq")|| !strcmp(name,"ttym")|| |
| 1283 |
!strcmp(name,"ttyf")|| !strcmp(name,"cuaa") |
| 1284 |
) |
| 1285 |
{ |
| 1286 |
#ifdef DEBUG |
| 1287 |
fprintf(stderr,"DEBUG: Ignoring Port %s\*\n",name); |
| 1288 |
#endif |
| 1289 |
return(JNI_FALSE); |
| 1290 |
} |
| 1291 |
#endif |
| •1292 |
#if defined(__FreeBSD_kernel__) |
| 1293 |
if(!strcmp(name,"tty0")|| !strcmp(name,"ttyd")|| |
| 1294 |
!strcmp(name,"ttyq")|| !strcmp(name,"ttym")|| |
| 1295 |
!strcmp(name,"ttyf")|| !strcmp(name,"ttyS")|| |
| 1296 |
!strcmp(name,"ttyI")|| !strcmp(name,"ttyW")|| |
| 1297 |
!strcmp(name,"ttyC")|| !strcmp(name,"ttyR") |
| 1298 |
) |
| 1299 |
{ |
| 1300 |
#ifdef DEBUG |
| 1301 |
fprintf(stderr,"DEBUG: Ignoring Port %s*\n",name); |
| 1302 |
#endif |
| 1303 |
return(JNI_FALSE); |
| 1304 |
} |
| 1305 |
#endif |
| 1306 |
#if defined(__NetBSD__) |
| 1307 |
if( !strcmp(name,"ttyd")|| |
| 1308 |
!strcmp(name,"ttyq")|| !strcmp(name,"ttym")|| |
| 1309 |
!strcmp(name,"ttyf")|| !strcmp(name,"ttyS")|| |
| 1310 |
!strcmp(name,"ttyI")|| !strcmp(name,"ttyW")|| |
| 1311 |
!strcmp(name,"ttyq")|| !strcmp(name,"ttym")|| |
| 1312 |
!strcmp(name,"ttyf")|| !strcmp(name,"cuaa")|| |
| 1313 |
!strcmp(name,"ttyC")|| !strcmp(name,"ttyR")|| |
| 1314 |
!strcmp(name,"ttyM") |
| 1315 |
) |
| 1316 |
{ |
| 1317 |
#ifdef DEBUG |
| 1318 |
fprintf(stderr,"DEBUG: Ignoring Port %s*\n",name); |
| 1319 |
#endif |
| 1320 |
return(JNI_FALSE); |
| 1321 |
} |
| 1322 |
#endif |
| 1323 |
for(i=0;i<64;i++){ |
| 1324 |
sprintf(teststring,"/dev/%s%i",name, i); |
| 1325 |
stat(teststring,&mystat); |
| 1326 |
if(S_ISCHR(mystat.st_mode)){ |
| 1327 |
fd=open(teststring,O_RDONLY|O_NONBLOCK); |
| 1328 |
if (fd>0){ |
| 1329 |
close(fd); |
| 1330 |
result=JNI_TRUE; |
| 1331 |
break; |
| 1332 |
} |
| 1333 |
result=JNI_FALSE; |
| 1334 |
} |
| 1335 |
else result=JNI_FALSE; |
| 1336 |
} |
| 1337 |
sprintf(teststring,"/dev/%s",name); |
| 1338 |
stat(teststring,&mystat); |
| 1339 |
if(S_ISCHR(mystat.st_mode)){ |
| 1340 |
fd=open(teststring,O_RDONLY|O_NONBLOCK); |
| 1341 |
if (fd>0){ |
| 1342 |
close(fd); |
| 1343 |
result=JNI_TRUE; |
| 1344 |
} |
| 1345 |
} |
| 1346 |
(*env)->ReleaseStringUTFChars(env, tty_name, name); |
| 1347 |
return(result); |
| 1348 |
} |
| 1349 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setInputBufferSize(JNIEnv *env, jobject jobj, jint size ) |
| 1350 |
{ |
| 1351 |
#ifdef DEBUG |
| 1352 |
fprintf(stderr,"setInputBufferSize is not implemented\n"); |
| 1353 |
#endif |
| 1354 |
} |
| 1355 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_getInputBufferSize(JNIEnv *env, jobject jobj) |
| 1356 |
{ |
| 1357 |
#ifdef DEBUG |
| 1358 |
fprintf(stderr,"getInputBufferSize is not implemented\n"); |
| 1359 |
#endif |
| 1360 |
return(1); |
| 1361 |
} |
| 1362 |
JNIEXPORT void JNICALL Java_gnu_io_RawPort_setOutputBufferSize(JNIEnv *env, jobject jobj, jint size ) |
| 1363 |
{ |
| 1364 |
#ifdef DEBUG |
| 1365 |
fprintf(stderr,"setOutputBufferSize is not implemented\n"); |
| 1366 |
#endif |
| 1367 |
} |
| 1368 |
JNIEXPORT jint JNICALL Java_gnu_io_RawPort_getOutputBufferSize(JNIEnv *env, jobject jobj) |
| 1369 |
{ |
| 1370 |
#ifdef DEBUG |
| 1371 |
fprintf(stderr,"getOutputBufferSize is not implemented\n"); |
| 1372 |
#endif |
| 1373 |
return(1); |
| 1374 |
} |
| 1375 |
|
| 1376 |
void dump_termios(char *foo,struct termios *ttyset) |
| 1377 |
{ |
| 1378 |
int i; |
| 1379 |
|
| 1380 |
fprintf(stderr,"%s %o\n",foo,ttyset->c_iflag); |
| 1381 |
fprintf(stderr,"%s %o\n",foo,ttyset->c_lflag); |
| 1382 |
fprintf(stderr,"%s %o\n",foo,ttyset->c_oflag); |
| 1383 |
fprintf(stderr,"%s %o\n",foo,ttyset->c_cflag); |
| 1384 |
for(i=0;i<NCCS;i++) |
| 1385 |
{ |
| 1386 |
fprintf(stderr,"%s %o ",foo,ttyset->c_cc[i]); |
| 1387 |
} |
| 1388 |
fprintf(stderr,"\n"); |
| 1389 |
} |