47 QList< QPair<QString, QString> > devs;
50#if defined(QT_POSITIONING_LIB)
51 devs << QPair<QString, QString>( QStringLiteral(
"internalGPS" ), tr(
"internal GPS" ) );
55 devs << QPair<QString, QString>( QStringLiteral(
"localhost:2947:" ), tr(
"local gpsd" ) );
58#if defined( HAVE_QTSERIALPORT )
59 for (
const QSerialPortInfo &p : QSerialPortInfo::availablePorts() )
61 devs << QPair<QString, QString>( p.portName(), tr(
"%1: %2" ).arg( p.portName(), p.description() ) );
69 : mUseUnsafeSignals( useUnsafeSignals )
71#if defined( HAVE_QTSERIALPORT )
72 mBaudList << QSerialPort::Baud4800 << QSerialPort::Baud9600 << QSerialPort::Baud38400 << QSerialPort::Baud57600 << QSerialPort::Baud115200;
75 if ( portName.isEmpty() )
77 QgsDebugMsgLevel( QStringLiteral(
"Attempting to autodetect GPS connection" ), 2 );
82 QgsDebugMsgLevel( QStringLiteral(
"Attempting GPS connection for %1" ).arg( portName ), 2 );
83 mPortList << QPair<QString, QString>( portName, portName );
86 mTimeoutTimer =
new QTimer(
this );
87 mTimeoutTimer->setSingleShot(
true );
88 connect( mTimeoutTimer, &QTimer::timeout,
this, &QgsGpsDetector::connectionTimeout );
129 QgsDebugMsgLevel( QStringLiteral(
"Destroying existing connection to attempt next configuration combination" ), 2 );
138 if ( mBaudIndex == mBaudList.size() )
144 if ( mPortIndex == mPortList.size() )
146 QgsDebugError( QStringLiteral(
"No more devices to try!" ) );
152 QgsDebugMsgLevel( QStringLiteral(
"Attempting connection to device %1 @ %2" ).arg( mPortIndex ).arg( mBaudIndex ), 2 );
154 if ( mPortList.at( mPortIndex ).first.contains(
':' ) )
156 mBaudIndex = mBaudList.size() - 1;
158 QStringList gpsParams = mPortList.at( mPortIndex ).first.split(
':' );
159 if ( gpsParams.size() < 3 )
161 QgsDebugError( QStringLiteral(
"If the port name contains a colon, then it should have more than one colon (e.g., host:port:device). Port name: %1" ).arg( mPortList.at( mPortIndex ).first ) );
167 QgsDebugMsgLevel( QStringLiteral(
"Connecting to GPSD device %1" ).arg( gpsParams.join(
',' ) ), 2 );
169 mConn = std::make_unique< QgsGpsdConnection >( gpsParams[0], gpsParams[1].toShort(), gpsParams[2] );
171 else if ( mPortList.at( mPortIndex ).first.contains( QLatin1String(
"internalGPS" ) ) )
173#if defined(QT_POSITIONING_LIB)
174 QgsDebugMsgLevel( QStringLiteral(
"Connecting to QtLocation service device" ), 2 );
175 mConn = std::make_unique< QgsQtLocationConnection >();
177 QgsDebugError( QStringLiteral(
"QT_POSITIONING_LIB not found and mPortList matches internalGPS, this should never happen" ) );
178 qWarning(
"QT_POSITIONING_LIB not found and mPortList matches internalGPS, this should never happen" );
183#if defined( HAVE_QTSERIALPORT )
184 auto serial = std::make_unique< QSerialPort >( mPortList.at( mPortIndex ).first );
186 serial->setBaudRate( mBaudList[ mBaudIndex ] );
188 serial->setFlowControl( QgsGpsDetector::settingsGpsFlowControl->value() );
189 serial->setParity( QgsGpsDetector::settingsGpsParity->value() );
190 serial->setDataBits( QgsGpsDetector::settingsGpsDataBits->value() );
191 serial->setStopBits( QgsGpsDetector::settingsGpsStopBits->value() );
193 QgsDebugMsgLevel( QStringLiteral(
"Connecting to serial GPS device %1 (@ %2)" ).arg( mPortList.at( mPortIndex ).first ).arg( mBaudList[ mBaudIndex ] ), 2 );
195 if ( serial->open( QIODevice::ReadOnly ) )
197 QgsDebugMsgLevel( QStringLiteral(
"Successfully opened, have a port connection ready" ), 2 );
198 mConn = std::make_unique< QgsNmeaConnection >( serial.release() );
202 QgsDebugError( QStringLiteral(
"Serial port could NOT be opened" ) );
205 QgsDebugError( QStringLiteral(
"QT5SERIALPORT not found and mPortList matches serial port, this should never happen" ) );
206 qWarning(
"QT5SERIALPORT not found and mPortList matches serial port, this should never happen" );
212 QgsDebugError( QStringLiteral(
"Got to end of connection handling loop, but have no connection!" ) );
216 QgsDebugMsgLevel( QStringLiteral(
"Have a connection, now listening for messages" ), 2 );
219 if ( mUseUnsafeSignals )
225 mTimeoutTimer->start( 2000 );
A template class for enum and flag settings entry.