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 | |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 20 | #include <cutils/properties.h> |
| 21 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace gnss { |
| 25 | namespace common { |
| 26 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 27 | using namespace measurement_corrections::V1_0; |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 28 | using V1_0::GnssLocationFlags; |
| 29 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 30 | void Utils::checkLocation(const V1_0::GnssLocation& location, bool check_speed, |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 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 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 97 | const MeasurementCorrections 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 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 105 | SingleSatCorrection 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, |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 110 | .constellation = V1_0::GnssConstellationType::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 | }; |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 118 | SingleSatCorrection 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, |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 122 | .constellation = V1_0::GnssConstellationType::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 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 130 | hidl_vec<SingleSatCorrection> singleSatCorrections = {singleSatCorrection1, |
| 131 | singleSatCorrection2}; |
| 132 | MeasurementCorrections 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 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 144 | const measurement_corrections::V1_1::MeasurementCorrections |
| 145 | Utils::getMockMeasurementCorrections_1_1() { |
| 146 | MeasurementCorrections mockCorrections_1_0 = getMockMeasurementCorrections(); |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 147 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 148 | measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection1 = { |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 149 | .v1_0 = mockCorrections_1_0.satCorrections[0], |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 150 | .constellation = V2_0::GnssConstellationType::IRNSS, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 151 | }; |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 152 | measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection2 = { |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 153 | .v1_0 = mockCorrections_1_0.satCorrections[1], |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 154 | .constellation = V2_0::GnssConstellationType::IRNSS, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 157 | mockCorrections_1_0.satCorrections[0].constellation = V1_0::GnssConstellationType::UNKNOWN; |
| 158 | mockCorrections_1_0.satCorrections[1].constellation = V1_0::GnssConstellationType::UNKNOWN; |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 159 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 160 | hidl_vec<measurement_corrections::V1_1::SingleSatCorrection> singleSatCorrections = { |
| 161 | singleSatCorrection1, singleSatCorrection2}; |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 162 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 163 | measurement_corrections::V1_1::MeasurementCorrections mockCorrections_1_1 = { |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 164 | .v1_0 = mockCorrections_1_0, |
| 165 | .hasEnvironmentBearing = true, |
| 166 | .environmentBearingDegrees = 45.0, |
| 167 | .environmentBearingUncertaintyDegrees = 4.0, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 168 | .satCorrections = singleSatCorrections, |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 169 | }; |
| 170 | return mockCorrections_1_1; |
| 171 | } |
| 172 | |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 173 | /* |
| 174 | * MapConstellationType: |
| 175 | * Given a GnssConstellationType_2_0 type constellation, maps to its equivalent |
| 176 | * GnssConstellationType_1_0 type constellation. For constellations that do not have |
| 177 | * an equivalent value, maps to GnssConstellationType_1_0::UNKNOWN |
| 178 | */ |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 179 | V1_0::GnssConstellationType Utils::mapConstellationType(V2_0::GnssConstellationType constellation) { |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 180 | switch (constellation) { |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 181 | case V2_0::GnssConstellationType::GPS: |
| 182 | return V1_0::GnssConstellationType::GPS; |
| 183 | case V2_0::GnssConstellationType::SBAS: |
| 184 | return V1_0::GnssConstellationType::SBAS; |
| 185 | case V2_0::GnssConstellationType::GLONASS: |
| 186 | return V1_0::GnssConstellationType::GLONASS; |
| 187 | case V2_0::GnssConstellationType::QZSS: |
| 188 | return V1_0::GnssConstellationType::QZSS; |
| 189 | case V2_0::GnssConstellationType::BEIDOU: |
| 190 | return V1_0::GnssConstellationType::BEIDOU; |
| 191 | case V2_0::GnssConstellationType::GALILEO: |
| 192 | return V1_0::GnssConstellationType::GALILEO; |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 193 | default: |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 194 | return V1_0::GnssConstellationType::UNKNOWN; |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 198 | bool Utils::isAutomotiveDevice() { |
| 199 | char buffer[PROPERTY_VALUE_MAX] = {0}; |
| 200 | property_get("ro.hardware.type", buffer, ""); |
| 201 | return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0; |
| 202 | } |
| 203 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 204 | } // namespace common |
| 205 | } // namespace gnss |
| 206 | } // namespace hardware |
| 207 | } // namespace android |