From 587238c201ada3b90ca5bf7adb4bf974a500b591 Mon Sep 17 00:00:00 2001 From: James Goppert Date: Wed, 30 Mar 2011 20:38:30 -0400 Subject: [PATCH] Fixed serial lag issues. --- lib/QMapControl/src/mapnetwork.cpp | 6 ++++-- src/comm/SerialInterface.h | 24 ++++++++++++++++-------- src/comm/SerialLink.cc | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/QMapControl/src/mapnetwork.cpp b/lib/QMapControl/src/mapnetwork.cpp index 63b6a28b9..de16b92df 100644 --- a/lib/QMapControl/src/mapnetwork.cpp +++ b/lib/QMapControl/src/mapnetwork.cpp @@ -100,7 +100,8 @@ namespace qmapcontrol // Silently ignore map request for a // 0xn pixel map qDebug() << "QMapControl: IGNORED 0x0 pixel map request, widthxheight:" << pm.width() << "x" << pm.height(); - qDebug() << "QMapControl: HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__; + // showing this html error message is horribly time consuming + //qDebug() << "QMapControl: HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__; } else { @@ -108,7 +109,8 @@ namespace qmapcontrol // TODO Error is currently undetected //qDebug() << "NETWORK_PIXMAP_ERROR: " << ax; qDebug() << "QMapControl external library: ERROR loading map:" << "width:" << pm.width() << "heigh:" << pm.height() << "at " << __FILE__ << __LINE__; - qDebug() << "QMapControl: HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__; + // showing this html error message is horribly time consuming + //qDebug() << "QMapControl: HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__; } } diff --git a/src/comm/SerialInterface.h b/src/comm/SerialInterface.h index ff34db568..4eb3ca80c 100644 --- a/src/comm/SerialInterface.h +++ b/src/comm/SerialInterface.h @@ -118,7 +118,7 @@ public: virtual bool isOpen() = 0; virtual bool isWritable() = 0; - virtual bool bytesAvailable() = 0; + virtual qint64 bytesAvailable() = 0; virtual int write(const char * data, qint64 size) = 0; virtual void read(char * data, qint64 numBytes) = 0; virtual void flush() = 0; @@ -141,17 +141,20 @@ signals: void aboutToClose(); public: SerialQextserial(QString porthandle, QextSerialPort::QueryMode mode) : _port(NULL) { - std::cout << "DEBUG: " << porthandle.toStdString() << std::endl; _port = new QextSerialPort(porthandle, QextSerialPort::Polling); QObject::connect(_port,SIGNAL(aboutToClose()),this,SIGNAL(aboutToClose())); } + ~SerialQextserial() { + delete _port; + _port = NULL; + } virtual bool isOpen() { return _port->isOpen(); } virtual bool isWritable() { return _port->isWritable(); } - virtual bool bytesAvailable() { + virtual qint64 bytesAvailable() { return _port->bytesAvailable(); } virtual int write(const char * data, qint64 size) { @@ -203,12 +206,17 @@ public: SerialQserial(QString porthandle, QIODevice::OpenModeFlag flag=QIODevice::ReadWrite) : _port(NULL) { QObject::connect(_port,SIGNAL(aboutToClose()),this,SIGNAL(aboutToClose())); - settings.setBaudRate(QPortSettings::BAUDR_38400); - settings.setStopBits(QPortSettings::STOP_2); + settings.setBaudRate(QPortSettings::BAUDR_57600); + settings.setStopBits(QPortSettings::STOP_1); settings.setDataBits(QPortSettings::DB_8); settings.setFlowControl(QPortSettings::FLOW_OFF); settings.setParity(QPortSettings::PAR_NONE); _port = new QSerialPort(porthandle,settings); + _port->setCommTimeouts(QSerialPort::CtScheme_NonBlockingRead); + } + ~SerialQserial() { + delete _port; + _port = NULL; } virtual bool isOpen() { return _port->isOpen(); @@ -216,7 +224,7 @@ public: virtual bool isWritable() { _port->isWritable(); } - virtual bool bytesAvailable() { + virtual qint64 bytesAvailable() { return _port->bytesAvailable(); } virtual int write(const char * data, qint64 size) { @@ -234,11 +242,11 @@ public: } virtual void open(QIODevice::OpenModeFlag flag) { _port->open(flag); - std::cout << "opened port" << std::endl; + //flush(); } virtual void setBaudRate(SerialInterface::baudRateType baudrate) { // TODO get the baudrate enum to map to one another - settings.setBaudRate(QPortSettings::BAUDR_38400); + settings.setBaudRate(QPortSettings::BAUDR_57600); } virtual void setParity(SerialInterface::parityType parity) { settings.setParity(QPortSettings::PAR_NONE); diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 3e5be7720..d729b2d09 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -191,6 +191,7 @@ void SerialLink::readBytes() const qint64 maxLength = 2048; char data[maxLength]; qint64 numBytes = port->bytesAvailable(); + //qDebug() << "numBytes: " << numBytes; if(numBytes > 0) { /* Read as much data in buffer as possible without overflow */ -- 2.22.0