summaryrefslogtreecommitdiff
path: root/src/positioning
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-06-12 03:00:35 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-06-12 03:00:36 +0200
commit7a7d355ac603283d05610e584d7c923e1d4caae0 (patch)
tree2b1e0991391b4fea05c9830e3831712bc0d6d26e /src/positioning
parentaff3782a97cb7b120b5586194acd1816c08abe79 (diff)
parent71bc98bf309ce433afb80344a7356e13b310c5c5 (diff)
downloadqtlocation-7a7d355ac603283d05610e584d7c923e1d4caae0.tar.gz
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Id27e5a31f3a72eac38b976d546a1f733226cd5ae
Diffstat (limited to 'src/positioning')
-rw-r--r--src/positioning/qlocationutils.cpp63
-rw-r--r--src/positioning/qlocationutils_p.h36
2 files changed, 67 insertions, 32 deletions
diff --git a/src/positioning/qlocationutils.cpp b/src/positioning/qlocationutils.cpp
index 5304392b..f5062eb6 100644
--- a/src/positioning/qlocationutils.cpp
+++ b/src/positioning/qlocationutils.cpp
@@ -258,6 +258,32 @@ static void qlocationutils_readZda(const char *data, int size, QGeoPositionInfo
info->setTimestamp(QDateTime(date, time, Qt::UTC));
}
+QLocationUtils::NmeaSentence QLocationUtils::getNmeaSentenceType(const char *data, int size)
+{
+ if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size))
+ return NmeaSentenceInvalid;
+
+ if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A')
+ return NmeaSentenceGGA;
+
+ if (data[3] == 'G' && data[4] == 'S' && data[5] == 'A')
+ return NmeaSentenceGSA;
+
+ if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L')
+ return NmeaSentenceGLL;
+
+ if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C')
+ return NmeaSentenceRMC;
+
+ if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G')
+ return NmeaSentenceVTG;
+
+ if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A')
+ return NmeaSentenceZDA;
+
+ return NmeaSentenceInvalid;
+}
+
bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info,
double uere, bool *hasFix)
{
@@ -266,7 +292,9 @@ bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPosition
if (hasFix)
*hasFix = false;
- if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size))
+
+ NmeaSentence nmeaType = getNmeaSentenceType(data, size);
+ if (nmeaType == NmeaSentenceInvalid)
return false;
// Adjust size so that * and following characters are not parsed by the following functions.
@@ -277,43 +305,28 @@ bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPosition
}
}
- if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A') {
- // "$--GGA" sentence.
+ switch (nmeaType) {
+ case NmeaSentenceGGA:
qlocationutils_readGga(data, size, info, uere, hasFix);
return true;
- }
-
- if (data[3] == 'G' && data[4] == 'S' && data[5] == 'A') {
- // "$--GSA" sentence.
+ case NmeaSentenceGSA:
qlocationutils_readGsa(data, size, info, uere, hasFix);
return true;
- }
-
- if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L') {
- // "$--GLL" sentence.
+ case NmeaSentenceGLL:
qlocationutils_readGll(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C') {
- // "$--RMC" sentence.
+ case NmeaSentenceRMC:
qlocationutils_readRmc(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G') {
- // "$--VTG" sentence.
+ case NmeaSentenceVTG:
qlocationutils_readVtg(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A') {
- // "$--ZDA" sentence.
+ case NmeaSentenceZDA:
qlocationutils_readZda(data, size, info, hasFix);
return true;
+ default:
+ return false;
}
-
- return false;
}
bool QLocationUtils::hasValidNmeaChecksum(const char *data, int size)
diff --git a/src/positioning/qlocationutils_p.h b/src/positioning/qlocationutils_p.h
index 69cf0fee..d9e6524a 100644
--- a/src/positioning/qlocationutils_p.h
+++ b/src/positioning/qlocationutils_p.h
@@ -54,6 +54,7 @@
#include <math.h> // needed for non-std:: versions of functions
#include <qmath.h>
#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/private/qpositioningglobal_p.h>
static const double offsetEpsilon = 1e-12; // = 0.000000000001
static const double leftOffset = -180.0 + offsetEpsilon;
@@ -64,7 +65,7 @@ class QTime;
class QByteArray;
class QGeoPositionInfo;
-class QLocationUtils
+class Q_POSITIONING_PRIVATE_EXPORT QLocationUtils
{
public:
enum CardinalDirection {
@@ -86,6 +87,16 @@ public:
CardinalNNW
};
+ enum NmeaSentence {
+ NmeaSentenceInvalid,
+ NmeaSentenceGGA, // Fix information
+ NmeaSentenceGSA, // Overall Satellite data, such as HDOP and VDOP
+ NmeaSentenceGLL, // Lat/Lon data
+ NmeaSentenceRMC, // Recommended minimum data for gps
+ NmeaSentenceVTG, // Vector track an Speed over the Ground
+ NmeaSentenceZDA // Date and Time
+ };
+
inline static bool isValidLat(double lat) {
return lat >= -90.0 && lat <= 90.0;
}
@@ -246,6 +257,11 @@ public:
}
/*
+ returns the NMEA sentence type.
+ */
+ static NmeaSentence getNmeaSentenceType(const char *data, int size);
+
+ /*
Creates a QGeoPositionInfo from a GGA, GLL, RMC, VTG or ZDA sentence.
Note:
@@ -254,25 +270,31 @@ public:
- RMC reports date with a two-digit year so in this case the year
is assumed to be after the year 2000.
*/
- Q_AUTOTEST_EXPORT static bool getPosInfoFromNmea(const char *data, int size,
- QGeoPositionInfo *info, double uere,
- bool *hasFix = 0);
+ static bool getPosInfoFromNmea(const char *data,
+ int size,
+ QGeoPositionInfo *info, double uere,
+ bool *hasFix = nullptr);
/*
Returns true if the given NMEA sentence has a valid checksum.
*/
- Q_AUTOTEST_EXPORT static bool hasValidNmeaChecksum(const char *data, int size);
+ static bool hasValidNmeaChecksum(const char *data, int size);
/*
Returns time from a string in hhmmss or hhmmss.z+ format.
*/
- Q_AUTOTEST_EXPORT static bool getNmeaTime(const QByteArray &bytes, QTime *time);
+ static bool getNmeaTime(const QByteArray &bytes, QTime *time);
/*
Accepts for example ("2734.7964", 'S', "15306.0124", 'E') and returns the
lat-long values. Fails if lat or long fail isValidLat() or isValidLong().
*/
- Q_AUTOTEST_EXPORT static bool getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lon);
+ static bool getNmeaLatLong(const QByteArray &latString,
+ char latDirection,
+ const QByteArray &lngString,
+ char lngDirection,
+ double *lat,
+ double *lon);
};
QT_END_NAMESPACE