blob: ccb91b100ffcdad9553cdcc91e34b094f24a14c8 [file] [log] [blame]
Yu-Han Yanga5098612019-02-08 16:22:07 -08001/*
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>
Yu-Han Yangc06b5362019-10-25 14:14:35 -070019#include <utils/SystemClock.h>
Yu-Han Yanga5098612019-02-08 16:22:07 -080020
21namespace android {
22namespace hardware {
23namespace gnss {
24namespace common {
25
26using GnssSvFlags = V1_0::IGnssCallback::GnssSvFlags;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070027using GnssMeasurementFlags = V1_0::IGnssMeasurementCallback::GnssMeasurementFlags;
28using GnssMeasurementStateV2_0 = V2_0::IGnssMeasurementCallback::GnssMeasurementState;
29using ElapsedRealtime = V2_0::ElapsedRealtime;
30using ElapsedRealtimeFlags = V2_0::ElapsedRealtimeFlags;
31using GnssConstellationTypeV2_0 = V2_0::GnssConstellationType;
32using IGnssMeasurementCallbackV2_0 = V2_0::IGnssMeasurementCallback;
Yu-Han Yanga5098612019-02-08 16:22:07 -080033
Yu-Han Yangc06b5362019-10-25 14:14:35 -070034GnssDataV2_1 Utils::getMockMeasurementV2_1() {
35 GnssDataV2_0 gnssDataV2_0 = Utils::getMockMeasurementV2_0();
36 V2_1::IGnssMeasurementCallback::GnssMeasurement gnssMeasurementV2_1 = {
37 .v2_0 = gnssDataV2_0.measurements[0],
38 .basebandCN0DbHz = 25.0,
39 };
40 hidl_vec<V2_1::IGnssMeasurementCallback::GnssMeasurement> measurements(1);
41 measurements[0] = gnssMeasurementV2_1;
42 GnssDataV2_1 gnssDataV2_1 = {
43 .measurements = measurements,
44 .clock = gnssDataV2_0.clock,
45 .elapsedRealtime = gnssDataV2_0.elapsedRealtime,
46 };
47 return gnssDataV2_1;
48}
49
50GnssDataV2_0 Utils::getMockMeasurementV2_0() {
51 V1_0::IGnssMeasurementCallback::GnssMeasurement measurement_1_0 = {
52 .flags = (uint32_t)GnssMeasurementFlags::HAS_CARRIER_FREQUENCY,
53 .svid = (int16_t)6,
54 .constellation = V1_0::GnssConstellationType::UNKNOWN,
55 .timeOffsetNs = 0.0,
56 .receivedSvTimeInNs = 8195997131077,
57 .receivedSvTimeUncertaintyInNs = 15,
58 .cN0DbHz = 30.0,
59 .pseudorangeRateMps = -484.13739013671875,
60 .pseudorangeRateUncertaintyMps = 1.0379999876022339,
61 .accumulatedDeltaRangeState = (uint32_t)V1_0::IGnssMeasurementCallback::
62 GnssAccumulatedDeltaRangeState::ADR_STATE_UNKNOWN,
63 .accumulatedDeltaRangeM = 0.0,
64 .accumulatedDeltaRangeUncertaintyM = 0.0,
65 .carrierFrequencyHz = 1.59975e+09,
66 .multipathIndicator =
67 V1_0::IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN};
68 V1_1::IGnssMeasurementCallback::GnssMeasurement measurement_1_1 = {.v1_0 = measurement_1_0};
69 V2_0::IGnssMeasurementCallback::GnssMeasurement measurement_2_0 = {
70 .v1_1 = measurement_1_1,
71 .codeType = "C",
72 .state = GnssMeasurementStateV2_0::STATE_CODE_LOCK |
73 GnssMeasurementStateV2_0::STATE_BIT_SYNC |
74 GnssMeasurementStateV2_0::STATE_SUBFRAME_SYNC |
75 GnssMeasurementStateV2_0::STATE_TOW_DECODED |
76 GnssMeasurementStateV2_0::STATE_GLO_STRING_SYNC |
77 GnssMeasurementStateV2_0::STATE_GLO_TOD_DECODED,
78 .constellation = GnssConstellationTypeV2_0::GLONASS,
79 };
80
81 hidl_vec<IGnssMeasurementCallbackV2_0::GnssMeasurement> measurements(1);
82 measurements[0] = measurement_2_0;
83 V1_0::IGnssMeasurementCallback::GnssClock clock = {.timeNs = 2713545000000,
84 .fullBiasNs = -1226701900521857520,
85 .biasNs = 0.59689998626708984,
86 .biasUncertaintyNs = 47514.989972114563,
87 .driftNsps = -51.757811607455452,
88 .driftUncertaintyNsps = 310.64968328491528,
89 .hwClockDiscontinuityCount = 1};
90
91 ElapsedRealtime timestamp = {
92 .flags = ElapsedRealtimeFlags::HAS_TIMESTAMP_NS |
93 ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS,
94 .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()),
95 // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
96 // In an actual implementation provide an estimate of the synchronization uncertainty
97 // or don't set the field.
98 .timeUncertaintyNs = 1000000};
99
100 GnssDataV2_0 gnssData = {
101 .measurements = measurements, .clock = clock, .elapsedRealtime = timestamp};
102 return gnssData;
103}
104
105V2_0::GnssLocation Utils::getMockLocationV2_0() {
106 const V2_0::ElapsedRealtime timestamp = {
107 .flags = V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS |
108 V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS,
109 .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()),
110 // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
111 // In an actual implementation provide an estimate of the synchronization uncertainty
112 // or don't set the field.
113 .timeUncertaintyNs = 1000000};
114
115 V2_0::GnssLocation location = {.v1_0 = Utils::getMockLocationV1_0(),
116 .elapsedRealtime = timestamp};
Yu-Han Yanga5098612019-02-08 16:22:07 -0800117 return location;
118}
119
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700120V1_0::GnssLocation Utils::getMockLocationV1_0() {
121 V1_0::GnssLocation location = {
122 .gnssLocationFlags = 0xFF,
123 .latitudeDegrees = kMockLatitudeDegrees,
124 .longitudeDegrees = kMockLongitudeDegrees,
125 .altitudeMeters = kMockAltitudeMeters,
126 .speedMetersPerSec = kMockSpeedMetersPerSec,
127 .bearingDegrees = kMockBearingDegrees,
128 .horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
129 .verticalAccuracyMeters = kMockVerticalAccuracyMeters,
130 .speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
131 .bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
132 .timestamp = kMockTimestamp};
133 return location;
134}
135
136hidl_vec<GnssSvInfoV2_1> Utils::getMockSvInfoListV2_1() {
137 GnssSvInfoV1_0 gnssSvInfoV1_0 =
138 Utils::getMockSvInfoV1_0(3, V1_0::GnssConstellationType::GPS, 32.5, 59.1, 166.5);
139 GnssSvInfoV2_0 gnssSvInfoV2_0 =
140 Utils::getMockSvInfoV2_0(gnssSvInfoV1_0, V2_0::GnssConstellationType::GPS);
141 hidl_vec<GnssSvInfoV2_1> gnssSvInfoList = {
142 Utils::getMockSvInfoV2_1(gnssSvInfoV2_0, 27.5),
143 getMockSvInfoV2_1(
144 getMockSvInfoV2_0(getMockSvInfoV1_0(5, V1_0::GnssConstellationType::GPS, 27.0,
145 29.0, 56.5),
146 V2_0::GnssConstellationType::GPS),
147 22.0),
148 getMockSvInfoV2_1(
149 getMockSvInfoV2_0(getMockSvInfoV1_0(17, V1_0::GnssConstellationType::GPS, 30.5,
150 71.0, 77.0),
151 V2_0::GnssConstellationType::GPS),
152 25.5),
153 getMockSvInfoV2_1(
154 getMockSvInfoV2_0(getMockSvInfoV1_0(26, V1_0::GnssConstellationType::GPS, 24.1,
155 28.0, 253.0),
156 V2_0::GnssConstellationType::GPS),
157 19.1),
158 getMockSvInfoV2_1(
159 getMockSvInfoV2_0(getMockSvInfoV1_0(5, V1_0::GnssConstellationType::GLONASS,
160 20.5, 11.5, 116.0),
161 V2_0::GnssConstellationType::GLONASS),
162 15.5),
163 getMockSvInfoV2_1(
164 getMockSvInfoV2_0(getMockSvInfoV1_0(17, V1_0::GnssConstellationType::GLONASS,
165 21.5, 28.5, 186.0),
166 V2_0::GnssConstellationType::GLONASS),
167 16.5),
168 getMockSvInfoV2_1(
169 getMockSvInfoV2_0(getMockSvInfoV1_0(18, V1_0::GnssConstellationType::GLONASS,
170 28.3, 38.8, 69.0),
171 V2_0::GnssConstellationType::GLONASS),
172 25.3),
173 getMockSvInfoV2_1(
174 getMockSvInfoV2_0(getMockSvInfoV1_0(10, V1_0::GnssConstellationType::GLONASS,
175 25.0, 66.0, 247.0),
176 V2_0::GnssConstellationType::GLONASS),
177 20.0),
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800178 getMockSvInfoV2_1(
179 getMockSvInfoV2_0(getMockSvInfoV1_0(3, V1_0::GnssConstellationType::UNKNOWN,
180 22.0, 35.0, 112.0),
181 V2_0::GnssConstellationType::IRNSS),
182 19.7),
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700183 };
184 return gnssSvInfoList;
185}
186
187GnssSvInfoV2_1 Utils::getMockSvInfoV2_1(GnssSvInfoV2_0 gnssSvInfoV2_0, float basebandCN0DbHz) {
188 GnssSvInfoV2_1 gnssSvInfoV2_1 = {
189 .v2_0 = gnssSvInfoV2_0,
190 .basebandCN0DbHz = basebandCN0DbHz,
191 };
192 return gnssSvInfoV2_1;
193}
194
195GnssSvInfoV2_0 Utils::getMockSvInfoV2_0(GnssSvInfoV1_0 gnssSvInfoV1_0,
196 V2_0::GnssConstellationType type) {
197 GnssSvInfoV2_0 gnssSvInfoV2_0 = {
198 .v1_0 = gnssSvInfoV1_0,
199 .constellation = type,
200 };
201 return gnssSvInfoV2_0;
202}
203
204GnssSvInfoV1_0 Utils::getMockSvInfoV1_0(int16_t svid, V1_0::GnssConstellationType type,
205 float cN0DbHz, float elevationDegrees,
206 float azimuthDegrees) {
207 GnssSvInfoV1_0 svInfo = {.svid = svid,
208 .constellation = type,
209 .cN0Dbhz = cN0DbHz,
210 .elevationDegrees = elevationDegrees,
211 .azimuthDegrees = azimuthDegrees,
212 .svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA |
213 GnssSvFlags::HAS_ALMANAC_DATA};
Yu-Han Yanga5098612019-02-08 16:22:07 -0800214 return svInfo;
215}
216
217} // namespace common
218} // namespace gnss
219} // namespace hardware
220} // namespace android