blob: d2d64b57c006e41ea3a58119db4472efd9d139d4 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2016 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 "GnssHAL_GnssDebugInterface"
18
19#include <log/log.h>
20
21#include "GnssDebug.h"
22
23namespace android {
24namespace hardware {
25namespace gnss {
26namespace V1_0 {
27namespace implementation {
28
29GnssDebug::GnssDebug(const GpsDebugInterface_ext* gpsDebugIface) : mGnssDebugIface(gpsDebugIface) {}
30
31// Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
32Return<void> GnssDebug::getDebugData(getDebugData_cb _hidl_cb) {
33 /*
34 * This is a new interface and hence there is no way to retrieve the
35 * debug data from the HAL.
36 */
37 if (mGnssDebugIface) {
38 ::DebugData debugData;
39 IGnssDebug::DebugData data;
40 bool ret = mGnssDebugIface->get_internal_state(&debugData);
41 if (ret) {
42 data.position = (IGnssDebug::PositionDebug){
43 .valid = debugData.position.valid,
44 .latitudeDegrees = debugData.position.latitudeDegrees,
45 .longitudeDegrees = debugData.position.longitudeDegrees,
46 .altitudeMeters = debugData.position.altitudeMeters,
47 .speedMetersPerSec = debugData.position.speedMetersPerSec,
48 .bearingDegrees = debugData.position.bearingDegrees,
49 .horizontalAccuracyMeters = debugData.position.horizontalAccuracyMeters,
50 .verticalAccuracyMeters = debugData.position.verticalAccuracyMeters,
51 .speedAccuracyMetersPerSecond = debugData.position.speedAccuracyMetersPerSecond,
52 .bearingAccuracyDegrees = debugData.position.bearingAccuracyDegrees,
53 .ageSeconds = debugData.position.ageSeconds
54 };
55 data.time = (IGnssDebug::TimeDebug){
56 .timeEstimate = debugData.time.timeEstimate,
57 .timeUncertaintyNs = debugData.time.timeUncertaintyNs,
58 .frequencyUncertaintyNsPerSec = debugData.time.frequencyUncertaintyNsPerSec,
59 };
60
61 int count = 0;
62 for (; count < GNSS_MAX_SVS; count++) {
63 if (debugData.satelliteDataArray[count].svid == 0) {
64 break;
65 }
66 }
67 data.satelliteDataArray.resize(count);
68 for (int i = 0; i < count; i++) {
69 auto entry = debugData.satelliteDataArray[i];
70 data.satelliteDataArray[i] = (IGnssDebug::SatelliteData) {
71 .svid = entry.svid,
72 .constellation = (V1_0::GnssConstellationType) entry.constellation,
73 .ephemerisType = (IGnssDebug::SatelliteEphemerisType) entry.ephemerisType,
74 .ephemerisSource = (IGnssDebug::SatelliteEphemerisSource)entry.ephemerisSource,
75 .ephemerisHealth = (IGnssDebug::SatelliteEphemerisHealth)entry.ephemerisHealth,
76 .ephemerisAgeSeconds = entry.ephemerisAgeSeconds,
77 .serverPredictionIsAvailable = entry.serverPredictionIsAvailable,
78 .serverPredictionAgeSeconds = entry.serverPredictionAgeSeconds
79 };
80 }
81 _hidl_cb(data);
82 }
83 }
84 return Void();
85}
86
87} // namespace implementation
88} // namespace V1_0
89} // namespace gnss
90} // namespace hardware
91} // namespace android