123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #define LOG_TAG "LocSvc_GnssDebugInterface"
- #include <log/log.h>
- #include <log_util.h>
- #include "Gnss.h"
- #include "GnssDebug.h"
- #include "LocationUtil.h"
- namespace android {
- namespace hardware {
- namespace gnss {
- namespace V1_0 {
- namespace implementation {
- using ::android::hardware::hidl_vec;
- #define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000)
- #define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000)
- #define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500)
- #define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180)
- #define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL)
- #define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC (1.57783680E17)
- #define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5)
- GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss)
- {
- }
- Return<void> GnssDebug::getDebugData(getDebugData_cb _hidl_cb)
- {
- LOC_LOGD("%s]: ", __func__);
- DebugData data = { };
- if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){
- LOC_LOGE("GnssDebug - Null GNSS interface");
- _hidl_cb(data);
- return Void();
- }
-
- GnssDebugReport reports = { };
- mGnss->getGnssInterface()->getDebugReport(reports);
-
- if (reports.mLocation.mValid) {
- data.position.valid = true;
- data.position.latitudeDegrees = reports.mLocation.mLocation.latitude;
- data.position.longitudeDegrees = reports.mLocation.mLocation.longitude;
- data.position.altitudeMeters = reports.mLocation.mLocation.altitude;
- data.position.speedMetersPerSec =
- (double)(reports.mLocation.mLocation.speed);
- data.position.bearingDegrees =
- (double)(reports.mLocation.mLocation.bearing);
- data.position.horizontalAccuracyMeters =
- (double)(reports.mLocation.mLocation.accuracy);
- data.position.verticalAccuracyMeters =
- reports.mLocation.verticalAccuracyMeters;
- data.position.speedAccuracyMetersPerSecond =
- reports.mLocation.speedAccuracyMetersPerSecond;
- data.position.bearingAccuracyDegrees =
- reports.mLocation.bearingAccuracyDegrees;
- timeval tv_now, tv_report;
- tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec;
- tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL;
- gettimeofday(&tv_now, NULL);
- data.position.ageSeconds =
- (tv_now.tv_sec - tv_report.tv_sec) +
- (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000;
- }
- else {
- data.position.valid = false;
- }
- if (data.position.horizontalAccuracyMeters <= 0 ||
- data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) {
- data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS;
- }
- if (data.position.verticalAccuracyMeters <= 0 ||
- data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) {
- data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS;
- }
- if (data.position.speedAccuracyMetersPerSecond <= 0 ||
- data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) {
- data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC;
- }
- if (data.position.bearingAccuracyDegrees <= 0 ||
- data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) {
- data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG;
- }
-
- if (reports.mTime.mValid) {
- data.time.timeEstimate = reports.mTime.timeEstimate;
- data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs;
- data.time.frequencyUncertaintyNsPerSec =
- reports.mTime.frequencyUncertaintyNsPerSec;
- }
- if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) {
- data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME;
- }
- if (data.time.timeUncertaintyNs <= 0 ||
- data.time.timeUncertaintyNs > (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC) {
- data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC;
- }
- if (data.time.frequencyUncertaintyNsPerSec <= 0 ||
- data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) {
- data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC;
- }
-
- SatelliteData s = { };
- std::vector<SatelliteData> s_array = { };
- for (uint32_t i=0; i<reports.mSatelliteInfo.size(); i++) {
- memset(&s, 0, sizeof(s));
- s.svid = reports.mSatelliteInfo[i].svid;
- convertGnssConstellationType(
- reports.mSatelliteInfo[i].constellation, s.constellation);
- convertGnssEphemerisType(
- reports.mSatelliteInfo[i].mEphemerisType, s.ephemerisType);
- convertGnssEphemerisSource(
- reports.mSatelliteInfo[i].mEphemerisSource, s.ephemerisSource);
- convertGnssEphemerisHealth(
- reports.mSatelliteInfo[i].mEphemerisHealth, s.ephemerisHealth);
- s.ephemerisAgeSeconds =
- reports.mSatelliteInfo[i].ephemerisAgeSeconds;
- s.serverPredictionIsAvailable =
- reports.mSatelliteInfo[i].serverPredictionIsAvailable;
- s.serverPredictionAgeSeconds =
- reports.mSatelliteInfo[i].serverPredictionAgeSeconds;
- s_array.push_back(s);
- }
- data.satelliteDataArray = s_array;
-
- _hidl_cb(data);
- return Void();
- }
- }
- }
- }
- }
- }
|