blob: 06bce9d3a7c3920212872faeee2d4af598bd1159 [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#include <Utils.h>
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080018#include <android/hardware/gnss/IGnss.h>
Yu-Han Yanga5098612019-02-08 16:22:07 -080019#include "gtest/gtest.h"
20
Tyler Trephan0d9206a2020-09-28 22:03:18 -070021#include <cutils/properties.h>
22
Yu-Han Yanga5098612019-02-08 16:22:07 -080023namespace android {
24namespace hardware {
25namespace gnss {
26namespace common {
27
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070028using namespace measurement_corrections::V1_0;
Yu-Han Yanga5098612019-02-08 16:22:07 -080029using V1_0::GnssLocationFlags;
30
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080031template <>
32int64_t Utils::getLocationTimestampMillis(const android::hardware::gnss::GnssLocation& location) {
33 return location.timestampMillis;
34}
Yu-Han Yanga5098612019-02-08 16:22:07 -080035
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080036template <>
37int64_t Utils::getLocationTimestampMillis(const V1_0::GnssLocation& location) {
38 return location.timestamp;
Yu-Han Yanga5098612019-02-08 16:22:07 -080039}
40
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070041const MeasurementCorrections Utils::getMockMeasurementCorrections() {
Yu-Han Yang08642f92019-03-02 14:22:14 -080042 ReflectingPlane reflectingPlane = {
43 .latitudeDegrees = 37.4220039,
44 .longitudeDegrees = -122.0840991,
45 .altitudeMeters = 250.35,
46 .azimuthDegrees = 203.0,
47 };
48
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070049 SingleSatCorrection singleSatCorrection1 = {
Yu-Han Yang08642f92019-03-02 14:22:14 -080050 .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 Yang3a75dc02021-09-27 01:01:06 -070054 .constellation = V1_0::GnssConstellationType::GPS,
Yu-Han Yang08642f92019-03-02 14:22:14 -080055 .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 Yang3a75dc02021-09-27 01:01:06 -070062 SingleSatCorrection singleSatCorrection2 = {
Yu-Han Yang08642f92019-03-02 14:22:14 -080063 .singleSatCorrectionFlags = GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY |
64 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH |
65 GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC,
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070066 .constellation = V1_0::GnssConstellationType::GPS,
Yu-Han Yang08642f92019-03-02 14:22:14 -080067 .svid = 9,
68 .carrierFrequencyHz = 1.59975e+09,
69 .probSatIsLos = 0.873,
70 .excessPathLengthMeters = 26.294,
71 .excessPathLengthUncertaintyMeters = 10.0,
72 };
73
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070074 hidl_vec<SingleSatCorrection> singleSatCorrections = {singleSatCorrection1,
75 singleSatCorrection2};
76 MeasurementCorrections mockCorrections = {
Yu-Han Yang08642f92019-03-02 14:22:14 -080077 .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 Yang3a75dc02021-09-27 01:01:06 -070088const measurement_corrections::V1_1::MeasurementCorrections
89Utils::getMockMeasurementCorrections_1_1() {
90 MeasurementCorrections mockCorrections_1_0 = getMockMeasurementCorrections();
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080091
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070092 measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection1 = {
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -080093 .v1_0 = mockCorrections_1_0.satCorrections[0],
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070094 .constellation = V2_0::GnssConstellationType::IRNSS,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -080095 };
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070096 measurement_corrections::V1_1::SingleSatCorrection singleSatCorrection2 = {
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -080097 .v1_0 = mockCorrections_1_0.satCorrections[1],
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070098 .constellation = V2_0::GnssConstellationType::IRNSS,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -080099 };
100
Yu-Han Yang3a75dc02021-09-27 01:01:06 -0700101 mockCorrections_1_0.satCorrections[0].constellation = V1_0::GnssConstellationType::UNKNOWN;
102 mockCorrections_1_0.satCorrections[1].constellation = V1_0::GnssConstellationType::UNKNOWN;
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800103
Yu-Han Yang3a75dc02021-09-27 01:01:06 -0700104 hidl_vec<measurement_corrections::V1_1::SingleSatCorrection> singleSatCorrections = {
105 singleSatCorrection1, singleSatCorrection2};
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800106
Yu-Han Yang3a75dc02021-09-27 01:01:06 -0700107 measurement_corrections::V1_1::MeasurementCorrections mockCorrections_1_1 = {
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800108 .v1_0 = mockCorrections_1_0,
109 .hasEnvironmentBearing = true,
110 .environmentBearingDegrees = 45.0,
111 .environmentBearingUncertaintyDegrees = 4.0,
Sasha Kuznetsov6678ffd2020-02-19 11:55:26 -0800112 .satCorrections = singleSatCorrections,
Sasha Kuznetsov31eea852020-01-03 13:06:38 -0800113 };
114 return mockCorrections_1_1;
115}
116
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -0700117/*
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 Yang3a75dc02021-09-27 01:01:06 -0700123V1_0::GnssConstellationType Utils::mapConstellationType(V2_0::GnssConstellationType constellation) {
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -0700124 switch (constellation) {
Yu-Han Yang3a75dc02021-09-27 01:01:06 -0700125 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 Yang4e5ffc22020-04-17 15:44:59 -0700137 default:
Yu-Han Yang3a75dc02021-09-27 01:01:06 -0700138 return V1_0::GnssConstellationType::UNKNOWN;
Yu-Han Yang4e5ffc22020-04-17 15:44:59 -0700139 }
140}
141
Tyler Trephan0d9206a2020-09-28 22:03:18 -0700142bool 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 Yanga5098612019-02-08 16:22:07 -0800148} // namespace common
149} // namespace gnss
150} // namespace hardware
151} // namespace android