< android.location.GnssStatus java examples

android.location.GnssStatus - java examples

Here are the examples of the java api android.location.GnssStatus taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

14 Examples 7

19 View Complete Implementation : GpsModuleCallback.java , under Apache License 2.0 , by androidthings
/**
 * Callback reporting GPS satellite status.
 *
 * @param status Latest status information from GPS module.
 */
public abstract void onGpsSatelliteStatus(GnssStatus status);

19 View Complete Implementation : FileLogger.java , under Apache License 2.0 , by google
@Override
public void onGnssStatusChanged(GnssStatus gnssStatus) {
}

19 View Complete Implementation : UiLogger.java , under Apache License 2.0 , by google
@Override
public void onGnssStatusChanged(GnssStatus gnssStatus) {
    logStatusEvent("onGnssStatusChanged: " + gnssStatusToString(gnssStatus));
}

19 View Complete Implementation : ShadowLocationManager.java , under MIT License , by robolectric
/**
 * Sends a {@link GnssStatus} to all registered {@link GnssStatus.Callback}s.
 */
public void sendGnssStatus(GnssStatus status) {
    Map<GnssStatus.Callback, Handler> callbacks;
    synchronized (gnssStatusCallbacks) {
        callbacks = new LinkedHashMap<>(gnssStatusCallbacks);
    }
    for (Map.Entry<GnssStatus.Callback, Handler> callback : callbacks.entrySet()) {
        callback.getValue().post(() -> callback.getKey().onSatelliteStatusChanged(status));
    }
}

18 View Complete Implementation : GnssStatusBuilderTest.java , under MIT License , by robolectric
@Test
public void emptyBuilder() {
    GnssStatus status = GnssStatusBuilder.create().build();
    assertThat(status.getSatelliteCount()).isEqualTo(0);
}

17 View Complete Implementation : GnssStatusBuilderTest.java , under MIT License , by robolectric
@Test
public void builder_addAll() {
    GnssSatelliteInfo.Builder infoBuilder = GnssSatelliteInfo.builder().setConstellation(GnssStatus.CONSTELLATION_GPS).setCn0DbHz(CN0).setElevation(ELEVATION).setAzimuth(AZIMUTH).setHasEphemeris(HAS_EPHEMERIS).setHasAlmanac(HAS_ALMANAC).setUsedInFix(USED_IN_FIX);
    List<GnssSatelliteInfo> satelliteInfos = new ArrayList<>();
    satelliteInfos.add(infoBuilder.setSvid(SVID).build());
    satelliteInfos.add(infoBuilder.setSvid(SVID + 1).build());
    satelliteInfos.add(infoBuilder.setSvid(SVID - 1).build());
    GnssStatus status = GnssStatusBuilder.create().addAllSatellites(satelliteInfos).build();
    assertThat(status.getSatelliteCount()).isEqualTo(3);
    assertThat(status.getSvid(0)).isEqualTo(SVID);
    assertThat(status.getSvid(1)).isEqualTo(SVID + 1);
    assertThat(status.getSvid(2)).isEqualTo(SVID - 1);
}

16 View Complete Implementation : GnssStatusBuilderTest.java , under MIT License , by robolectric
@Test
public void builder_buildFrom() {
    GnssSatelliteInfo.Builder infoBuilder = GnssSatelliteInfo.builder().setConstellation(GnssStatus.CONSTELLATION_GPS).setCn0DbHz(CN0).setElevation(ELEVATION).setAzimuth(AZIMUTH).setHasEphemeris(HAS_EPHEMERIS).setHasAlmanac(HAS_ALMANAC).setUsedInFix(USED_IN_FIX);
    GnssSatelliteInfo info1 = infoBuilder.setSvid(SVID).build();
    GnssSatelliteInfo info2 = infoBuilder.setSvid(SVID * 2).build();
    GnssStatus status = GnssStatusBuilder.buildFrom(info1, info2);
    assertThat(status.getSatelliteCount()).isEqualTo(2);
    assertThat(status.getSvid(0)).isEqualTo(SVID);
    assertThat(status.getSvid(1)).isEqualTo(SVID * 2);
}

