blob: 9bf68e609f55aa5146b9d1529399d82dad3b6e62 [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 <Utils.h>
18#include "gtest/gtest.h"
19
20namespace android {
21namespace hardware {
22namespace gnss {
23namespace common {
24
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -080025using GnssConstellationType_V1_0 = V1_0::GnssConstellationType;
26using GnssConstellationType_V2_0 = V2_0::GnssConstellationType;
27
Yu-Han Yanga5098612019-02-08 16:22:07 -080028using V1_0::GnssLocationFlags;
29
30void Utils::checkLocation(const GnssLocation& location, bool check_speed,
31 bool check_more_accuracies) {
32 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
33 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
34 if (check_speed) {
35 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
36 }
37 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
38 // New uncertainties available in O must be provided,
39 // at least when paired with modern hardware (2017+)
40 if (check_more_accuracies) {
41 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
42 if (check_speed) {
43 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
44 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
45 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
46 }
47 }
48 }
49 EXPECT_GE(location.latitudeDegrees, -90.0);
50 EXPECT_LE(location.latitudeDegrees, 90.0);
51 EXPECT_GE(location.longitudeDegrees, -180.0);
52 EXPECT_LE(location.longitudeDegrees, 180.0);
53 EXPECT_GE(location.altitudeMeters, -1000.0);
54 EXPECT_LE(location.altitudeMeters, 30000.0);
55 if (check_speed) {
56 EXPECT_GE(location.speedMetersPerSec, 0.0);
57 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
58
59 // Non-zero speeds must be reported with an associated bearing
60 if (location.speedMetersPerSec > 0.0) {
61 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
62 }
63 }
64
65 /*
66 * Tolerating some especially high values for accuracy estimate, in case of
67 * first fix with especially poor geometry (happens occasionally)
68 */
69 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
70 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
71
72 /*
73 * Some devices may define bearing as -180 to +180, others as 0 to 360.
74 * Both are okay & understandable.
75 */
76 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
77 EXPECT_GE(location.bearingDegrees, -180.0);
78 EXPECT_LE(location.bearingDegrees, 360.0);
79 }
80 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
81 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
82 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
83 }
84 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
85 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
86 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
87 }
88 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
89 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
90 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
91 }
92
93 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
94 EXPECT_GT(location.timestamp, 1.48e12);
95}
96
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080097const MeasurementCorrections_1_0 Utils::getMockMeasurementCorrections() {
Yu-Han Yang08642f92019-03-02 14:22:14 -080098 ReflectingPlane reflectingPlane = {
99 .latitudeDegrees = 37.4220039,
100 .longitudeDegrees = -122.0840991,
101 .altitudeMeters = 250.35,
102 .azimuthDegrees = 203.0,
103 };
104
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800105 SingleSatCorrection_V1_0 singleSatCorrection1 = {
Yu-Han Yang08642f92019-03-02 14:22:14 -0800106 .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY |
107 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH |
108 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC |
109 GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800110 .constellation = GnssConstellationType_V1_0::GPS,
Yu-Han Yang08642f92019-03-02 14:22:14 -0800111 .svid = 12,
112 .carrierFrequencyHz = 1.59975e+09,
113 .probSatIsLos = 0.50001,
114 .excessPathLengthMeters = 137.4802,
115 .excessPathLengthUncertaintyMeters = 25.5,
116 .reflectingPlane = reflectingPlane,
117 };
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800118 SingleSatCorrection_V1_0 singleSatCorrection2 = {
Yu-Han Yang08642f92019-03-02 14:22:14 -0800119 .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY |
120 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH |
121 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800122 .constellation = GnssConstellationType_V1_0::GPS,
Yu-Han Yang08642f92019-03-02 14:22:14 -0800123 .svid = 9,
124 .carrierFrequencyHz = 1.59975e+09,
125 .probSatIsLos = 0.873,
126 .excessPathLengthMeters = 26.294,
127 .excessPathLengthUncertaintyMeters = 10.0,
128 };
129
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800130 hidl_vec<SingleSatCorrection_V1_0> singleSatCorrections = {singleSatCorrection1,
131 singleSatCorrection2};
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800132 MeasurementCorrections_1_0 mockCorrections = {
Yu-Han Yang08642f92019-03-02 14:22:14 -0800133 .latitudeDegrees = 37.4219999,
134 .longitudeDegrees = -122.0840575,
135 .altitudeMeters = 30.60062531,
136 .horizontalPositionUncertaintyMeters = 9.23542,
137 .verticalPositionUncertaintyMeters = 15.02341,
138 .toaGpsNanosecondsOfWeek = 2935633453L,
139 .satCorrections = singleSatCorrections,
140 };
141 return mockCorrections;
142}
143
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800144const MeasurementCorrections_1_1 Utils::getMockMeasurementCorrections_1_1() {
145 MeasurementCorrections_1_0 mockCorrections_1_0 = getMockMeasurementCorrections();
146
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800147 SingleSatCorrection_V1_1 singleSatCorrection1 = {
148 .v1_0 = mockCorrections_1_0.satCorrections[0],
149 .constellation = GnssConstellationType_V2_0::IRNSS,
150 };
151 SingleSatCorrection_V1_1 singleSatCorrection2 = {
152 .v1_0 = mockCorrections_1_0.satCorrections[1],
153 .constellation = GnssConstellationType_V2_0::IRNSS,
154 };
155
156 mockCorrections_1_0.satCorrections[0].constellation = GnssConstellationType_V1_0::UNKNOWN;
157 mockCorrections_1_0.satCorrections[1].constellation = GnssConstellationType_V1_0::UNKNOWN;
158
159 hidl_vec<SingleSatCorrection_V1_1> singleSatCorrections = {singleSatCorrection1,
160 singleSatCorrection2};
161
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800162 MeasurementCorrections_1_1 mockCorrections_1_1 = {
163 .v1_0 = mockCorrections_1_0,
164 .hasEnvironmentBearing = true,
165 .environmentBearingDegrees = 45.0,
166 .environmentBearingUncertaintyDegrees = 4.0,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800167 .satCorrections = singleSatCorrections,
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800168 };
169 return mockCorrections_1_1;
170}
171
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -0700172/*
173 * MapConstellationType:
174 * Given a GnssConstellationType_2_0 type constellation, maps to its equivalent
175 * GnssConstellationType_1_0 type constellation. For constellations that do not have
176 * an equivalent value, maps to GnssConstellationType_1_0::UNKNOWN
177 */
178GnssConstellationType_1_0 Utils::mapConstellationType(GnssConstellationType_2_0 constellation) {
179 switch (constellation) {
180 case GnssConstellationType_2_0::GPS:
181 return GnssConstellationType_1_0::GPS;
182 case GnssConstellationType_2_0::SBAS:
183 return GnssConstellationType_1_0::SBAS;
184 case GnssConstellationType_2_0::GLONASS:
185 return GnssConstellationType_1_0::GLONASS;
186 case GnssConstellationType_2_0::QZSS:
187 return GnssConstellationType_1_0::QZSS;
188 case GnssConstellationType_2_0::BEIDOU:
189 return GnssConstellationType_1_0::BEIDOU;
190 case GnssConstellationType_2_0::GALILEO:
191 return GnssConstellationType_1_0::GALILEO;
192 default:
193 return GnssConstellationType_1_0::UNKNOWN;
194 }
195}
196
Yu-Han Yanga5098612019-02-08 16:22:07 -0800197} // namespace common
198} // namespace gnss
199} // namespace hardware
200} // namespace android