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;
200 if ( nmea_parse_GPGST( data, len, &result ) )
203 double sig_lat = result.sig_lat;
204 double sig_lon = result.sig_lon;
205 double sig_alt = result.sig_alt;
219 if ( nmea_parse_GPHDT( data, len, &result ) )
228 if ( nmea_parse_HCHDG( data, len, &result ) )
231 if ( result.ew_variation ==
'E' )
241 if ( nmea_parse_HCHDT( data, len, &result ) )
250 if ( nmea_parse_GPRMC( data, len, &result ) )
252 double longitude = result.lon;
253 if ( result.ew ==
'W' )
255 longitude = -longitude;
257 double latitude = result.lat;
258 if ( result.ns ==
'S' )
260 latitude = -latitude;
265 if ( !std::isnan( result.direction ) )
270 QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
271 QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec );
272 if ( date.isValid() && time.isValid() )
288 if ( nmea_parse_GPGSV( data, len, &result ) )
291 if ( result.pack_index == 1 )
299 for (
int i = 0; i < NMEA_SATINPACK; ++i )
301 nmeaSATELLITE currentSatellite = result.sat_data[i];
303 satelliteInfo.
azimuth = currentSatellite.azimuth;
304 satelliteInfo.
elevation = currentSatellite.elv;
305 satelliteInfo.
id = currentSatellite.id;
306 satelliteInfo.
inUse = currentSatellite.in_use;
307 satelliteInfo.
signal = currentSatellite.sig;
317 if ( nmea_parse_GPVTG( data, len, &result ) )
326 if ( nmea_parse_GPGSA( data, len, &result ) )
334 for (
int i = 0; i < NMEA_MAXSAT; i++ )
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.
#define QgsDebugMsgLevel(str, level)