16 View Complete Implementation : GnssStatusBuilderTest.java , under MIT License , by robolectric
@Test
@Config(minSdk = O)
public void addSatellite_carrierFrequency() {
    GnssSatelliteInfo.Builder infoBuilder = GnssSatelliteInfo.builder().setConstellation(GnssStatus.CONSTELLATION_GPS).setCn0DbHz(CN0).setElevation(ELEVATION).setAzimuth(AZIMUTH).setHasEphemeris(HAS_EPHEMERIS).setHasAlmanac(HAS_ALMANAC).setUsedInFix(USED_IN_FIX);
    GnssStatus status = GnssStatusBuilder.create().addSatellite(infoBuilder.setSvid(SVID).build()).addSatellite(infoBuilder.setSvid(SVID + 1).setCarrierFrequencyHz(null).build()).addSatellite(infoBuilder.setSvid(SVID - 1).setCarrierFrequencyHz(1575.42f).build()).build();
    assertThat(status.getSatelliteCount()).isEqualTo(3);
    assertThat(status.hasCarrierFrequencyHz(0)).isFalse();
    assertThat(status.getCarrierFrequencyHz(0)).isEqualTo(0.0f);
    assertThat(status.hasCarrierFrequencyHz(1)).isFalse();
    assertThat(status.getCarrierFrequencyHz(1)).isEqualTo(0.0f);
    assertThat(status.hasCarrierFrequencyHz(2)).isTrue();
    assertThat(status.getCarrierFrequencyHz(2)).isEqualTo(1575.42f);
}

15 View Complete Implementation : UiLogger.java , under Apache License 2.0 , by google
private String gnssStatusToString(GnssStatus gnssStatus) {
    StringBuilder builder = new StringBuilder("SATELLITE_STATUS | [Satellites:\n");
    for (int i = 0; i < gnssStatus.getSatelliteCount(); i++) {
        builder.append("Constellation = ").append(getConstellationName(gnssStatus.getConstellationType(i))).append(", ");
        builder.append("Svid = ").append(gnssStatus.getSvid(i)).append(", ");
        builder.append("Cn0DbHz = ").append(gnssStatus.getCn0DbHz(i)).append(", ");
        builder.append("Elevation = ").append(gnssStatus.getElevationDegrees(i)).append(", ");
        builder.append("Azimuth = ").append(gnssStatus.getAzimuthDegrees(i)).append(", ");
        builder.append("hasEphemeris = ").append(gnssStatus.hasEphemerisData(i)).append(", ");
        builder.append("hasAlmanac = ").append(gnssStatus.hasAlmanacData(i)).append(", ");
        builder.append("usedInFix = ").append(gnssStatus.usedInFix(i)).append("\n");
    }
    builder.append("]");
    return builder.toString();
}

14 View Complete Implementation : NmeaTest.java , under Apache License 2.0 , by androidthings
@Test
public void testGps_Satellites_NoFix() throws IOException {
    // Set up fake device
    LoopbackUartDevice gpsDevice = new LoopbackUartDevice();
    NmeaGpsModule gpsModule = new NmeaGpsModule(gpsDevice, DEFAULT_BAUD, DEFAULT_ACCURACY, null);
    GpsModuleCallback mockCallback = Mockito.mock(GpsModuleCallback.class);
    gpsModule.setGpsModuleCallback(mockCallback);
    // Inject NMEA test data
    byte[] buffer = NmeaSampleData.SAMPLE_SAT_VIEW_NO_FIX;
    gpsDevice.write(buffer, buffer.length);
    // Verify callback results
    Mockito.verify(mockCallback, times(6)).onNmeaMessage(anyString());
    Mockito.verify(mockCallback, never()).onGpsTimeUpdate(anyLong());
    Mockito.verify(mockCallback, never()).onGpsLocationUpdate(any(Location.class));
    ArgumentCaptor<GnssStatus> args = ArgumentCaptor.forClass(GnssStatus.class);
    Mockito.verify(mockCallback, times(1)).onGpsSatelliteStatus(args.capture());
    GnssStatus status = args.getValue();
    assertEquals(NmeaSampleData.EXPECTED_SAT_COUNT, status.getSatelliteCount());
}

14 View Complete Implementation : ShadowLocationManagerTest.java , under MIT License , by robolectric
@Test
@Config(minSdk = N)
@LooperMode(Mode.PAUSED)
public void testRegisterGnssStatusCallback_withNonMainHandler() throws Exception {
    HandlerThread ht = new HandlerThread("BackgroundThread");
    ht.start();
    try {
        TestGnssCallback callback = new TestGnssCallback();
        GnssStatus status = GnssStatusBuilder.create().build();
        Handler handler = new Handler(ht.getLooper());
        locationManager.registerGnssStatusCallback(callback, handler);
        shadowLocationManager.sendGnssStatus(status);
        assertThat(callback.lastGnssStatus).isNull();
        shadowOf(ht.getLooper()).idle();
        assertThat(callback.lastGnssStatus).isEqualTo(status);
    } finally {
        ht.quit();
        ht.join();
    }
}

