home *** CD-ROM | disk | FTP | other *** search
- /* asixon.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1985-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * int asixon(port,low_water,hi_water,xon_character,xoff_character)
- * int port; - Port 0..MAX_PORT-1
- * int low_water; - Integer % of buffer at which to send xon_character
- * int hi_water; - Integer % of buffer at which to send xoff_character
- * int xon_character; - Character to send that starts remote transmitter
- * int xoff_character; - Character to send that stops remote transmitter
- *
- * DESCRIPTION
- *
- * Enables XON/XOFF type flow control
- *
- * Computes a number of characters offset into Rx buffer (for sending xon
- * of xoff) based on integer arithmetic; percentages must be specified as
- * percent of total buffer (which this function determines from the structure)
- * - must be in range 1..99. If result offset is 0, it is incremented to 1.
- *
- * SIDE EFFECTS
- * Offsets into buffer computed will not be exact due to integer math;
- * they are within 1% in any case, with a floor of 1 byte.
- *
- * RETURNS
- *
- * Value Meaning
- * ------- --------
- * ASSUCCESS Successful
- * ASINVPORT Requested port is out of range
- * ASNOTSETUP Requested port not setup with asifirst()
- * ASINVPAR hi or lo water <1 or >99
- *
- * MODIFICATIONS
- * 2-15-86 Don Killen - release 2.0
- *
- * 23-FEB-1987 15:05:48.62
- * Modified to correctly calculate hi/lo water points when buffer size
- * is less than 100 bytes.
- */
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
-
- int GF_CONV asixon(port,low_water,hi_water,xon_character,xoff_character)
- int port,low_water,hi_water;
- int xon_character,xoff_character;
- {
- struct PORT_TABLE *p;
-
- if((p=_aschkcnl(port))==NULL)
- return(_aserror);
- p->chmode_bits.is_xoffmode=1;
- if(xoff_character==0)
- p->stop_xmt=p->stop_rem_xmt=XOFF;
- else
- p->stop_xmt=p->stop_rem_xmt=(unsigned)xoff_character;
- if(xon_character==0)
- p->start_xmt=p->start_rem_xmt=XON;
- else
- p->start_xmt=p->start_rem_xmt=(unsigned)xon_character;
- if((low_water<1)||(low_water>99))
- return (ASINVPAR);
- if((hi_water<1)||(hi_water>99))
- return (ASINVPAR);
- p->rx_lowater=(unsigned)(((long)p->rx_size * (long)low_water)/(long)100)&0x0000ffff;
- if(p->rx_lowater==0)
- ++p->rx_lowater;
- p->rx_hiwater=(unsigned)(((long)p->rx_size * (long)hi_water)/(long)100)&0x0000ffff;
- if(p->rx_hiwater==0)
- ++p->rx_hiwater;
-
- return(ASSUCCESS);
- }
-
-