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 #define LOG_TAG "GnssMeasurementCorrections"
18 
19 #include "v2_1/GnssMeasurementCorrections.h"
20 #include <log/log.h>
21 
22 namespace android::hardware::gnss::measurement_corrections::V1_1::implementation {
23 
GnssMeasurementCorrections()24 GnssMeasurementCorrections::GnssMeasurementCorrections() {}
25 
~GnssMeasurementCorrections()26 GnssMeasurementCorrections::~GnssMeasurementCorrections() {}
27 
28 // Methods from V1_0::IMeasurementCorrections follow.
setCorrections(const V1_0::MeasurementCorrections & corrections)29 Return<bool> GnssMeasurementCorrections::setCorrections(
30         const V1_0::MeasurementCorrections& corrections) {
31     ALOGD("setCorrections");
32     ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu, "
33           "satCorrections.size: %d",
34           corrections.latitudeDegrees, corrections.longitudeDegrees, corrections.altitudeMeters,
35           corrections.horizontalPositionUncertaintyMeters,
36           corrections.verticalPositionUncertaintyMeters,
37           static_cast<unsigned long long>(corrections.toaGpsNanosecondsOfWeek),
38           static_cast<int>(corrections.satCorrections.size()));
39     for (auto singleSatCorrection : corrections.satCorrections) {
40         ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
41               " epl: %f, eplUnc: %f",
42               static_cast<int>(singleSatCorrection.singleSatCorrectionFlags),
43               static_cast<int>(singleSatCorrection.constellation),
44               static_cast<int>(singleSatCorrection.svid), singleSatCorrection.carrierFrequencyHz,
45               singleSatCorrection.probSatIsLos, singleSatCorrection.excessPathLengthMeters,
46               singleSatCorrection.excessPathLengthUncertaintyMeters);
47         ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
48               singleSatCorrection.reflectingPlane.latitudeDegrees,
49               singleSatCorrection.reflectingPlane.longitudeDegrees,
50               singleSatCorrection.reflectingPlane.altitudeMeters,
51               singleSatCorrection.reflectingPlane.azimuthDegrees);
52     }
53 
54     return true;
55 }
56 
setCallback(const sp<V1_0::IMeasurementCorrectionsCallback> & callback)57 Return<bool> GnssMeasurementCorrections::setCallback(
58         const sp<V1_0::IMeasurementCorrectionsCallback>& callback) {
59     using Capabilities = V1_0::IMeasurementCorrectionsCallback::Capabilities;
60     auto ret =
61             callback->setCapabilitiesCb(Capabilities::LOS_SATS | Capabilities::EXCESS_PATH_LENGTH |
62                                         Capabilities::REFLECTING_PLANE);
63     if (!ret.isOk()) {
64         ALOGE("%s: Unable to invoke callback", __func__);
65         return false;
66     }
67     return true;
68 }
69 
70 // Methods from V1_1::IMeasurementCorrections follow.
setCorrections_1_1(const V1_1::MeasurementCorrections & corrections)71 Return<bool> GnssMeasurementCorrections::setCorrections_1_1(
72         const V1_1::MeasurementCorrections& corrections) {
73     ALOGD("setCorrections_1_1");
74     ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu,"
75           "satCorrections.size: %d, hasEnvironmentBearing: %d, environmentBearingDeg: %f,"
76           "environmentBearingUncDeg: %f",
77           corrections.v1_0.latitudeDegrees, corrections.v1_0.longitudeDegrees,
78           corrections.v1_0.altitudeMeters, corrections.v1_0.horizontalPositionUncertaintyMeters,
79           corrections.v1_0.verticalPositionUncertaintyMeters,
80           static_cast<unsigned long long>(corrections.v1_0.toaGpsNanosecondsOfWeek),
81           static_cast<int>(corrections.v1_0.satCorrections.size()),
82           corrections.hasEnvironmentBearing, corrections.environmentBearingDegrees,
83           corrections.environmentBearingUncertaintyDegrees);
84     for (auto singleSatCorrection : corrections.satCorrections) {
85         ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
86               " epl: %f, eplUnc: %f",
87               static_cast<int>(singleSatCorrection.v1_0.singleSatCorrectionFlags),
88               static_cast<int>(singleSatCorrection.constellation),
89               static_cast<int>(singleSatCorrection.v1_0.svid),
90               singleSatCorrection.v1_0.carrierFrequencyHz, singleSatCorrection.v1_0.probSatIsLos,
91               singleSatCorrection.v1_0.excessPathLengthMeters,
92               singleSatCorrection.v1_0.excessPathLengthUncertaintyMeters);
93         ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
94               singleSatCorrection.v1_0.reflectingPlane.latitudeDegrees,
95               singleSatCorrection.v1_0.reflectingPlane.longitudeDegrees,
96               singleSatCorrection.v1_0.reflectingPlane.altitudeMeters,
97               singleSatCorrection.v1_0.reflectingPlane.azimuthDegrees);
98     }
99 
100     return true;
101 }
102 
103 }  // namespace android::hardware::gnss::measurement_corrections::V1_1::implementation
104