Esempio n. 1
0
    @Override
    public void onGpsStatusChanged(final int event) {
      switch (event) {
        case GpsStatus.GPS_EVENT_FIRST_FIX:
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
          {
            final GpsStatus status = geoManager.getGpsStatus(null);
            int visible = 0;
            int fixed = 0;
            for (final GpsSatellite satellite : status.getSatellites()) {
              if (satellite.usedInFix()) {
                fixed++;
              }
              visible++;
            }
            if (visible == latest.satellitesVisible && fixed == latest.satellitesFixed) {
              return;
            }
            latest = new Status(true, visible, fixed);
            break;
          }
        case GpsStatus.GPS_EVENT_STARTED:
          latest = new Status(true, 0, 0);
          break;
        case GpsStatus.GPS_EVENT_STOPPED:
          latest = new Status(false, 0, 0);
          break;
        default:
          throw new IllegalStateException();
      }

      subscriber.onNext(latest);
    }
Esempio n. 2
0
  /**
   * Tracks the current GPS status. Is called when the GPS is started, stopped, and receives
   * updates.
   */
  @Override
  public void onGpsStatusChanged(int event) {

    // Count the current number of satellites in contact with the GPS
    GpsStatus status = mLocationManager.getGpsStatus(null);
    int count = 0;
    Iterable<GpsSatellite> sats = status.getSatellites();
    for (Iterator<GpsSatellite> i = sats.iterator(); i.hasNext(); i.next()) {
      count++;
    }

    // If there are 3 or fewer satellites that we are connected, we've
    // probably lost GPS a lock
    if (count < 4) gpsWorking = false;
  }
Esempio n. 3
0
 public void onGpsStatusChanged(int state) {
   GpsStatus gpsStatus = locationManager.getGpsStatus(null);
   if (state == GpsStatus.GPS_EVENT_STOPPED) {
     hasFix = false;
     numSatellites = 0;
     updateSolution(LocationProvider.OUT_OF_SERVICE);
   } else if ((System.currentTimeMillis() - lastFixTimestamp) > 3000) {
     invalidateFix();
   }
   if (state == GpsStatus.GPS_EVENT_STARTED) {
     // FIXME do what's needed
     updateSolution(LocationProvider.AVAILABLE);
   }
   gpsState = state;
   if (state == GpsStatus.GPS_EVENT_SATELLITE_STATUS && gpsStatus != null) {
     for (int j = 0; j < 36; j++) {
       /** Resetting all the satellites to non locked */
       if ((satellites[j] != null)) {
         satellites[j].isLocked(false);
       }
     }
     Iterable<GpsSatellite> andSatellites = gpsStatus.getSatellites();
     Iterator<GpsSatellite> sat = andSatellites.iterator();
     int i = 0;
     while (sat.hasNext()) {
       GpsSatellite satellite = sat.next();
       if (satellites[i] == null) {
         satellites[i] = new Satellite();
       }
       if (i < 36) {
         satellites[i].isLocked(satellite.usedInFix());
         satellites[i].id = i;
         satellites[i].azimut = satellite.getAzimuth();
         satellites[i].elev = satellite.getElevation();
         satellites[i].snr = (int) satellite.getSnr();
         if (satellite.usedInFix()) {
           i++;
         }
       }
     }
     numSatellites = i;
     if (numSatellites > 0) {
       receiverList.receiveSatellites(satellites);
     }
   }
   // updateSolution(state);
 }
 private void showSats() {
   int satNum = 0;
   StringBuilder builder = new StringBuilder();
   for (GpsSatellite sat : gps.getSatellites()) {
     builder.append("Satellite Data: ");
     builder.append("\nnumber: ");
     builder.append(satNum);
     builder.append("\nAzimuth: ");
     builder.append(sat.getAzimuth());
     builder.append("\nElevation: ");
     builder.append(sat.getElevation());
     builder.append("\nSNR: ");
     builder.append(sat.getSnr());
     builder.append("\nUsed in fix?: ");
     builder.append(sat.usedInFix());
     log("\n\n" + builder.toString());
     builder.delete(0, builder.length());
     satNum++;
   }
 }
