📄 ulibos2.c
字号:
hangupNeeded = FALSE; /* Don't fiddle with port any more */
/*--------------------------------------------------------------------*/
/* Lower DTR */
/*--------------------------------------------------------------------*/
com_signals.fbModemOn = 0x00;
com_signals.fbModemOff = DTR_OFF | RTS_OFF;
#ifdef __OS2__
ParmLengthInOut = sizeof(com_signals);
DataLengthInOut = sizeof(com_error);
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC,
ASYNC_SETMODEMCTRL,
(PVOID)&com_signals,
sizeof(com_signals),
&ParmLengthInOut,
(PVOID) &com_error,
sizeof(com_error),
&DataLengthInOut);
#else
rc = DosDevIOCtl( &com_error,
&com_signals,
ASYNC_SETMODEMCTRL,
IOCTL_ASYNC,
com_handle);
#endif
if ( rc )
{
printmsg(0,"ncloseline: Unable to lower DTR/RTS for port");
printOS2error( "DosDevIOCtl", rc );
}
else if ( com_error )
ShowError( com_error );
/*--------------------------------------------------------------------*/
/* Actually close the port */
/*--------------------------------------------------------------------*/
rc = DosClose( com_handle );
if ( rc != 0 )
printOS2error( "DosClose", rc );
/*--------------------------------------------------------------------*/
/* Stop logging the data to disk */
/*--------------------------------------------------------------------*/
traceStop();
} /* ncloseline */
/*--------------------------------------------------------------------*/
/* n h a n g u p */
/* */
/* Hangup the telephone by dropping DTR. Works with HAYES and */
/* many compatibles. */
/* 14 May 89 Drew Derbyshire */
/*--------------------------------------------------------------------*/
void nhangup( void )
{
#ifdef __OS2__
ULONG ParmLengthInOut;
ULONG DataLengthInOut;
#endif
USHORT com_error;
APIRET rc;
if (!hangupNeeded)
return;
hangupNeeded = FALSE;
/*--------------------------------------------------------------------*/
/* Drop DTR */
/*--------------------------------------------------------------------*/
com_signals.fbModemOn = 0x00;
com_signals.fbModemOff = DTR_OFF;
#ifdef __OS2__
ParmLengthInOut = sizeof(com_signals);
DataLengthInOut = sizeof(com_error);
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC,
ASYNC_SETMODEMCTRL,
(PVOID)&com_signals,
sizeof(com_signals),
&ParmLengthInOut,
(PVOID) &com_error,
sizeof(com_error),
&DataLengthInOut);
#else
rc = DosDevIOCtl( &com_error,
&com_signals,
ASYNC_SETMODEMCTRL,
IOCTL_ASYNC,
com_handle);
#endif
if ( rc )
{
printmsg(0,"hangup: Unable to lower DTR for comm port");
printOS2error( "DosDevIOCtl", rc );
} /*if */
else if ( com_error )
ShowError( com_error );
/*--------------------------------------------------------------------*/
/* Wait for the telephone to hangup */
/*--------------------------------------------------------------------*/
printmsg(3,"hangup: Dropped DTR");
carrierDetect = FALSE; /* Modem is not connected */
ddelay(500); /* Really only need 250 milliseconds */
/*--------------------------------------------------------------------*/
/* Bring DTR back up */
/*--------------------------------------------------------------------*/
com_signals.fbModemOn = DTR_ON;
com_signals.fbModemOff = 0xff;
#ifdef __OS2__
ParmLengthInOut = sizeof(com_signals);
DataLengthInOut = sizeof(com_error);
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC, ASYNC_SETMODEMCTRL,
(PVOID)&com_signals,
sizeof(com_signals),
&ParmLengthInOut,
(PVOID) &com_error,
sizeof(com_error),
&DataLengthInOut);
#else
rc = DosDevIOCtl( &com_error,
&com_signals,
ASYNC_SETMODEMCTRL,
IOCTL_ASYNC,
com_handle);
#endif
if ( rc )
{
printmsg(0,"hangup: Unable to raise DTR for comm port");
printOS2error( "DosDevIOCtl", rc );
} /*if */
else if ( com_error )
ShowError( com_error );
ddelay(2000); /* Now wait for the poor thing to recover */
} /* nhangup */
/*--------------------------------------------------------------------*/
/* n S I O S p e e d */
/* */
/* Re-specify the speed of an opened serial port */
/* */
/* Dropped the DTR off/on calls because this makes a Hayes drop */
/* the line if configured properly, and we don't want the modem */
/* to drop the phone on the floor if we are performing */
/* autobaud. */
/* */
/* (Configured properly = standard method of making a Hayes */
/* hang up the telephone, especially when you can't get it into */
/* command state because it is at the wrong speed or whatever.) */
/*--------------------------------------------------------------------*/
void nSIOSpeed(BPS baud)
{
APIRET rc;
#ifdef __OS2__
ULONG ParmLengthInOut;
ULONG DataLengthInOut;
struct
{
ULONG baud; // this structure is needed to set the extended
BYTE fraction; // baud rate using function 41h DosDevIOCtl
} com_baud;
#else
USHORT speed = (USHORT) baud;
#endif
#ifdef UDEBUG
printmsg(15,"SIOSpeed: Setting baud rate to %lu",
(unsigned long) baud);
#endif
#ifdef __OS2__
/*--------------------------------------------------------------------*/
/* OS/2 2.x Format of call for DosDevIOCtl accepts baud */
/* rates greater than 19200. */
/*--------------------------------------------------------------------*/
com_baud.baud = baud;
com_baud.fraction = 0;
ParmLengthInOut = sizeof(com_baud);
DataLengthInOut = 0;
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC,
ASYNC_SETBAUDRATE,
(PVOID) &com_baud,
sizeof(com_baud),
&ParmLengthInOut,
NULL,
0L,
&DataLengthInOut);
#else
rc = DosDevIOCtl( FAR_NULL,
&speed,
ASYNC_SETBAUDRATE,
IOCTL_ASYNC,
com_handle);
#endif
if (rc)
{
printmsg(0,"SIOSPeed: Unable to set baud rate for port to %lu",
baud);
printOS2error( "DosDevIOCtl", rc );
panic();
} /*if */
currentSpeed = (unsigned short) baud;
} /* nSIOSpeed */
/*--------------------------------------------------------------------*/
/* n f l o w c o n t r o l */
/* */
/* Enable/Disable in band (XON/XOFF) flow control */
/*--------------------------------------------------------------------*/
void nflowcontrol( boolean flow )
{
APIRET rc;
#ifdef __OS2__
ULONG ParmLengthInOut;
ULONG DataLengthInOut;
#endif
if ( flow )
com_dcbinfo.fbFlowReplace = (char)
(com_dcbinfo.fbFlowReplace |
(MODE_AUTO_TRANSMIT | MODE_AUTO_RECEIVE));
else
com_dcbinfo.fbFlowReplace = (char)
(com_dcbinfo.fbFlowReplace &
(0xff - MODE_AUTO_TRANSMIT - MODE_AUTO_RECEIVE));
#ifdef __OS2__
ParmLengthInOut = sizeof(com_dcbinfo);
DataLengthInOut = 0;
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC,
ASYNC_SETDCBINFO,
(PVOID) &com_dcbinfo,
sizeof(com_dcbinfo),
&ParmLengthInOut,
NULL,
0L,
&DataLengthInOut);
#else
rc = DosDevIOCtl( FAR_NULL,
&com_dcbinfo,
ASYNC_SETDCBINFO,
IOCTL_ASYNC,
com_handle);
#endif
if ( rc )
{
printmsg(0,"flowcontrol: Unable to set flow control");
printOS2error( "DosDevIOCtl", rc );
panic();
} /*if */
} /* nflowcontrol */
/*--------------------------------------------------------------------*/
/* n G e t S p e e d */
/* */
/* Report current speed of communications connection */
/*--------------------------------------------------------------------*/
BPS nGetSpeed( void )
{
return currentSpeed;
} /* nGetSpeed */
/*--------------------------------------------------------------------*/
/* n C D */
/* */
/* Return status of carrier detect */
/*--------------------------------------------------------------------*/
boolean nCD( void )
{
boolean previousCarrierDetect = carrierDetect;
APIRET rc;
#ifdef __OS2__
ULONG ParmLengthInOut;
ULONG DataLengthInOut;
#endif
BYTE status;
static BYTE oldstatus = (BYTE) 0xDEAD;
#ifdef __OS2__
ParmLengthInOut = 0;
DataLengthInOut = sizeof(status);
rc = DosDevIOCtl( com_handle,
IOCTL_ASYNC,
ASYNC_GETMODEMINPUT,
NULL,
0L,
&ParmLengthInOut,
(PVOID) &status,
sizeof(status),
&DataLengthInOut);
#else
rc = DosDevIOCtl( &status,
0L,
ASYNC_GETMODEMINPUT,
IOCTL_ASYNC,
com_handle );
#endif
if ( rc )
{
printmsg(0,"CD: Unable to get modem status");
printOS2error( "DosDevIOCtl", rc );
} /*if */
if ( status != oldstatus )
{
ShowModem( status );
oldstatus = status;
}
/*--------------------------------------------------------------------*/
/* If we previously had carrier detect but have lost it, we */
/* report it was lost. If we do not yet have carrier detect, */
/* we return success because we may not have connected yet. */
/*--------------------------------------------------------------------*/
carrierDetect = status && DCD_ON;
if (previousCarrierDetect)
return carrierDetect;
else
return (status && DSR_ON);
} /* nCD */
/*--------------------------------------------------------------------*/
/* S h o w M o d e m */
/* */
/* Report current modem status */
/*--------------------------------------------------------------------*/
#define mannounce(flag, bits, text ) ((flag & bits) ? text : "" )
static void ShowModem( const BYTE status )
{
if ( debuglevel < 4 )
return;
printmsg(0, "ShowModem: %#02x%s%s%s%s",
(int) status,
mannounce(DCD_ON, status, " Carrier Detect"),
mannounce(RI_ON, status, " Ring Indicator"),
mannounce(DSR_ON, status, " Data Set Ready"),
mannounce(CTS_ON, status, " Clear to Send"));
} /* ShowModem */
/*--------------------------------------------------------------------*/
/* S h o w E r r o r */
/* */
/* Report modem error bits in English (more or less) */
/*--------------------------------------------------------------------*/
static void ShowError( const USHORT status )
{
printmsg(2, "Port Error: %#04x%s%s%s%s",
(int) status,
mannounce(RX_QUE_OVERRUN, status, " Queue Overrrun"),
mannounce(RX_HARDWARE_OVERRUN, status, " Hardware Overrun"),
mannounce(PARITY_ERROR, status, " Parity Error"),
mannounce(FRAMING_ERROR, status, " Framing Error"));
} /* ShowError */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -