Exemplo n.º 1
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++;
   }
 }
Exemplo n.º 3
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();
        }
      }
    }
  }