GnssDebug.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  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. #define LOG_TAG "LocSvc_GnssDebugInterface"
  17. #include <log/log.h>
  18. #include <log_util.h>
  19. #include "Gnss.h"
  20. #include "GnssDebug.h"
  21. #include "LocationUtil.h"
  22. namespace android {
  23. namespace hardware {
  24. namespace gnss {
  25. namespace V1_1 {
  26. namespace implementation {
  27. using ::android::hardware::hidl_vec;
  28. #define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000)
  29. #define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000)
  30. #define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500)
  31. #define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180)
  32. #define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT
  33. #define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns
  34. #define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns
  35. #define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm
  36. GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss)
  37. {
  38. }
  39. /*
  40. * This methods requests position, time and satellite ephemeris debug information
  41. * from the HAL.
  42. *
  43. * @return void
  44. */
  45. Return<void> GnssDebug::getDebugData(getDebugData_cb _hidl_cb)
  46. {
  47. LOC_LOGD("%s]: ", __func__);
  48. DebugData data = { };
  49. if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){
  50. LOC_LOGE("GnssDebug - Null GNSS interface");
  51. _hidl_cb(data);
  52. return Void();
  53. }
  54. // get debug report snapshot via hal interface
  55. GnssDebugReport reports = { };
  56. mGnss->getGnssInterface()->getDebugReport(reports);
  57. // location block
  58. if (reports.mLocation.mValid) {
  59. data.position.valid = true;
  60. data.position.latitudeDegrees = reports.mLocation.mLocation.latitude;
  61. data.position.longitudeDegrees = reports.mLocation.mLocation.longitude;
  62. data.position.altitudeMeters = reports.mLocation.mLocation.altitude;
  63. data.position.speedMetersPerSec =
  64. (double)(reports.mLocation.mLocation.speed);
  65. data.position.bearingDegrees =
  66. (double)(reports.mLocation.mLocation.bearing);
  67. data.position.horizontalAccuracyMeters =
  68. (double)(reports.mLocation.mLocation.accuracy);
  69. data.position.verticalAccuracyMeters =
  70. reports.mLocation.verticalAccuracyMeters;
  71. data.position.speedAccuracyMetersPerSecond =
  72. reports.mLocation.speedAccuracyMetersPerSecond;
  73. data.position.bearingAccuracyDegrees =
  74. reports.mLocation.bearingAccuracyDegrees;
  75. timeval tv_now, tv_report;
  76. tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec;
  77. tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL;
  78. gettimeofday(&tv_now, NULL);
  79. data.position.ageSeconds =
  80. (tv_now.tv_sec - tv_report.tv_sec) +
  81. (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000;
  82. }
  83. else {
  84. data.position.valid = false;
  85. }
  86. if (data.position.horizontalAccuracyMeters <= 0 ||
  87. data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) {
  88. data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS;
  89. }
  90. if (data.position.verticalAccuracyMeters <= 0 ||
  91. data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) {
  92. data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS;
  93. }
  94. if (data.position.speedAccuracyMetersPerSecond <= 0 ||
  95. data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) {
  96. data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC;
  97. }
  98. if (data.position.bearingAccuracyDegrees <= 0 ||
  99. data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) {
  100. data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG;
  101. }
  102. // time block
  103. if (reports.mTime.mValid) {
  104. data.time.timeEstimate = reports.mTime.timeEstimate;
  105. data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs;
  106. data.time.frequencyUncertaintyNsPerSec =
  107. reports.mTime.frequencyUncertaintyNsPerSec;
  108. }
  109. if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) {
  110. data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME;
  111. }
  112. if (data.time.timeUncertaintyNs <= 0) {
  113. data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN;
  114. } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) {
  115. data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX;
  116. }
  117. if (data.time.frequencyUncertaintyNsPerSec <= 0 ||
  118. data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) {
  119. data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC;
  120. }
  121. // satellite data block
  122. SatelliteData s = { };
  123. std::vector<SatelliteData> s_array = { };
  124. for (uint32_t i=0; i<reports.mSatelliteInfo.size(); i++) {
  125. memset(&s, 0, sizeof(s));
  126. s.svid = reports.mSatelliteInfo[i].svid;
  127. convertGnssConstellationType(
  128. reports.mSatelliteInfo[i].constellation, s.constellation);
  129. convertGnssEphemerisType(
  130. reports.mSatelliteInfo[i].mEphemerisType, s.ephemerisType);
  131. convertGnssEphemerisSource(
  132. reports.mSatelliteInfo[i].mEphemerisSource, s.ephemerisSource);
  133. convertGnssEphemerisHealth(
  134. reports.mSatelliteInfo[i].mEphemerisHealth, s.ephemerisHealth);
  135. s.ephemerisAgeSeconds =
  136. reports.mSatelliteInfo[i].ephemerisAgeSeconds;
  137. s.serverPredictionIsAvailable =
  138. reports.mSatelliteInfo[i].serverPredictionIsAvailable;
  139. s.serverPredictionAgeSeconds =
  140. reports.mSatelliteInfo[i].serverPredictionAgeSeconds;
  141. s_array.push_back(s);
  142. }
  143. data.satelliteDataArray = s_array;
  144. // callback HIDL with collected debug data
  145. _hidl_cb(data);
  146. return Void();
  147. }
  148. } // namespace implementation
  149. } // namespace V1_1
  150. } // namespace gnss
  151. } // namespace hardware
  152. } // namespace android