home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / researchmachines.zip / rmlsau.c < prev    next >
Text File  |  1985-07-11  |  5KB  |  217 lines

  1.  
  2. /***********************************************************************/
  3.  
  4. /* File KSAUX.C - S4 Drivers for Nimbus Piconet; interface from
  5.     Kermit calls to Mike Maloney standard interface for RS422 mode.
  6.             Chris Kennington    1st July 1985    */
  7.  
  8. /* All procedures in this file map down into calls to the functions
  9.     described In Mike Maloney's "Nimbus Piconet interface
  10.     specification" of 1st July 1985.
  11.    422 mode uses piconet address 1fH.                */
  12.  
  13. #define  PIC422     0x1f
  14.  
  15. extern    int    p_break(), p_close(), p_flush(),  p_getc(),  p_open(),
  16.         p_putc(),  p_speed(), p_status(), p_xonxoff();    /* MikeM procs    */
  17.  
  18. static  int    status;
  19. static  char    alive = 0;        /* initialized flag        */
  20. static  char    awake = 0;        /* awake flag            */
  21. static    char    parity = 0;
  22. static    char    speed = 1;
  23. static    int    picspeed[] = {110,300,600,1200,2400,4800,9600,19200,0};
  24.     /* all valid speeds:    0   1    2    3      4    5    6      7   */
  25. static  char  partab[] = {
  26. /* character-parity table, 7-bit chars;    0 if even, 1 if odd.    */
  27.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /*  0-15, 00-0f    */
  28.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 16-31, 10-1f    */
  29.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 32-47, 20-2f    */
  30.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 48-63, 30-3f    */
  31.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 64-79, 40-4f    */
  32.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 80-95, 50-5f    */
  33.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 96-111, 60-6f */
  34.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1    /* 112-127, 70-7f */
  35.     };                /* end of parity table    */
  36.     
  37.  
  38.  
  39. char par(c,p)        /* return with parity            */
  40. /* strips to 7 bits, then adds correct parity; even if p=0, else odd    */
  41. char    c, p;
  42. {
  43.     char  b, d;
  44.  
  45.     c &= 0x7f;
  46.     b = (partab[c] == 0) ? 0 : 0x80;
  47.     if (p != 0)
  48.     b ^= 0x80;
  49.     d = b | c;
  50.     return(d);
  51. }            /* end of par()                    */
  52.  
  53.  
  54.  
  55. s4break(len)        /* send break - official        */
  56. char    len;
  57. {
  58.     int      time;
  59.  
  60.     if ( (alive == 0) || (awake == 0) ) {
  61.     printf(" not in contact ");
  62.     return(-1);
  63.     }
  64.     time = len << 7;            /* sec/8 => msec    */
  65.     p_break(PIC422,time);
  66.     outc(' ');
  67.     return(0);
  68. }            /* end of s4break()            */
  69.  
  70.  
  71. s4env()            /* return environment value        */
  72. /* Environment codes are:-
  73.     0  -  480Z, via SIO4;        1  -  480Z, via IDC;
  74.     2  -  Nimbus, via DCC;        3  -  Nimbus, via RS422 Aux;
  75.     4  -  Nimbus, via Piconet SIM;
  76.     5  -  either, via Network Comms Server (n.y.i.).
  77. (see KDATA.C for texts used on bottom header)            */
  78. {
  79.     return(3);
  80. }            /* end of s4env()            */
  81.  
  82.  
  83. s4get(n,buff)        /* read some character, maybe        */
  84. char    n, *buff;
  85. {
  86.     awake = 1;
  87.     if ( (p_getc(PIC422,buff)) != 0 )
  88.     return(0);
  89.     else
  90.     return(1);
  91. }            /* end of s4get()            */
  92.  
  93.  
  94. s4get7(n,buff)        /* read some 7-character, maybe        */
  95. char    n, *buff;
  96. {
  97.     awake = 1;
  98.     if ( (p_getc(PIC422,buff)) != 0 )
  99.     return(0);
  100.     else {
  101.     *buff &= 0x7f;
  102.     return(1);
  103.     }
  104. }            /* end of s4get7()            */
  105.  
  106.  
  107. s4go()            /* fire up RS422 comms            */
  108. {
  109.     int       i;
  110.     char   *addr;
  111.  
  112.     awake = 1;
  113.     if (alive != 0)
  114.     return(0);
  115.     if ( (addr = malloc (1610)) == 0 ) {
  116.     printf("\nNo store for comms.\n");
  117.     kermkill(1);
  118.     }
  119.     else {
  120.     if ( (i = p_open(PIC422,'I',1600,addr)) != 0 ) {
  121.         printf("\nCannot open comms, error-code %xx.\n",i);
  122.         kermkill(1);
  123.     }
  124.     alive = 1;
  125.     }
  126.     return(0);
  127. }            /* end of s4go()            */
  128.  
  129.  
  130. s4put(n,buff)        /* send some chars            */
  131. char    n, *buff;
  132. {
  133.     char    c;
  134.  
  135.     awake = 1;
  136.     c = *buff;
  137.     switch(parity) {
  138.       default:            /* 0 or > 3 (impossible)    */
  139.     break;
  140.       case 1:            /* 1 = odd            */
  141.     c = par(c,1);
  142.     break;
  143.       case 2:            /* 2 = even            */
  144.     c = par(c,0);
  145.     break;
  146.       case 3:            /* 3 = mark            */
  147.     c |= 0x80;
  148.     break;
  149.     }            /* end switch                */
  150.     if (p_putc(PIC422,c) == 0)
  151.     return(1);
  152.     else
  153.      return(0);
  154. }            /* end of s4put                */
  155.  
  156.  
  157. s4set(facil,wr5)    /* set facilities - dummy        */
  158. int    facil;
  159. char    wr5;
  160. {
  161.     char    x;
  162.  
  163.     parity = (facil & 0x0300) >> 8;
  164.     x = ( (facil & 0x0002) == 0 ) ? 0 : 0xff;
  165.     p_xonxoff(PIC422,x);
  166.     return(0);
  167. }            /* end of s4set()            */
  168.  
  169.  
  170. s4sleep()        /* dummy deactivate            */
  171. {
  172.     awake = 0;
  173.     return(0);
  174. }
  175.  
  176.  
  177. s4speed(kspeed)        /* set line-speed            */
  178. char    kspeed;            /* 480Z speed-code        */
  179. {
  180.     int     i, spd;
  181.  
  182.     speed = kspeed;
  183.     if (alive != 0) {
  184.     spd = picspeed[kspeed];
  185.     if ( (i = p_speed(PIC422,spd,spd)) != 0 ) {
  186.         printf("\nCannot set speed, error-code %xx.\n",i);
  187.         kermkill(1);
  188.     }    }
  189.     return(0);
  190. }            /* end of s4speed()            */
  191.  
  192.  
  193. s4status()        /* return status-byte (in int)        */
  194. {
  195.     return(p_status(PIC422));
  196. }            /* end of s4status()            */
  197.  
  198.  
  199. s4stop()        /* close down communications        */
  200. {
  201.     if (alive = 0)
  202.     return(0);
  203.     alive = awake = 0;
  204.     p_close(PIC422);
  205.     return(0);
  206. }            /* end of s4stop()            */
  207.  
  208.  
  209.  
  210. s4test()        /* return status - dummy        */
  211. {
  212.     return(0);
  213. }            /* end of s4test()            */
  214.  
  215.  
  216. /******************  END of file KSMIKE.C  *******************************/
  217.