summaryrefslogtreecommitdiffstats
path: root/src/common/port/serial.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-30 00:15:53 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-30 00:15:53 +0000
commit0aaa8e3fc8f8a1481333b564f0922277c8d8ad59 (patch)
treeb95c0ca86c4876dd139af376b9f4afd8917cf0cd /src/common/port/serial.cpp
parentb79a2c28534cf09987eeeba3077fff9236df182a (diff)
downloadpiklab-0aaa8e3fc8f8a1481333b564f0922277c8d8ad59.tar.gz
piklab-0aaa8e3fc8f8a1481333b564f0922277c8d8ad59.zip
TQt4 port piklab
This enables compilation under both Qt3 and Qt4 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1238822 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/common/port/serial.cpp')
-rw-r--r--src/common/port/serial.cpp78
1 files changed, 39 insertions, 39 deletions
diff --git a/src/common/port/serial.cpp b/src/common/port/serial.cpp
index b370d22..5942561 100644
--- a/src/common/port/serial.cpp
+++ b/src/common/port/serial.cpp
@@ -20,17 +20,17 @@
# include <errno.h>
# include <unistd.h> // needed on some system
#endif
-#include <qdatetime.h>
+#include <tqdatetime.h>
//-----------------------------------------------------------------------------
-QStringList *Port::Serial::_list = 0;
+TQStringList *Port::Serial::_list = 0;
#if defined(Q_OS_UNIX)
const Port::Serial::Handle Port::Serial::INVALID_HANDLE = -1;
#elif defined(Q_OS_WIN)
const Port::Serial::Handle Port::Serial::INVALID_HANDLE = INVALID_HANDLE_VALUE;
#endif
-Port::Serial::Handle Port::Serial::openHandle(const QString &device, IODirs dirs)
+Port::Serial::Handle Port::Serial::openHandle(const TQString &device, IODirs dirs)
{
#if defined(Q_OS_UNIX)
// open non blocking: avoid missing DCD (comment from xwisp2)
@@ -57,7 +57,7 @@ void Port::Serial::closeHandle(Handle handle)
#endif
}
-Port::IODirs Port::Serial::probe(const QString &device)
+Port::IODirs Port::Serial::probe(const TQString &device)
{
Handle handle = openHandle(device, In);
if ( handle==INVALID_HANDLE ) return NoIO;
@@ -68,35 +68,35 @@ Port::IODirs Port::Serial::probe(const QString &device)
return (In | Out);
}
-QStringList Port::Serial::deviceList()
+TQStringList Port::Serial::deviceList()
{
- QStringList list;
+ TQStringList list;
#if defined(Q_OS_UNIX)
// standard serport in user space
- for (uint i=0; i<8; i++) list.append(QString("/dev/ttyS%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/ttyS%1").tqarg(i));
// new devfs serport flavour
- for (uint i=0; i<8; i++) list.append(QString("/dev/tts/%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/tts/%1").tqarg(i));
// standard USB serport in user space
- for (uint i=0; i<8; i++) list.append(QString("/dev/ttyUSB%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/ttyUSB%1").tqarg(i));
// new devfs USB serport flavour
- for (uint i=0; i<8; i++) list.append(QString("/dev/usb/tts/%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/usb/tts/%1").tqarg(i));
// FreeBSD
- for (uint i=0; i<8; i++) list.append(QString("/dev/ttyd%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/ttyd%1").tqarg(i));
// Slackware 11 devfs USB Serial port support.
- for (uint i=0; i<8; i++) list.append(QString("/dev/tts/USB%1").arg(i));
+ for (uint i=0; i<8; i++) list.append(TQString("/dev/tts/USB%1").tqarg(i));
// MacOSX devfs USB Serial port support.
list.append("/dev/tty.usbserial");
#elif defined(Q_OS_WIN)
- for (uint i=1; i<10; i++) list.append(QString("COM%1").arg(i));
+ for (uint i=1; i<10; i++) list.append(TQString("COM%1").tqarg(i));
#endif
return list;
}
-const QStringList &Port::Serial::probedDeviceList()
+const TQStringList &Port::Serial::probedDeviceList()
{
if ( _list==0 ) {
- QStringList all = deviceList();
- _list = new QStringList;
+ TQStringList all = deviceList();
+ _list = new TQStringList;
for (uint i=0; i<uint(all.count()); i++)
if( probe(all[i]) & (In | Out) ) _list->append(all[i]);
}
@@ -130,9 +130,9 @@ const Port::Serial::SPinData Port::Serial::PIN_DATA[Nb_Pins] = {
{ Out, "RI" }
};
-QValueVector<Port::PinData> Port::Serial::pinData(IODir dir) const
+TQValueVector<Port::PinData> Port::Serial::pinData(IODir dir) const
{
- QValueVector<PinData> v;
+ TQValueVector<PinData> v;
for (uint i=0; i<Nb_Pins; i++) {
if ( PIN_DATA[i].dir!=dir ) continue;
PinData pd = { i, PIN_DATA[i].label };
@@ -142,7 +142,7 @@ QValueVector<Port::PinData> Port::Serial::pinData(IODir dir) const
}
bool Port::Serial::isGroundPin(uint pin) const
{
- return ( PIN_DATA[pin].label==QString("GND") );
+ return ( PIN_DATA[pin].label==TQString("GND") );
}
Port::IODir Port::Serial::ioDir(uint pin) const
@@ -150,7 +150,7 @@ Port::IODir Port::Serial::ioDir(uint pin) const
return PIN_DATA[pin].dir;
}
-Port::Serial::Serial(const QString &device, Properties properties, Log::Base &base)
+Port::Serial::Serial(const TQString &device, Properties properties, Log::Base &base)
: Base(base), _device(device), _properties(properties), _fd(INVALID_HANDLE)
{}
@@ -187,7 +187,7 @@ bool Port::Serial::internalOpen()
{
_fd = openHandle(_device, In | Out);
if ( _fd==INVALID_HANDLE ) {
- setSystemError(i18n("Could not open device \"%1\" read-write").arg(_device));
+ setSystemError(i18n("Could not open device \"%1\" read-write").tqarg(_device));
return false;
}
if ( !getParameters(_oldParameters) ) return false; // save configuration
@@ -216,7 +216,7 @@ void Port::Serial::internalClose()
bool Port::Serial::internalSend(const char *data, uint size, uint timeout)
{
if ( _fd==INVALID_HANDLE ) return false;
- QTime time;
+ TQTime time;
time.start();
for (uint todo=size; todo!=0; ) {
#if defined(Q_OS_UNIX)
@@ -232,7 +232,7 @@ bool Port::Serial::internalSend(const char *data, uint size, uint timeout)
if ( res>0 ) todo -= res;
else {
if ( uint(time.elapsed())>timeout ) {
- log(Log::LineType::Error, i18n("Timeout sending data (%1/%2 bytes sent).").arg(size-todo).arg(size));
+ log(Log::LineType::Error, i18n("Timeout sending data (%1/%2 bytes sent).").tqarg(size-todo).tqarg(size));
return false;
}
msleep(1);
@@ -245,7 +245,7 @@ bool Port::Serial::internalSend(const char *data, uint size, uint timeout)
bool Port::Serial::internalReceive(uint size, char *data, uint timeout)
{
if ( _fd==INVALID_HANDLE ) return false;
- QTime time;
+ TQTime time;
time.start();
for(uint todo=size; todo!=0; ) {
#if defined(Q_OS_UNIX)
@@ -277,7 +277,7 @@ bool Port::Serial::internalReceive(uint size, char *data, uint timeout)
if ( res>0 ) todo -= res;
else {
if ( uint(time.elapsed())>timeout ) {
- log(Log::LineType::Error, i18n("Timeout receiving data (%1/%2 bytes received).").arg(size-todo).arg(size));
+ log(Log::LineType::Error, i18n("Timeout receiving data (%1/%2 bytes received).").tqarg(size-todo).tqarg(size));
return false;
}
msleep(1);
@@ -292,7 +292,7 @@ bool Port::Serial::drain(uint timeout)
#if defined(Q_OS_UNIX)
// tcdrain will block if the serial cable is disconnected
// so we first check for data in output buffer...
- QTime time;
+ TQTime time;
time.start();
for (;;) {
int nb;
@@ -303,7 +303,7 @@ bool Port::Serial::drain(uint timeout)
if ( nb==0 ) break;
if ( uint(time.elapsed())>timeout ) {
_fd = INVALID_HANDLE; // otherwise close blocks...
- log(Log::LineType::Error, i18n("Timeout sending data (%1 bytes left).").arg(nb));
+ log(Log::LineType::Error, i18n("Timeout sending data (%1 bytes left).").tqarg(nb));
return false;
}
}
@@ -364,7 +364,7 @@ bool Port::Serial::setPinOn(uint pin, bool on, LogicType type)
Q_ASSERT( pin<Nb_Pins );
Q_ASSERT( PIN_DATA[pin].dir==Out );
if ( !internalSetPinOn(Pin(pin), on) ) {
- setSystemError(i18n("Error setting bit %1 of serial port to %2").arg(PIN_DATA[pin].label).arg(on));
+ setSystemError(i18n("Error setting bit %1 of serial port to %2").tqarg(PIN_DATA[pin].label).tqarg(on));
return false;
}
return true;
@@ -375,19 +375,19 @@ bool Port::Serial::internalReadPin(Pin pin, LogicType type, bool &value)
#if defined(Q_OS_UNIX)
int bits;
if ( ioctl(_fd, TIOCMGET, &bits)<0 ) return false;
- int mask = 0;
+ int tqmask = 0;
switch (pin) {
- case DCD: mask = TIOCM_CD; break;
- case RX : mask = TIOCM_SR; break;
- case DSR: mask = TIOCM_DSR; break;
- case CTS: mask = TIOCM_CTS; break;
+ case DCD: tqmask = TIOCM_CD; break;
+ case RX : tqmask = TIOCM_SR; break;
+ case DSR: tqmask = TIOCM_DSR; break;
+ case CTS: tqmask = TIOCM_CTS; break;
default: Q_ASSERT(false); return false;
}
- value = ((type==NegativeLogic ? ~bits : bits) & mask);
+ value = ((type==NegativeLogic ? ~bits : bits) & tqmask);
return true;
#elif defined(Q_OS_WIN)
DWORD status;
- if ( GetCommModemStatus(_fd, &status)==0 ) return false;
+ if ( GetCommModemtqStatus(_fd, &status)==0 ) return false;
switch (pin) {
case DCD: value = (status & MS_RLSD_ON); break;
case DSR: value = (status & MS_DSR_ON); break;
@@ -406,7 +406,7 @@ bool Port::Serial::internalReadPin(Pin pin, LogicType type, bool &value)
Q_ASSERT( pin<Nb_Pins );
Q_ASSERT( PIN_DATA[pin].dir==In );
if ( !internalReadPin(Pin(pin), type, value) ) {
- setSystemError(i18n("Error reading serial pin %1").arg(PIN_DATA[pin].label));
+ setSystemError(i18n("Error reading serial pin %1").tqarg(PIN_DATA[pin].label));
return false;
}
return true;
@@ -510,14 +510,14 @@ bool Port::Serial::setHardwareFlowControl(bool on)
return setParameters(parameters);
}
-void Port::Serial::setSystemError(const QString &message)
+void Port::Serial::setSystemError(const TQString &message)
{
#if defined(Q_OS_UNIX)
- log(Log::LineType::Error, message + QString(" (errno=%1)").arg(strerror(errno)));
+ log(Log::LineType::Error, message + TQString(" (errno=%1)").tqarg(strerror(errno)));
#elif defined(Q_OS_WIN)
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
- log(Log::LineType::Error, message + QString(" (last error=%1 %2)").arg(GetLastError()).arg((const char *)(LPCTSTR)lpMsgBuf));
+ log(Log::LineType::Error, message + TQString(" (last error=%1 %2)").tqarg(GetLastError()).tqarg((const char *)(LPCTSTR)lpMsgBuf));
LocalFree(lpMsgBuf);
#endif
}