Example usage for android.location GpsSatellite getPrn

List of usage examples for android.location GpsSatellite getPrn

Introduction

In this page you can find the example usage for android.location GpsSatellite getPrn.

Prototype

public int getPrn() 

Source Link

Document

Returns the PRN (pseudo-random number) for the satellite.

Usage

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts GpsStatus into JSON.//from   w w w  . ja v  a 2  s. c o  m
 * @param gpsStatus Send a GpsStatus whenever the GPS fires
 * @return JSON representation of the satellite data
 */
public static String satelliteDataJSON(GpsStatus gpsStatus) {

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    try {
        json.put("provider", SATELLITE_PROVIDER);
        json.put("timestamp", calendar.getTimeInMillis());

        if (gpsStatus.getSatellites() != null) {
            int count = 0;
            final int timeToFirstFix = gpsStatus.getTimeToFirstFix();

            for (GpsSatellite sat : gpsStatus.getSatellites()) {
                final JSONObject satelliteInfo = new JSONObject();

                satelliteInfo.put("PRN", sat.getPrn());
                satelliteInfo.put("timeToFirstFix", timeToFirstFix);
                satelliteInfo.put("usedInFix", sat.usedInFix());
                satelliteInfo.put("azimuth", sat.getAzimuth());
                satelliteInfo.put("elevation", sat.getElevation());
                satelliteInfo.put("hasEphemeris", sat.hasEphemeris());
                satelliteInfo.put("hasAlmanac", sat.hasAlmanac());
                satelliteInfo.put("SNR", sat.getSnr());

                json.put(Integer.toString(count), satelliteInfo);

                count++;
            }
        }
    } catch (JSONException exc) {
        logJSONException(exc);
    }

    return json.toString();
}

From source file:uk.ac.horizon.ubihelper.service.channel.GpsStatusChannel.java

public void onGpsStatusChanged(int type) {
    if (location != null) {
        GpsStatus status = location.getGpsStatus(null);
        JSONObject value = new JSONObject();
        try {/*w  w w .  ja v a  2s  . c  o  m*/
            // event time is in nanoseconds
            value.put("timestamp", System.currentTimeMillis());
            value.put("status", type);
            value.put("maxSatellites", status.getMaxSatellites());
            value.put("timeToFirstFix", status.getTimeToFirstFix());
            JSONArray sats = new JSONArray();
            value.put("satellites", sats);
            for (GpsSatellite satellite : status.getSatellites()) {
                JSONObject s = new JSONObject();
                s.put("used", satellite.usedInFix());
                s.put("azimuth", satellite.getAzimuth());
                s.put("elevation", satellite.getElevation());
                s.put("prn", satellite.getPrn());
                s.put("snr", satellite.getSnr());
                sats.put(s);
            }
            onNewValue(value);

        } catch (JSONException e) {
            /* ignore */
        }
    }
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onGpsStatusChanged(int arg0) {
    long triggerTime = System.currentTimeMillis();
    int gpsSatellitesCount = 0;
    int glonassSatellitesCount = 0;
    HashMap<String, String> mSatInfo;
    itemListGps.clear();//ww  w. ja v  a2 s  .c  o  m
    itemListGlonass.clear();
    GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
    Iterable<GpsSatellite> gpsSats = gpsStatus.getSatellites();
    for (GpsSatellite sat : gpsSats) {
        if (sat.getPrn() <= 32) {
            gpsSatellitesCount++;
            mSatInfo = new HashMap<String, String>();
            mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn()));
            String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE";
            mSatInfo.put(SAT_FIX_KEY, usedinfix);
            itemListGps.add(mSatInfo);
        } else {
            glonassSatellitesCount++;
            mSatInfo = new HashMap<String, String>();
            mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn()));
            String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE";
            mSatInfo.put(SAT_FIX_KEY, usedinfix);
            itemListGlonass.add(mSatInfo);
        }
    }
    if (isLogging && mGpsLog != null) {
        try {
            mGpsLog.logEvent(triggerTime, gpsSatellitesCount + glonassSatellitesCount, gpsSats, mLatitude,
                    mLongitude, mAltitude, mAccuracy);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    satView.setSatellites(gpsSats);
    mGpsListAdapter.notifyDataSetChanged();
    mGlonassListAdapter.notifyDataSetChanged();
    satView.invalidate();
}

From source file:com.android.gpstest.GpsStatusFragment.java

private void updateStatus(GpsStatus status) {

    setStarted(true);/* w  w w . j av  a  2  s  .  c  om*/
    // update the fix time regularly, since it is displaying relative time
    updateFixTime();

    Iterator<GpsSatellite> satellites = status.getSatellites().iterator();

    if (mPrns == null) {
        int length = status.getMaxSatellites();
        mPrns = new int[length];
        mSnrs = new float[length];
        mSvElevations = new float[length];
        mSvAzimuths = new float[length];
    }

    mSvCount = 0;
    mEphemerisMask = 0;
    mAlmanacMask = 0;
    mUsedInFixMask = 0;
    while (satellites.hasNext()) {
        GpsSatellite satellite = satellites.next();
        int prn = satellite.getPrn();
        int prnBit = (1 << (prn - 1));
        mPrns[mSvCount] = prn;
        mSnrs[mSvCount] = satellite.getSnr();
        mSvElevations[mSvCount] = satellite.getElevation();
        mSvAzimuths[mSvCount] = satellite.getAzimuth();
        if (satellite.hasEphemeris()) {
            mEphemerisMask |= prnBit;
        }
        if (satellite.hasAlmanac()) {
            mAlmanacMask |= prnBit;
        }
        if (satellite.usedInFix()) {
            mUsedInFixMask |= prnBit;
        }
        mSvCount++;
    }

    mAdapter.notifyDataSetChanged();
}