diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 64d2334aaf9de7fe3ced886d2345793e5e99be9e..08e3df9c2003e2768ccdb130ffcf8220a514ce5e 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -282,6 +282,8 @@ public: static const int cMaxRcChannels = 18; + bool containsLink(LinkInterface* link) { return _links.contains(link); } + public slots: void setLatitude(double latitude); void setLongitude(double longitude); diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index d5761132204a08700651a071d71e6d2a83fa22fb..68e57613641f3c9d88f8e18e633d5214b7e5a3b6 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -87,6 +87,10 @@ LinkManager::LinkManager(QGCApplication* app) _autoconnectPixhawk = settings.value(_autoconnectPixhawkKey, true).toBool(); _autoconnect3DRRadio = settings.value(_autoconnect3DRRadioKey, true).toBool(); _autoconnectPX4Flow = settings.value(_autoconnectPX4FlowKey, true).toBool(); + + _activeLinkCheckTimer.setInterval(_activeLinkCheckTimeoutMSecs); + _activeLinkCheckTimer.setSingleShot(false); + connect(&_activeLinkCheckTimer, &QTimer::timeout, this, &LinkManager::_activeLinkCheck); } LinkManager::~LinkManager() @@ -112,8 +116,19 @@ LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config) switch(config->type()) { #ifndef __ios__ case LinkConfiguration::TypeSerial: - pLink = new SerialLink(dynamic_cast(config)); - break; + { + SerialConfiguration* serialConfig = dynamic_cast(config); + if (serialConfig) { + pLink = new SerialLink(serialConfig); + if (serialConfig->usbDirect()) { + _activeLinkCheckList.append(pLink); + if (!_activeLinkCheckTimer.isActive()) { + _activeLinkCheckTimer.start(); + } + } + } + } + break; #endif case LinkConfiguration::TypeUdp: pLink = new UDPLink(dynamic_cast(config)); @@ -447,7 +462,7 @@ void LinkManager::_updateAutoConnectLinks(void) break; } } - if (!foundUDP) { + if (!foundUDP && _autoconnectUDP) { qCDebug(LinkManagerLog) << "New auto-connect UDP port added"; UDPConfiguration* udpConfig = new UDPConfiguration(_defaultUPDLinkName); udpConfig->setLocalPort(QGC_UDP_LOCAL_PORT); @@ -824,3 +839,31 @@ bool LinkManager::isBluetoothAvailable(void) { return qgcApp()->isBluetoothAvailable(); } + +void LinkManager::_activeLinkCheck(void) +{ + bool found = false; + + if (_activeLinkCheckList.count() != 0) { + LinkInterface* link = _activeLinkCheckList.takeFirst(); + if (_links.contains(link) && link->isConnected()) { + // Make sure there is a vehicle on the link + QmlObjectListModel* vehicles = _toolbox->multiVehicleManager()->vehicles(); + for (int i=0; icount(); i++) { + Vehicle* vehicle = qobject_cast(vehicles->get(i)); + if (vehicle->containsLink(link)) { + found = true; + break; + } + } + } + } + + if (_activeLinkCheckList.count() == 0) { + _activeLinkCheckTimer.stop(); + } + + if (!found) { + qgcApp()->showMessage("You have connected to a Vehicle which does not have an SD Card inserted. Please insert an SD card and try again."); + } +} diff --git a/src/comm/LinkManager.h b/src/comm/LinkManager.h index 28c2f51c705e42ca57d8200feaffe8018e9e680f..b7c933232d7f6041449ad9efa98e4668cb1ff255 100644 --- a/src/comm/LinkManager.h +++ b/src/comm/LinkManager.h @@ -210,6 +210,7 @@ signals: private slots: void _linkConnected(void); void _linkDisconnected(void); + void _activeLinkCheck(void); private: bool _connectionsSuspendedMsg(void); @@ -243,6 +244,10 @@ private: bool _autoconnect3DRRadio; bool _autoconnectPX4Flow; + QTimer _activeLinkCheckTimer; // Timer which checks for a vehicle showing up on a usb direct link + QList _activeLinkCheckList; // List of links we are waiting for a vehicle to show up on + static const int _activeLinkCheckTimeoutMSecs = 7000; + static const char* _settingsGroup; static const char* _autoconnectUDPKey; static const char* _autoconnectPixhawkKey;