Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Comms/LinkManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ void LinkManager::_updateAutoConnectLinks()
_reconnectAutoConnectLinks();

// check to see if nmea gps is configured for UDP input, if so, set it up to connect
if (_autoConnectSettings->autoConnectNmeaPort()->cookedValueString() == "UDP Port") {
const QString nmeaPortValue = _autoConnectSettings->autoConnectNmeaPort()->cookedValueString();
if (nmeaPortValue == "UDP Port") {
if ((_nmeaSocket->localPort() != _autoConnectSettings->nmeaUdpPort()->rawValue().toUInt()) || (_nmeaSocket->state() != UdpIODevice::BoundState)) {
Comment on lines +512 to 514
qCDebug(LinkManagerLog) << "Changing port for UDP NMEA stream";
_nmeaSocket->close();
Expand All @@ -526,6 +527,22 @@ void LinkManager::_updateAutoConnectLinks()
#endif
} else {
_nmeaSocket->close();

// Only tear things down when NMEA is switched off entirely ("Disabled"). Any other
// value is a serial NMEA port, which is set up by _addSerialAutoConnectLink() below;
// touching _nmeaPort / the position source here would break it on every tick.
if (nmeaPortValue == "Disabled") {
#ifndef QGC_NO_SERIAL_LINK
if (_nmeaPort) {
_nmeaPort->close();
delete _nmeaPort;
_nmeaPort = nullptr;
_nmeaDeviceName = "";
}
#endif
// Revert QGCPositionManager to the integrated GPS if it was using an NMEA source
QGCPositionManager::instance()->resetNmeaSourceDevice();
}
}

#ifndef QGC_NO_SERIAL_LINK
Expand Down
20 changes: 20 additions & 0 deletions src/PositionManager/PositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ void QGCPositionManager::setNmeaSourceDevice(QIODevice *device)
_setPositionSource(QGCPositionManager::NmeaGPS);
}

void QGCPositionManager::resetNmeaSourceDevice()
{
if (!_nmeaSource) {
return;
}

if (_currentSource == _nmeaSource) {
// Switch away while the NMEA source is still valid so _setPositionSource() can run its
// usual cleanup (stop updates, disconnect, and reset the stale GCS position/accuracy)
// before we delete it. Falls back to the platform's default source (e.g. integrated GPS).
_setPositionSource(QGCPositionManager::InternalGPS);
} else {
Comment on lines +110 to +115
_nmeaSource->stopUpdates();
(void) disconnect(_nmeaSource);
}

delete _nmeaSource;
_nmeaSource = nullptr;
}

void QGCPositionManager::_positionUpdated(const QGeoPositionInfo &update)
{
_geoPositionInfo = update;
Expand Down
3 changes: 3 additions & 0 deletions src/PositionManager/PositionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class QGCPositionManager : public QObject
int updateInterval() const { return _updateInterval; }

void setNmeaSourceDevice(QIODevice *device);
/// Tears down any active NMEA source and falls back to the platform's default
/// position source (e.g. the integrated Android GPS).
void resetNmeaSourceDevice();

signals:
void gcsPositionChanged(QGeoCoordinate gcsPosition);
Expand Down
Loading