1 /*
2  * Copyright (C) 2021 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 "MeasurementCorrectionsInterface"
18 
19 #include "MeasurementCorrectionsInterface.h"
20 #include <inttypes.h>
21 #include <log/log.h>
22 
23 namespace aidl::android::hardware::gnss::measurement_corrections {
24 
25 std::shared_ptr<IMeasurementCorrectionsCallback> MeasurementCorrectionsInterface::sCallback =
26         nullptr;
27 
setCorrections(const MeasurementCorrections & corrections)28 ndk::ScopedAStatus MeasurementCorrectionsInterface::setCorrections(
29         const MeasurementCorrections& corrections) {
30     ALOGD("setCorrections");
31     ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu, "
32           "satCorrections.size: %d",
33           corrections.latitudeDegrees, corrections.longitudeDegrees, corrections.altitudeMeters,
34           corrections.horizontalPositionUncertaintyMeters,
35           corrections.verticalPositionUncertaintyMeters,
36           static_cast<unsigned long long>(corrections.toaGpsNanosecondsOfWeek),
37           static_cast<int>(corrections.satCorrections.size()));
38     for (auto singleSatCorrection : corrections.satCorrections) {
39         ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d"
40               ", cfHz: %" PRId64
41               ", probLos: %f, combinedEpl: %f, combinedEplUnc: %f, combinedAttenuation: %f"
42               ", excessPathInfos.size: %d",
43               singleSatCorrection.singleSatCorrectionFlags, singleSatCorrection.constellation,
44               singleSatCorrection.svid, singleSatCorrection.carrierFrequencyHz,
45               singleSatCorrection.probSatIsLos, singleSatCorrection.combinedExcessPathLengthMeters,
46               singleSatCorrection.combinedExcessPathLengthUncertaintyMeters,
47               singleSatCorrection.combinedAttenuationDb,
48               static_cast<int>(singleSatCorrection.excessPathInfos.size()));
49 
50         for (auto excessPathInfo : singleSatCorrection.excessPathInfos) {
51             ALOGD("excessPathInfo = epl: %f, eplUnc: %f, attenuation: %f",
52                   excessPathInfo.excessPathLengthMeters,
53                   excessPathInfo.excessPathLengthUncertaintyMeters, excessPathInfo.attenuationDb);
54             ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
55                   excessPathInfo.reflectingPlane.latitudeDegrees,
56                   excessPathInfo.reflectingPlane.longitudeDegrees,
57                   excessPathInfo.reflectingPlane.altitudeMeters,
58                   excessPathInfo.reflectingPlane.reflectingPlaneAzimuthDegrees);
59         }
60     }
61     return ndk::ScopedAStatus::ok();
62 }
63 
setCallback(const std::shared_ptr<IMeasurementCorrectionsCallback> & callback)64 ndk::ScopedAStatus MeasurementCorrectionsInterface::setCallback(
65         const std::shared_ptr<IMeasurementCorrectionsCallback>& callback) {
66     ALOGD("MeasurementCorrections::setCallback");
67     std::unique_lock<std::mutex> lock(mMutex);
68     sCallback = callback;
69     auto ret = sCallback->setCapabilitiesCb(
70             IMeasurementCorrectionsCallback::CAPABILITY_LOS_SATS |
71             IMeasurementCorrectionsCallback::CAPABILITY_EXCESS_PATH_LENGTH |
72             IMeasurementCorrectionsCallback::CAPABILITY_REFLECTING_PLANE);
73     if (!ret.isOk()) {
74         ALOGE("%s: Unable to invoke callback", __func__);
75     }
76     return ndk::ScopedAStatus::ok();
77 }
78 }  // namespace aidl::android::hardware::gnss::measurement_corrections
79