Skip to content

Commit

Permalink
fix: Use bitmask to check valid measurement ADR state
Browse files Browse the repository at this point in the history
Closes #478
  • Loading branch information
barbeau committed Feb 15, 2021
1 parent b9d99b9 commit c4aed07
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.android.gpstest

import android.location.GnssMeasurement.*
import android.os.Build
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.android.gpstest.model.GnssType
import com.android.gpstest.model.SatelliteStatus
import com.android.gpstest.model.SbasType
import com.android.gpstest.util.SatelliteUtils
import org.junit.Assert.assertEquals
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

Expand Down Expand Up @@ -181,4 +182,48 @@ class SatelliteUtilsTest {
assertEquals("1 NAVSTAR unsupported", gpsBadCfKey)
}
}

/**
* Test checking support for accumulated delta range state
*/
@Test
fun testAccumulatedDeltaRangeStateSupport() {
// Valid states
var adrState = ADR_STATE_VALID
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_VALID or ADR_STATE_HALF_CYCLE_REPORTED
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_VALID or ADR_STATE_HALF_CYCLE_RESOLVED
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_VALID or ADR_STATE_HALF_CYCLE_REPORTED or ADR_STATE_RESET
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_VALID or ADR_STATE_HALF_CYCLE_REPORTED or ADR_STATE_HALF_CYCLE_RESOLVED
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_VALID or ADR_STATE_HALF_CYCLE_REPORTED or ADR_STATE_HALF_CYCLE_RESOLVED or ADR_STATE_CYCLE_SLIP
assertTrue(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

// Invalid states
adrState = ADR_STATE_UNKNOWN
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_HALF_CYCLE_REPORTED
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_CYCLE_SLIP
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_RESET
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_CYCLE_SLIP or ADR_STATE_HALF_CYCLE_REPORTED
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))

adrState = ADR_STATE_CYCLE_SLIP or ADR_STATE_HALF_CYCLE_REPORTED or ADR_STATE_RESET
assertFalse(SatelliteUtils.isAccumulatedDeltaRangeStateValid(adrState))
}
}
26 changes: 17 additions & 9 deletions GPSTest/src/main/java/com/android/gpstest/util/SatelliteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,24 @@ public static boolean isAutomaticGainControlSupported(GnssMeasurement gnssMeasur
* @param gnssMeasurement
* @return true if carrier phase is supported for this GNSS measurement, false if it is not
*/
@RequiresApi(api = Build.VERSION_CODES.N)
public static boolean isCarrierPhaseSupported(GnssMeasurement gnssMeasurement) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return gnssMeasurement.getAccumulatedDeltaRangeState() == GnssMeasurement.ADR_STATE_VALID
&& gnssMeasurement.getAccumulatedDeltaRangeMeters() != 0.0d;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return gnssMeasurement.hasCarrierPhase()
&& gnssMeasurement.getCarrierPhase() != 0.0d;
} else {
return false;
}
return isAccumulatedDeltaRangeStateValid(gnssMeasurement.getAccumulatedDeltaRangeState())
&& gnssMeasurement.getAccumulatedDeltaRangeMeters() != 0.0d;
}


/**
* Returns the result of the GnssMeasurement.ADR_STATE_VALID bitmask being applied to the
* AccumulatedDeltaRangeState from a GnssMeasurement - true if the ADR state is valid,
* false if it is not
* @param accumulatedDeltaRangeState accumulatedDeltaRangeState from GnssMeasurement
* @return the result of the GnssMeasurement.ADR_STATE_VALID bitmask being applied to the
* * AccumulatedDeltaRangeState of the given GnssMeasurement - true if the ADR state is valid,
* * false if it is not
*/
public static boolean isAccumulatedDeltaRangeStateValid(int accumulatedDeltaRangeState) {
return (GnssMeasurement.ADR_STATE_VALID & accumulatedDeltaRangeState) == GnssMeasurement.ADR_STATE_VALID;
}

/**
Expand Down

0 comments on commit c4aed07

Please sign in to comment.