From 42972a51e3e786a49a3266fc30feed74bc8ea286 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Tue, 15 May 2018 21:24:21 +0200 Subject: 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 --- src/positioning/qnmeapositioninfosource.cpp | 14 ++++++++------ 1 file 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 -- cgit v1.2.1