SatelliteModel::SatelliteModel(QObject *parent) :
    QAbstractListModel(parent), source(0), m_componentCompleted(false), m_running(false),
    m_runningRequested(false), demo(false), isSingle(false), singleRequestServed(false)
{
    source = QGeoSatelliteInfoSource::createDefaultSource(this);
    if (!demo && !source) {
        qWarning() << "No satellite data source found. Changing to demo mode.";
        demo = true;
    }
    if (!demo) {
        source->setUpdateInterval(3000);
        connect(source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)),
                this, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)));
        connect(source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)),
                this, SLOT(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)));
        connect(source, SIGNAL(error(QGeoSatelliteInfoSource::Error)),
                this, SLOT(error(QGeoSatelliteInfoSource::Error)));
    }

    if (demo) {
        timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(updateDemoData()));
        timer->start(3000);
    }
}
void SatelliteModel::updateDemoData()
{
    static bool flag = true;
    QList<QGeoSatelliteInfo> satellites;
    if (flag) {
        for (int i = 0; i<5; i++) {
            QGeoSatelliteInfo info;
            info.setSatelliteIdentifier(i);
            info.setSignalStrength(20 + 20*i);
            satellites.append(info);
        }
    } else {
        for (int i = 0; i<9; i++) {
            QGeoSatelliteInfo info;
            info.setSatelliteIdentifier(i*2);
            info.setSignalStrength(20 + 10*i);
            satellites.append(info);
        }
    }


    satellitesInViewUpdated(satellites);
    flag ? satellitesInUseUpdated(QList<QGeoSatelliteInfo>() << satellites.at(2))
         : satellitesInUseUpdated(QList<QGeoSatelliteInfo>() << satellites.at(3));
    flag = !flag;

    emit errorFound(flag);

    if (isSingleRequest() && !singleRequestServed) {
        singleRequestServed = true;
        setRunning(false);
    }
}
void QGeoSatelliteInfoSourceGeoclueMaster::updateSatelliteInfo(int timestamp, int satellitesUsed,
                                                               int satellitesVisible,
                                                               const QList<int> &usedPrn,
                                                               const QList<QGeoSatelliteInfo> &satInfos)
{
    Q_UNUSED(timestamp)

    QList<QGeoSatelliteInfo> inUse;

    foreach (const QGeoSatelliteInfo &si, satInfos)
        if (usedPrn.contains(si.satelliteIdentifier()))
            inUse.append(si);

    if (satInfos.length() != satellitesVisible) {
        qWarning("QGeoSatelliteInfoSourceGeoclueMaster number of in view QGeoSatelliteInfos (%d) "
                 "does not match expected number of in view satellites (%d).", satInfos.length(),
                 satellitesVisible);
    }

    if (inUse.length() != satellitesUsed) {
        qWarning("QGeoSatelliteInfoSourceGeoclueMaster number of in use QGeoSatelliteInfos (%d) "
                 "does not match expected number of in use satellites (%d).", inUse.length(),
                 satellitesUsed);
    }

    m_inView = satInfos;
    emit satellitesInViewUpdated(m_inView);

    m_inUse = inUse;
    emit satellitesInUseUpdated(m_inUse);

    m_requestTimer.start(updateInterval());
}
Пример #4
0
androidGps::androidGps(QObject *parent) : QObject(parent)
{
   QGeoPositionInfoSource *source1 = QGeoPositionInfoSource::createDefaultSource(0);

               connect(source1, SIGNAL(positionUpdated(QGeoPositionInfo)),
                       this, SLOT(positionUpdated(QGeoPositionInfo)));

               connect(source1, SIGNAL(error(QGeoPositionInfoSource::Error)),
                       this, SLOT(error(QGeoPositionInfoSource::Error)));

          if (source1) {
               source1->setUpdateInterval(1000);
               source1->startUpdates();


               qDebug() << "Gps1 status: " << source1->sourceName();
           }



           QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0);
           if (source)
           {
               source->setUpdateInterval(1000);
               source->startUpdates();
           }

           connect(source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)), this, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)));

           qDebug() << source->sourceName() << "Source name";

}
void QGeoSatelliteInfoSourceMaemo::satelliteStatus()
{
    QList<QGeoSatelliteInfo> satellitesInView = 
            LiblocationWrapper::instance()->satellitesInView();
    QList<QGeoSatelliteInfo> satellitesInUse = 
            LiblocationWrapper::instance()->satellitesInUse();

    if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) {
        satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::RequestActive;

        requestTimer->stop();

        if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) {
            if (LiblocationWrapper::instance()->isActive()) {
                LiblocationWrapper::instance()->stop();
            }
        }

        // Ensure that requested satellite info is emitted even though
        // powersave is active and GPS would normally be off.
        if ((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) &&
           (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped)) {
            if (satellitesInView.length()) {
                emit satellitesInViewUpdated(satellitesInView);
                emit satellitesInUseUpdated(satellitesInUse);
            }
        }
    }

    // Make sure that if update is triggered when waking up, there
    // is no false position update.
    if (!((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) &&
         (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped))) {
        if (satellitesInView.length()) {
            emit satellitesInViewUpdated(satellitesInView);
            emit satellitesInUseUpdated(satellitesInUse);
        }
    }

    activateTimer();
}
void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdateTimeout()
{
    // If we end up here, there has not been a valid satellite info update.
    if (m_running) {
        m_inView.clear();
        m_inUse.clear();
        emit satellitesInViewUpdated(m_inView);
        emit satellitesInUseUpdated(m_inUse);
    } else {
        emit requestTimeout();

        // Only stop satellite info if regular updates not active.
        cleanupSatelliteSource();
        m_master->releaseMasterClient();
    }
}
/*
 This is _only_ called when QGeoSatelliteInfoValidator::valid() returns true for the position.
 This means that it is implied that:
 - (data.dwValidFields & GPS_VALID_SATELLITE_COUNT) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_PRNS) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_SIGNAL_TO_NOISE_RATIO) != 0

 This guarantees that the newly created position will be valid.
 If the code is changed such that this is no longer guaranteed then this method will need to be
 updated to test for those conditions.
*/
void QGeoSatelliteInfoSourceWinCE::dataUpdated(GPS_POSITION data)
{
    // Satellites in view are hashed on the PRN values since the PRN value is how we
    // determine which of the satellites are in use.
    QHash<int, QGeoSatelliteInfo> satellitesInView;

    for (unsigned int i = 0; i < data.dwSatellitesInView; ++i) {
        QGeoSatelliteInfo satellite;

        satellite.setPrnNumber(data.rgdwSatellitesInViewPRNs[i]);
        satellite.setSignalStrength(data.rgdwSatellitesInViewSignalToNoiseRatio[i]);

        // The following properties are optional, and so are set if the data is present and valid
        // in the GPS_POSITION structure.
        if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_AZIMUTH) != 0) {
            satellite.setAttribute(QGeoSatelliteInfo::Azimuth,
                                   data.rgdwSatellitesInViewAzimuth[i]);
        }

        if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_ELEVATION) != 0) {
            satellite.setAttribute(QGeoSatelliteInfo::Elevation,
                                   data.rgdwSatellitesInViewElevation[i]);
        }

        satellitesInView.insert(satellite.prnNumber(), satellite);
    }

    emit satellitesInViewUpdated(satellitesInView.values());

    // If the PRN data for the satellites which were used is unavailable we are done...
    if ((data.dwValidFields & GPS_VALID_SATELLITES_USED_PRNS) == 0)
        return;

    // ...otherwise we construct the list of satellites which are in use and emit the appropriate
    // signal
    QList<QGeoSatelliteInfo> satellitesInUse;

    for (unsigned int i = 0; i < data.dwSatelliteCount; ++i) {
        int inUsePRN = data.rgdwSatellitesUsedPRNs[i];
        if (satellitesInView.contains(inUsePRN))
            satellitesInUse << satellitesInView.value(inUsePRN);
    }

    emit satellitesInUseUpdated(satellitesInUse);
}
void QGeoSatelliteInfoSourceGypsy::satellitesChanged(GypsySatellite* satellite,
                                                     GPtrArray* satellites)
{
    if (!satellite || !satellites)
        return;
    // We have satellite data and assume it is valid.
    // If a single updateRequest was active, send signals right away.
    // If a periodic timer was running (meaning that the client wishes
    // to have updates at defined intervals), store the data for later sending.
    QList<QtMobility::QGeoSatelliteInfo> lastSatellitesInView;
    QList<QtMobility::QGeoSatelliteInfo> lastSatellitesInUse;

    unsigned int i;
    for (i = 0; i < satellites->len; i++) {
        GypsySatelliteDetails *details = (GypsySatelliteDetails*)satellites->pdata[i];
        QGeoSatelliteInfo info;
        info.setAttribute(QGeoSatelliteInfo::Elevation, details->elevation);
        info.setAttribute(QGeoSatelliteInfo::Azimuth, details->azimuth);
        info.setPrnNumber(details->satellite_id);
        info.setSignalStrength(details->snr);
        if (details->in_use)
            lastSatellitesInUse.append(info);
        lastSatellitesInView.append(info);
    }
    bool sendUpdates(false);
    // If a single updateRequest() has been issued:
    if (m_requestOngoing) {
        sendUpdates = true;
        m_requestTimer.stop();
        m_requestOngoing = false;
        // If there is no regular updates ongoing, disconnect now.
        if (!m_updatesOngoing) {
            m_engine->eng_g_signal_handlers_disconnect_by_func(G_OBJECT(m_satellite), (void*)satellites_changed, this);
        }
    }
    // If regular updates are to be delivered as they come:
    if (m_updatesOngoing)
        sendUpdates = true;

    if (sendUpdates) {
        emit satellitesInUseUpdated(lastSatellitesInUse);
        emit satellitesInViewUpdated(lastSatellitesInView);
    }
}
void QGeoSatelliteInfoSourceSimulator::updateData()
{
    QList<QGeoSatelliteInfo> satellitesInUse;
    QList<QGeoSatelliteInfo> satellitesInView;

    QGeoSatelliteInfoData *data = qtSatelliteInfo();
    for(int i = 0; i < data->satellites.count(); i++) {
        QGeoSatelliteInfoData::SatelliteInfo info = data->satellites.at(i);
        QGeoSatelliteInfo satInfo;
        satInfo.setPrnNumber(info.prn);
        satInfo.setAttribute(QGeoSatelliteInfo::Azimuth, info.azimuth);
        satInfo.setAttribute(QGeoSatelliteInfo::Elevation, info.elevation);
        satInfo.setSignalStrength(info.signalStrength);
        satellitesInView.append(satInfo);
        if (info.inUse)
            satellitesInUse.append(satInfo);
    }
    emit satellitesInViewUpdated(satellitesInView);
    emit satellitesInUseUpdated(satellitesInUse);
}
void QGeoSatelliteInfoSourceNpeBackend::onSatelliteUpdate(const QList<SatelliteData> &satellites)
{
    QList<QGeoSatelliteInfo> inUse;
    QList<QGeoSatelliteInfo> inView;
    QListIterator<SatelliteData> it(satellites);

    if (!satellites.empty()) {
        while (it.hasNext())
        {
            QGeoSatelliteInfo satinfo;
            const SatelliteData &satellite = it.next();
            satinfo.setAttribute(QGeoSatelliteInfo::Elevation, satellite.elevation);
            satinfo.setAttribute(QGeoSatelliteInfo::Azimuth, satellite.azimuth);
            satinfo.setSatelliteIdentifier(satellite.id);
            satinfo.setSignalStrength(satellite.signalStrength);
            if (satellite.satSystem == LocationdStrings::PositionInfo::kGPS)
                satinfo.setSatelliteSystem(QGeoSatelliteInfo::GPS);
            else if (satellite.satSystem == LocationdStrings::PositionInfo::kGLONASS)
                satinfo.setSatelliteSystem(QGeoSatelliteInfo::GLONASS);
            else
                satinfo.setSatelliteSystem(QGeoSatelliteInfo::Undefined);
            if (satellite.status & SATELLITES_STATUS_VISIBLE) {
                inView.append(satinfo);
                if (satellite.status & SATELLITES_STATUS_USED_POS)
                    inUse.append(satinfo);
            }
        }
        if (inUse.count() > 0) // emit updated signal if satellite list is not empty
            emit satellitesInUseUpdated(inUse);
        qDebug() << "emit satelliteUpdated signals: in use count: " << inUse.count() << ", in view count: " <<inView.count();
        if (inView.count() > 0)
            emit satellitesInViewUpdated(inView);
        if ( requestTimer->isActive() )
            shutdownRequestSession();
    }
}