GnssDebug.cpp 6.4 KB

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