22#include <QApplication>
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 );
112 else if ( substring.startsWith( QLatin1String(
"$GPGSV" ) ) || substring.startsWith( QLatin1String(
"$GNGSV" ) ) || substring.startsWith( QLatin1String(
"$GLGSV" ) ) || substring.startsWith( QLatin1String(
"$GAGSV" ) ) || substring.startsWith( QLatin1String(
"$GBGSV" ) ) || substring.startsWith( QLatin1String(
"$GQGSV" ) ) )
117 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
119 else if ( substring.startsWith( QLatin1String(
"$GPVTG" ) ) || substring.startsWith( QLatin1String(
"$GNVTG" ) ) )
124 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
126 else if ( substring.startsWith( QLatin1String(
"$GPGSA" ) ) || substring.startsWith( QLatin1String(
"$GNGSA" ) ) )
131 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
133 else if ( substring.startsWith( QLatin1String(
"$GPGST" ) ) || substring.startsWith( QLatin1String(
"$GNGST" ) ) )
138 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
140 else if ( substring.startsWith( QLatin1String(
"$GPHDT" ) ) || substring.startsWith( QLatin1String(
"$GNHDT" ) ) )
145 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
147 else if ( substring.startsWith( QLatin1String(
"$HCHDG" ) ) )
152 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
154 else if ( substring.startsWith( QLatin1String(
"$HCHDT" ) ) )
159 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
163 QgsDebugMsgLevel( QStringLiteral(
"unknown nmea sentence: %1" ).arg( substring ), 2 );
180 if ( nmea_parse_GPGGA( data, len, &result ) )
183 double longitude = result.lon;
184 if ( result.ew ==
'W' )
186 longitude = -longitude;
188 double latitude = result.lat;
189 if ( result.ns ==
'S' )
191 latitude = -latitude;
200 if ( result.sig >= 0 && result.sig <= 8 )
216 if ( nmea_parse_GPGST( data, len, &result ) )
219 const double sig_lat = result.sig_lat;
220 const double sig_lon = result.sig_lon;
221 const double sig_alt = result.sig_alt;
235 if ( nmea_parse_GPHDT( data, len, &result ) )
244 if ( nmea_parse_HCHDG( data, len, &result ) )
247 if ( result.ew_variation ==
'E' )
257 if ( nmea_parse_HCHDT( data, len, &result ) )
266 if ( nmea_parse_GPRMC( data, len, &result ) )
268 double longitude = result.lon;
269 if ( result.ew ==
'W' )
271 longitude = -longitude;
273 double latitude = result.lat;
274 if ( result.ns ==
'S' )
276 latitude = -latitude;
281 if ( !std::isnan( result.direction ) )
286 const QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
287 const QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
288 if ( date.isValid() && time.isValid() )
301 if ( result.status ==
'A' )
303 if ( result.mode ==
'A' )
308 else if ( result.mode ==
'D' )
313 else if ( result.mode ==
'P' )
318 else if ( result.mode ==
'R' )
323 else if ( result.mode ==
'F' )
328 else if ( result.mode ==
'E' )
333 else if ( result.mode ==
'M' )
338 else if ( result.mode ==
'S' )
360 if ( nmea_parse_GPGSV( data, len, &result ) )
368 for (
int i = 0; i < NMEA_SATINPACK; ++i )
370 const nmeaSATELLITE currentSatellite = result.sat_data[i];
372 satelliteInfo.
azimuth = currentSatellite.azimuth;
373 satelliteInfo.
elevation = currentSatellite.elv;
374 satelliteInfo.
id = currentSatellite.id;
375 satelliteInfo.
inUse =
false;
380 satelliteInfo.
inUse =
true;
383 satelliteInfo.
signal = currentSatellite.sig;
384 satelliteInfo.
satType = result.pack_type;
385 if ( satelliteInfo.
satType ==
'P' && satelliteInfo.
id > 32 )
388 satelliteInfo.
id = currentSatellite.id + 87;
391 bool idAlreadyPresent =
false;
396 if ( existingSatInView.id == currentSatellite.id )
398 idAlreadyPresent =
true;
404 if ( currentSatellite.sig > 0 )
406 satelliteInfo.
inUse = 1;
408 if ( !idAlreadyPresent && currentSatellite.azimuth > 0 && currentSatellite.elv > 0 )
420 if ( nmea_parse_GPVTG( data, len, &result ) )
429 if ( nmea_parse_GPGSA( data, len, &result ) )
437 for (
int i = 0; i < NMEA_MAXSAT; i++ )
439 if ( result.sat_prn[ i ] > 0 )
GpsQualityIndicator
GPS signal quality indicator.
@ RTK
Real-time-kynematic.
@ Simulation
Simulation mode.
@ FloatRTK
Float real-time-kynematic.
@ Manual
Manual input mode.
Abstract base class for connection to a GPS device.
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
void nmeaSentenceReceived(const QString &substring)
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
Status mStatus
Connection status.
void stateChanged(const QgsGpsInformation &info)
void processVtgSentence(const char *data, int len)
process VTG sentence
void processRmcSentence(const char *data, int len)
process RMC sentence
void processHchdtSentence(const char *data, int len)
process HCHDT sentence
void parseData() override
Parse available data source content.
void processHchdgSentence(const char *data, int len)
process HCHDG sentence
void processGgaSentence(const char *data, int len)
process GGA sentence
void processGsvSentence(const char *data, int len)
process GSV sentence
void processGstSentence(const char *data, int len)
process GST sentence
void processHdtSentence(const char *data, int len)
process HDT sentence
void processGsaSentence(const char *data, int len)
process GSA sentence
QString mStringBuffer
Store data from the device before it is processed.
QgsNmeaConnection(QIODevice *device)
Constructs a QgsNmeaConnection with given device.
void processStringBuffer()
Splits mStringBuffer into sentences and calls libnmea.
Encapsulates information relating to a GPS satellite.
double elevation
Elevation of the satellite, in degrees.
bool inUse
true if satellite was used in obtaining the position fix.
int signal
Signal strength (0-99dB), or -1 if not available.
int id
Contains the satellite identifier number.
double azimuth
The azimuth of the satellite to true north, in degrees.
QChar satType
satType value from NMEA message $GxGSV, where x: P = GPS; S = SBAS (GPSid> 32 then SBasid = GPSid + 8...
#define QgsDebugMsgLevel(str, level)