22 #include <QApplication> 23 #include <QStringList> 34 #define KNOTS_TO_KMH 1.852 50 if ( !
mSource->isSequential() )
56 numBytes =
mSource->bytesAvailable();
59 QgsDebugMsg(
"numBytes:" + QString::number( numBytes ) );
77 int endSentenceIndex = 0;
80 while ( ( endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) ) ) && endSentenceIndex != -1 )
82 endSentenceIndex =
mStringBuffer.indexOf( QLatin1String(
"\r\n" ) );
85 if ( endSentenceIndex == -1 )
91 if ( endSentenceIndex >= dollarIndex )
93 if ( dollarIndex != -1 )
95 QString substring =
mStringBuffer.mid( dollarIndex, endSentenceIndex );
96 QByteArray ba = substring.toLocal8Bit();
97 if ( substring.startsWith( QLatin1String(
"$GPGGA" ) ) )
102 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
104 else if ( substring.startsWith( QLatin1String(
"$GPRMC" ) ) || substring.startsWith( QLatin1String(
"$GNRMC" ) ) )
109 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
111 else if ( substring.startsWith( QLatin1String(
"$GPGSV" ) ) )
116 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
118 else if ( substring.startsWith( QLatin1String(
"$GPVTG" ) ) )
123 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
125 else if ( substring.startsWith( QLatin1String(
"$GPGSA" ) ) )
130 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
132 else if ( substring.startsWith( QLatin1String(
"$GPGST" ) ) )
137 QgsDebugMsg( QStringLiteral(
"*******************GPS data received****************" ) );
149 if ( nmea_parse_GPGGA( data, len, &result ) )
152 double longitude = result.lon;
153 if ( result.ew ==
'W' )
155 longitude = -longitude;
157 double latitude = result.lat;
158 if ( result.ns ==
'S' )
160 latitude = -latitude;
174 if ( nmea_parse_GPGST( data, len, &result ) )
177 double sig_lat = result.sig_lat;
178 double sig_lon = result.sig_lon;
179 double sig_alt = result.sig_alt;
191 if ( nmea_parse_GPRMC( data, len, &result ) )
193 double longitude = result.lon;
194 if ( result.ew ==
'W' )
196 longitude = -longitude;
198 double latitude = result.lat;
199 if ( result.ns ==
'S' )
201 latitude = -latitude;
210 QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
211 QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
212 if ( date.isValid() && time.isValid() )
228 if ( nmea_parse_GPGSV( data, len, &result ) )
231 if ( result.pack_index == 1 )
239 for (
int i = 0; i < NMEA_SATINPACK; ++i )
241 nmeaSATELLITE currentSatellite = result.sat_data[i];
243 satelliteInfo.
azimuth = currentSatellite.azimuth;
244 satelliteInfo.
elevation = currentSatellite.elv;
245 satelliteInfo.
id = currentSatellite.id;
246 satelliteInfo.
inUse = currentSatellite.in_use;
247 satelliteInfo.
signal = currentSatellite.sig;
257 if ( nmea_parse_GPVTG( data, len, &result ) )
266 if ( nmea_parse_GPGSA( data, len, &result ) )
274 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.
void processGstSentence(const char *data, int len)
process GST sentence
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.