19 #include "qextserialenumerator.h" 25 #if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB) 29 #include <QStringList> 35 QList< QPair<QString, QString> > devs;
38 #if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB) 39 devs << QPair<QString, QString>( QStringLiteral(
"internalGPS" ), tr(
"internal GPS" ) );
43 devs << QPair<QString, QString>( QStringLiteral(
"localhost:2947:" ), tr(
"local gpsd" ) );
47 const QStringList devices { QStringLiteral(
"/dev/ttyS%1" ),
48 QStringLiteral(
"/dev/ttyUSB%1" ),
49 QStringLiteral(
"/dev/rfcomm%1" ), QStringLiteral(
"/dev/ttyACM%1" ) };
50 for (
const QString &linuxDev : devices )
52 for (
int i = 0; i < 10; ++i )
54 if ( QFileInfo::exists( linuxDev.arg( i ) ) )
56 devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
64 Q_FOREACH (
const QString &freebsdDev, QStringList() <<
"/dev/cuaa%1" <<
"/dev/ucom%1" )
66 for (
int i = 0; i < 10; ++i )
68 if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
70 devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
78 QString solarisDev(
"/dev/cua/%1" );
79 for (
char i =
'a'; i <
'k'; ++i )
81 if ( QFileInfo( solarisDev.arg( i ) ).exists() )
83 devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
88 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) 89 QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
90 Q_FOREACH ( QextPortInfo port, ports )
92 devs << QPair<QString, QString>( port.portName, port.friendName );
104 mBaudList << BAUD4800 << BAUD9600 << BAUD38400 << BAUD57600 << BAUD115200;
106 if ( portName.isEmpty() )
112 mPortList << QPair<QString, QString>( portName, portName );
137 if ( mBaudIndex == mBaudList.size() )
143 if ( mPortIndex == mPortList.size() )
150 if ( mPortList.at( mPortIndex ).first.contains(
':' ) )
152 mBaudIndex = mBaudList.size() - 1;
154 QStringList gpsParams = mPortList.at( mPortIndex ).first.split(
':' );
156 Q_ASSERT( gpsParams.size() >= 3 );
158 mConn =
new QgsGpsdConnection( gpsParams[0], gpsParams[1].toShort(), gpsParams[2] );
160 else if ( mPortList.at( mPortIndex ).first.contains( QLatin1String(
"internalGPS" ) ) )
162 #if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB) 165 qWarning(
"QT_MOBILITY_LOCATION not found and mPortList matches internalGPS, this should never happen" );
170 QextSerialPort *serial =
new QextSerialPort( mPortList.at( mPortIndex ).first, QextSerialPort::EventDriven );
172 serial->setBaudRate( mBaudList[ mBaudIndex ] );
173 serial->setFlowControl( FLOW_OFF );
174 serial->setParity( PAR_NONE );
175 serial->setDataBits( DATA_8 );
176 serial->setStopBits( STOP_1 );
178 if ( serial->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) )
Evaluates NMEA sentences coming from gpsd.
Class to detect the GPS port.
void detected(const QgsGpsInformation &)
~QgsGpsDetector() override
void connDestroyed(QObject *)
void stateChanged(const QgsGpsInformation &info)
Evaluates NMEA sentences coming from a GPS device.
Status status() const
Returns the status. Possible state are not connected, connected, data received.
static QList< QPair< QString, QString > > availablePorts()
QgsGpsDetector(const QString &portName)
Abstract base class for connection to a GPS device.