diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index cf92e8f34962495334d99cabfa61ac163415c838..f36aca45213b5a2543beb9113a5554b5b96294b0 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 4effbfc9ba80eab65e4b0595e5365f0b86cf6649..0194c034252d4c701fda25a35e745470ff7413ec 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();