1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package android.location; 18 19 import java.util.List; 20 21 /* 22 * Helper class to store single Satellite info, only used it in the unit test. 23 */ 24 public class SatelliteInfo { 25 private static final int SVID_MAX_BIT_INDEX = 32; 26 private static final int SVID_SHIFT_WIDTH = 8; 27 private static final int CONSTELLATION_TYPE_SHIFT_WIDTH = 4; 28 29 // Index for the bits in mSvidWithFlag 30 private static final int GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA_BIT_INDEX = 0; 31 private static final int GNSS_SV_FLAGS_HAS_ALMANAC_DATA_BIT_INDEX = 1; 32 private static final int GNSS_SV_FLAGS_USED_IN_FIX_BIT_INDEX = 2; 33 private static final int GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY_BIT_INDEX = 3; 34 public int mSvid; 35 public int mSvidWithFlag; 36 public float mCn0DbHz; 37 public float mElevation; 38 public float mAzimuth; 39 public float mCarrierFrequency; 40 41 /* 42 * Flag fields, it stores the same information as svidWithFlag, but in different format, easy for 43 * the unit test. 44 */ 45 public int mConstellationType; 46 public boolean mHasEphemris; 47 public boolean mHasAlmanac; 48 public boolean mUsedInFix; 49 public boolean mHasCarriesFrequency; 50 51 public SatelliteInfo(int svid, int constellationType, boolean hasEphemris, boolean hasAlmanac, 52 boolean usedInFix, boolean hasCarriesFrequency, float cn0, float elevation, float azimuth, 53 float carrierFrequency) { 54 mSvidWithFlag = 55 setRange(mSvidWithFlag, constellationType, CONSTELLATION_TYPE_SHIFT_WIDTH, SVID_SHIFT_WIDTH); 56 mSvidWithFlag = setRange(mSvidWithFlag, svid, SVID_SHIFT_WIDTH, SVID_MAX_BIT_INDEX); 57 mSvidWithFlag = setBit(mSvidWithFlag, hasEphemris, GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA_BIT_INDEX); 58 mSvidWithFlag = setBit(mSvidWithFlag, hasAlmanac, GNSS_SV_FLAGS_HAS_ALMANAC_DATA_BIT_INDEX); 59 mSvidWithFlag = setBit(mSvidWithFlag, usedInFix, GNSS_SV_FLAGS_USED_IN_FIX_BIT_INDEX); 60 mSvidWithFlag = 61 setBit(mSvidWithFlag, hasCarriesFrequency, GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY_BIT_INDEX); 62 this.mSvid = svid; 63 this.mConstellationType = constellationType; 64 this.mCn0DbHz = cn0; 65 this.mElevation = elevation; 66 this.mAzimuth = azimuth; 67 this.mCarrierFrequency = carrierFrequency; 68 this.mHasEphemris = hasEphemris; 69 this.mHasAlmanac = hasAlmanac; 70 this.mUsedInFix = usedInFix; 71 this.mHasCarriesFrequency = hasCarriesFrequency; 72 } 73 74 /* 75 * Gernerate svidWithFlags array from svInfos 76 */ 77 public static int[] getSvidWithFlagsArray(List<SatelliteInfo> svInfos) { 78 int[] svidWithFlags = new int[svInfos.size()]; 79 for (int i = 0; i< svInfos.size(); i++) { 80 svidWithFlags[i] = svInfos.get(i).mSvidWithFlag; 81 } 82 return svidWithFlags; 83 } 84 85 /* 86 * Gernerate cn0s array from svInfos 87 */ 88 public static float[] getCn0sArray(List<SatelliteInfo> svInfos) { 89 float[] cn0s = new float[svInfos.size()]; 90 for (int i = 0; i< svInfos.size(); i++) { 91 cn0s[i] = svInfos.get(i).mCn0DbHz; 92 } 93 return cn0s; 94 } 95 96 /* 97 * Gernerate elevations array from svInfos 98 */ 99 public static float[] getElevationsArray(List<SatelliteInfo> svInfos) { 100 float[] elevations = new float[svInfos.size()]; 101 for (int i = 0; i< svInfos.size(); i++) { 102 elevations[i] = svInfos.get(i).mElevation; 103 } 104 return elevations; 105 } 106 107 /* 108 * Gernerate azimuths array from svInfos 109 */ 110 public static float[] getAzimuthsArray(List<SatelliteInfo> svInfos) { 111 float[] azimuths = new float[svInfos.size()]; 112 for (int i = 0; i< svInfos.size(); i++) { 113 azimuths[i] = svInfos.get(i).mAzimuth; 114 } 115 return azimuths; 116 } 117 118 /* 119 * Gernerate carrierFrequency array from svInfos 120 */ 121 public static float[] getCarrierFrequencyArray(List<SatelliteInfo> svInfos) { 122 float[] carrierFrequencies = new float[svInfos.size()]; 123 for (int i = 0; i< svInfos.size(); i++) { 124 carrierFrequencies[i] = svInfos.get(i).mCarrierFrequency; 125 } 126 return carrierFrequencies; 127 } 128 129 private int setBit(int targetValue, boolean value, int index) { 130 if (value) { 131 targetValue = targetValue | (1 << index); 132 } else { 133 targetValue = targetValue & ~(1 << index); 134 } 135 return targetValue; 136 } 137 138 /* 139 * Set the bit in the range [fromIndex, toIndex), index start from the lowest bit. 140 * value -> 1 1 0 1 1 0 1 0 141 * index -> 7 6 5 4 3 2 1 0 142 * This function will set the bit in the range to the lowest X bits of the value. 143 */ 144 private int setRange(int targetValue, int value, int fromIndex, int toIndex) { 145 int rangeLen = toIndex - fromIndex; 146 int valueMask = (1 << rangeLen) -1; 147 value &= valueMask; 148 value = value << fromIndex; 149 valueMask = valueMask << fromIndex; 150 targetValue &= (~valueMask); 151 targetValue |= value; 152 return targetValue; 153 } 154 155 }