void QGeoSatelliteInfoSourceAndroid::onSatelliteInfoAvailable(QList<QtLocationJni::SatelliteInfo> &satInfoList)
{
    QtLocationJni::SatelliteInfo satInfo;
    QList<QGeoSatelliteInfo> qSatellites;

    if (m_satelliteInfoState & QGeoSatelliteInfoSourceAndroid::RequestActive)
    {
        m_requestTimer->stop();
        m_satelliteInfoState &= ~QGeoSatelliteInfoSourceAndroid::RequestActive;
        if(m_satelliteInfoState & QGeoSatelliteInfoSourceAndroid::Stopped)
        {
            QtLocationJni::satelliteDisableupdates(this);
        }
    }

    foreach(satInfo,satInfoList)
    {
        QGeoSatelliteInfo qSatellite;
        qSatellite.setPrnNumber(satInfo.m_prnNumber);
        //10 log10 (ratio of the powers)
        int signalStrength=(satInfo.m_signalStrength==0) ? 0:(int)(10 * ::log10(satInfo.m_signalStrength));
        qSatellite.setSignalStrength(signalStrength);
        qSatellite.setAttribute(QGeoSatelliteInfo::Elevation,satInfo.m_elevation);
        qSatellite.setAttribute(QGeoSatelliteInfo::Azimuth,satInfo.m_azimuth);
        qSatellites.append(qSatellite);
    }
void QgsQtLocationConnection::satellitesInUseUpdated(
    const QList<QGeoSatelliteInfo>& satellites )
{
    // The number of satellites in use is updated
    mLastGPSInformation.satellitesUsed = QString::number( satellites.count() ).toInt();

    mLastGPSInformation.satPrn.clear();
    for ( int i = 0; i < satellites.size(); ++i )
    {
        QGeoSatelliteInfo currentSatellite = satellites.at( i );
        //add pnr to mLastGPSInformation.satPrn
        mLastGPSInformation.satPrn.append( currentSatellite.prnNumber() );

        //set QgsSatelliteInfo.inuse to true for the satellites in use
        for ( int i = 0; i < mLastGPSInformation.satellitesInView.size(); ++i )
        {
            QgsSatelliteInfo satInView = mLastGPSInformation.satellitesInView.at( i );
            if ( satInView.id == currentSatellite.prnNumber() )
            {
                satInView.inUse = true;
                break;
            }
        }
    }
    mLastGPSInformation.satInfoComplete = true;  //to be used to determine when to graph signal and satellite position
    emit stateChanged( mLastGPSInformation );
    QgsDebugMsg( "satellitesInUseUpdated" );
}
    void addTestData_update()
    {
        QTest::addColumn<QGeoSatelliteInfo>("info");

        QList<int> intValues = tst_qgeosatelliteinfo_intTestValues();

        for (int i=0; i<intValues.count(); i++) {
            QGeoSatelliteInfo info;
            info.setSignalStrength(intValues[i]);
            QTest::newRow("signal strength") << info;
        }

        for (int i=0; i<intValues.count(); i++) {
            QGeoSatelliteInfo info;
            info.setSatelliteIdentifier(intValues[i]);
            QTest::newRow("satellite identifier") << info;
        }

            QGeoSatelliteInfo info;
            info.setSatelliteSystem(QGeoSatelliteInfo::GPS);
            QTest::newRow("satellite system") << info;
            info.setSatelliteSystem(QGeoSatelliteInfo::GLONASS);
            QTest::newRow("satellite system") << info;

        QList<QGeoSatelliteInfo::Attribute> attributes = tst_qgeosatelliteinfo_getAttributes();
        QList<qreal> qrealValues = tst_qgeosatelliteinfo_qrealTestValues();
        for (int i=0; i<attributes.count(); i++) {
            QTest::newRow(qPrintable(QString("Attribute %1 = %2").arg(attributes[i]).arg(qrealValues[i])))
                    << updateWithAttribute(attributes[i], qrealValues[i]);
        }
    }
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 QgsQtLocationConnection::satellitesInViewUpdated(
    const QList<QGeoSatelliteInfo>& satellites )
{
    // The number of satellites in view is updated
    mLastGPSInformation.satellitesInView.clear();
    for ( int i = 0; i < satellites.size(); ++i )
    {
        QGeoSatelliteInfo currentSatellite = satellites.at( i );
        QgsSatelliteInfo satelliteInfo;
        satelliteInfo.azimuth = currentSatellite.attribute( QGeoSatelliteInfo::Azimuth );
        satelliteInfo.elevation = currentSatellite.attribute( QGeoSatelliteInfo::Elevation );
        satelliteInfo.id = currentSatellite.prnNumber();
        satelliteInfo.signal = currentSatellite.signalStrength();
        mLastGPSInformation.satellitesInView.append( satelliteInfo );
    }
    mLastGPSInformation.satInfoComplete = true;  //to be used to determine when to graph signal and satellite position
    emit stateChanged( mLastGPSInformation );
    QgsDebugMsg( "satellitesInViewUpdated" );
}
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 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);
    }
}
// From a QvariantMap representing a location response from the Location Manager fill the lists of
// QGeoSatelliteInfo instances intended to be emitted via satellitesInUseUpdated() and
// satellitesInViewUpdated() signals.
void QGeoSatelliteInfoSourceBbPrivate::populateSatelliteLists(const QVariantMap &map)
{
    // populate _currentSatelliteInfo
    QVariantMap datMap = map.value("dat").toMap();
    QVariantList satelliteList = datMap.value("satellites").toList();

    _satellitesInView.clear();
    _satellitesInUse.clear();

    Q_FOREACH (const QVariant &satelliteData, satelliteList) {
        datMap = satelliteData.toMap();
        QGeoSatelliteInfo satelliteInfo = QGeoSatelliteInfo();

        if (datMap.contains("id"))
            satelliteInfo.setSatelliteIdentifier(static_cast<int>(datMap.value("id").toDouble()));

        satelliteInfo.setSatelliteSystem(determineSatSystem(satelliteInfo.satelliteIdentifier()));

        if (datMap.contains("cno"))
            satelliteInfo.setSignalStrength(static_cast<int>(datMap.value("cno").toDouble()));

        // attributes
        if (datMap.contains("elevation"))
            satelliteInfo.setAttribute(QGeoSatelliteInfo::Elevation,
                                       static_cast<qreal>(datMap.value("elevation").toDouble()));
        else
            satelliteInfo.removeAttribute(QGeoSatelliteInfo::Elevation);

        if (datMap.contains("azimuth"))
            satelliteInfo.setAttribute(QGeoSatelliteInfo::Azimuth,
                                       static_cast<qreal>(datMap.value("azimuth").toDouble()));
        else
            satelliteInfo.removeAttribute(QGeoSatelliteInfo::Azimuth);

        // each satellite in this list is considered "in view"
        _satellitesInView.append(satelliteInfo);

        if (datMap.value("used").toBool() == true)
            _satellitesInUse.append(satelliteInfo);
    }
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();
    }
}
/*
 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);
}
Esempio n. 11
0
void LiblocationWrapper::locationChanged(LocationGPSDevice *device,
        gpointer data)
{
    QGeoPositionInfo posInfo;
    QGeoCoordinate coordinate;
    QGeoSatelliteInfo satInfo;
    int satellitesInUseCount = 0;
    LiblocationWrapper *object;

    if (!data || !device) {
        return;
    }

    object = (LiblocationWrapper *)data;

    if (device) {
        if (device->fix) {
            if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
                posInfo.setTimestamp(QDateTime::fromTime_t(device->fix->time));
            }

            if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
                coordinate.setLatitude(device->fix->latitude);
                coordinate.setLongitude(device->fix->longitude);
                posInfo.setAttribute(QGeoPositionInfo::HorizontalAccuracy,
                                     device->fix->eph / 100.0);
                posInfo.setAttribute(QGeoPositionInfo::VerticalAccuracy,
                                     device->fix->epv);
            }

            if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
                coordinate.setAltitude(device->fix->altitude);
            }

            if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
                posInfo.setAttribute(QGeoPositionInfo::GroundSpeed,
                                     device->fix->speed / 3.6);
            }

            if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
                posInfo.setAttribute(QGeoPositionInfo::VerticalSpeed,
                                     device->fix->climb);
            }

            if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
                posInfo.setAttribute(QGeoPositionInfo::Direction,
                                     device->fix->track);
            }
        }

        if (device->satellites_in_view) {
            QList<QGeoSatelliteInfo> satsInView;
            QList<QGeoSatelliteInfo> satsInUse;
            unsigned int i;
            for (i = 0;i < device->satellites->len;i++) {
                LocationGPSDeviceSatellite *satData =
                    (LocationGPSDeviceSatellite *)g_ptr_array_index(device->satellites,
                            i);
                satInfo.setSignalStrength(satData->signal_strength);
                satInfo.setPrnNumber(satData->prn);
                satInfo.setAttribute(QGeoSatelliteInfo::Elevation,
                                     satData->elevation);
                satInfo.setAttribute(QGeoSatelliteInfo::Azimuth,
                                     satData->azimuth);

                satsInView.append(satInfo);
                if (satData->in_use) {
                    satellitesInUseCount++;
                    satsInUse.append(satInfo);
                }
            }

            if (!satsInView.isEmpty())
                object->satellitesInViewUpdated(satsInView);

            if (!satsInUse.isEmpty())
                object->satellitesInUseUpdated(satsInUse);
        }
    }

    posInfo.setCoordinate(coordinate);

    emit object->positionUpdated(posInfo);
}
QT_BEGIN_NAMESPACE
inline bool operator<(const QGeoSatelliteInfo& a, const QGeoSatelliteInfo& b)
{
    return a.satelliteIdentifier() < b.satelliteIdentifier();
}