19#include "moc_qgsgpsdetector.cpp" 
   27#if defined(QT_POSITIONING_LIB) 
   35#if defined( HAVE_QTSERIALPORT ) 
   36#include <QSerialPortInfo> 
   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 );
 
 
   98  if ( mUseUnsafeSignals )
 
  100    QgsDebugError( QStringLiteral( 
"QgsGpsDetector::takeConnection() incorrectly called when useUnsafeSignals option is in effect" ) );
 
  108    mConn->disconnect( 
this );
 
  114    QgsDebugMsgLevel( QStringLiteral( 
"Detected GPS connection is being taken by caller" ), 2 );
 
  118    QgsDebugError( QStringLiteral( 
"Something is trying to take the GPS connection, but it doesn't exist!" ) );
 
  122  return mConn.release();
 
 
  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 );
 
 
  234    mTimeoutTimer->stop();
 
  237    QgsDebugError( QStringLiteral( 
"Got information, but CONNECTION WAS DESTROYED EXTERNALLY!" ) );
 
  242    mTimeoutTimer->stop();
 
  248    QgsDebugMsgLevel( QStringLiteral( 
"Connection status IS GPSDataReceived" ), 2 );
 
  250    if ( mUseUnsafeSignals )
 
  267    QgsDebugMsgLevel( QStringLiteral( 
"Connection status is NOT GPSDataReceived. It is %1" ).arg( mConn->status() ), 2 );
 
 
  271void QgsGpsDetector::connectionTimeout()
 
  273  QgsDebugMsgLevel( QStringLiteral( 
"No data received within max listening time" ), 2 );
 
  279  QgsDebugError( QStringLiteral( 
"CONNECTION WAS DESTROYED EXTERNALLY!" ) );
 
  282  if ( obj == mConn.get() )
 
 
Abstract base class for connections to a GPS device.
 
void stateChanged(const QgsGpsInformation &info)
Emitted whenever the GPS state is changed.
 
~QgsGpsDetector() override
 
void connDestroyed(QObject *)
 
void detected(const QgsGpsInformation &)
 
static QList< QPair< QString, QString > > availablePorts()
 
QgsGpsConnection * takeConnection()
Returns the detected GPS connection, and removes it from the detector.
 
void connectionDetected()
Emitted when a GPS connection is successfully detected.
 
QgsGpsDetector(const QString &portName=QString(), bool useUnsafeSignals=true)
Constructor for QgsGpsDetector.
 
void detectionFailed()
Emitted when the detector could not find a valid GPS connection.
 
A template class for enum and flag settings entry.
 
static QgsSettingsTreeNode * sTreeGps
 
#define Q_NOWARN_DEPRECATED_POP
 
#define Q_NOWARN_DEPRECATED_PUSH
 
#define QgsDebugMsgLevel(str, level)
 
#define QgsDebugError(str)