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