22 #include <QApplication>
23 #include <QStringList>
34 #define KNOTS_TO_KMH 1.852
50 if ( !
mSource->isSequential() )
56 numBytes =
mSource->bytesAvailable();
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 const QString substring =
mStringBuffer.mid( dollarIndex, endSentenceIndex );
96 QByteArray ba = substring.toLocal8Bit();
97 if ( substring.startsWith( QLatin1String(
"$GPGGA" ) ) || substring.startsWith( QLatin1String(
"$GNGGA" ) ) )
102 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
104 else if ( substring.startsWith( QLatin1String(
"$GPRMC" ) ) || substring.startsWith( QLatin1String(
"$GNRMC" ) ) )
109 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
111 else if ( substring.startsWith( QLatin1String(
"$GPGSV" ) ) || substring.startsWith( QLatin1String(
"$GNGSV" ) ) )
116 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
118 else if ( substring.startsWith( QLatin1String(
"$GPVTG" ) ) || substring.startsWith( QLatin1String(
"$GNVTG" ) ) )
123 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
125 else if ( substring.startsWith( QLatin1String(
"$GPGSA" ) ) || substring.startsWith( QLatin1String(
"$GNGSA" ) ) )
130 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
132 else if ( substring.startsWith( QLatin1String(
"$GPGST" ) ) || substring.startsWith( QLatin1String(
"$GNGST" ) ) )
137 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
139 else if ( substring.startsWith( QLatin1String(
"$GPHDT" ) ) || substring.startsWith( QLatin1String(
"$GNHDT" ) ) )
144 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
146 else if ( substring.startsWith( QLatin1String(
"$HCHDG" ) ) )
151 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
153 else if ( substring.startsWith( QLatin1String(
"$HCHDT" ) ) )
158 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
162 QgsDebugMsgLevel( QStringLiteral(
"unknown nmea sentence: %1" ).arg( substring ), 2 );
174 if ( nmea_parse_GPGGA( data, len, &result ) )
177 double longitude = result.lon;
178 if ( result.ew ==
'W' )
180 longitude = -longitude;
182 double latitude = result.lat;
183 if ( result.ns ==
'S' )
185 latitude = -latitude;
194 if ( result.sig >= 0 && result.sig <= 8 )
210 if ( nmea_parse_GPGST( data, len, &result ) )
213 const double sig_lat = result.sig_lat;
214 const double sig_lon = result.sig_lon;
215 const double sig_alt = result.sig_alt;
229 if ( nmea_parse_GPHDT( data, len, &result ) )
238 if ( nmea_parse_HCHDG( data, len, &result ) )
241 if ( result.ew_variation ==
'E' )
251 if ( nmea_parse_HCHDT( data, len, &result ) )
260 if ( nmea_parse_GPRMC( data, len, &result ) )
262 double longitude = result.lon;
263 if ( result.ew ==
'W' )
265 longitude = -longitude;
267 double latitude = result.lat;
268 if ( result.ns ==
'S' )
270 latitude = -latitude;
275 if ( !std::isnan( result.direction ) )
280 const QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
281 const QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
282 if ( date.isValid() && time.isValid() )
295 if ( result.status ==
'A' )
297 if ( result.mode ==
'A' )
302 else if ( result.mode ==
'D' )
307 else if ( result.mode ==
'P' )
312 else if ( result.mode ==
'R' )
317 else if ( result.mode ==
'F' )
322 else if ( result.mode ==
'E' )
327 else if ( result.mode ==
'M' )
332 else if ( result.mode ==
'S' )
354 if ( nmea_parse_GPGSV( data, len, &result ) )
357 if ( result.pack_index == 1 )
365 for (
int i = 0; i < NMEA_SATINPACK; ++i )
367 const nmeaSATELLITE currentSatellite = result.sat_data[i];
369 satelliteInfo.
azimuth = currentSatellite.azimuth;
370 satelliteInfo.
elevation = currentSatellite.elv;
371 satelliteInfo.
id = currentSatellite.id;
372 satelliteInfo.
inUse = currentSatellite.in_use;
373 satelliteInfo.
signal = currentSatellite.sig;
383 if ( nmea_parse_GPVTG( data, len, &result ) )
392 if ( nmea_parse_GPGSA( data, len, &result ) )
400 for (
int i = 0; i < NMEA_MAXSAT; i++ )