Esempio n. 5
0
  @Override
  public void onGpsStatusChanged(int event) {
    if (locationManager == null) return;

    android.location.GpsStatus gpsStatus = locationManager.getGpsStatus(null);

    if (gpsStatus == null) return;

    int cnt0 = 0, cnt1 = 0;
    Iterable<GpsSatellite> list = gpsStatus.getSatellites();
    for (GpsSatellite satellite : list) {
      cnt0++;
      if (satellite.usedInFix()) {
        cnt1++;
      }
    }
    mKnownSatellites = cnt0;
    mUsedInLastFixSatellites = cnt1;
    if (listener != null) listener.onTick();
  }
Esempio n. 6
0
  /////// GPS status callback
  public void onGpsStatusChanged(int status) {
    DataOutputStream file = fout[2];
    long tim = System.currentTimeMillis();

    // Get the status
    GpsStatus lStatus = null;
    lStatus = mLocMan.getGpsStatus(null);

    if (status == GpsStatus.GPS_EVENT_FIRST_FIX) {
      mLV.addtext("GPS_EVENT_FIRST_FIX - TTFX =" + lStatus.getTimeToFirstFix());
    } else if (status == GpsStatus.GPS_EVENT_STARTED) {
      mLV.addtext("GPS_EVENT_STARTED " + tim);
    } else if (status == GpsStatus.GPS_EVENT_STOPPED) {
      mLV.addtext("GPS_EVENT_STOPPED " + tim);
    }

    if (lStatus != null) {
      if (file != null) {
        try {
          file.writeLong(tim);
          Iterable<GpsSatellite> satlist = lStatus.getSatellites();
          for (GpsSatellite sat : satlist) {
            file.writeInt(sat.getPrn());
            file.writeFloat(sat.getAzimuth());
            file.writeFloat(sat.getElevation());
            file.writeFloat(sat.getSnr());
            file.writeBoolean(sat.hasAlmanac());
            file.writeBoolean(sat.hasEphemeris());
            file.writeBoolean(sat.usedInFix());
            if (satlist.iterator().hasNext()) file.writeChar('@');
            else file.writeChar('#');
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
Esempio n. 7
0
  /* (non-Javadoc)
   * @see android.location.GpsStatus.Listener#onGpsStatusChanged(int)
   */
  @Override
  public void onGpsStatusChanged(final int event) {
    int satCount = -1;

    switch (event) {
      case GpsStatus.GPS_EVENT_FIRST_FIX:
        satCount = 0;
        break;
      case GpsStatus.GPS_EVENT_STARTED:
        satCount = -1;
        break;
      case GpsStatus.GPS_EVENT_STOPPED:
        satCount = -1;
        break;
      case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        // first of all we check if the time from the last used fix to the current fix is greater
        // than the logging interval
        if ((event != GpsStatus.GPS_EVENT_SATELLITE_STATUS)
            || (mLastGPSTimestamp + gpsLoggingInterval) < System.currentTimeMillis()) {
          mLastGPSTimestamp = System.currentTimeMillis(); // save the time of this fix

          final GpsStatus status = lmgr.getGpsStatus(null);

          // Count active satellites
          satCount = 0;
          for (@SuppressWarnings("unused") final GpsSatellite sat : status.getSatellites()) {
            satCount++;
          }
        }
        break;
      default:
        break;
    }

    if (mListener != null) {
      mListener.onSatInfo(satCount);
    }
  }
Esempio n. 8
0
 static String gpsToString(GpsStatus status, int eventType) {
   StringBuilder sb = new StringBuilder();
   sb.append(eventType);
   sb.append("|ttff:");
   sb.append(status.getTimeToFirstFix());
   sb.append("|maxSatellites:");
   sb.append(status.getMaxSatellites());
   sb.append("|");
   int i = 0;
   for (GpsSatellite sat : status.getSatellites()) {
     i++;
     sb.append("Satellite_");
     sb.append(i);
     sb.append("::hasAlmanac:");
     sb.append(sat.hasAlmanac());
     sb.append("::hasEphemeris:");
     sb.append(sat.hasEphemeris());
     sb.append("::usedInFix:");
     sb.append(sat.usedInFix());
     sb.append("|");
   }
   return sb.toString();
 }
Esempio n. 9
0
  public void onGpsStatusChanged(int event) {
    switch (event) {
      case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
        int satsInView = 0;
        int satsUsed = 0;
        Iterable<GpsSatellite> sats = gpsStatus.getSatellites();
        for (GpsSatellite sat : sats) {
          satsInView++;
          if (sat.usedInFix()) {
            satsUsed++;
          }
        }
        satellite.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView));
        if (satsUsed == 0) {
          fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play));
          data.setRunning(false);
          status.setText("");
          stopService(new Intent(getBaseContext(), GpsServices.class));
          fab.setVisibility(View.INVISIBLE);
          refresh.setVisibility(View.INVISIBLE);
          accuracy.setText("");
          status.setText(getResources().getString(R.string.waiting_for_fix));
          firstfix = true;
        }
        break;

      case GpsStatus.GPS_EVENT_STOPPED:
        if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
          showGpsDisabledDialog();
        }
        break;
      case GpsStatus.GPS_EVENT_FIRST_FIX:
        break;
    }
  }
