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> |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 18 | #include <android/hardware/gnss/BnGnss.h> |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 19 | #include <android/hardware/gnss/IGnss.h> |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 20 | #include "gtest/gtest.h" |
| 21 | |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 22 | #include <cutils/properties.h> |
| 23 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace gnss { |
| 27 | namespace common { |
| 28 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 29 | using namespace measurement_corrections::V1_0; |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 30 | using V1_0::GnssLocationFlags; |
| 31 | |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 32 | using MeasurementCorrectionsAidl = |
| 33 | android::hardware::gnss::measurement_corrections::MeasurementCorrections; |
| 34 | using ReflectingPlaneAidl = android::hardware::gnss::measurement_corrections::ReflectingPlane; |
| 35 | using SingleSatCorrectionAidl = |
| 36 | android::hardware::gnss::measurement_corrections::SingleSatCorrection; |
| 37 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 38 | template <> |
| 39 | int64_t Utils::getLocationTimestampMillis(const android::hardware::gnss::GnssLocation& location) { |
| 40 | return location.timestampMillis; |
| 41 | } |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 42 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 43 | template <> |
| 44 | int64_t Utils::getLocationTimestampMillis(const V1_0::GnssLocation& location) { |
| 45 | return location.timestamp; |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 48 | const MeasurementCorrections Utils::getMockMeasurementCorrections() { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 49 | ReflectingPlane reflectingPlane = { |
| 50 | .latitudeDegrees = 37.4220039, |
| 51 | .longitudeDegrees = -122.0840991, |
| 52 | .altitudeMeters = 250.35, |
| 53 | .azimuthDegrees = 203.0, |
| 54 | }; |
| 55 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 56 | SingleSatCorrection singleSatCorrection1 = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 57 | .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY | |
| 58 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH | |
| 59 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC | |
| 60 | GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE, |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 61 | .constellation = V1_0::GnssConstellationType::GPS, |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 62 | .svid = 12, |
| 63 | .carrierFrequencyHz = 1.59975e+09, |
| 64 | .probSatIsLos = 0.50001, |
| 65 | .excessPathLengthMeters = 137.4802, |
| 66 | .excessPathLengthUncertaintyMeters = 25.5, |
| 67 | .reflectingPlane = reflectingPlane, |
| 68 | }; |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 69 | SingleSatCorrection singleSatCorrection2 = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 70 | .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY | |
| 71 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH | |
| 72 | GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC, |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 73 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 74 | .constellation = V1_0::GnssConstellationType::GPS, |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 75 | .svid = 9, |
| 76 | .carrierFrequencyHz = 1.59975e+09, |
| 77 | .probSatIsLos = 0.873, |
| 78 | .excessPathLengthMeters = 26.294, |
| 79 | .excessPathLengthUncertaintyMeters = 10.0, |
| 80 | }; |
| 81 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 82 | hidl_vec<SingleSatCorrection> singleSatCorrections = {singleSatCorrection1, |
| 83 | singleSatCorrection2}; |
| 84 | MeasurementCorrections mockCorrections = { |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 85 | .latitudeDegrees = 37.4219999, |
| 86 | .longitudeDegrees = -122.0840575, |
| 87 | .altitudeMeters = 30.60062531, |
| 88 | .horizontalPositionUncertaintyMeters = 9.23542, |
| 89 | .verticalPositionUncertaintyMeters = 15.02341, |
| 90 | .toaGpsNanosecondsOfWeek = 2935633453L, |
| 91 | .satCorrections = singleSatCorrections, |
| 92 | }; |
| 93 | return mockCorrections; |
| 94 | } |
| 95 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 96 | const measurement_corrections::V1_1::MeasurementCorrections |
| 97 | Utils::getMockMeasurementCorrections_1_1() { |
| 98 | MeasurementCorrections mockCorrections_1_0 = getMockMeasurementCorrections(); |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 99 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 100 | measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection1 = { |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 101 | .v1_0 = mockCorrections_1_0.satCorrections[0], |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 102 | .constellation = V2_0::GnssConstellationType::IRNSS, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 103 | }; |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 104 | measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection2 = { |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 105 | .v1_0 = mockCorrections_1_0.satCorrections[1], |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 106 | .constellation = V2_0::GnssConstellationType::IRNSS, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 109 | mockCorrections_1_0.satCorrections[0].constellation = V1_0::GnssConstellationType::UNKNOWN; |
| 110 | mockCorrections_1_0.satCorrections[1].constellation = V1_0::GnssConstellationType::UNKNOWN; |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 111 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 112 | hidl_vec<measurement_corrections::V1_1::SingleSatCorrection> singleSatCorrections = { |
| 113 | singleSatCorrection1, singleSatCorrection2}; |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 114 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 115 | measurement_corrections::V1_1::MeasurementCorrections mockCorrections_1_1 = { |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 116 | .v1_0 = mockCorrections_1_0, |
| 117 | .hasEnvironmentBearing = true, |
| 118 | .environmentBearingDegrees = 45.0, |
| 119 | .environmentBearingUncertaintyDegrees = 4.0, |
Sasha Kuznetsov | 6678ffd | 2020-02-19 11:55:26 -0800 | [diff] [blame] | 120 | .satCorrections = singleSatCorrections, |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 121 | }; |
| 122 | return mockCorrections_1_1; |
| 123 | } |
| 124 | |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 125 | const MeasurementCorrectionsAidl Utils::getMockMeasurementCorrections_aidl() { |
| 126 | ReflectingPlaneAidl reflectingPlane; |
| 127 | reflectingPlane.latitudeDegrees = 37.4220039; |
| 128 | reflectingPlane.longitudeDegrees = -122.0840991; |
| 129 | reflectingPlane.altitudeMeters = 250.35; |
| 130 | reflectingPlane.azimuthDegrees = 203.0; |
| 131 | |
| 132 | SingleSatCorrectionAidl singleSatCorrection1; |
| 133 | singleSatCorrection1.singleSatCorrectionFlags = |
| 134 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_SAT_IS_LOS_PROBABILITY | |
| 135 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_EXCESS_PATH_LENGTH | |
| 136 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_EXCESS_PATH_LENGTH_UNC | |
| 137 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_REFLECTING_PLANE; |
| 138 | singleSatCorrection1.constellation = android::hardware::gnss::GnssConstellationType::GPS; |
| 139 | singleSatCorrection1.svid = 12; |
| 140 | singleSatCorrection1.carrierFrequencyHz = 1.59975e+09; |
| 141 | singleSatCorrection1.probSatIsLos = 0.50001; |
| 142 | singleSatCorrection1.excessPathLengthMeters = 137.4802; |
| 143 | singleSatCorrection1.excessPathLengthUncertaintyMeters = 25.5; |
| 144 | singleSatCorrection1.reflectingPlane = reflectingPlane; |
| 145 | |
| 146 | SingleSatCorrectionAidl singleSatCorrection2; |
| 147 | singleSatCorrection2.singleSatCorrectionFlags = |
| 148 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_SAT_IS_LOS_PROBABILITY | |
| 149 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_EXCESS_PATH_LENGTH | |
| 150 | SingleSatCorrectionAidl::SINGLE_SAT_CORRECTION_HAS_EXCESS_PATH_LENGTH_UNC; |
| 151 | singleSatCorrection2.constellation = GnssConstellationType::GPS; |
| 152 | singleSatCorrection2.svid = 9; |
| 153 | singleSatCorrection2.carrierFrequencyHz = 1.59975e+09; |
| 154 | singleSatCorrection2.probSatIsLos = 0.873; |
| 155 | singleSatCorrection2.excessPathLengthMeters = 26.294; |
| 156 | singleSatCorrection2.excessPathLengthUncertaintyMeters = 10.0; |
| 157 | |
| 158 | std::vector<SingleSatCorrectionAidl> singleSatCorrections = {singleSatCorrection1, |
| 159 | singleSatCorrection2}; |
| 160 | MeasurementCorrectionsAidl mockCorrections; |
| 161 | mockCorrections.latitudeDegrees = 37.4219999; |
| 162 | mockCorrections.longitudeDegrees = -122.0840575; |
| 163 | mockCorrections.altitudeMeters = 30.60062531; |
| 164 | mockCorrections.horizontalPositionUncertaintyMeters = 9.23542; |
| 165 | mockCorrections.verticalPositionUncertaintyMeters = 15.02341; |
| 166 | mockCorrections.toaGpsNanosecondsOfWeek = 2935633453L; |
| 167 | mockCorrections.hasEnvironmentBearing = true; |
| 168 | mockCorrections.environmentBearingDegrees = 45.0; |
| 169 | mockCorrections.environmentBearingUncertaintyDegrees = 4.0; |
| 170 | mockCorrections.satCorrections = singleSatCorrections; |
| 171 | |
| 172 | return mockCorrections; |
| 173 | } |
| 174 | |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 175 | /* |
| 176 | * MapConstellationType: |
| 177 | * Given a GnssConstellationType_2_0 type constellation, maps to its equivalent |
| 178 | * GnssConstellationType_1_0 type constellation. For constellations that do not have |
| 179 | * an equivalent value, maps to GnssConstellationType_1_0::UNKNOWN |
| 180 | */ |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 181 | V1_0::GnssConstellationType Utils::mapConstellationType(V2_0::GnssConstellationType constellation) { |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 182 | switch (constellation) { |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 183 | case V2_0::GnssConstellationType::GPS: |
| 184 | return V1_0::GnssConstellationType::GPS; |
| 185 | case V2_0::GnssConstellationType::SBAS: |
| 186 | return V1_0::GnssConstellationType::SBAS; |
| 187 | case V2_0::GnssConstellationType::GLONASS: |
| 188 | return V1_0::GnssConstellationType::GLONASS; |
| 189 | case V2_0::GnssConstellationType::QZSS: |
| 190 | return V1_0::GnssConstellationType::QZSS; |
| 191 | case V2_0::GnssConstellationType::BEIDOU: |
| 192 | return V1_0::GnssConstellationType::BEIDOU; |
| 193 | case V2_0::GnssConstellationType::GALILEO: |
| 194 | return V1_0::GnssConstellationType::GALILEO; |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 195 | default: |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 196 | return V1_0::GnssConstellationType::UNKNOWN; |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 200 | bool Utils::isAutomotiveDevice() { |
| 201 | char buffer[PROPERTY_VALUE_MAX] = {0}; |
| 202 | property_get("ro.hardware.type", buffer, ""); |
| 203 | return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0; |
| 204 | } |
| 205 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 206 | } // namespace common |
| 207 | } // namespace gnss |
| 208 | } // namespace hardware |
| 209 | } // namespace android |