Commit 02352b14 authored by Don Gagne's avatar Don Gagne

Merge pull request #567 from DonLakeFlyer/QSerialPortFix

QSerialPort emitting stream of errors
parents f5e5d137 9e38f8ca
...@@ -429,7 +429,8 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) ...@@ -429,7 +429,8 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs)
bool timedOut = false; bool timedOut = false;
if (!waitForReadOrWrite(&readyToRead, &readyToWrite, true, !writeBuffer.isEmpty(), if (!waitForReadOrWrite(&readyToRead, &readyToWrite, true, !writeBuffer.isEmpty(),
timeoutValue(msecs, stopWatch.elapsed()), &timedOut)) { timeoutValue(msecs, stopWatch.elapsed()), &timedOut)) {
q_ptr->setError(decodeSystemError()); if (!timedOut)
q_ptr->setError(decodeSystemError());
return false; return false;
} }
...@@ -460,7 +461,8 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) ...@@ -460,7 +461,8 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs)
bool timedOut = false; bool timedOut = false;
if (!waitForReadOrWrite(&readyToRead, &readyToWrite, true, !writeBuffer.isEmpty(), if (!waitForReadOrWrite(&readyToRead, &readyToWrite, true, !writeBuffer.isEmpty(),
timeoutValue(msecs, stopWatch.elapsed()), &timedOut)) { timeoutValue(msecs, stopWatch.elapsed()), &timedOut)) {
q_ptr->setError(decodeSystemError()); if (!timedOut)
q_ptr->setError(decodeSystemError());
return false; return false;
} }
......
...@@ -26,7 +26,6 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl, ...@@ -26,7 +26,6 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl,
m_stopp(false), m_stopp(false),
m_reqReset(false) m_reqReset(false)
{ {
// Get the name of the current port in use. // Get the name of the current port in use.
m_portName = portname.trimmed(); m_portName = portname.trimmed();
if (m_portName == "" && getCurrentPorts().size() > 0) if (m_portName == "" && getCurrentPorts().size() > 0)
...@@ -445,7 +444,13 @@ bool SerialLink::hardwareConnect() ...@@ -445,7 +444,13 @@ bool SerialLink::hardwareConnect()
void SerialLink::linkError(QSerialPort::SerialPortError error) void SerialLink::linkError(QSerialPort::SerialPortError error)
{ {
qDebug() << error; if (error != QSerialPort::NoError) {
// You can use the following qDebug output as needed during development. Make sure to comment it back out
// when you are done. The reason for this is that this signal is very noisy. For example if you try to
// connect to a PixHawk before it is ready to accept the connection it will output a continuous stream
// of errors until the Pixhawk responds.
//qDebug() << "SerialLink::linkError" << error;
}
} }
......
...@@ -36,10 +36,14 @@ This file is part of the QGROUNDCONTROL project ...@@ -36,10 +36,14 @@ This file is part of the QGROUNDCONTROL project
#include <QThread> #include <QThread>
#include <QMutex> #include <QMutex>
#include <QString> #include <QString>
#include <qserialport.h>
#include <configuration.h> #include <configuration.h>
#include "SerialLinkInterface.h" #include "SerialLinkInterface.h"
// We use QSerialPort::SerialPortError in a signal so we must declare it as a meta type
#include <qserialport.h>
#include <QMetaType>
Q_DECLARE_METATYPE(QSerialPort::SerialPortError)
/** /**
* @brief The SerialLink class provides cross-platform access to serial links. * @brief The SerialLink class provides cross-platform access to serial links.
* It takes care of the link management and provides a common API to higher * It takes care of the link management and provides a common API to higher
......
...@@ -34,10 +34,16 @@ ...@@ -34,10 +34,16 @@
#include <QMap> #include <QMap>
#include <QMutex> #include <QMutex>
#include <QHostAddress> #include <QHostAddress>
#include <QTcpSocket>
#include <LinkInterface.h> #include <LinkInterface.h>
#include <configuration.h> #include <configuration.h>
// Even though QAbstractSocket::SocketError is used in a signal by Qt, Qt doesn't declare it as a meta type.
// This in turn causes debug output to be kicked out about not being able to queue the signal. We declare it
// as a meta type to silence that.
#include <QMetaType>
#include <QTcpSocket>
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
//#define TCPLINK_READWRITE_DEBUG // Use to debug data reads/writes //#define TCPLINK_READWRITE_DEBUG // Use to debug data reads/writes
class TCPLink : public LinkInterface class TCPLink : public LinkInterface
......
...@@ -32,6 +32,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -32,6 +32,8 @@ This file is part of the QGROUNDCONTROL project
#include "QGCCore.h" #include "QGCCore.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "configuration.h" #include "configuration.h"
#include "SerialLink.h"
#include "TCPLink.h"
#ifdef QT_DEBUG #ifdef QT_DEBUG
#include "AutoTest.h" #include "AutoTest.h"
#endif #endif
...@@ -70,6 +72,13 @@ int main(int argc, char *argv[]) ...@@ -70,6 +72,13 @@ int main(int argc, char *argv[])
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
qInstallMsgHandler( msgHandler ); qInstallMsgHandler( msgHandler );
#endif #endif
// The following calls to qRegisterMetaType are done to silence debug output which warns
// that we use these types in signals, and without calling qRegisterMetaType we can't queue
// these signals. In general we don't queue these signals, but we do what the warning says
// anyway to silence the debug output.
qRegisterMetaType<QSerialPort::SerialPortError>();
qRegisterMetaType<QAbstractSocket::SocketError>();
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (argc > 1 && QString(argv[1]).compare("--unittest", Qt::CaseInsensitive) == 0) { if (argc > 1 && QString(argv[1]).compare("--unittest", Qt::CaseInsensitive) == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment