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 | #ifndef android_hardware_gnss_common_vts_Utils_H_ |
| 18 | #define android_hardware_gnss_common_vts_Utils_H_ |
| 19 | |
| 20 | #include <android/hardware/gnss/1.0/IGnss.h> |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 21 | #include <android/hardware/gnss/2.0/IGnss.h> |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 22 | #include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h> |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 23 | #include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h> |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame^] | 24 | #include <gtest/gtest.h> |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 25 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace gnss { |
| 29 | namespace common { |
| 30 | |
| 31 | struct Utils { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame^] | 32 | public: |
| 33 | template <class T> |
| 34 | static void checkLocation(const T& location, bool check_speed, bool check_more_accuracies); |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 35 | static const measurement_corrections::V1_0::MeasurementCorrections |
| 36 | getMockMeasurementCorrections(); |
| 37 | static const measurement_corrections::V1_1::MeasurementCorrections |
| 38 | getMockMeasurementCorrections_1_1(); |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 39 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 40 | static V1_0::GnssConstellationType mapConstellationType( |
| 41 | V2_0::GnssConstellationType constellation); |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 42 | |
| 43 | static bool isAutomotiveDevice(); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame^] | 44 | |
| 45 | private: |
| 46 | template <class T> |
| 47 | static int64_t getLocationTimestampMillis(const T&); |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame^] | 50 | template <class T> |
| 51 | void Utils::checkLocation(const T& location, bool check_speed, bool check_more_accuracies) { |
| 52 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_LAT_LONG); |
| 53 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_ALTITUDE); |
| 54 | if (check_speed) { |
| 55 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED); |
| 56 | } |
| 57 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_HORIZONTAL_ACCURACY); |
| 58 | // New uncertainties available in O must be provided, |
| 59 | // at least when paired with modern hardware (2017+) |
| 60 | if (check_more_accuracies) { |
| 61 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY); |
| 62 | if (check_speed) { |
| 63 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY); |
| 64 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) { |
| 65 | EXPECT_TRUE(location.gnssLocationFlags & |
| 66 | V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | EXPECT_GE(location.latitudeDegrees, -90.0); |
| 71 | EXPECT_LE(location.latitudeDegrees, 90.0); |
| 72 | EXPECT_GE(location.longitudeDegrees, -180.0); |
| 73 | EXPECT_LE(location.longitudeDegrees, 180.0); |
| 74 | EXPECT_GE(location.altitudeMeters, -1000.0); |
| 75 | EXPECT_LE(location.altitudeMeters, 30000.0); |
| 76 | if (check_speed) { |
| 77 | EXPECT_GE(location.speedMetersPerSec, 0.0); |
| 78 | EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary. |
| 79 | |
| 80 | // Non-zero speeds must be reported with an associated bearing |
| 81 | if (location.speedMetersPerSec > 0.0) { |
| 82 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Tolerating some especially high values for accuracy estimate, in case of |
| 88 | * first fix with especially poor geometry (happens occasionally) |
| 89 | */ |
| 90 | EXPECT_GT(location.horizontalAccuracyMeters, 0.0); |
| 91 | EXPECT_LE(location.horizontalAccuracyMeters, 250.0); |
| 92 | |
| 93 | /* |
| 94 | * Some devices may define bearing as -180 to +180, others as 0 to 360. |
| 95 | * Both are okay & understandable. |
| 96 | */ |
| 97 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) { |
| 98 | EXPECT_GE(location.bearingDegrees, -180.0); |
| 99 | EXPECT_LE(location.bearingDegrees, 360.0); |
| 100 | } |
| 101 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY) { |
| 102 | EXPECT_GT(location.verticalAccuracyMeters, 0.0); |
| 103 | EXPECT_LE(location.verticalAccuracyMeters, 500.0); |
| 104 | } |
| 105 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY) { |
| 106 | EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0); |
| 107 | EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0); |
| 108 | } |
| 109 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY) { |
| 110 | EXPECT_GT(location.bearingAccuracyDegrees, 0.0); |
| 111 | EXPECT_LE(location.bearingAccuracyDegrees, 360.0); |
| 112 | } |
| 113 | |
| 114 | // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+) |
| 115 | EXPECT_GT(getLocationTimestampMillis(location), 1.48e12); |
| 116 | } |
| 117 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 118 | } // namespace common |
| 119 | } // namespace gnss |
| 120 | } // namespace hardware |
| 121 | } // namespace android |
| 122 | |
| 123 | #endif // android_hardware_gnss_common_vts_Utils_H_ |