home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / ASIXON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  2.7 KB  |  78 lines

  1. /* asixon.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asixon(port,low_water,hi_water,xon_character,xoff_character)
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  int low_water;       - Integer % of buffer at which to send xon_character
  10. *  int hi_water;        - Integer % of buffer at which to send xoff_character
  11. *  int xon_character;   - Character to send that starts remote transmitter
  12. *  int xoff_character;  - Character to send that stops remote transmitter
  13. *
  14. * DESCRIPTION
  15. *
  16. *  Enables XON/XOFF type flow control
  17. *
  18. *  Computes a number of characters offset into Rx buffer (for sending xon
  19. *  of xoff) based on integer arithmetic;  percentages must be specified as
  20. *  percent of total buffer (which this function determines from the structure)
  21. *  - must be in range 1..99.  If result offset is 0, it is incremented to 1.
  22. *
  23. * SIDE EFFECTS
  24. *  Offsets into buffer computed will not be exact due to integer math;
  25. *  they are within 1% in any case, with a floor of 1 byte.
  26. *
  27. * RETURNS
  28. *
  29. *       Value           Meaning
  30. *     -------          --------
  31. *       ASSUCCESS       Successful
  32. *       ASINVPORT       Requested port is out of range
  33. *       ASNOTSETUP      Requested port not setup with asifirst()
  34. *       ASINVPAR        hi or lo water <1 or >99
  35. *
  36. * MODIFICATIONS
  37. *       2-15-86 Don Killen - release 2.0
  38. *
  39. *       23-FEB-1987  15:05:48.62
  40. *       Modified to correctly calculate hi/lo water points when buffer size
  41. *       is less than 100 bytes.
  42. */
  43. #include <stdio.h>
  44. #include "gf.h"
  45. #include "asiports.h"
  46.  
  47. int GF_CONV asixon(port,low_water,hi_water,xon_character,xoff_character)
  48. int port,low_water,hi_water;
  49. int xon_character,xoff_character;
  50. {
  51.         struct PORT_TABLE *p;
  52.  
  53.         if((p=_aschkcnl(port))==NULL)
  54.                 return(_aserror);
  55.         p->chmode_bits.is_xoffmode=1;
  56.         if(xoff_character==0)
  57.                 p->stop_xmt=p->stop_rem_xmt=XOFF;
  58.         else
  59.                 p->stop_xmt=p->stop_rem_xmt=(unsigned)xoff_character;
  60.         if(xon_character==0)
  61.                 p->start_xmt=p->start_rem_xmt=XON;
  62.         else
  63.                 p->start_xmt=p->start_rem_xmt=(unsigned)xon_character;
  64.         if((low_water<1)||(low_water>99))
  65.                 return (ASINVPAR);
  66.         if((hi_water<1)||(hi_water>99))
  67.                 return (ASINVPAR);
  68.         p->rx_lowater=(unsigned)(((long)p->rx_size * (long)low_water)/(long)100)&0x0000ffff;
  69.         if(p->rx_lowater==0)
  70.                 ++p->rx_lowater;
  71.         p->rx_hiwater=(unsigned)(((long)p->rx_size * (long)hi_water)/(long)100)&0x0000ffff;
  72.         if(p->rx_hiwater==0)
  73.                 ++p->rx_hiwater;
  74.  
  75.         return(ASSUCCESS);
  76. }
  77.  
  78.