diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index c8869e2..ac628f9 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -115,6 +115,32 @@ QList SerialLink::getCurrentPorts() return m_ports; } +bool SerialLink::isBootloader() +{ + QList portList = QSerialPortInfo::availablePorts(); + + if( portList.count() == 0){ + return false; + } + + foreach (const QSerialPortInfo &info, portList) + { +// qDebug() << "PortName : " << info.portName() +// << "Description : " << info.description(); +// qDebug() << "Manufacturer: " << info.manufacturer(); + + if (info.portName().trimmed() == this->m_portName.trimmed() && + (info.description().toLower().contains("bootloader") || + info.description().toLower().contains("px4 bl"))) { + qDebug() << "BOOTLOADER FOUND"; + return true; + } + } + + // Not found + return false; +} + void SerialLink::loadSettings() { // Load defaults from settings @@ -445,6 +471,28 @@ bool SerialLink::hardwareConnect(QString &type) } qDebug() << "SerialLink: hardwareConnect to " << m_portName; + + if (isBootloader()) { + qDebug() << "Not connecting to a bootloader, waiting for 2nd chance"; + + const unsigned retry_limit = 12; + unsigned retries; + + for (retries = 0; retries < retry_limit; retries++) { + if (!isBootloader()) { + break; + } + QGC::SLEEP::msleep(500); + } + + // Check limit + if (retries == retry_limit) { + + // bail out + return false; + } + } + m_port = new QSerialPort(m_portName); m_port->moveToThread(this); diff --git a/src/comm/SerialLink.h b/src/comm/SerialLink.h index 6f27e4b..0534417 100644 --- a/src/comm/SerialLink.h +++ b/src/comm/SerialLink.h @@ -72,6 +72,9 @@ public: /** @brief Get a list of the currently available ports */ QList getCurrentPorts(); + /** @brief Check if the current port is a bootloader */ + bool isBootloader(); + void requestReset(); bool isConnected() const;