blob: 4ea6cd617dfc13817cb7c8c0958c10c14a68bd52 [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 Yang08642f92019-03-02 14:22:14 -080022#include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h>
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080023#include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h>
Edwin Tungbbf7fb92021-12-27 12:13:02 +080024#include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h>
25
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080026#include <gtest/gtest.h>
Yu-Han Yanga5098612019-02-08 16:22:07 -080027
Yu-Han Yanga5098612019-02-08 16:22:07 -080028namespace android {
29namespace hardware {
30namespace gnss {
31namespace common {
32
33struct Utils {
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080034 public:
35 template <class T>
36 static void checkLocation(const T& location, bool check_speed, bool check_more_accuracies);
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070037 static const measurement_corrections::V1_0::MeasurementCorrections
38 getMockMeasurementCorrections();
39 static const measurement_corrections::V1_1::MeasurementCorrections
40 getMockMeasurementCorrections_1_1();
Edwin Tungbbf7fb92021-12-27 12:13:02 +080041 static const android::hardware::gnss::measurement_corrections::MeasurementCorrections
42 getMockMeasurementCorrections_aidl();
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -070043
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070044 static V1_0::GnssConstellationType mapConstellationType(
45 V2_0::GnssConstellationType constellation);
Tyler Trephan0d9206a2020-09-28 22:03:18 -070046
47 static bool isAutomotiveDevice();
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080048
49 private:
50 template <class T>
51 static int64_t getLocationTimestampMillis(const T&);
Yu-Han Yanga5098612019-02-08 16:22:07 -080052};
53
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080054template <class T>
55void Utils::checkLocation(const T& location, bool check_speed, bool check_more_accuracies) {
56 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_LAT_LONG);
57 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_ALTITUDE);
58 if (check_speed) {
59 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED);
60 }
61 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
62 // New uncertainties available in O must be provided,
63 // at least when paired with modern hardware (2017+)
64 if (check_more_accuracies) {
65 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY);
66 if (check_speed) {
67 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY);
68 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) {
69 EXPECT_TRUE(location.gnssLocationFlags &
70 V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY);
71 }
72 }
73 }
74 EXPECT_GE(location.latitudeDegrees, -90.0);
75 EXPECT_LE(location.latitudeDegrees, 90.0);
76 EXPECT_GE(location.longitudeDegrees, -180.0);
77 EXPECT_LE(location.longitudeDegrees, 180.0);
78 EXPECT_GE(location.altitudeMeters, -1000.0);
79 EXPECT_LE(location.altitudeMeters, 30000.0);
80 if (check_speed) {
81 EXPECT_GE(location.speedMetersPerSec, 0.0);
82 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
83
84 // Non-zero speeds must be reported with an associated bearing
85 if (location.speedMetersPerSec > 0.0) {
86 EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING);
87 }
88 }
89
90 /*
91 * Tolerating some especially high values for accuracy estimate, in case of
92 * first fix with especially poor geometry (happens occasionally)
93 */
94 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
95 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
96
97 /*
98 * Some devices may define bearing as -180 to +180, others as 0 to 360.
99 * Both are okay & understandable.
100 */
101 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) {
102 EXPECT_GE(location.bearingDegrees, -180.0);
103 EXPECT_LE(location.bearingDegrees, 360.0);
104 }
105 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
106 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
107 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
108 }
109 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY) {
110 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
111 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
112 }
113 if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY) {
114 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
115 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
116 }
117
118 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
119 EXPECT_GT(getLocationTimestampMillis(location), 1.48e12);
120}
121
Yu-Han Yanga5098612019-02-08 16:22:07 -0800122} // namespace common
123} // namespace gnss
124} // namespace hardware
125} // namespace android
126
127#endif // android_hardware_gnss_common_vts_Utils_H_