Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 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 | |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 25 | using GnssConstellationType_V1_0 = V1_0::GnssConstellationType; |
| 26 | using GnssConstellationType_V2_0 = V2_0::GnssConstellationType; |
| 27 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 28 | using V1_0::GnssLocationFlags; |
| 29 | |
| 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 | |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 97 | const MeasurementCorrections_1_0 Utils::getMockMeasurementCorrections() { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 98 | ReflectingPlane reflectingPlane = { |
| 99 | .latitudeDegrees = 37.4220039, |
| 100 | .longitudeDegrees = -122.0840991, |
| 101 | .altitudeMeters = 250.35, |
| 102 | .azimuthDegrees = 203.0, |
| 103 | }; |
| 104 | |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 105 | SingleSatCorrection_V1_0 singleSatCorrection1 = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 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, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 110 | .constellation = GnssConstellationType_V1_0::GPS, |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 111 | .svid = 12, |
| 112 | .carrierFrequencyHz = 1.59975e+09, |
| 113 | .probSatIsLos = 0.50001, |
| 114 | .excessPathLengthMeters = 137.4802, |
| 115 | .excessPathLengthUncertaintyMeters = 25.5, |
| 116 | .reflectingPlane = reflectingPlane, |
| 117 | }; |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 118 | SingleSatCorrection_V1_0 singleSatCorrection2 = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 119 | .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY | |
| 120 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH | |
| 121 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 122 | .constellation = GnssConstellationType_V1_0::GPS, |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 123 | .svid = 9, |
| 124 | .carrierFrequencyHz = 1.59975e+09, |
| 125 | .probSatIsLos = 0.873, |
| 126 | .excessPathLengthMeters = 26.294, |
| 127 | .excessPathLengthUncertaintyMeters = 10.0, |
| 128 | }; |
| 129 | |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 130 | hidl_vec<SingleSatCorrection_V1_0> singleSatCorrections = {singleSatCorrection1, |
| 131 | singleSatCorrection2}; |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 132 | MeasurementCorrections_1_0 mockCorrections = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 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 | |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 144 | const MeasurementCorrections_1_1 Utils::getMockMeasurementCorrections_1_1() { |
| 145 | MeasurementCorrections_1_0 mockCorrections_1_0 = getMockMeasurementCorrections(); |
| 146 | |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 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 | |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 162 | MeasurementCorrections_1_1 mockCorrections_1_1 = { |
| 163 | .v1_0 = mockCorrections_1_0, |
| 164 | .hasEnvironmentBearing = true, |
| 165 | .environmentBearingDegrees = 45.0, |
| 166 | .environmentBearingUncertaintyDegrees = 4.0, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame^] | 167 | .satCorrections = singleSatCorrections, |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 168 | }; |
| 169 | return mockCorrections_1_1; |
| 170 | } |
| 171 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 172 | } // namespace common |
| 173 | } // namespace gnss |
| 174 | } // namespace hardware |
| 175 | } // namespace android |