blob: 7b890781dbf63563622d810774a49d91346e1fc0 [file] [log] [blame]
Yu-Han Yanga5098612019-02-08 16:22:07 -08001/*
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 Yang4e5ffc22020-04-17 15:44:59 -070021#include <android/hardware/gnss/2.0/IGnss.h>
Yu-Han Yang4165ed12022-02-09 14:47:50 -080022#include <android/hardware/gnss/IGnss.h>
Yu-Han Yang08642f92019-03-02 14:22:14 -080023#include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h>
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080024#include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h>
Edwin Tungbbf7fb92021-12-27 12:13:02 +080025#include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h>
26
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080027#include <gtest/gtest.h>
Yu-Han Yang4165ed12022-02-09 14:47:50 -080028#include <type_traits>
Yu-Han Yanga5098612019-02-08 16:22:07 -080029
Yu-Han Yanga5098612019-02-08 16:22:07 -080030namespace android {
31namespace hardware {
32namespace gnss {
33namespace common {
34
35struct Utils {
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080036 public:
Yu-Han Yang4165ed12022-02-09 14:47:50 -080037 static const int64_t kMockTimestamp = 1519930775453L;
38
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080039 template <class T>
40 static void checkLocation(const T& location, bool check_speed, bool check_more_accuracies);
Yu-Han Yang4165ed12022-02-09 14:47:50 -080041 template <class T>
42 static void checkLocationElapsedRealtime(const T& location);
43
44 static void checkElapsedRealtime(
45 const android::hardware::gnss::ElapsedRealtime& elapsedRealtime);
46
47 static const android::hardware::gnss::GnssLocation getMockLocation(
48 double latitudeDegrees, double longitudeDegrees, double horizontalAccuracyMeters);
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070049 static const measurement_corrections::V1_0::MeasurementCorrections
50 getMockMeasurementCorrections();
51 static const measurement_corrections::V1_1::MeasurementCorrections
52 getMockMeasurementCorrections_1_1();
Edwin Tungbbf7fb92021-12-27 12:13:02 +080053 static const android::hardware::gnss::measurement_corrections::MeasurementCorrections
54 getMockMeasurementCorrections_aidl();
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -070055
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070056 static V1_0::GnssConstellationType mapConstellationType(
57 V2_0::GnssConstellationType constellation);
Tyler Trephan0d9206a2020-09-28 22:03:18 -070058
59 static bool isAutomotiveDevice();
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080060
61 private:
62 template <class T>
63 static int64_t getLocationTimestampMillis(const T&);
Yu-Han Yanga5098612019-02-08 16:22:07 -080064};
65
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080066template <class T>
67void Utils::checkLocation(const T& location, bool check_speed, bool check_more_accuracies) {
68 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_LAT_LONG);
69 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_ALTITUDE);
70 if (check_speed) {
71 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED);
72 }
73 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
74 // New uncertainties available in O must be provided,
75 // at least when paired with modern hardware (2017+)
76 if (check_more_accuracies) {
77 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY);
78 if (check_speed) {
79 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY);
80 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) {
81 EXPECT_TRUE(location.gnssLocationFlags &
82 V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY);
83 }
84 }
85 }
86 EXPECT_GE(location.latitudeDegrees, -90.0);
87 EXPECT_LE(location.latitudeDegrees, 90.0);
88 EXPECT_GE(location.longitudeDegrees, -180.0);
89 EXPECT_LE(location.longitudeDegrees, 180.0);
90 EXPECT_GE(location.altitudeMeters, -1000.0);
91 EXPECT_LE(location.altitudeMeters, 30000.0);
92 if (check_speed) {
93 EXPECT_GE(location.speedMetersPerSec, 0.0);
94 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
95
96 // Non-zero speeds must be reported with an associated bearing
97 if (location.speedMetersPerSec > 0.0) {
98 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING);
99 }
100 }
101
102 /*
103 * Tolerating some especially high values for accuracy estimate, in case of
104 * first fix with especially poor geometry (happens occasionally)
105 */
106 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
107 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
108
109 /*
110 * Some devices may define bearing as -180 to +180, others as 0 to 360.
111 * Both are okay & understandable.
112 */
113 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) {
114 EXPECT_GE(location.bearingDegrees, -180.0);
115 EXPECT_LE(location.bearingDegrees, 360.0);
116 }
117 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
118 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
119 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
120 }
121 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY) {
122 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
123 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
124 }
125 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY) {
126 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
127 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
128 }
129
130 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
131 EXPECT_GT(getLocationTimestampMillis(location), 1.48e12);
Yu-Han Yang4165ed12022-02-09 14:47:50 -0800132
133 checkLocationElapsedRealtime(location);
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -0800134}
135
Yu-Han Yanga5098612019-02-08 16:22:07 -0800136} // namespace common
137} // namespace gnss
138} // namespace hardware
139} // namespace android
140
141#endif // android_hardware_gnss_common_vts_Utils_H_