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" ) ) )
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" ) ) )
137 QgsDebugMsgLevel( QStringLiteral(
"*******************GPS data received****************" ), 2 );
139 else if ( substring.startsWith( QLatin1String(
"$GPHDT" ) ) )
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++ )
bool inUse
true if satellite was used in obtaining the position fix.
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
Encapsulates information relating to a GPS satellite.
void processHdtSentence(const char *data, int len)
process HDT sentence
void processHchdtSentence(const char *data, int len)
process HCHDT sentence
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.
int signal
Signal strength (0-99dB), or -1 if not available.
double elevation
Elevation of the satellite, in degrees.
#define QgsDebugMsgLevel(str, level)
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
void processHchdgSentence(const char *data, int len)
process HCHDG 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
double azimuth
The azimuth of the satellite to true north, in degrees.
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
void nmeaSentenceReceived(const QString &substring)
void processVtgSentence(const char *data, int len)
process VTG sentence
int id
Contains the satellite identifier number.
Abstract base class for connection to a GPS device.