Esempio n. 10
0
  public void onGpsStatusChanged(int event) {
    switch (event) {
      case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        boolean switchedAlready = switchToNetwork;
        status = locationManager.getGpsStatus(status);
        if (!switchToNetwork) {
          int sat_counter = 0;
          Iterator<GpsSatellite> it = status.getSatellites().iterator();
          while (it.hasNext()) {
            it.next();
            sat_counter++;
          }
          satsAvailable = sat_counter;
          if (firstFixReceived) {
            // If after a firstFix was received, we get less than 3 sats
            // available, we switch to network
            if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_2_NUMBER) {
              switchToNetwork = true;
            }
          } else {
            timeInterval = System.currentTimeMillis() - startTime;

            if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_1) {
              // Check do we have enough satellites on wait interval 1
              if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_1_NUMBER) {
                switchToNetwork = true;
              }
            }
            if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_2) {
              // Check do we have enough satellites on wait interval 2
              if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_2_NUMBER) {
                switchToNetwork = true;
              }
            }
            if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_3) {
              // Check do we have enough satellites on wait interval 3
              if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_3_NUMBER) {
                switchToNetwork = true;
              }
            }

            if (timeInterval > GPS_FINAL_WAIT_INTERVAL) {
              // If we are unable to get the fix till now, we switch
              // to network anyway
              switchToNetwork = true;
            }
          }
        }
        if (!switchedAlready && switchToNetwork) {
          locationManager.removeUpdates(locationListener);
          if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, minTime, minDistance, locationListener);
            ((TextView) activity.findViewById(R.id.information))
                .setText(R.string.geo_message_receiving_from_network);
          } else {
            Toast.makeText(
                    activity.getApplicationContext(),
                    R.string.gps_failed_network_disabled,
                    Toast.LENGTH_LONG)
                .show();
            openSettings();
          }
        }

        break;
      case GpsStatus.GPS_EVENT_STARTED:
        startTime = System.currentTimeMillis();
        switchToNetwork = false;
        firstFixReceived = false;
        break;
      case GpsStatus.GPS_EVENT_FIRST_FIX:
        firstFixReceived = true;
        break;
    }

    ((TextView) activity.findViewById(R.id.satscount))
        .setText(activity.getText(R.string.geo_text_sats_available) + ": " + satsAvailable);
    ((TextView) activity.findViewById(R.id.time))
        .setText(
            activity.getText(R.string.geo_text_wait)
                + ": "
                + Math.round(timeInterval / 1000)
                + " s");
  }