home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c / qnxio.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  112 lines

  1. #include <io.h>
  2. #include <dev.h>
  3. #include <task.h>
  4. #include <stdio.h>
  5.  
  6. #ifdef quantum
  7. #define MODEM_PORT 0x3fb
  8. #define DELAY 4
  9. #include <timer.h>
  10. #endif
  11.  
  12. #define SUCCESS    0
  13.  
  14. extern int turn,speed;
  15. extern char *ttyname;
  16.  
  17. FILE *
  18. ttopen(tn, mode)
  19. char *tn, *mode;
  20. {
  21.     FILE *fp;
  22.  
  23.     if ( !(strcmp(tn,"$con")) && !(strcmp(mode, "r")) ) return(stdin);
  24.     if ( !(strcmp(tn,"$con")) && !(strcmp(mode, "w")) ) return(stdout);
  25.     if ((fp = fopen(tn, mode)) == NULL)
  26.     {
  27.     printmsg("Cannot open %s with mode %s",tn, mode);
  28.     exit(1);
  29.     }
  30.     return(fp);
  31. }
  32.  
  33.  
  34. ttbin(fp,old)
  35. int fp;
  36. unsigned *old;
  37. {
  38.     unsigned new;
  39.     char baudcmd[80], buf[10];
  40.     
  41.     *old = get_option(fp);        /* Save current mode for later restoration */
  42.  
  43.     new =  get_option(fp);        /* set tty to "RAW" mode */ 
  44.  
  45.     new &= ~ECHO;               /* turn off automatic echoing */
  46.     new &= ~EDIT;               /* turn off line editing of input */
  47.     new &= ~EDEL;               /* don't expand DEL to <BS><SP><BS> */
  48.     new &= ~MAPCR;              /* don't expand CR to record separator */
  49.     if (!turn) new |= XON_XOFF; /* use xon/xoff if no handshaking */
  50.     
  51.     set_option(fp, new);        /* finally set the option */
  52.  
  53.     /*
  54.      * set the baud rate by spawning "stty"
  55.      */
  56.     if (speed)
  57.     {
  58.         strcpy(baudcmd, "stty baud=");
  59.         sprintf(buf, "%d >", speed);
  60.         strcat(baudcmd, buf);
  61.         strcat(baudcmd, ttyname);
  62.  
  63.         if (shell(baudcmd) != SUCCESS)
  64.         {
  65.             printmsg("Unable to set the %s's baud rate to %d", ttyname, speed); 
  66.             exit(1);
  67.         }
  68.     }
  69. }
  70.  
  71. ttres(fp,old)
  72. int fp;
  73. unsigned *old;
  74. {
  75.     sleep(1);                    /* wait before releasing the line */
  76.     set_option(fp, *old);
  77. }
  78.  
  79. /*
  80.  *    C O M B R E A K - send a break to the comm line
  81.  */
  82.  
  83. combreak(fp)
  84. FILE *fp;
  85. {
  86.     unsigned admin;
  87.     char buf[3];
  88.  
  89. /*
  90.  *    Send break request to DEV_ADMIN for version 1.1x
  91.  *  otherwise send to the administrator that owns the task
  92.  */
  93.  
  94.     admin = (((unsigned)task_info(0, 6)) < 120) ? DEV_ADMIN : fp->_admin_tid;
  95.  
  96.     buf.mtype = STTY_MESSAGE;
  97.     buf.stty_devno = fp->_dev_no;
  98.     buf.stty_type = STTY_SEND_BREAK;
  99.     send(admin, &buf, &buf, 3);
  100. }
  101.  
  102. /************** comment out **********************************************    
  103.     mask = io_in(MODEM_PORT);
  104.     io_out(MODEM_PORT, mask | 0x040);
  105.  
  106.     set_timer(TIMER_WAKEUP, RELATIVE, DELAY);
  107.  
  108.     io_out(MODEM_PORT, mask);
  109.  
  110. }
  111. ************ end comment out *********************************************/
  112.