diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-05-15 21:24:21 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-05-18 10:58:01 +0000 |
commit | 42972a51e3e786a49a3266fc30feed74bc8ea286 (patch) | |
tree | f2858766489724e4142ad00883fa08a144a8602a | |
parent | e806810524ec64f8d0e9fc0dc270b43af0cd287f (diff) | |
download | qtlocation-42972a51e3e786a49a3266fc30feed74bc8ea286.tar.gz |
QNmeaPositionInfoSource: improve timestamp comparison for updates
It can happen that sentences arrive out of order (older sentences
after newer sentences).
In this case, discard the old data.
Task-number: QTBUG-64699
Change-Id: Id1c965c5ecc32d59dbf271410bc0191e262fa269
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/positioning/qnmeapositioninfosource.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/positioning/qnmeapositioninfosource.cpp b/src/positioning/qnmeapositioninfosource.cpp index 27711323..63410022 100644 --- a/src/positioning/qnmeapositioninfosource.cpp +++ b/src/positioning/qnmeapositioninfosource.cpp @@ -243,16 +243,18 @@ static int processSentence(QGeoPositionInfo &info, // the sentences containing the full timestamp (e.g., GPRMC) *first* ! if (infoTime.isValid()) { if (pos.timestamp().time().isValid()) { - if (infoTime != pos.timestamp().time() || - (infoDate.isValid() // if time is valid but one date or both are not, match only on time + if (infoTime < pos.timestamp().time() || + (infoDate.isValid() // if time is valid but one date or both are not, && pos.timestamp().date().isValid() - && infoDate != pos.timestamp().date())) { - // Effectively read data for different update, so copy buf into m_nextLine + && infoDate < pos.timestamp().date())) { + // Effectively read data for different update, that is also newer, so copy buf into m_nextLine m_nextLine = QByteArray(buf, size); break; } else { - // timestamps match -- merge into info - mergePositions(info, pos, QByteArray(buf, size)); + if (infoTime == pos.timestamp().time()) + // timestamps match -- merge into info + mergePositions(info, pos, QByteArray(buf, size)); + // else discard out of order outdated info. } } else { // no timestamp available -- merge into info |