1 /*
2 * Copyright (C) 2022 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_SERVER_MEASUREMENTCORRECTIONS_H
18 #define _ANDROID_SERVER_MEASUREMENTCORRECTIONS_H
19
20 #pragma once
21
22 #ifndef LOG_TAG
23 #error LOG_TAG must be defined before including this file.
24 #endif
25
26 #include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h>
27 #include <log/log.h>
28
29 #include "MeasurementCorrectionsCallback.h"
30 #include "jni.h"
31
32 namespace android::gnss {
33
34 namespace {
35 extern jmethodID method_correctionsGetLatitudeDegrees;
36 extern jmethodID method_correctionsGetLongitudeDegrees;
37 extern jmethodID method_correctionsGetAltitudeMeters;
38 extern jmethodID method_correctionsGetHorPosUncMeters;
39 extern jmethodID method_correctionsGetVerPosUncMeters;
40 extern jmethodID method_correctionsGetToaGpsNanosecondsOfWeek;
41 extern jmethodID method_correctionsGetSingleSatCorrectionList;
42 extern jmethodID method_correctionsHasEnvironmentBearing;
43 extern jmethodID method_correctionsGetEnvironmentBearingDegrees;
44 extern jmethodID method_correctionsGetEnvironmentBearingUncertaintyDegrees;
45 extern jmethodID method_listSize;
46 extern jmethodID method_listGet;
47 extern jmethodID method_correctionSatFlags;
48 extern jmethodID method_correctionSatConstType;
49 extern jmethodID method_correctionSatId;
50 extern jmethodID method_correctionSatCarrierFreq;
51 extern jmethodID method_correctionSatIsLosProb;
52 extern jmethodID method_correctionSatEpl;
53 extern jmethodID method_correctionSatEplUnc;
54 extern jmethodID method_correctionSatRefPlane;
55 extern jmethodID method_correctionSatExcessPathInfos;
56 extern jmethodID method_correctionPlaneLatDeg;
57 extern jmethodID method_correctionPlaneLngDeg;
58 extern jmethodID method_correctionPlaneAltDeg;
59 extern jmethodID method_correctionPlaneAzimDeg;
60 } // anonymous namespace
61
62 void MeasurementCorrections_class_init_once(JNIEnv* env, jclass clazz);
63
64 class MeasurementCorrectionsInterface {
65 public:
~MeasurementCorrectionsInterface()66 virtual ~MeasurementCorrectionsInterface() {}
67 virtual jboolean setCorrections(JNIEnv* env, jobject correctionsObj) = 0;
68 virtual jboolean setCallback(
69 const std::unique_ptr<MeasurementCorrectionsCallback>& callback) = 0;
70 };
71
72 class MeasurementCorrectionsIface_Aidl : public MeasurementCorrectionsInterface {
73 public:
74 MeasurementCorrectionsIface_Aidl(
75 const sp<android::hardware::gnss::measurement_corrections::
76 IMeasurementCorrectionsInterface>& iMeasurementCorrections);
77 jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
78 jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
79
80 private:
81 const sp<android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsInterface>
82 mIMeasurementCorrectionsAidl;
83 };
84
85 class MeasurementCorrectionsIface_V1_0 : public MeasurementCorrectionsInterface {
86 public:
87 MeasurementCorrectionsIface_V1_0(
88 const sp<android::hardware::gnss::measurement_corrections::V1_0::
89 IMeasurementCorrections>& iMeasurementCorrections);
90 jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
91 jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
92
93 private:
94 const sp<android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections>
95 mIMeasurementCorrections_V1_0;
96 };
97
98 class MeasurementCorrectionsIface_V1_1 : public MeasurementCorrectionsInterface {
99 public:
100 MeasurementCorrectionsIface_V1_1(
101 const sp<android::hardware::gnss::measurement_corrections::V1_1::
102 IMeasurementCorrections>& iMeasurementCorrections);
103 jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
104 jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
105
106 private:
107 const sp<android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections>
108 mIMeasurementCorrections_V1_1;
109 };
110
111 struct MeasurementCorrectionsUtil {
112 static android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection
113 getSingleSatCorrection_1_0_withoutConstellation(JNIEnv* env, jobject singleSatCorrectionObj);
114 static android::hardware::gnss::measurement_corrections::SingleSatCorrection
115 getSingleSatCorrection_Aidl(JNIEnv* env, jobject singleSatCorrectionObj);
116 static void getSingleSatCorrectionList_1_1(
117 JNIEnv* env, jobject singleSatCorrectionList,
118 hardware::hidl_vec<
119 android::hardware::gnss::measurement_corrections::V1_1::SingleSatCorrection>&
120 list);
121 static void getSingleSatCorrectionList_1_0(
122 JNIEnv* env, jobject singleSatCorrectionList,
123 hardware::hidl_vec<
124 android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection>&
125 list);
126 static void getSingleSatCorrectionList_Aidl(
127 JNIEnv* env, jobject singleSatCorrectionList,
128 std::vector<android::hardware::gnss::measurement_corrections::SingleSatCorrection>&
129 list);
130 template <class T>
131 static bool translateMeasurementCorrections(JNIEnv* env, jobject correctionsObj,
132 T& corrections);
133 template <class T>
134 static void setReflectingPlane(JNIEnv* env, jobject reflectingPlaneObj, T& reflectingPlane);
135 template <class T>
136 static void setReflectingPlaneAzimuthDegrees(T& reflectingPlane, double azimuthDegreeRefPlane);
137
138 static std::vector<
139 android::hardware::gnss::measurement_corrections::SingleSatCorrection::ExcessPathInfo>
140 getExcessPathInfoList(JNIEnv* env, jobject correctionsObj);
141 static android::hardware::gnss::measurement_corrections::SingleSatCorrection::ExcessPathInfo
142 getExcessPathInfo(JNIEnv* env, jobject correctionsObj);
143 };
144
145 template <class T>
setReflectingPlane(JNIEnv * env,jobject reflectingPlaneObj,T & reflectingPlane)146 void MeasurementCorrectionsUtil::setReflectingPlane(JNIEnv* env, jobject reflectingPlaneObj,
147 T& reflectingPlane) {
148 jdouble latitudeDegreesRefPlane =
149 env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLatDeg);
150 jdouble longitudeDegreesRefPlane =
151 env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLngDeg);
152 jdouble altitudeDegreesRefPlane =
153 env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAltDeg);
154 jdouble azimuthDegreeRefPlane =
155 env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAzimDeg);
156 reflectingPlane.latitudeDegrees = latitudeDegreesRefPlane;
157 reflectingPlane.longitudeDegrees = longitudeDegreesRefPlane;
158 reflectingPlane.altitudeMeters = altitudeDegreesRefPlane;
159 setReflectingPlaneAzimuthDegrees<T>(reflectingPlane, azimuthDegreeRefPlane);
160 }
161
162 } // namespace android::gnss
163
164 #endif // _ANDROID_SERVER_MEASUREMENTCORRECTIONS_H
165