19 #include "qextserialport.h" 23 #include <QApplication> 24 #include <QStringList> 32 #define KNOTS_TO_KMH 1.852 48 if ( !
mSource->isSequential() )
54 numBytes =
mSource->bytesAvailable();
57 QgsDebugMsg(
"numBytes:" + QString::number( numBytes ) );
75 int endSentenceIndex = 0;
78 while ( ( endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) ) ) && endSentenceIndex != -1 )
80 endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) );
83 if ( endSentenceIndex == -1 )
89 if ( endSentenceIndex >= dollarIndex )
91 if ( dollarIndex != -1 )
93 QString substring =
mStringBuffer.mid( dollarIndex, endSentenceIndex );
94 QByteArray ba = substring.toLocal8Bit();
95 if ( substring.startsWith( QLatin1String(
"$GPGGA" ) ) )
100 QgsDebugMsg(
"*******************GPS data received****************" );
102 else if ( substring.startsWith( QLatin1String(
"$GPRMC" ) ) || substring.startsWith( QLatin1String(
"$GNRMC" ) ) )
107 QgsDebugMsg(
"*******************GPS data received****************" );
109 else if ( substring.startsWith( QLatin1String(
"$GPGSV" ) ) )
114 QgsDebugMsg(
"*******************GPS data received****************" );
116 else if ( substring.startsWith( QLatin1String(
"$GPVTG" ) ) )
121 QgsDebugMsg(
"*******************GPS data received****************" );
123 else if ( substring.startsWith( QLatin1String(
"$GPGSA" ) ) )
128 QgsDebugMsg(
"*******************GPS data received****************" );
140 if ( nmea_parse_GPGGA( data, len, &result ) )
143 double longitude = result.lon;
144 if ( result.ew ==
'W' )
146 longitude = -longitude;
148 double latitude = result.lat;
149 if ( result.ns ==
'S' )
151 latitude = -latitude;
165 if ( nmea_parse_GPRMC( data, len, &result ) )
167 double longitude = result.lon;
168 if ( result.ew ==
'W' )
170 longitude = -longitude;
172 double latitude = result.lat;
173 if ( result.ns ==
'S' )
175 latitude = -latitude;
184 QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
185 QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
186 if ( date.isValid() && time.isValid() )
202 if ( nmea_parse_GPGSV( data, len, &result ) )
205 if ( result.pack_index == 1 )
213 for (
int i = 0; i < NMEA_SATINPACK; ++i )
215 nmeaSATELLITE currentSatellite = result.sat_data[i];
217 satelliteInfo.
azimuth = currentSatellite.azimuth;
218 satelliteInfo.
elevation = currentSatellite.elv;
219 satelliteInfo.
id = currentSatellite.id;
220 satelliteInfo.
inUse = currentSatellite.in_use;
221 satelliteInfo.
signal = currentSatellite.sig;
231 if ( nmea_parse_GPVTG( data, len, &result ) )
240 if ( nmea_parse_GPGSA( data, len, &result ) )
248 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.