From cbaa538cf8bf52c8952ff3dccde793c231e8da33 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 16 Mar 2014 23:40:26 +0100 Subject: [PATCH] Do not configure the port if talking to PX4 units (since USB does not know anything about baud rate) --- src/comm/SerialLink.cc | 43 +++++++++++++++++++++++++++++++++++------- src/comm/SerialLink.h | 3 ++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index cf92e8f34..f36aca452 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -137,8 +137,35 @@ void SerialLink::writeSettings() **/ void SerialLink::run() { + + QString description = "X"; + foreach (QSerialPortInfo info,QSerialPortInfo::availablePorts()) + { + qDebug() << m_portName << "portname == info" << info.portName(); + if (m_portName == info.portName()) + { + description = info.description(); + break; + } + } + if (description.toLower().contains("mega") && description.contains("2560")) + { + type = "apm"; + qDebug() << "Attempting connection to an APM, with description:" << description; + } + else if (description.toLower().contains("px4")) + { + type = "px4"; + qDebug() << "Attempting connection to a PX4 unit with description:" << description; + } + else + { + type = "other"; + qDebug() << "Attempting connection to something unknown with description:" << description; + } + // Initialize the connection - if (!hardwareConnect()) { + if (!hardwareConnect(type)) { //Need to error out here. emit communicationError(getName(),"Error connecting: " + m_port->errorString()); disconnect(); // This tidies up and sends the necessary signals @@ -395,7 +422,7 @@ bool SerialLink::connect() * @return True if the connection could be established, false otherwise * @see connect() For the right function to establish the connection. **/ -bool SerialLink::hardwareConnect() +bool SerialLink::hardwareConnect(QString &type) { if(m_port) { qDebug() << "SerialLink:" << QString::number((long)this, 16) << "closing port"; @@ -425,11 +452,13 @@ bool SerialLink::hardwareConnect() emit communicationUpdate(getName(),"Opened port!"); // Need to configure the port - m_port->setBaudRate(m_baud); - m_port->setDataBits(static_cast(m_dataBits)); - m_port->setFlowControl(static_cast(m_flowControl)); - m_port->setStopBits(static_cast(m_stopBits)); - m_port->setParity(static_cast(m_parity)); + if (type != "px4") { + m_port->setBaudRate(m_baud); + m_port->setDataBits(static_cast(m_dataBits)); + m_port->setFlowControl(static_cast(m_flowControl)); + m_port->setStopBits(static_cast(m_stopBits)); + m_port->setParity(static_cast(m_parity)); + } emit connected(); emit connected(true); diff --git a/src/comm/SerialLink.h b/src/comm/SerialLink.h index 4effbfc9b..0194c0342 100644 --- a/src/comm/SerialLink.h +++ b/src/comm/SerialLink.h @@ -154,6 +154,7 @@ protected: QMutex m_dataMutex; // Mutex for reading data from m_port QMutex m_writeMutex; // Mutex for accessing the m_transmitBuffer. QList m_ports; + QString type; private: volatile bool m_stopp; @@ -161,7 +162,7 @@ private: QMutex m_stoppMutex; // Mutex for accessing m_stopp QByteArray m_transmitBuffer; // An internal buffer for receiving data from member functions and actually transmitting them via the serial port. - bool hardwareConnect(); + bool hardwareConnect(QString &type); signals: void aboutToCloseFlag(); -- 2.22.0