home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / baud1.c < prev    next >
Text File  |  1985-12-15  |  2KB  |  61 lines

  1. /* Determine the baud rate to operate at by getting characters until
  2. we find something recognizable. Return with the global 'rate' set and
  3. Novation type modems put in transparent mode. The initial delay is because
  4. the answer modem returns connect info much earlier than the originate. */
  5.  
  6. connect() {
  7.  
  8. unsigned n;
  9.  
  10.         delay(100);                             /* delay */
  11.         flush(1);                               /* flush garbage */
  12.         cd_flag= 0;                             /* watch carrier */
  13.  
  14.         while (1) {
  15.                 rate= 300;
  16.                 baud(rate);                     /* test at 300 baud */
  17.                 n= mrconin();                   /* get a raw key */
  18.  
  19. /* At 1200 and above, one byte (CR or anything) fits into 1/4th a character,
  20. so the rest of it is ones. If we find f0h, try more or less the same thing
  21. as the 300 vs. 600 case, but at 1200 baud. */
  22.  
  23.                 if ((n & 0xf0) == 0xf0) {
  24.                         rate= 1200;
  25.                         baud(rate);
  26.                         n= mrconin();           /* RAW Modem conin() */
  27.                         if ((n & 0x7f) == CR) break;
  28.                         if ((n & 0x7f) == ' ') break;
  29.                         if ((n & 0xf0) == 0xf0) {
  30.                                 rate= 2400;
  31.                                 baud(rate);
  32.                                 break;
  33.                         }
  34.  
  35. /* For 300 baud, we should get a CR. If so, get another to make sure. It
  36. might have been garbage or a leftover result code. Baud rate is already
  37. set to 300. */
  38.  
  39.                 } else {
  40.                         n= mrconin();
  41.                         if ((n & 0x7f) == CR) break;
  42.                         if ((n & 0x7f) == ' ') break;
  43.                 }
  44.  
  45. /* None of the above. Now we need to flush before we try again, as we
  46. somehow might have ended up receiving 300 baud chars at 1200, and that
  47. generates multiple garbage bytes. */
  48.  
  49.                 flush(5);                     /* 50 mS quiet, flush garbage */
  50.         }
  51.  
  52. /* All set. Put Novation modems to sleep, and flush the software ring buffer
  53. and things. */
  54.  
  55.         if (mdmtype == SMARTCAT) atp("\016U 0",CR);
  56.         if (mdmtype == IBMJR) atp("\016T 0",CR);
  57.         if ((mdmtype == IBMJR) || (mdmtype == SMARTCAT)) delay(100);
  58.         mconflush();
  59. }
  60. {
  61.