summaryrefslogtreecommitdiff
path: root/ace/TTY_IO.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/TTY_IO.cpp')
-rw-r--r--ace/TTY_IO.cpp155
1 files changed, 139 insertions, 16 deletions
diff --git a/ace/TTY_IO.cpp b/ace/TTY_IO.cpp
index 7ab0036890e..44f937d646e 100644
--- a/ace/TTY_IO.cpp
+++ b/ace/TTY_IO.cpp
@@ -399,17 +399,24 @@ int ACE_TTY_IO::control (Control_Mode cmd, Serial_Params *arg) const
return -1; // Wrong cmd.
}
#elif defined (ACE_WIN32)
+ DCB dcb;
+ dcb.DCBlength = sizeof dcb;
+ if (!::GetCommState (this->get_handle (), &dcb))
+ {
+ ACE_OS::set_errno_to_last_error ();
+ return -1;
+ }
+
+ COMMTIMEOUTS timeouts;
+ if (!::GetCommTimeouts (this->get_handle(), &timeouts))
+ {
+ ACE_OS::set_errno_to_last_error ();
+ return -1;
+ }
+
switch (cmd)
{
case SETPARAMS:
- DCB dcb;
- dcb.DCBlength = sizeof dcb;
- if (!::GetCommState (this->get_handle (), &dcb))
- {
- ACE_OS::set_errno_to_last_error ();
- return -1;
- }
-
dcb.BaudRate = arg->baudrate;
switch (arg->databits)
@@ -522,13 +529,6 @@ int ACE_TTY_IO::control (Control_Mode cmd, Serial_Params *arg) const
return -1;
}
- COMMTIMEOUTS timeouts;
- if (!::GetCommTimeouts (this->get_handle(), &timeouts))
- {
- ACE_OS::set_errno_to_last_error ();
- return -1;
- }
-
if (arg->readtimeoutmsec < 0)
{
// Settings for infinite timeout.
@@ -560,7 +560,130 @@ int ACE_TTY_IO::control (Control_Mode cmd, Serial_Params *arg) const
return 0;
case GETPARAMS:
- ACE_NOTSUP_RETURN (-1); // Not yet implemented.
+ arg->baudrate = dcb.BaudRate;
+
+ switch (dcb.ByteSize)
+ {
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ arg->databits = dcb.ByteSize;
+ break;
+ default:
+ return -1;
+ }
+
+ switch (dcb.StopBits)
+ {
+ case ONESTOPBIT:
+ arg->stopbits = 1;
+ break;
+ case TWOSTOPBITS:
+ arg->stopbits = 2;
+ break;
+ default:
+ return -1;
+ }
+
+ if (!dcb.fParity)
+ {
+ arg->paritymode = ACE_TTY_IO_NONE;
+ }
+ else
+ {
+ switch (dcb.Parity)
+ {
+ case ODDPARITY:
+ arg->paritymode = ACE_TTY_IO_ODD;
+ break;
+ case EVENPARITY:
+ arg->paritymode = ACE_TTY_IO_EVEN;
+ break;
+ case NOPARITY:
+ arg->paritymode = ACE_TTY_IO_NONE;
+ break;
+ case MARKPARITY:
+ arg->paritymode = ACE_TTY_IO_MARK;
+ break;
+ case SPACEPARITY:
+ arg->paritymode = ACE_TTY_IO_SPACE;
+ break;
+ default:
+ return -1;
+ }
+ }
+
+ // Enable/disable RTS protocol.
+ switch (dcb.fRtsControl)
+ {
+ case RTS_CONTROL_ENABLE:
+ arg->rtsenb = 1;
+ break;
+ case RTS_CONTROL_HANDSHAKE:
+ arg->rtsenb = 2;
+ break;
+ case RTS_CONTROL_TOGGLE:
+ arg->rtsenb = 3;
+ break;
+ case RTS_CONTROL_DISABLE:
+ arg->rtsenb = 0;
+ break;
+ default:
+ return -1;
+ }
+
+ // Enable/disable CTS protocol.
+ if (dcb.fOutxCtsFlow)
+ arg->ctsenb = true;
+ else
+ arg->ctsenb = false;
+
+ // Enable/disable DSR protocol.
+ if (dcb.fOutxDsrFlow)
+ arg->dsrenb = true;
+ else
+ arg->dsrenb = false;
+
+ // Disable/enable DTR protocol
+ // Attention: DTR_CONTROL_HANDSHAKE is not supported.
+ switch (dcb.fDtrControl)
+ {
+ case DTR_CONTROL_DISABLE:
+ arg->dtrdisable = true;
+ break;
+ case DTR_CONTROL_ENABLE:
+ arg->dtrdisable = false;
+ break;
+ default:
+ return -1;
+ }
+
+ // Enable/disable software flow control on input
+ if (dcb.fInX)
+ arg->xinenb = true;
+ else
+ arg->xinenb = false;
+
+ // Enable/disable software flow control on output
+ if (dcb.fOutX)
+ arg->xoutenb = true;
+ else
+ arg->xoutenb = false;
+
+ arg->xonlim = static_cast<int>(dcb.XonLim);
+ arg->xofflim = static_cast<int>(dcb.XoffLim);
+
+ if (timeouts.ReadIntervalTimeout == 0 &&
+ timeouts.ReadTotalTimeoutMultiplier == 0 &&
+ timeouts.ReadTotalTimeoutConstant == 0)
+ arg->readtimeoutmsec = -1;
+ else
+ arg->readtimeoutmsec = timeouts.ReadTotalTimeoutConstant;
+
+ return 0;
+
default:
return -1; // Wrong cmd.