22 #include <QApplication> 23 #include <QStringList> 31 #define KNOTS_TO_KMH 1.852 47 if ( !
mSource->isSequential() )
53 numBytes =
mSource->bytesAvailable();
56 QgsDebugMsg(
"numBytes:" + QString::number( numBytes ) );
74 int endSentenceIndex = 0;
77 while ( ( endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) ) ) && endSentenceIndex != -1 )
79 endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) );
82 if ( endSentenceIndex == -1 )
88 if ( endSentenceIndex >= dollarIndex )
90 if ( dollarIndex != -1 )
92 QString substring =
mStringBuffer.mid( dollarIndex, endSentenceIndex );
93 QByteArray ba = substring.toLocal8Bit();
94 if ( substring.startsWith( QLatin1String(
"$GPGGA" ) ) )
99 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
101 else if ( substring.startsWith( QLatin1String(
"$GPRMC" ) ) || substring.startsWith( QLatin1String(
"$GNRMC" ) ) )
106 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
108 else if ( substring.startsWith( QLatin1String(
"$GPGSV" ) ) )
113 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
115 else if ( substring.startsWith( QLatin1String(
"$GPVTG" ) ) )
120 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
122 else if ( substring.startsWith( QLatin1String(
"$GPGSA" ) ) )
127 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
139 if ( nmea_parse_GPGGA( data, len, &result ) )
142 double longitude = result.lon;
143 if ( result.ew ==
'W' )
145 longitude = -longitude;
147 double latitude = result.lat;
148 if ( result.ns ==
'S' )
150 latitude = -latitude;
164 if ( nmea_parse_GPRMC( data, len, &result ) )
166 double longitude = result.lon;
167 if ( result.ew ==
'W' )
169 longitude = -longitude;
171 double latitude = result.lat;
172 if ( result.ns ==
'S' )
174 latitude = -latitude;
183 QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
184 QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
185 if ( date.isValid() && time.isValid() )
201 if ( nmea_parse_GPGSV( data, len, &result ) )
204 if ( result.pack_index == 1 )
212 for (
int i = 0; i < NMEA_SATINPACK; ++i )
214 nmeaSATELLITE currentSatellite = result.sat_data[i];
216 satelliteInfo.
azimuth = currentSatellite.azimuth;
217 satelliteInfo.
elevation = currentSatellite.elv;
218 satelliteInfo.
id = currentSatellite.id;
219 satelliteInfo.
inUse = currentSatellite.in_use;
220 satelliteInfo.
signal = currentSatellite.sig;
230 if ( nmea_parse_GPVTG( data, len, &result ) )
239 if ( nmea_parse_GPGSA( data, len, &result ) )
247 for (
int i = 0; i < NMEA_MAXSAT; i++ )
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
QString mStringBuffer
Store data from the device before it is processed.
void processGsaSentence(const char *data, int len)
process GSA sentence
void parseData() override
Parse available data source content.
QIODevice * mSource
Data source (e.g. serial device, socket, file,...)
void stateChanged(const QgsGpsInformation &info)
void processGsvSentence(const char *data, int len)
process GSV sentence
void processStringBuffer()
Splits mStringBuffer into sentences and calls libnmea.
QgsNmeaConnection(QIODevice *device)
Constructs a QgsNmeaConnection with given device.
void processRmcSentence(const char *data, int len)
process RMC sentence
Status mStatus
Connection status.
void processGgaSentence(const char *data, int len)
process GGA sentence
void nmeaSentenceReceived(const QString &substring)
void processVtgSentence(const char *data, int len)
process VTG sentence
Abstract base class for connection to a GPS device.