1 /*
2 * Copyright (C) 2019 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 #include <Constants.h>
18 #include <Utils.h>
19 #include <utils/SystemClock.h>
20
21 namespace android {
22 namespace hardware {
23 namespace gnss {
24 namespace common {
25
26 using GnssSvFlags = V1_0::IGnssCallback::GnssSvFlags;
27 using GnssMeasurementFlagsV1_0 = V1_0::IGnssMeasurementCallback::GnssMeasurementFlags;
28 using GnssMeasurementFlagsV2_1 = V2_1::IGnssMeasurementCallback::GnssMeasurementFlags;
29 using GnssMeasurementStateV2_0 = V2_0::IGnssMeasurementCallback::GnssMeasurementState;
30 using ElapsedRealtime = V2_0::ElapsedRealtime;
31 using ElapsedRealtimeFlags = V2_0::ElapsedRealtimeFlags;
32 using GnssConstellationTypeV2_0 = V2_0::GnssConstellationType;
33 using IGnssMeasurementCallbackV2_0 = V2_0::IGnssMeasurementCallback;
34 using GnssSignalType = V2_1::GnssSignalType;
35
getMockMeasurementV2_1()36 GnssDataV2_1 Utils::getMockMeasurementV2_1() {
37 GnssDataV2_0 gnssDataV2_0 = Utils::getMockMeasurementV2_0();
38 V2_1::IGnssMeasurementCallback::GnssMeasurement gnssMeasurementV2_1 = {
39 .v2_0 = gnssDataV2_0.measurements[0],
40 .flags = (uint32_t)(GnssMeasurementFlagsV2_1::HAS_CARRIER_FREQUENCY |
41 GnssMeasurementFlagsV2_1::HAS_CARRIER_PHASE |
42 GnssMeasurementFlagsV2_1::HAS_FULL_ISB |
43 GnssMeasurementFlagsV2_1::HAS_FULL_ISB_UNCERTAINTY |
44 GnssMeasurementFlagsV2_1::HAS_SATELLITE_ISB |
45 GnssMeasurementFlagsV2_1::HAS_SATELLITE_ISB_UNCERTAINTY),
46 .fullInterSignalBiasNs = 30.0,
47 .fullInterSignalBiasUncertaintyNs = 250.0,
48 .satelliteInterSignalBiasNs = 20.0,
49 .satelliteInterSignalBiasUncertaintyNs = 150.0,
50 .basebandCN0DbHz = 25.0,
51 };
52 GnssSignalType referenceSignalTypeForIsb = {
53 .constellation = GnssConstellationTypeV2_0::GPS,
54 .carrierFrequencyHz = 1.59975e+09,
55 .codeType = "C",
56 };
57 V2_1::IGnssMeasurementCallback::GnssClock gnssClockV2_1 = {
58 .v1_0 = gnssDataV2_0.clock,
59 .referenceSignalTypeForIsb = referenceSignalTypeForIsb,
60 };
61 hidl_vec<V2_1::IGnssMeasurementCallback::GnssMeasurement> measurements(1);
62 measurements[0] = gnssMeasurementV2_1;
63 GnssDataV2_1 gnssDataV2_1 = {
64 .measurements = measurements,
65 .clock = gnssClockV2_1,
66 .elapsedRealtime = gnssDataV2_0.elapsedRealtime,
67 };
68 return gnssDataV2_1;
69 }
70
getMockMeasurementV2_0()71 GnssDataV2_0 Utils::getMockMeasurementV2_0() {
72 V1_0::IGnssMeasurementCallback::GnssMeasurement measurement_1_0 = {
73 .flags = (uint32_t)GnssMeasurementFlagsV1_0::HAS_CARRIER_FREQUENCY,
74 .svid = (int16_t)6,
75 .constellation = V1_0::GnssConstellationType::UNKNOWN,
76 .timeOffsetNs = 0.0,
77 .receivedSvTimeInNs = 8195997131077,
78 .receivedSvTimeUncertaintyInNs = 15,
79 .cN0DbHz = 30.0,
80 .pseudorangeRateMps = -484.13739013671875,
81 .pseudorangeRateUncertaintyMps = 1.0379999876022339,
82 .accumulatedDeltaRangeState = (uint32_t)V1_0::IGnssMeasurementCallback::
83 GnssAccumulatedDeltaRangeState::ADR_STATE_UNKNOWN,
84 .accumulatedDeltaRangeM = 0.0,
85 .accumulatedDeltaRangeUncertaintyM = 0.0,
86 .carrierFrequencyHz = 1.59975e+09,
87 .multipathIndicator =
88 V1_0::IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN};
89 V1_1::IGnssMeasurementCallback::GnssMeasurement measurement_1_1 = {.v1_0 = measurement_1_0};
90 V2_0::IGnssMeasurementCallback::GnssMeasurement measurement_2_0 = {
91 .v1_1 = measurement_1_1,
92 .codeType = "C",
93 .state = GnssMeasurementStateV2_0::STATE_CODE_LOCK |
94 GnssMeasurementStateV2_0::STATE_BIT_SYNC |
95 GnssMeasurementStateV2_0::STATE_SUBFRAME_SYNC |
96 GnssMeasurementStateV2_0::STATE_TOW_DECODED |
97 GnssMeasurementStateV2_0::STATE_GLO_STRING_SYNC |
98 GnssMeasurementStateV2_0::STATE_GLO_TOD_DECODED,
99 .constellation = GnssConstellationTypeV2_0::GLONASS,
100 };
101
102 hidl_vec<IGnssMeasurementCallbackV2_0::GnssMeasurement> measurements(1);
103 measurements[0] = measurement_2_0;
104 V1_0::IGnssMeasurementCallback::GnssClock clock = {.timeNs = 2713545000000,
105 .fullBiasNs = -1226701900521857520,
106 .biasNs = 0.59689998626708984,
107 .biasUncertaintyNs = 47514.989972114563,
108 .driftNsps = -51.757811607455452,
109 .driftUncertaintyNsps = 310.64968328491528,
110 .hwClockDiscontinuityCount = 1};
111
112 ElapsedRealtime timestamp = {
113 .flags = ElapsedRealtimeFlags::HAS_TIMESTAMP_NS |
114 ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS,
115 .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()),
116 // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
117 // In an actual implementation provide an estimate of the synchronization uncertainty
118 // or don't set the field.
119 .timeUncertaintyNs = 1000000};
120
121 GnssDataV2_0 gnssData = {
122 .measurements = measurements, .clock = clock, .elapsedRealtime = timestamp};
123 return gnssData;
124 }
125
getMockLocationV2_0()126 V2_0::GnssLocation Utils::getMockLocationV2_0() {
127 const V2_0::ElapsedRealtime timestamp = {
128 .flags = V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS |
129 V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS,
130 .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()),
131 // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
132 // In an actual implementation provide an estimate of the synchronization uncertainty
133 // or don't set the field.
134 .timeUncertaintyNs = 1000000};
135
136 V2_0::GnssLocation location = {.v1_0 = Utils::getMockLocationV1_0(),
137 .elapsedRealtime = timestamp};
138 return location;
139 }
140
getMockLocationV1_0()141 V1_0::GnssLocation Utils::getMockLocationV1_0() {
142 V1_0::GnssLocation location = {
143 .gnssLocationFlags = 0xFF,
144 .latitudeDegrees = kMockLatitudeDegrees,
145 .longitudeDegrees = kMockLongitudeDegrees,
146 .altitudeMeters = kMockAltitudeMeters,
147 .speedMetersPerSec = kMockSpeedMetersPerSec,
148 .bearingDegrees = kMockBearingDegrees,
149 .horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
150 .verticalAccuracyMeters = kMockVerticalAccuracyMeters,
151 .speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
152 .bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
153 .timestamp = kMockTimestamp};
154 return location;
155 }
156
getMockSvInfoListV2_1()157 hidl_vec<GnssSvInfoV2_1> Utils::getMockSvInfoListV2_1() {
158 GnssSvInfoV1_0 gnssSvInfoV1_0 =
159 Utils::getMockSvInfoV1_0(3, V1_0::GnssConstellationType::GPS, 32.5, 59.1, 166.5);
160 GnssSvInfoV2_0 gnssSvInfoV2_0 =
161 Utils::getMockSvInfoV2_0(gnssSvInfoV1_0, V2_0::GnssConstellationType::GPS);
162 hidl_vec<GnssSvInfoV2_1> gnssSvInfoList = {
163 Utils::getMockSvInfoV2_1(gnssSvInfoV2_0, 27.5),
164 getMockSvInfoV2_1(
165 getMockSvInfoV2_0(getMockSvInfoV1_0(5, V1_0::GnssConstellationType::GPS, 27.0,
166 29.0, 56.5),
167 V2_0::GnssConstellationType::GPS),
168 22.0),
169 getMockSvInfoV2_1(
170 getMockSvInfoV2_0(getMockSvInfoV1_0(17, V1_0::GnssConstellationType::GPS, 30.5,
171 71.0, 77.0),
172 V2_0::GnssConstellationType::GPS),
173 25.5),
174 getMockSvInfoV2_1(
175 getMockSvInfoV2_0(getMockSvInfoV1_0(26, V1_0::GnssConstellationType::GPS, 24.1,
176 28.0, 253.0),
177 V2_0::GnssConstellationType::GPS),
178 19.1),
179 getMockSvInfoV2_1(
180 getMockSvInfoV2_0(getMockSvInfoV1_0(5, V1_0::GnssConstellationType::GLONASS,
181 20.5, 11.5, 116.0),
182 V2_0::GnssConstellationType::GLONASS),
183 15.5),
184 getMockSvInfoV2_1(
185 getMockSvInfoV2_0(getMockSvInfoV1_0(17, V1_0::GnssConstellationType::GLONASS,
186 21.5, 28.5, 186.0),
187 V2_0::GnssConstellationType::GLONASS),
188 16.5),
189 getMockSvInfoV2_1(
190 getMockSvInfoV2_0(getMockSvInfoV1_0(18, V1_0::GnssConstellationType::GLONASS,
191 28.3, 38.8, 69.0),
192 V2_0::GnssConstellationType::GLONASS),
193 25.3),
194 getMockSvInfoV2_1(
195 getMockSvInfoV2_0(getMockSvInfoV1_0(10, V1_0::GnssConstellationType::GLONASS,
196 25.0, 66.0, 247.0),
197 V2_0::GnssConstellationType::GLONASS),
198 20.0),
199 getMockSvInfoV2_1(
200 getMockSvInfoV2_0(getMockSvInfoV1_0(3, V1_0::GnssConstellationType::UNKNOWN,
201 22.0, 35.0, 112.0),
202 V2_0::GnssConstellationType::IRNSS),
203 19.7),
204 };
205 return gnssSvInfoList;
206 }
207
getMockSvInfoV2_1(GnssSvInfoV2_0 gnssSvInfoV2_0,float basebandCN0DbHz)208 GnssSvInfoV2_1 Utils::getMockSvInfoV2_1(GnssSvInfoV2_0 gnssSvInfoV2_0, float basebandCN0DbHz) {
209 GnssSvInfoV2_1 gnssSvInfoV2_1 = {
210 .v2_0 = gnssSvInfoV2_0,
211 .basebandCN0DbHz = basebandCN0DbHz,
212 };
213 return gnssSvInfoV2_1;
214 }
215
getMockSvInfoV2_0(GnssSvInfoV1_0 gnssSvInfoV1_0,V2_0::GnssConstellationType type)216 GnssSvInfoV2_0 Utils::getMockSvInfoV2_0(GnssSvInfoV1_0 gnssSvInfoV1_0,
217 V2_0::GnssConstellationType type) {
218 GnssSvInfoV2_0 gnssSvInfoV2_0 = {
219 .v1_0 = gnssSvInfoV1_0,
220 .constellation = type,
221 };
222 return gnssSvInfoV2_0;
223 }
224
getMockSvInfoV1_0(int16_t svid,V1_0::GnssConstellationType type,float cN0DbHz,float elevationDegrees,float azimuthDegrees)225 GnssSvInfoV1_0 Utils::getMockSvInfoV1_0(int16_t svid, V1_0::GnssConstellationType type,
226 float cN0DbHz, float elevationDegrees,
227 float azimuthDegrees) {
228 GnssSvInfoV1_0 svInfo = {.svid = svid,
229 .constellation = type,
230 .cN0Dbhz = cN0DbHz,
231 .elevationDegrees = elevationDegrees,
232 .azimuthDegrees = azimuthDegrees,
233 .svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA |
234 GnssSvFlags::HAS_ALMANAC_DATA};
235 return svInfo;
236 }
237
getMockAntennaInfos()238 hidl_vec<GnssAntennaInfo> Utils::getMockAntennaInfos() {
239 GnssAntennaInfo mockAntennaInfo_1 = {
240 .carrierFrequencyMHz = 123412.12,
241 .phaseCenterOffsetCoordinateMillimeters = Coord{.x = 1,
242 .xUncertainty = 0.1,
243 .y = 2,
244 .yUncertainty = 0.1,
245 .z = 3,
246 .zUncertainty = 0.1},
247 .phaseCenterVariationCorrectionMillimeters =
248 {
249 Row{hidl_vec<double>{1, -1, 5, -2, 3, -1}},
250 Row{hidl_vec<double>{-2, 3, 2, 0, 1, 2}},
251 Row{hidl_vec<double>{1, 3, 2, -1, -3, 5}},
252 },
253 .phaseCenterVariationCorrectionUncertaintyMillimeters =
254 {
255 Row{hidl_vec<double>{0.1, 0.2, 0.4, 0.1, 0.2, 0.3}},
256 Row{hidl_vec<double>{0.3, 0.2, 0.3, 0.6, 0.1, 0.1}},
257 Row{hidl_vec<double>{0.1, 0.1, 0.4, 0.2, 0.5, 0.3}},
258 },
259 .signalGainCorrectionDbi =
260 {
261 Row{hidl_vec<double>{2, -3, 1, -3, 0, -4}},
262 Row{hidl_vec<double>{1, 0, -4, 1, 3, -2}},
263 Row{hidl_vec<double>{3, -2, 0, -2, 3, 0}},
264 },
265 .signalGainCorrectionUncertaintyDbi =
266 {
267 Row{hidl_vec<double>{0.3, 0.1, 0.2, 0.6, 0.1, 0.3}},
268 Row{hidl_vec<double>{0.1, 0.1, 0.5, 0.2, 0.3, 0.1}},
269 Row{hidl_vec<double>{0.2, 0.4, 0.2, 0.1, 0.1, 0.2}},
270 },
271 };
272
273 GnssAntennaInfo mockAntennaInfo_2 = {
274 .carrierFrequencyMHz = 532324.23,
275 .phaseCenterOffsetCoordinateMillimeters = Coord{.x = 5,
276 .xUncertainty = 0.1,
277 .y = 6,
278 .yUncertainty = 0.1,
279 .z = 7,
280 .zUncertainty = 0.1},
281 };
282
283 hidl_vec<GnssAntennaInfo> mockAntennaInfos = {
284 mockAntennaInfo_1,
285 mockAntennaInfo_2,
286 };
287 return mockAntennaInfos;
288 }
289
290 } // namespace common
291 } // namespace gnss
292 } // namespace hardware
293 } // namespace android
294