19 #include "qextserialenumerator.h"
25 #ifdef HAVE_QT_MOBILITY_LOCATION
29 #include <QStringList>
35 QList< QPair<QString, QString> > devs;
38 #ifdef HAVE_QT_MOBILITY_LOCATION
39 devs << QPair<QString, QString>(
"internalGPS",
tr(
"internal GPS" ) );
42 devs << QPair<QString, QString>(
"localhost:2947:",
tr(
"local gpsd" ) );
46 foreach ( QString linuxDev, QStringList() <<
"/dev/ttyS%1" <<
"/dev/ttyUSB%1" <<
"/dev/rfcomm%1" <<
"/dev/ttyACM%1" )
48 for (
int i = 0; i < 10; ++i )
50 if ( QFileInfo( linuxDev.arg( i ) ).exists() )
52 devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
58 #ifdef __FreeBSD__ // freebsd
60 foreach ( QString freebsdDev, QStringList() <<
"/dev/cuaa%1" <<
"/dev/ucom%1" )
62 for (
int i = 0; i < 10; ++i )
64 if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
66 devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
74 QString solarisDev(
"/dev/cua/%1" );
75 for (
char i =
'a'; i <
'k'; ++i )
77 if ( QFileInfo( solarisDev.arg( i ) ).exists() )
79 devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
84 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
85 QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
86 foreach ( QextPortInfo port, ports )
88 devs << QPair<QString, QString>( port.portName, port.friendName );
100 mBaudList << BAUD4800 << BAUD9600 << BAUD38400 << BAUD57600 << BAUD115200;
102 if ( portName.isEmpty() )
108 mPortList << QPair<QString, QString>( portName, portName );
133 if ( mBaudIndex == mBaudList.size() )
139 if ( mPortIndex == mPortList.size() )
146 if ( mPortList[ mPortIndex ].first.contains(
":" ) )
148 mBaudIndex = mBaudList.size() - 1;
150 QStringList gpsParams = mPortList[ mPortIndex ].first.split(
":" );
152 Q_ASSERT( gpsParams.size() >= 3 );
154 mConn =
new QgsGpsdConnection( gpsParams[0], gpsParams[1].toShort(), gpsParams[2] );
156 else if ( mPortList[ mPortIndex ].first.contains(
"internalGPS" ) )
158 #ifdef HAVE_QT_MOBILITY_LOCATION
161 qWarning(
"QT_MOBILITY_LOCATION not found and mPortList matches internalGPS, this should never happen" );
167 QextSerialPort *serial =
new QextSerialPort( mPortList[ mPortIndex ].first, QextSerialPort::EventDriven );
169 serial->setBaudRate( mBaudList[ mBaudIndex ] );
170 serial->setFlowControl( FLOW_OFF );
171 serial->setParity( PAR_NONE );
172 serial->setDataBits( DATA_8 );
173 serial->setStopBits( STOP_1 );
175 if ( serial->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) )
187 connect( mConn, SIGNAL( destroyed( QObject * ) ),
this, SLOT(
connDestroyed( QObject * ) ) );
190 QTimer::singleShot( 2000,
this, SLOT(
advance() ) );