14 View Complete Implementation : ShadowLocationManagerTest.java , under MIT License , by robolectric
@Test
@Config(minSdk = N)
@LooperMode(Mode.PAUSED)
public void testRegisterGnssStatusCallback_withMainHandler() {
    TestGnssCallback callback = new TestGnssCallback();
    GnssStatus status = GnssStatusBuilder.create().build();
    shadowLocationManager.sendGnssStatus(status);
    assertThat(callback.lastGnssStatus).isNull();
    locationManager.registerGnssStatusCallback(callback);
    shadowLocationManager.sendGnssStatus(status);
    assertThat(callback.lastGnssStatus).isNull();
    shadowOf(Looper.getMainLooper()).idle();
    assertThat(callback.lastGnssStatus).isEqualTo(status);
    callback.lastGnssStatus = null;
    locationManager.unregisterGnssStatusCallback(callback);
    shadowLocationManager.sendGnssStatus(status);
    assertThat(callback.lastGnssStatus).isNull();
}

13 View Complete Implementation : NmeaTest.java , under Apache License 2.0 , by androidthings
@Test
public void testGps_ValidFix() throws IOException {
    // Set up fake device
    LoopbackUartDevice gpsDevice = new LoopbackUartDevice();
    NmeaGpsModule gpsModule = new NmeaGpsModule(gpsDevice, DEFAULT_BAUD, DEFAULT_ACCURACY, null);
    GpsModuleCallback mockCallback = Mockito.mock(GpsModuleCallback.class);
    gpsModule.setGpsModuleCallback(mockCallback);
    // Inject NMEA test data
    byte[] buffer = NmeaSampleData.SAMPLE_VALID_FIX;
    gpsDevice.write(buffer, buffer.length);
    // Verify callback results
    Mockito.verify(mockCallback, times(6)).onNmeaMessage(anyString());
    Mockito.verify(mockCallback, times(1)).onGpsTimeUpdate(NmeaSampleData.EXPECTED_TIMESTAMP);
    ArgumentCaptor<GnssStatus> statusArgs = ArgumentCaptor.forClass(GnssStatus.class);
    Mockito.verify(mockCallback, times(1)).onGpsSatelliteStatus(statusArgs.capture());
    GnssStatus status = statusArgs.getValue();
    assertEquals(NmeaSampleData.EXPECTED_SAT_COUNT, status.getSatelliteCount());
    ArgumentCaptor<Location> locationArgs = ArgumentCaptor.forClass(Location.class);
    Mockito.verify(mockCallback, times(3)).onGpsLocationUpdate(locationArgs.capture());
    // Verify lat/lng for each report
    for (Location item : locationArgs.getAllValues()) {
        assertEquals(NmeaSampleData.EXPECTED_LATITUDE, item.getLatitude(), 0.0001);
        assertEquals(NmeaSampleData.EXPECTED_LONGITUDE, item.getLongitude(), 0.0001);
    }
}

13 View Complete Implementation : GnssStatusBuilderTest.java , under MIT License , by robolectric
@Test
public void builder_addSatellite() {
    GnssStatusBuilder builder = GnssStatusBuilder.create();
    builder.addSatellite(GnssSatelliteInfo.builder().setConstellation(GnssStatus.CONSTELLATION_GPS).setSvid(SVID).setCn0DbHz(CN0).setElevation(ELEVATION).setAzimuth(AZIMUTH).setHasEphemeris(HAS_EPHEMERIS).setHasAlmanac(HAS_ALMANAC).setUsedInFix(USED_IN_FIX).build());
    GnssStatus status = builder.build();
    assertThat(status.getSatelliteCount()).isEqualTo(1);
    assertThat(status.getConstellationType(0)).isEqualTo(GnssStatus.CONSTELLATION_GPS);
    assertThat(status.getSvid(0)).isEqualTo(SVID);
    assertThat(status.getCn0DbHz(0)).isEqualTo(CN0);
    assertThat(status.getElevationDegrees(0)).isEqualTo(ELEVATION);
    assertThat(status.getAzimuthDegrees(0)).isEqualTo(AZIMUTH);
    assertThat(status.hasEphemerisData(0)).isEqualTo(HAS_EPHEMERIS);
    assertThat(status.hasAlmanacData(0)).isEqualTo(HAS_ALMANAC);
    assertThat(status.usedInFix(0)).isEqualTo(USED_IN_FIX);
}