qtmobility/src/location/qnmeapositioninfosource.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    42 #include "qlocationutils_p.h"
    42 #include "qlocationutils_p.h"
    43 
    43 
    44 #include <QIODevice>
    44 #include <QIODevice>
    45 #include <QBasicTimer>
    45 #include <QBasicTimer>
    46 #include <QTimerEvent>
    46 #include <QTimerEvent>
    47 #include <QDebug>
       
    48 #include <QTimer>
    47 #include <QTimer>
    49 
    48 
    50 QTM_BEGIN_NAMESPACE
    49 QTM_BEGIN_NAMESPACE
    51 
    50 
    52 QNmeaRealTimeReader::QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate)
    51 QNmeaRealTimeReader::QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate)
   117         char buf[1024];
   116         char buf[1024];
   118         qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf));
   117         qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf));
   119         if (size <= 0)
   118         if (size <= 0)
   120             continue;
   119             continue;
   121         bool ok = m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix);
   120         bool ok = m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix);
   122         if (ok && update.dateTime().isValid()) {
   121         if (ok && update.timestamp().isValid()) {
   123             QPendingGeoPositionInfo pending;
   122             QPendingGeoPositionInfo pending;
   124             pending.info = update;
   123             pending.info = update;
   125             pending.hasFix = hasFix;
   124             pending.hasFix = hasFix;
   126             m_pendingUpdates.enqueue(pending);
   125             m_pendingUpdates.enqueue(pending);
   127             return true;
   126             return true;
   154     QGeoPositionInfo info;
   153     QGeoPositionInfo info;
   155     bool hasFix = false;
   154     bool hasFix = false;
   156     int timeToNextUpdate = -1;
   155     int timeToNextUpdate = -1;
   157     QTime prevTime;
   156     QTime prevTime;
   158     if (m_pendingUpdates.size() > 0)
   157     if (m_pendingUpdates.size() > 0)
   159         prevTime = m_pendingUpdates.head().info.dateTime().time();
   158         prevTime = m_pendingUpdates.head().info.timestamp().time();
   160 
   159 
   161     // find the next update with a valid time (as long as the time is valid,
   160     // find the next update with a valid time (as long as the time is valid,
   162     // we can calculate when the update should be emitted)
   161     // we can calculate when the update should be emitted)
   163     while (m_proxy->m_device && m_proxy->m_device->bytesAvailable() > 0) {
   162     while (m_proxy->m_device && m_proxy->m_device->bytesAvailable() > 0) {
   164         char buf[1024];
   163         char buf[1024];
   165         qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf));
   164         qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf));
   166         if (size <= 0)
   165         if (size <= 0)
   167             continue;
   166             continue;
   168         if (m_proxy->parsePosInfoFromNmeaData(buf, size, &info, &hasFix)) {
   167         if (m_proxy->parsePosInfoFromNmeaData(buf, size, &info, &hasFix)) {
   169             QTime time = info.dateTime().time();
   168             QTime time = info.timestamp().time();
   170             if (time.isValid()) {
   169             if (time.isValid()) {
   171                 if (!prevTime.isValid()) {
   170                 if (!prevTime.isValid()) {
   172                     timeToNextUpdate = 0;
   171                     timeToNextUpdate = 0;
   173                     break;
   172                     break;
   174                 }
   173                 }
   359     emit m_source->updateTimeout();
   358     emit m_source->updateTimeout();
   360 }
   359 }
   361 
   360 
   362 void QNmeaPositionInfoSourcePrivate::notifyNewUpdate(QGeoPositionInfo *update, bool hasFix)
   361 void QNmeaPositionInfoSourcePrivate::notifyNewUpdate(QGeoPositionInfo *update, bool hasFix)
   363 {
   362 {
   364     //qDebug() << "QNmeaPositionInfoSourcePrivate::notifyNewUpdate()" << update->dateTime() << hasFix << m_invokedStart << (m_requestTimer && m_requestTimer->isActive());
   363     // include <QDebug> before uncommenting
   365 
   364     //qDebug() << "QNmeaPositionInfoSourcePrivate::notifyNewUpdate()" << update->timestamp() << hasFix << m_invokedStart << (m_requestTimer && m_requestTimer->isActive());
   366     QDate date = update->dateTime().date();
   365 
       
   366     QDate date = update->timestamp().date();
   367     if (date.isValid()) {
   367     if (date.isValid()) {
   368         m_currentDate = date;
   368         m_currentDate = date;
   369     } else {
   369     } else {
   370         // some sentence have time but no date
   370         // some sentence have time but no date
   371         QTime time = update->dateTime().time();
   371         QTime time = update->timestamp().time();
   372         if (time.isValid() && m_currentDate.isValid())
   372         if (time.isValid() && m_currentDate.isValid())
   373             update->setDateTime(QDateTime(m_currentDate, time, Qt::UTC));
   373             update->setTimestamp(QDateTime(m_currentDate, time, Qt::UTC));
   374     }
   374     }
   375 
   375 
   376     if (hasFix && update->isValid()) {
   376     if (hasFix && update->isValid()) {
   377         if (m_requestTimer && m_requestTimer->isActive()) {
   377         if (m_requestTimer && m_requestTimer->isActive()) {
   378             m_requestTimer->stop();
   378             m_requestTimer->stop();