• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <Utils.h>
18 #include "gtest/gtest.h"
19 
20 namespace android {
21 namespace hardware {
22 namespace gnss {
23 namespace common {
24 
25 using GnssConstellationType_V1_0 = V1_0::GnssConstellationType;
26 using GnssConstellationType_V2_0 = V2_0::GnssConstellationType;
27 
28 using V1_0::GnssLocationFlags;
29 
checkLocation(const GnssLocation & location,bool check_speed,bool check_more_accuracies)30 void 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 
getMockMeasurementCorrections()97 const MeasurementCorrections_1_0 Utils::getMockMeasurementCorrections() {
98     ReflectingPlane reflectingPlane = {
99             .latitudeDegrees = 37.4220039,
100             .longitudeDegrees = -122.0840991,
101             .altitudeMeters = 250.35,
102             .azimuthDegrees = 203.0,
103     };
104 
105     SingleSatCorrection_V1_0 singleSatCorrection1 = {
106             .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,
110             .constellation = GnssConstellationType_V1_0::GPS,
111             .svid = 12,
112             .carrierFrequencyHz = 1.59975e+09,
113             .probSatIsLos = 0.50001,
114             .excessPathLengthMeters = 137.4802,
115             .excessPathLengthUncertaintyMeters = 25.5,
116             .reflectingPlane = reflectingPlane,
117     };
118     SingleSatCorrection_V1_0 singleSatCorrection2 = {
119             .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY |
120                                         GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH |
121                                         GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC,
122             .constellation = GnssConstellationType_V1_0::GPS,
123             .svid = 9,
124             .carrierFrequencyHz = 1.59975e+09,
125             .probSatIsLos = 0.873,
126             .excessPathLengthMeters = 26.294,
127             .excessPathLengthUncertaintyMeters = 10.0,
128     };
129 
130     hidl_vec<SingleSatCorrection_V1_0> singleSatCorrections = {singleSatCorrection1,
131                                                                singleSatCorrection2};
132     MeasurementCorrections_1_0 mockCorrections = {
133             .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 
getMockMeasurementCorrections_1_1()144 const MeasurementCorrections_1_1 Utils::getMockMeasurementCorrections_1_1() {
145     MeasurementCorrections_1_0 mockCorrections_1_0 = getMockMeasurementCorrections();
146 
147     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 
162     MeasurementCorrections_1_1 mockCorrections_1_1 = {
163             .v1_0 = mockCorrections_1_0,
164             .hasEnvironmentBearing = true,
165             .environmentBearingDegrees = 45.0,
166             .environmentBearingUncertaintyDegrees = 4.0,
167             .satCorrections = singleSatCorrections,
168     };
169     return mockCorrections_1_1;
170 }
171 
172 /*
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  */
mapConstellationType(GnssConstellationType_2_0 constellation)178 GnssConstellationType_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 
197 }  // namespace common
198 }  // namespace gnss
199 }  // namespace hardware
200 }  // namespace android
201