From 891e1d564856913dbd8b63089783c069186d1d67 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Thu, 21 Jan 2016 11:56:51 -0800 Subject: [PATCH] Prompt for missing SD Card --- src/Vehicle/Vehicle.h | 2 ++ src/comm/LinkManager.cc | 49 ++++++++++++++++++++++++++++++++++++++--- src/comm/LinkManager.h | 5 +++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 64d2334aa..08e3df9c2 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 d57611322..68e576136 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 28c2f51c7..b7c933232 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; -- 2.22.0