void simuart_start(void) { pthread_t tid; /* This thread runs in the host domain */ /* Perform the NuttX domain initialization */ simuart_initialize(); /* Put stdin into raw mode */ setrawmode(); /* Start the simulated UART thread -- all default settings; no error * checking. */ (void)pthread_create(&tid, NULL, simuart_thread, NULL); }
int ipipe_main( int argc, char ** argv ) { int fd, ch; char * input_file = NULL; char * output_file = NULL; extern int optind; extern char * optarg; srandom(getpid() * time(NULL)); signal( SIGTTIN, SIG_IGN ); options = 0; while (( ch = getopt( argc, argv, "qfsndvepl:i:o:" )) != -1 ) { switch ( ch ) { case 'f': SET(OPT_FLOOD); break; case 's': SET(OPT_STAT); break; case 'v': SET(OPT_VERBOSE); break; case 'e': SET(OPT_ECHO); break; case 'q': SET(OPT_RAWQ); break; case 'n': SET(OPT_NOSTDIN); break; case 'd': SET(OPT_DELNULS); break; case 'p': SET(OPT_PINGACK); break; case 'i': input_file = optarg; break; case 'o': output_file = optarg; break; default: usage(); } } argc -= optind; argv += optind; switch ( argc ) { case 1: fd = do_connect( NULL, atoi( argv[0] )); break; case 3: /* redirect port to a pty; same as case 2, except that local file descriptors 0 and 1 are redefined. */ fd = open( argv[2], O_RDWR ); if ( fd < 0 ) { fprintf( stderr, "error %d opening pty\n", errno ); return -1; } dup2( fd, 0 ); dup2( fd, 1 ); setrawmode( fd ); /* fall through */ case 2: if ( ISSET(OPT_RAWQ) ) { setrawmode( 0 ); } fd = do_connect( argv[0], atoi( argv[1] )); break; default: usage(); } #ifndef O_BINARY #define O_BINARY 0 #endif if ( input_file ) { int fd2 = open( input_file, O_RDONLY | O_BINARY ); if ( fd2 < 0 ) { fprintf( stderr, "error %d opening input file\n", errno ); return -1; } dup2( fd2, 0 ); close( fd2 ); } if ( output_file ) { int fd2 = open( output_file, O_WRONLY | O_CREAT | O_BINARY, 0600 ); if ( fd2 < 0 ) { fprintf( stderr, "error %d opening output file\n", errno ); return -1; } dup2( fd2, 1 ); close( fd2 ); } read_write( fd ); return 0; }