diff options
author | Yu-Han Yang <yuhany@google.com> | 2019-11-22 13:50:41 -0800 |
---|---|---|
committer | Yu-Han Yang <yuhany@google.com> | 2019-11-26 16:37:16 +0000 |
commit | 15e4303a5bfe69a90c6003dd7fb90010ee70cd97 (patch) | |
tree | 066bc2040b5db329102ba4a1bd92e3e89f3aad62 /location/tests | |
parent | b485ee50a14c1b7838bedaae37dc7857d9f30869 (diff) |
Add basebandCn0DbHz to GnssStatus
The new basebandCn0DbHz is the carrier-to-noise density measured at the
baseband. The old Cn0DbHz is measured at the attenna port. Adding
the new field so that ecosystem will report both and avoid reporting
inconsistent signal strengths in one field. See go/r-gnss-hal for
detailed design.
Bug: 136136192
Test: atest GnssStatusTest
Change-Id: Idbfb611c6cb1c8d00c1f3bb719e422177a5ff7f2
Diffstat (limited to 'location/tests')
-rw-r--r-- | location/tests/locationtests/src/android/location/GnssStatusTest.java | 130 | ||||
-rw-r--r-- | location/tests/locationtests/src/android/location/SatelliteInfo.java | 155 |
2 files changed, 0 insertions, 285 deletions
diff --git a/location/tests/locationtests/src/android/location/GnssStatusTest.java b/location/tests/locationtests/src/android/location/GnssStatusTest.java deleted file mode 100644 index 79ea0d61b799..000000000000 --- a/location/tests/locationtests/src/android/location/GnssStatusTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package android.location; - -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.List; -import junit.framework.TestCase; - -/** - * Unit tests for {@link GnssStatus}. - */ -@SmallTest -public class GnssStatusTest extends TestCase { - - private static final String TAG = GnssStatusTest.class.getSimpleName(); - public void setUp() throws Exception { - super.setUp(); - } - - /* - * Create {@link GnssStatus} with default value, verify whether its fields are set correctly. - * - */ - public void testEmptyGnssStatus() throws Exception { - Log.i(TAG, "testEmptyGnssStatus"); - List<SatelliteInfo> svInfos = new ArrayList<>(); - GnssStatus gnssStatus = createGnssStatus(svInfos); - verifyGnssStatus(svInfos, gnssStatus); - } - - /* - * Create {@link GnssStatus} with only one satellite info, verify whether its fields are set - * correctly. - */ - public void testOneSatelliteGnssStatus() throws Exception { - Log.i(TAG, "testOneSatelliteGnssStatus"); - List<SatelliteInfo> svInfos = new ArrayList<>(); - SatelliteInfo svInfo = - new SatelliteInfo(100,1, true, true, true, true, 100f, 20.3f, 45.5f, 100.23f); - svInfos.add(svInfo); - GnssStatus gnssStatus = createGnssStatus(svInfos); - verifyGnssStatus(svInfos, gnssStatus); - } - - /* - * Create {@link GnssStatus} with multiple satellite info, verify whether its fields are set - * correctly. - */ - public void testMultipleSatellitesGnssStatus() throws Exception { - Log.i(TAG, "testMultipleSatellitesGnssStatus"); - List<SatelliteInfo> svInfos = new ArrayList<>(); - SatelliteInfo svInfo1 = - new SatelliteInfo(20, 1,true, true, true, true, 10.1f, 20.3f, 45.5f, 111.23f); - SatelliteInfo svInfo2 = - new SatelliteInfo(50, 2, true, false, true, false, 20.2f, 21.3f, 46.5f, 222.23f); - SatelliteInfo svInfo3 = - new SatelliteInfo(192, 3, false, true, false, true, 30.3f, 22.3f, 47.5f, 333.23f); - SatelliteInfo svInfo4 = - new SatelliteInfo(250, 4, false, false, false, false, 40.4f, 23.3f, 48.5f, 444.23f); - svInfos.add(svInfo1); - svInfos.add(svInfo2); - svInfos.add(svInfo3); - svInfos.add(svInfo4); - GnssStatus gnssStatus = createGnssStatus(svInfos); - verifyGnssStatus(svInfos, gnssStatus); - } - - private void verifyGnssStatus(List<SatelliteInfo> svInfos, GnssStatus gnssStatus) { - Log.i(TAG, String.format("Verifing {0} satellites info.",svInfos.size())); - assertEquals(TAG + "::SatelliteCount", svInfos.size(), - gnssStatus.getSatelliteCount()); - for (int i = 0; i< svInfos.size(); i++) { - SatelliteInfo svInfo = svInfos.get(i); - assertEquals(TAG + "::Svid", svInfo.mSvid, gnssStatus.getSvid(i)); - assertEquals(TAG + "::ConstellationType", svInfo.mConstellationType, - gnssStatus.getConstellationType(i)); - assertEquals(TAG + "::Cn0DbHz", svInfo.mCn0DbHz, gnssStatus.getCn0DbHz(i)); - assertEquals(TAG + "::Elevation", svInfo.mElevation, - gnssStatus.getElevationDegrees(i)); - assertEquals(TAG + "::Azimuth", svInfo.mAzimuth, gnssStatus.getAzimuthDegrees(i)); - assertEquals(TAG + "::CarrierFrequencyHz", svInfo.mCarrierFrequency, - gnssStatus.getCarrierFrequencyHz(i)); - assertEquals(TAG + "::hasEphemerisData", svInfo.mHasEphemris, - gnssStatus.hasEphemerisData(i)); - assertEquals(TAG + "::HasAlmanacData", svInfo.mHasAlmanac, - gnssStatus.hasAlmanacData(i)); - assertEquals(TAG + "::UsedInFix", svInfo.mUsedInFix, gnssStatus.usedInFix(i)); - assertEquals(TAG + "::HasCarrierFrequencyHz", svInfo.mHasCarriesFrequency, - gnssStatus.hasCarrierFrequencyHz(i)); - } - } - - private static GnssStatus createGnssStatus(List<SatelliteInfo> svInfos) throws Exception { - Class<?> intClass = Integer.TYPE; - Class<?> floatArrayClass = Class.forName("[F"); - Class<?> intArrayClass = Class.forName("[I"); - Class[] cArg = new Class[6]; - cArg[0] = intClass; - cArg[1] = intArrayClass; - cArg[2] = floatArrayClass; - cArg[3] = floatArrayClass; - cArg[4] = floatArrayClass; - cArg[5] = floatArrayClass; - Constructor<GnssStatus> ctor = GnssStatus.class.getDeclaredConstructor(cArg); - ctor.setAccessible(true); - return ctor.newInstance(svInfos.size(), - SatelliteInfo.getSvidWithFlagsArray(svInfos), - SatelliteInfo.getCn0sArray(svInfos), - SatelliteInfo.getElevationsArray(svInfos), - SatelliteInfo.getAzimuthsArray(svInfos), - SatelliteInfo.getCarrierFrequencyArray(svInfos)); - } -} diff --git a/location/tests/locationtests/src/android/location/SatelliteInfo.java b/location/tests/locationtests/src/android/location/SatelliteInfo.java deleted file mode 100644 index b6453ef0eabc..000000000000 --- a/location/tests/locationtests/src/android/location/SatelliteInfo.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package android.location; - -import java.util.List; - -/* - * Helper class to store single Satellite info, only used it in the unit test. - */ -public class SatelliteInfo { - private static final int SVID_MAX_BIT_INDEX = 32; - private static final int SVID_SHIFT_WIDTH = 8; - private static final int CONSTELLATION_TYPE_SHIFT_WIDTH = 4; - - // Index for the bits in mSvidWithFlag - private static final int GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA_BIT_INDEX = 0; - private static final int GNSS_SV_FLAGS_HAS_ALMANAC_DATA_BIT_INDEX = 1; - private static final int GNSS_SV_FLAGS_USED_IN_FIX_BIT_INDEX = 2; - private static final int GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY_BIT_INDEX = 3; - public int mSvid; - public int mSvidWithFlag; - public float mCn0DbHz; - public float mElevation; - public float mAzimuth; - public float mCarrierFrequency; - - /* - * Flag fields, it stores the same information as svidWithFlag, but in different format, easy for - * the unit test. - */ - public int mConstellationType; - public boolean mHasEphemris; - public boolean mHasAlmanac; - public boolean mUsedInFix; - public boolean mHasCarriesFrequency; - - public SatelliteInfo(int svid, int constellationType, boolean hasEphemris, boolean hasAlmanac, - boolean usedInFix, boolean hasCarriesFrequency, float cn0, float elevation, float azimuth, - float carrierFrequency) { - mSvidWithFlag = - setRange(mSvidWithFlag, constellationType, CONSTELLATION_TYPE_SHIFT_WIDTH, SVID_SHIFT_WIDTH); - mSvidWithFlag = setRange(mSvidWithFlag, svid, SVID_SHIFT_WIDTH, SVID_MAX_BIT_INDEX); - mSvidWithFlag = setBit(mSvidWithFlag, hasEphemris, GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA_BIT_INDEX); - mSvidWithFlag = setBit(mSvidWithFlag, hasAlmanac, GNSS_SV_FLAGS_HAS_ALMANAC_DATA_BIT_INDEX); - mSvidWithFlag = setBit(mSvidWithFlag, usedInFix, GNSS_SV_FLAGS_USED_IN_FIX_BIT_INDEX); - mSvidWithFlag = - setBit(mSvidWithFlag, hasCarriesFrequency, GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY_BIT_INDEX); - this.mSvid = svid; - this.mConstellationType = constellationType; - this.mCn0DbHz = cn0; - this.mElevation = elevation; - this.mAzimuth = azimuth; - this.mCarrierFrequency = carrierFrequency; - this.mHasEphemris = hasEphemris; - this.mHasAlmanac = hasAlmanac; - this.mUsedInFix = usedInFix; - this.mHasCarriesFrequency = hasCarriesFrequency; - } - - /* - * Gernerate svidWithFlags array from svInfos - */ - public static int[] getSvidWithFlagsArray(List<SatelliteInfo> svInfos) { - int[] svidWithFlags = new int[svInfos.size()]; - for (int i = 0; i< svInfos.size(); i++) { - svidWithFlags[i] = svInfos.get(i).mSvidWithFlag; - } - return svidWithFlags; - } - - /* - * Gernerate cn0s array from svInfos - */ - public static float[] getCn0sArray(List<SatelliteInfo> svInfos) { - float[] cn0s = new float[svInfos.size()]; - for (int i = 0; i< svInfos.size(); i++) { - cn0s[i] = svInfos.get(i).mCn0DbHz; - } - return cn0s; - } - - /* - * Gernerate elevations array from svInfos - */ - public static float[] getElevationsArray(List<SatelliteInfo> svInfos) { - float[] elevations = new float[svInfos.size()]; - for (int i = 0; i< svInfos.size(); i++) { - elevations[i] = svInfos.get(i).mElevation; - } - return elevations; - } - - /* - * Gernerate azimuths array from svInfos - */ - public static float[] getAzimuthsArray(List<SatelliteInfo> svInfos) { - float[] azimuths = new float[svInfos.size()]; - for (int i = 0; i< svInfos.size(); i++) { - azimuths[i] = svInfos.get(i).mAzimuth; - } - return azimuths; - } - - /* - * Gernerate carrierFrequency array from svInfos - */ - public static float[] getCarrierFrequencyArray(List<SatelliteInfo> svInfos) { - float[] carrierFrequencies = new float[svInfos.size()]; - for (int i = 0; i< svInfos.size(); i++) { - carrierFrequencies[i] = svInfos.get(i).mCarrierFrequency; - } - return carrierFrequencies; - } - - private int setBit(int targetValue, boolean value, int index) { - if (value) { - targetValue = targetValue | (1 << index); - } else { - targetValue = targetValue & ~(1 << index); - } - return targetValue; - } - - /* - * Set the bit in the range [fromIndex, toIndex), index start from the lowest bit. - * value -> 1 1 0 1 1 0 1 0 - * index -> 7 6 5 4 3 2 1 0 - * This function will set the bit in the range to the lowest X bits of the value. - */ - private int setRange(int targetValue, int value, int fromIndex, int toIndex) { - int rangeLen = toIndex - fromIndex; - int valueMask = (1 << rangeLen) -1; - value &= valueMask; - value = value << fromIndex; - valueMask = valueMask << fromIndex; - targetValue &= (~valueMask); - targetValue |= value; - return targetValue; - } - -}
\ No newline at end of file |