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 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;
199 if ( nmea_parse_GPGST( data, len, &result ) )
202 double sig_lat = result.sig_lat;
203 double sig_lon = result.sig_lon;
204 double sig_alt = result.sig_alt;
216 if ( nmea_parse_GPHDT( data, len, &result ) )
225 if ( nmea_parse_HCHDG( data, len, &result ) )
228 if ( result.ew_variation ==
'E' )
238 if ( nmea_parse_HCHDT( data, len, &result ) )
247 if ( nmea_parse_GPRMC( data, len, &result ) )
249 double longitude = result.lon;
250 if ( result.ew ==
'W' )
252 longitude = -longitude;
254 double latitude = result.lat;
255 if ( result.ns ==
'S' )
257 latitude = -latitude;
262 if ( !std::isnan( result.direction ) )
267 QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
268 QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
269 if ( date.isValid() && time.isValid() )
285 if ( nmea_parse_GPGSV( data, len, &result ) )
288 if ( result.pack_index == 1 )
296 for (
int i = 0; i < NMEA_SATINPACK; ++i )
298 nmeaSATELLITE currentSatellite = result.sat_data[i];
300 satelliteInfo.
azimuth = currentSatellite.azimuth;
301 satelliteInfo.
elevation = currentSatellite.elv;
302 satelliteInfo.
id = currentSatellite.id;
303 satelliteInfo.
inUse = currentSatellite.in_use;
304 satelliteInfo.
signal = currentSatellite.sig;
314 if ( nmea_parse_GPVTG( data, len, &result ) )
323 if ( nmea_parse_GPGSA( data, len, &result ) )
331 for (
int i = 0; i < NMEA_MAXSAT; i++ )