From 1ea7afee468a4150888308c447b4bb19e85bcb43 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 12 Dec 2007 11:53:27 +0100 Subject: [PATCH] Issue 25: Use common backend for setting and clearing the DTR bit --- diku_mch/SerialControl.cc | 21 +++++---------------- diku_mch/SerialControl.h | 3 +-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/diku_mch/SerialControl.cc b/diku_mch/SerialControl.cc index 871d3b1..5231741 100644 --- a/diku_mch/SerialControl.cc +++ b/diku_mch/SerialControl.cc @@ -154,7 +154,7 @@ result_t SerialControl::reset() result_t SerialControl::start() { - if (!isOpen() || !clearDTR()) + if (!isOpen() || !controlDTR(false)) return FAILURE; isRunning = true; return SUCCESS; @@ -162,29 +162,18 @@ result_t SerialControl::start() result_t SerialControl::stop() { - if (!isOpen() || !setDTR()) + if (!isOpen() || !controlDTR(true)) return FAILURE; isRunning = false; return SUCCESS; } -bool SerialControl::setDTR() +bool SerialControl::controlDTR(bool enable) { int tmp = TIOCM_DTR; + int req = enable ? TIOCMBIS : TIOCMBIC; - if (ioctl(port, TIOCMBIS, &tmp) == -1) { - Log::error("ioctl(%s) failed: %s", tty.c_str(), strerror(errno)); - portIsOpen = false; - return false; - } - return true; -} - -bool SerialControl::clearDTR() -{ - int tmp = TIOCM_DTR; - - if (ioctl(port, TIOCMBIC, &tmp) == -1) { + if (ioctl(port, req, &tmp) == -1) { Log::error("ioctl(%s) failed: %s", tty.c_str(), strerror(errno)); portIsOpen = false; return false; diff --git a/diku_mch/SerialControl.h b/diku_mch/SerialControl.h index 3560f00..da4078f 100644 --- a/diku_mch/SerialControl.h +++ b/diku_mch/SerialControl.h @@ -45,8 +45,7 @@ class SerialControl result_t openTty(); result_t closeTty(); bool endChild(bool killChild); - bool clearDTR(); - bool setDTR(); + bool controlDTR(bool enable); int port; bool isRunning, portIsOpen; pid_t childPid; -- 2.11.4.GIT