1717#ifndef QGC_NO_SERIAL_LINK
1818#include " SerialLink.h"
1919#include " GPSManager.h"
20- #include " PositionManager.h"
21- #include " UdpIODevice.h"
22- #include " GPSRtk.h"
2320#endif
2421
2522#ifdef QT_DEBUG
@@ -38,9 +35,6 @@ LinkManager::LinkManager(QObject *parent)
3835 : QObject(parent)
3936 , _portListTimer(new QTimer(this ))
4037 , _qmlConfigurations(new QmlObjectListModel(this ))
41- #ifndef QGC_NO_SERIAL_LINK
42- , _nmeaSocket(new UdpIODevice(this ))
43- #endif
4438{
4539 qCDebug (LinkManagerLog) << this ;
4640
@@ -432,26 +426,6 @@ void LinkManager::_updateAutoConnectLinks()
432426 _addUDPAutoConnectLink ();
433427 _addMAVLinkForwardingLink ();
434428
435- // check to see if nmea gps is configured for UDP input, if so, set it up to connect
436- if (_autoConnectSettings->autoConnectNmeaPort ()->cookedValueString () == " UDP Port" ) {
437- if ((_nmeaSocket->localPort () != _autoConnectSettings->nmeaUdpPort ()->rawValue ().toUInt ()) || (_nmeaSocket->state () != UdpIODevice::BoundState)) {
438- qCDebug (LinkManagerLog) << " Changing port for UDP NMEA stream" ;
439- _nmeaSocket->close ();
440- _nmeaSocket->bind (QHostAddress::AnyIPv4, _autoConnectSettings->nmeaUdpPort ()->rawValue ().toUInt ());
441- QGCPositionManager::instance ()->setNmeaSourceDevice (_nmeaSocket);
442- }
443- #ifndef QGC_NO_SERIAL_LINK
444- if (_nmeaPort) {
445- _nmeaPort->close ();
446- delete _nmeaPort;
447- _nmeaPort = nullptr ;
448- _nmeaDeviceName = " " ;
449- }
450- #endif
451- } else {
452- _nmeaSocket->close ();
453- }
454-
455429#ifndef QGC_NO_SERIAL_LINK
456430 _addSerialAutoConnectLink ();
457431#endif
@@ -758,27 +732,7 @@ void LinkManager::_addSerialAutoConnectLink()
758732 QGCSerialPortInfo::BoardType_t boardType;
759733 QString boardName;
760734
761- // check to see if nmea gps is configured for current Serial port, if so, set it up to connect
762- if (portInfo.systemLocation ().trimmed () == _autoConnectSettings->autoConnectNmeaPort ()->cookedValueString ()) {
763- if (portInfo.systemLocation ().trimmed () != _nmeaDeviceName) {
764- _nmeaDeviceName = portInfo.systemLocation ().trimmed ();
765- qCDebug (LinkManagerLog) << " Configuring nmea port" << _nmeaDeviceName;
766- QSerialPort* newPort = new QSerialPort (portInfo, this );
767- _nmeaBaud = _autoConnectSettings->autoConnectNmeaBaud ()->cookedValue ().toUInt ();
768- newPort->setBaudRate (static_cast <qint32>(_nmeaBaud));
769- qCDebug (LinkManagerLog) << " Configuring nmea baudrate" << _nmeaBaud;
770- // This will stop polling old device if previously set
771- QGCPositionManager::instance ()->setNmeaSourceDevice (newPort);
772- if (_nmeaPort) {
773- delete _nmeaPort;
774- }
775- _nmeaPort = newPort;
776- } else if (_autoConnectSettings->autoConnectNmeaBaud ()->cookedValue ().toUInt () != _nmeaBaud) {
777- _nmeaBaud = _autoConnectSettings->autoConnectNmeaBaud ()->cookedValue ().toUInt ();
778- _nmeaPort->setBaudRate (static_cast <qint32>(_nmeaBaud));
779- qCDebug (LinkManagerLog) << " Configuring nmea baudrate" << _nmeaBaud;
780- }
781- } else if (portInfo.getBoardInfo (boardType, boardName)) {
735+ if (portInfo.getBoardInfo (boardType, boardName)) {
782736 // Should we be auto-connecting to this board type?
783737 if (!_allowAutoConnectToBoard (boardType)) {
784738 continue ;
@@ -789,7 +743,7 @@ void LinkManager::_addSerialAutoConnectLink()
789743 qCDebug (LinkManagerLog) << " Waiting for bootloader to finish" << portInfo.systemLocation ();
790744 continue ;
791745 }
792- if (_portAlreadyConnected (portInfo.systemLocation ()) || (_autoConnectRTKPort == portInfo.systemLocation ())) {
746+ if (_portAlreadyConnected (portInfo.systemLocation ()) || _autoConnectRTKPorts. contains ( portInfo.systemLocation ())) {
793747 qCDebug (LinkManagerVerboseLog) << " Skipping existing autoconnect" << portInfo.systemLocation ();
794748 } else if (!_autoconnectPortWaitList.contains (portInfo.systemLocation ())) {
795749 // We don't connect to the port the first time we see it. The ability to correctly detect whether we
@@ -812,9 +766,9 @@ void LinkManager::_addSerialAutoConnectLink()
812766 pSerialConfig = new SerialConfiguration (tr (" %1 on %2 (AutoConnect)" ).arg (boardName, portInfo.portName ().trimmed ()));
813767 break ;
814768 case QGCSerialPortInfo::BoardTypeRTKGPS:
815- qCDebug (LinkManagerLog) << " RTK GPS auto-connected" << portInfo.portName ().trimmed ();
816- _autoConnectRTKPort = portInfo.systemLocation ();
817- GPSManager::instance ()->gpsRtk ()-> connectGPS (portInfo.systemLocation (), boardName);
769+ qCDebug (LinkManagerLog) << " RTK GPS auto-connected" << portInfo.portName ().trimmed () << boardName ;
770+ _autoConnectRTKPorts. append ( portInfo.systemLocation () );
771+ GPSManager::instance ()->connectGPS (portInfo.systemLocation (), boardName);
818772 break ;
819773 default :
820774 qCWarning (LinkManagerLog) << " Internal error: Unknown board type" << boardType;
@@ -835,11 +789,14 @@ void LinkManager::_addSerialAutoConnectLink()
835789 }
836790 }
837791
838- // Check for RTK GPS connection gone
839- if (!_autoConnectRTKPort.isEmpty () && !currentPorts.contains (_autoConnectRTKPort)) {
840- qCDebug (LinkManagerLog) << " RTK GPS disconnected" << _autoConnectRTKPort;
841- GPSManager::instance ()->gpsRtk ()->disconnectGPS ();
842- _autoConnectRTKPort.clear ();
792+ // Check for RTK GPS connections gone
793+ for (int i = _autoConnectRTKPorts.size () - 1 ; i >= 0 ; --i) {
794+ const QString &port = _autoConnectRTKPorts.at (i);
795+ if (!currentPorts.contains (port)) {
796+ qCDebug (LinkManagerLog) << " RTK GPS disconnected" << port;
797+ GPSManager::instance ()->disconnectGPS (port);
798+ _autoConnectRTKPorts.removeAt (i);
799+ }
843800 }
844801}
845802
@@ -862,7 +819,7 @@ bool LinkManager::_allowAutoConnectToBoard(QGCSerialPortInfo::BoardType_t boardT
862819 }
863820 break ;
864821 case QGCSerialPortInfo::BoardTypeRTKGPS:
865- if (_autoConnectSettings->autoConnectRTKGPS ()->rawValue ().toBool () && !GPSManager::instance ()->gpsRtk ()-> connected ()) {
822+ if (_autoConnectSettings->autoConnectRTKGPS ()->rawValue ().toBool () && !GPSManager::instance ()->connected ()) {
866823 return true ;
867824 }
868825 break ;
0 commit comments