GnssMeasurementInterface.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  3. * Not a Contribution
  4. */
  5. /*
  6. * Copyright (C) 2020 The Android Open Source Project
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #define LOG_TAG "GnssMeasurementInterfaceAidl"
  21. #include <log_util.h>
  22. #include "GnssMeasurementInterface.h"
  23. #include <android/binder_auto_utils.h>
  24. #include <aidl/android/hardware/gnss/BnGnss.h>
  25. #include <inttypes.h>
  26. #include <loc_misc_utils.h>
  27. using aidl::android::hardware::gnss::ElapsedRealtime;
  28. using aidl::android::hardware::gnss::GnssClock;
  29. using aidl::android::hardware::gnss::GnssData;
  30. using aidl::android::hardware::gnss::GnssMeasurement;
  31. using aidl::android::hardware::gnss::GnssSignalType;
  32. using aidl::android::hardware::gnss::GnssConstellationType;
  33. using aidl::android::hardware::gnss::GnssMultipathIndicator;
  34. namespace android {
  35. namespace hardware {
  36. namespace gnss {
  37. namespace aidl {
  38. namespace implementation {
  39. GnssMeasurementInterface::GnssMeasurementInterface() :
  40. mDeathRecipient(AIBinder_DeathRecipient_new(GnssMeasurementInterface::gnssMeasurementDied)),
  41. mTracking(false) {
  42. }
  43. ::ndk::ScopedAStatus GnssMeasurementInterface::setCallback(
  44. const std::shared_ptr<IGnssMeasurementCallback>& in_callback,
  45. bool in_enableFullTracking, bool in_enableCorrVecOutputs) {
  46. LOC_LOGd("setCallback: enableFullTracking: %d enableCorrVecOutputs: %d",
  47. (int)in_enableFullTracking,
  48. (int)in_enableCorrVecOutputs);
  49. std::unique_lock<std::mutex> lock(mMutex);
  50. if (nullptr == in_callback) {
  51. LOC_LOGe("callback is nullptr");
  52. return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
  53. }
  54. AIBinder_linkToDeath(in_callback->asBinder().get(), mDeathRecipient, this);
  55. mGnssMeasurementCbIface = in_callback;
  56. lock.unlock();
  57. startTracking(in_enableFullTracking ? GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2);
  58. return ndk::ScopedAStatus::ok();
  59. }
  60. ::ndk::ScopedAStatus GnssMeasurementInterface::close() {
  61. LOC_LOGd("()");
  62. if (nullptr != mGnssMeasurementCbIface) {
  63. AIBinder_unlinkToDeath(mGnssMeasurementCbIface->asBinder().get(), mDeathRecipient, this);
  64. mGnssMeasurementCbIface = nullptr;
  65. }
  66. std::unique_lock<std::mutex> lock(mMutex);
  67. mTracking = false;
  68. lock.unlock();
  69. locAPIStopTracking();
  70. return ndk::ScopedAStatus::ok();
  71. }
  72. void GnssMeasurementInterface::onGnssMeasurementsCb(
  73. GnssMeasurementsNotification gnssMeasurementsNotification) {
  74. std::unique_lock<std::mutex> lock(mMutex);
  75. LOC_LOGd("(count: %u active: %d)", gnssMeasurementsNotification.count, mTracking);
  76. if (mTracking) {
  77. auto gnssMeasurementCbIface = mGnssMeasurementCbIface;
  78. if (gnssMeasurementCbIface != nullptr) {
  79. GnssData gnssData = {};
  80. convertGnssData(gnssMeasurementsNotification, gnssData);
  81. printGnssData(gnssData);
  82. lock.unlock();
  83. gnssMeasurementCbIface->gnssMeasurementCb(gnssData);
  84. }
  85. }
  86. }
  87. void GnssMeasurementInterface::gnssMeasurementDied(void* cookie) {
  88. LOC_LOGe("IGnssMeasurementCallback service died");
  89. GnssMeasurementInterface* iface = static_cast<GnssMeasurementInterface*>(cookie);
  90. //clean up, i.e. iface->close();
  91. if (iface != nullptr) {
  92. iface->close();
  93. }
  94. }
  95. void GnssMeasurementInterface::startTracking(
  96. GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) {
  97. LocationCallbacks locationCallbacks;
  98. memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
  99. locationCallbacks.size = sizeof(LocationCallbacks);
  100. locationCallbacks.trackingCb = nullptr;
  101. locationCallbacks.batchingCb = nullptr;
  102. locationCallbacks.geofenceBreachCb = nullptr;
  103. locationCallbacks.geofenceStatusCb = nullptr;
  104. locationCallbacks.gnssLocationInfoCb = nullptr;
  105. locationCallbacks.gnssNiCb = nullptr;
  106. locationCallbacks.gnssSvCb = nullptr;
  107. locationCallbacks.gnssNmeaCb = nullptr;
  108. locationCallbacks.gnssMeasurementsCb = nullptr;
  109. if (nullptr != mGnssMeasurementCbIface) {
  110. locationCallbacks.gnssMeasurementsCb =
  111. [this](GnssMeasurementsNotification gnssMeasurementsNotification) {
  112. onGnssMeasurementsCb(gnssMeasurementsNotification);
  113. };
  114. }
  115. locAPISetCallbacks(locationCallbacks);
  116. TrackingOptions options = {};
  117. memset(&options, 0, sizeof(TrackingOptions));
  118. options.size = sizeof(TrackingOptions);
  119. options.minInterval = 1000;
  120. options.mode = GNSS_SUPL_MODE_STANDALONE;
  121. if (GNSS_POWER_MODE_INVALID != powerMode) {
  122. options.powerMode = powerMode;
  123. options.tbm = timeBetweenMeasurement;
  124. }
  125. std::unique_lock<std::mutex> lock(mMutex);
  126. mTracking = true;
  127. lock.unlock();
  128. LOC_LOGd("start tracking session");
  129. locAPIStartTracking(options);
  130. }
  131. void GnssMeasurementInterface::convertGnssData(GnssMeasurementsNotification& in, GnssData& out) {
  132. out.measurements.resize(in.count);
  133. for (size_t i = 0; i < in.count; i++) {
  134. out.measurements[i].flags = 0;
  135. convertGnssMeasurement(in.measurements[i], out.measurements[i]);
  136. }
  137. convertGnssClock(in.clock, out.clock);
  138. convertElapsedRealtimeNanos(in, out.elapsedRealtime);
  139. }
  140. void GnssMeasurementInterface::convertGnssMeasurement(
  141. GnssMeasurementsData& in, GnssMeasurement& out) {
  142. // flags
  143. convertGnssFlags(in, out);
  144. // svid
  145. convertGnssSvId(in, out.svid);
  146. // signalType
  147. convertGnssSignalType(in, out.signalType);
  148. // timeOffsetNs
  149. out.timeOffsetNs = in.timeOffsetNs;
  150. // state
  151. convertGnssState(in, out);
  152. // receivedSvTimeInNs
  153. out.receivedSvTimeInNs = in.receivedSvTimeNs;
  154. // receivedSvTimeUncertaintyInNs
  155. out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
  156. // antennaCN0DbHz
  157. out.antennaCN0DbHz = in.carrierToNoiseDbHz;
  158. // basebandCN0DbHz
  159. out.basebandCN0DbHz = in.basebandCarrierToNoiseDbHz;
  160. // pseudorangeRateMps
  161. out.pseudorangeRateMps = in.pseudorangeRateMps;
  162. // pseudorangeRateUncertaintyMps
  163. out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
  164. // accumulatedDeltaRangeState
  165. convertGnssAccumulatedDeltaRangeState(in, out);
  166. // accumulatedDeltaRangeM
  167. out.accumulatedDeltaRangeM = in.adrMeters;
  168. // accumulatedDeltaRangeUncertaintyM
  169. out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
  170. // carrierCycles
  171. out.carrierCycles = in.carrierCycles;
  172. // carrierPhase
  173. out.carrierPhase = in.carrierPhase;
  174. // carrierPhaseUncertainty
  175. out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
  176. // multipathIndicator
  177. convertGnssMultipathIndicator(in, out);
  178. // snrDb
  179. out.snrDb = in.signalToNoiseRatioDb;
  180. // agcLevelDb
  181. out.agcLevelDb = in.agcLevelDb;
  182. // fullInterSignalBiasNs
  183. out.fullInterSignalBiasNs = in.fullInterSignalBiasNs;
  184. // fullInterSignalBiasUncertaintyNs
  185. out.fullInterSignalBiasUncertaintyNs = in.fullInterSignalBiasUncertaintyNs;
  186. // satelliteInterSignalBiasNs
  187. out.satelliteInterSignalBiasNs = in.satelliteInterSignalBiasNs;
  188. // satelliteInterSignalBiasUncertaintyNs
  189. out.satelliteInterSignalBiasUncertaintyNs = in.satelliteInterSignalBiasUncertaintyNs;
  190. // satellitePvt
  191. convertGnssSatellitePvt(in, out);
  192. // correlationVectors
  193. /* This is not supported, the corresponding flag is not set */
  194. }
  195. void GnssMeasurementInterface::convertGnssFlags(GnssMeasurementsData& in, GnssMeasurement& out) {
  196. if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
  197. out.flags |= out.HAS_SNR;
  198. if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
  199. out.flags |= out.HAS_CARRIER_FREQUENCY;
  200. if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
  201. out.flags |= out.HAS_CARRIER_CYCLES;
  202. if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
  203. out.flags |= out.HAS_CARRIER_PHASE;
  204. if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
  205. out.flags |= out.HAS_CARRIER_PHASE_UNCERTAINTY;
  206. if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT)
  207. out.flags |= out.HAS_AUTOMATIC_GAIN_CONTROL;
  208. if (in.flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_BIT)
  209. out.flags |= out.HAS_FULL_ISB;
  210. if (in.flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_UNCERTAINTY_BIT)
  211. out.flags |= out.HAS_FULL_ISB_UNCERTAINTY;
  212. if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_BIT)
  213. out.flags |= out.HAS_SATELLITE_ISB;
  214. if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_UNCERTAINTY_BIT)
  215. out.flags |= out.HAS_SATELLITE_ISB_UNCERTAINTY;
  216. if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_PVT_BIT)
  217. out.flags |= out.HAS_SATELLITE_PVT;
  218. if (in.flags & GNSS_MEASUREMENTS_DATA_CORRELATION_VECTOR_BIT)
  219. out.flags |= out.HAS_CORRELATION_VECTOR;
  220. }
  221. void GnssMeasurementInterface::convertGnssSvId(GnssMeasurementsData& in, int& out) {
  222. switch (in.svType) {
  223. case GNSS_SV_TYPE_GPS:
  224. out = in.svId;
  225. break;
  226. case GNSS_SV_TYPE_SBAS:
  227. out = in.svId;
  228. break;
  229. case GNSS_SV_TYPE_GLONASS:
  230. if (in.svId != 255) { // OSN is known
  231. out = in.svId - GLO_SV_PRN_MIN + 1;
  232. } else { // OSN is not known, report FCN
  233. out = in.gloFrequency + 92;
  234. }
  235. break;
  236. case GNSS_SV_TYPE_QZSS:
  237. out = in.svId;
  238. break;
  239. case GNSS_SV_TYPE_BEIDOU:
  240. out = in.svId - BDS_SV_PRN_MIN + 1;
  241. break;
  242. case GNSS_SV_TYPE_GALILEO:
  243. out = in.svId - GAL_SV_PRN_MIN + 1;
  244. break;
  245. case GNSS_SV_TYPE_NAVIC:
  246. out = in.svId - NAVIC_SV_PRN_MIN + 1;
  247. break;
  248. default:
  249. out = in.svId;
  250. break;
  251. }
  252. }
  253. void GnssMeasurementInterface::convertGnssSignalType(
  254. GnssMeasurementsData& in, GnssSignalType& out) {
  255. convertGnssConstellationType(in.svType, out.constellation);
  256. out.carrierFrequencyHz = in.carrierFrequencyHz;
  257. convertGnssMeasurementsCodeType(in.codeType, in.otherCodeTypeName, out);
  258. }
  259. void GnssMeasurementInterface::convertGnssConstellationType(
  260. GnssSvType& in, GnssConstellationType& out) {
  261. switch (in) {
  262. case GNSS_SV_TYPE_GPS:
  263. out = GnssConstellationType::GPS;
  264. break;
  265. case GNSS_SV_TYPE_SBAS:
  266. out = GnssConstellationType::SBAS;
  267. break;
  268. case GNSS_SV_TYPE_GLONASS:
  269. out = GnssConstellationType::GLONASS;
  270. break;
  271. case GNSS_SV_TYPE_QZSS:
  272. out = GnssConstellationType::QZSS;
  273. break;
  274. case GNSS_SV_TYPE_BEIDOU:
  275. out = GnssConstellationType::BEIDOU;
  276. break;
  277. case GNSS_SV_TYPE_GALILEO:
  278. out = GnssConstellationType::GALILEO;
  279. break;
  280. case GNSS_SV_TYPE_NAVIC:
  281. out = GnssConstellationType::IRNSS;
  282. break;
  283. case GNSS_SV_TYPE_UNKNOWN:
  284. default:
  285. out = GnssConstellationType::UNKNOWN;
  286. break;
  287. }
  288. }
  289. void GnssMeasurementInterface::convertGnssMeasurementsCodeType(
  290. GnssMeasurementsCodeType& inCodeType,
  291. char* inOtherCodeTypeName, GnssSignalType& out) {
  292. switch (inCodeType) {
  293. case GNSS_MEASUREMENTS_CODE_TYPE_A:
  294. out.codeType = out.CODE_TYPE_A;
  295. break;
  296. case GNSS_MEASUREMENTS_CODE_TYPE_B:
  297. out.codeType = out.CODE_TYPE_B;
  298. break;
  299. case GNSS_MEASUREMENTS_CODE_TYPE_C:
  300. out.codeType = out.CODE_TYPE_C;
  301. break;
  302. case GNSS_MEASUREMENTS_CODE_TYPE_I:
  303. out.codeType = out.CODE_TYPE_I;
  304. break;
  305. case GNSS_MEASUREMENTS_CODE_TYPE_L:
  306. out.codeType = out.CODE_TYPE_L;
  307. break;
  308. case GNSS_MEASUREMENTS_CODE_TYPE_M:
  309. out.codeType = out.CODE_TYPE_M;
  310. break;
  311. case GNSS_MEASUREMENTS_CODE_TYPE_N:
  312. out.codeType = out.CODE_TYPE_N;
  313. break;
  314. case GNSS_MEASUREMENTS_CODE_TYPE_P:
  315. out.codeType = out.CODE_TYPE_P;
  316. break;
  317. case GNSS_MEASUREMENTS_CODE_TYPE_Q:
  318. out.codeType = out.CODE_TYPE_Q;
  319. break;
  320. case GNSS_MEASUREMENTS_CODE_TYPE_S:
  321. out.codeType = out.CODE_TYPE_S;
  322. break;
  323. case GNSS_MEASUREMENTS_CODE_TYPE_W:
  324. out.codeType = out.CODE_TYPE_W;
  325. break;
  326. case GNSS_MEASUREMENTS_CODE_TYPE_X:
  327. out.codeType = out.CODE_TYPE_X;
  328. break;
  329. case GNSS_MEASUREMENTS_CODE_TYPE_Y:
  330. out.codeType = out.CODE_TYPE_Y;
  331. break;
  332. case GNSS_MEASUREMENTS_CODE_TYPE_Z:
  333. out.codeType = out.CODE_TYPE_Z;
  334. break;
  335. case GNSS_MEASUREMENTS_CODE_TYPE_OTHER:
  336. default:
  337. out.codeType = inOtherCodeTypeName;
  338. break;
  339. }
  340. }
  341. void GnssMeasurementInterface::convertGnssState(GnssMeasurementsData& in, GnssMeasurement& out) {
  342. if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
  343. out.state |= out.STATE_CODE_LOCK;
  344. if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
  345. out.state |= out.STATE_BIT_SYNC;
  346. if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
  347. out.state |= out.STATE_SUBFRAME_SYNC;
  348. if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
  349. out.state |= out.STATE_TOW_DECODED;
  350. if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
  351. out.state |= out.STATE_MSEC_AMBIGUOUS;
  352. if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
  353. out.state |= out.STATE_SYMBOL_SYNC;
  354. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
  355. out.state |= out.STATE_GLO_STRING_SYNC;
  356. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
  357. out.state |= out.STATE_GLO_TOD_DECODED;
  358. if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
  359. out.state |= out.STATE_BDS_D2_BIT_SYNC;
  360. if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
  361. out.state |= out.STATE_BDS_D2_SUBFRAME_SYNC;
  362. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
  363. out.state |= out.STATE_GAL_E1BC_CODE_LOCK;
  364. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
  365. out.state |= out.STATE_GAL_E1C_2ND_CODE_LOCK;
  366. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
  367. out.state |= out.STATE_GAL_E1B_PAGE_SYNC;
  368. if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
  369. out.state |= out.STATE_SBAS_SYNC;
  370. if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT)
  371. out.state |= out.STATE_TOW_KNOWN;
  372. if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT)
  373. out.state |= out.STATE_GLO_TOD_KNOWN;
  374. if (in.stateMask & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT)
  375. out.state |= out.STATE_2ND_CODE_LOCK;
  376. }
  377. void GnssMeasurementInterface::convertGnssAccumulatedDeltaRangeState(
  378. GnssMeasurementsData& in, GnssMeasurement& out) {
  379. if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
  380. out.accumulatedDeltaRangeState |= out.ADR_STATE_VALID;
  381. if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
  382. out.accumulatedDeltaRangeState |= out.ADR_STATE_RESET;
  383. if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
  384. out.accumulatedDeltaRangeState |= out.ADR_STATE_CYCLE_SLIP;
  385. if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
  386. out.accumulatedDeltaRangeState |= out.ADR_STATE_HALF_CYCLE_RESOLVED;
  387. }
  388. void GnssMeasurementInterface::convertGnssMultipathIndicator(
  389. GnssMeasurementsData& in, GnssMeasurement& out) {
  390. switch (in.multipathIndicator) {
  391. case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT:
  392. out.multipathIndicator = GnssMultipathIndicator::PRESENT;
  393. break;
  394. case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT:
  395. out.multipathIndicator = GnssMultipathIndicator::NOT_PRESENT;
  396. break;
  397. case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_UNKNOWN:
  398. default:
  399. out.multipathIndicator = GnssMultipathIndicator::UNKNOWN;
  400. break;
  401. }
  402. }
  403. void GnssMeasurementInterface::convertGnssSatellitePvtFlags(GnssMeasurementsData& in,
  404. GnssMeasurement& out) {
  405. if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_POSITION_VELOCITY_CLOCK_INFO_BIT)
  406. out.satellitePvt.flags |= out.satellitePvt.HAS_POSITION_VELOCITY_CLOCK_INFO;
  407. if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_IONO_BIT)
  408. out.satellitePvt.flags |= out.satellitePvt.HAS_IONO;
  409. if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_TROPO_BIT)
  410. out.satellitePvt.flags |= out.satellitePvt.HAS_TROPO;
  411. }
  412. void GnssMeasurementInterface::convertGnssSatellitePvt(
  413. GnssMeasurementsData& in, GnssMeasurement& out) {
  414. // flags
  415. convertGnssSatellitePvtFlags(in, out);
  416. // satPosEcef
  417. out.satellitePvt.satPosEcef.posXMeters = in.satellitePvt.satPosEcef.posXMeters;
  418. out.satellitePvt.satPosEcef.posYMeters = in.satellitePvt.satPosEcef.posYMeters;
  419. out.satellitePvt.satPosEcef.posZMeters = in.satellitePvt.satPosEcef.posZMeters;
  420. out.satellitePvt.satPosEcef.ureMeters = in.satellitePvt.satPosEcef.ureMeters;
  421. // satVelEcef
  422. out.satellitePvt.satVelEcef.velXMps = in.satellitePvt.satVelEcef.velXMps;
  423. out.satellitePvt.satVelEcef.velYMps = in.satellitePvt.satVelEcef.velYMps;
  424. out.satellitePvt.satVelEcef.velZMps = in.satellitePvt.satVelEcef.velZMps;
  425. out.satellitePvt.satVelEcef.ureRateMps = in.satellitePvt.satVelEcef.ureRateMps;
  426. // satClockInfo
  427. out.satellitePvt.satClockInfo.satHardwareCodeBiasMeters =
  428. in.satellitePvt.satClockInfo.satHardwareCodeBiasMeters;
  429. out.satellitePvt.satClockInfo.satTimeCorrectionMeters =
  430. in.satellitePvt.satClockInfo.satTimeCorrectionMeters;
  431. out.satellitePvt.satClockInfo.satClkDriftMps = in.satellitePvt.satClockInfo.satClkDriftMps;
  432. // ionoDelayMeters
  433. out.satellitePvt.ionoDelayMeters = in.satellitePvt.ionoDelayMeters;
  434. // tropoDelayMeters
  435. out.satellitePvt.tropoDelayMeters = in.satellitePvt.tropoDelayMeters;
  436. }
  437. void GnssMeasurementInterface::convertGnssClock(
  438. GnssMeasurementsClock& in, GnssClock& out) {
  439. // gnssClockFlags
  440. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
  441. out.gnssClockFlags |= out.HAS_LEAP_SECOND;
  442. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
  443. out.gnssClockFlags |= out.HAS_TIME_UNCERTAINTY;
  444. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
  445. out.gnssClockFlags |= out.HAS_FULL_BIAS;
  446. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
  447. out.gnssClockFlags |= out.HAS_BIAS;
  448. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
  449. out.gnssClockFlags |= out.HAS_BIAS_UNCERTAINTY;
  450. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
  451. out.gnssClockFlags |= out.HAS_DRIFT;
  452. if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
  453. out.gnssClockFlags |= out.HAS_DRIFT_UNCERTAINTY;
  454. // leapSecond
  455. out.leapSecond = in.leapSecond;
  456. // timeNs
  457. out.timeNs = in.timeNs;
  458. // timeUncertaintyNs
  459. out.timeUncertaintyNs = in.timeUncertaintyNs;
  460. // fullBiasNs
  461. out.fullBiasNs = in.fullBiasNs;
  462. // biasNs
  463. out.biasNs = in.biasNs;
  464. // biasUncertaintyNs
  465. out.biasUncertaintyNs = in.biasUncertaintyNs;
  466. // driftNsps
  467. out.driftNsps = in.driftNsps;
  468. // driftUncertaintyNsps
  469. out.driftUncertaintyNsps = in.driftUncertaintyNsps;
  470. // hwClockDiscontinuityCount
  471. out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
  472. // referenceSignalTypeForIsb
  473. convertGnssConstellationType(in.referenceSignalTypeForIsb.svType,
  474. out.referenceSignalTypeForIsb.constellation);
  475. out.referenceSignalTypeForIsb.carrierFrequencyHz =
  476. in.referenceSignalTypeForIsb.carrierFrequencyHz;
  477. convertGnssMeasurementsCodeType(in.referenceSignalTypeForIsb.codeType,
  478. in.referenceSignalTypeForIsb.otherCodeTypeName,
  479. out.referenceSignalTypeForIsb);
  480. }
  481. void GnssMeasurementInterface::convertElapsedRealtimeNanos(
  482. GnssMeasurementsNotification& in, ElapsedRealtime& elapsedRealtime) {
  483. if (in.clock.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT) {
  484. elapsedRealtime.flags |= elapsedRealtime.HAS_TIMESTAMP_NS;
  485. elapsedRealtime.timestampNs = in.clock.elapsedRealTime;
  486. elapsedRealtime.flags |= elapsedRealtime.HAS_TIME_UNCERTAINTY_NS;
  487. elapsedRealtime.timeUncertaintyNs = in.clock.elapsedRealTimeUnc;
  488. LOC_LOGd("elapsedRealtime.timestampNs=%" PRIi64 ""
  489. " elapsedRealtime.timeUncertaintyNs=%lf elapsedRealtime.flags=0x%X",
  490. elapsedRealtime.timestampNs,
  491. elapsedRealtime.timeUncertaintyNs, elapsedRealtime.flags);
  492. }
  493. }
  494. void GnssMeasurementInterface::printGnssData(GnssData& data) {
  495. LOC_LOGd(" Measurements Info for %zu satellites", data.measurements.size());
  496. for (size_t i = 0; i < data.measurements.size(); i++) {
  497. LOC_LOGd("%zu : flags: 0x%08x,"
  498. " svid: %d,"
  499. " signalType.constellation: %u,"
  500. " signalType.carrierFrequencyHz: %.2f,"
  501. " signalType.codeType: %s,"
  502. " timeOffsetNs: %.2f,"
  503. " state: 0x%08x,"
  504. " receivedSvTimeInNs: %" PRIu64
  505. " receivedSvTimeUncertaintyInNs: %" PRIu64
  506. " antennaCN0DbHz: %.2f,"
  507. " basebandCN0DbHz: %.2f,"
  508. " pseudorangeRateMps : %.2f,"
  509. " pseudorangeRateUncertaintyMps : %.2f,\n"
  510. " accumulatedDeltaRangeState: 0x%08x,"
  511. " accumulatedDeltaRangeM: %.2f, "
  512. " accumulatedDeltaRangeUncertaintyM : %.2f, "
  513. " carrierCycles: %" PRIu64
  514. " carrierPhase: %.2f,"
  515. " carrierPhaseUncertainty: %.2f,"
  516. " multipathIndicator: %u,"
  517. " snrDb: %.2f,"
  518. " agcLevelDb: %.2f,"
  519. " fullInterSignalBiasNs: %.2f,"
  520. " fullInterSignalBiasUncertaintyNs: %.2f,"
  521. " satelliteInterSignalBiasNs: %.2f,"
  522. " satelliteInterSignalBiasUncertaintyNs: %.2f",
  523. i + 1,
  524. data.measurements[i].flags,
  525. data.measurements[i].svid,
  526. data.measurements[i].signalType.constellation,
  527. data.measurements[i].signalType.carrierFrequencyHz,
  528. data.measurements[i].signalType.codeType.c_str(),
  529. data.measurements[i].timeOffsetNs,
  530. data.measurements[i].state,
  531. data.measurements[i].receivedSvTimeInNs,
  532. data.measurements[i].receivedSvTimeUncertaintyInNs,
  533. data.measurements[i].antennaCN0DbHz,
  534. data.measurements[i].basebandCN0DbHz,
  535. data.measurements[i].pseudorangeRateMps,
  536. data.measurements[i].pseudorangeRateUncertaintyMps,
  537. data.measurements[i].accumulatedDeltaRangeState,
  538. data.measurements[i].accumulatedDeltaRangeM,
  539. data.measurements[i].accumulatedDeltaRangeUncertaintyM,
  540. data.measurements[i].carrierCycles,
  541. data.measurements[i].carrierPhase,
  542. data.measurements[i].carrierPhaseUncertainty,
  543. data.measurements[i].multipathIndicator,
  544. data.measurements[i].snrDb,
  545. data.measurements[i].agcLevelDb,
  546. data.measurements[i].fullInterSignalBiasNs,
  547. data.measurements[i].fullInterSignalBiasUncertaintyNs,
  548. data.measurements[i].satelliteInterSignalBiasNs,
  549. data.measurements[i].satelliteInterSignalBiasUncertaintyNs
  550. );
  551. LOC_LOGd(" satellitePvt.flags: 0x%04x,"
  552. " satellitePvt.satPosEcef.posXMeters: %.2f,"
  553. " satellitePvt.satPosEcef.posYMeters: %.2f,"
  554. " satellitePvt.satPosEcef.posZMeters: %.2f,"
  555. " satellitePvt.satPosEcef.ureMeters: %.2f,"
  556. " satellitePvt.satVelEcef.velXMps: %.2f,"
  557. " satellitePvt.satVelEcef.velYMps: %.2f,"
  558. " satellitePvt.satVelEcef.velZMps: %.2f,"
  559. " satellitePvt.satVelEcef.ureRateMps: %.2f,"
  560. " satellitePvt.satClockInfo.satHardwareCodeBiasMeters: %.2f,"
  561. " satellitePvt.satClockInfo.satTimeCorrectionMeters: %.2f,"
  562. " satellitePvt.satClockInfo.satClkDriftMps: %.2f,"
  563. " satellitePvt.ionoDelayMeters: %.2f,"
  564. " satellitePvt.tropoDelayMeters: %.2f",
  565. data.measurements[i].satellitePvt.flags,
  566. data.measurements[i].satellitePvt.satPosEcef.posXMeters,
  567. data.measurements[i].satellitePvt.satPosEcef.posYMeters,
  568. data.measurements[i].satellitePvt.satPosEcef.posZMeters,
  569. data.measurements[i].satellitePvt.satPosEcef.ureMeters,
  570. data.measurements[i].satellitePvt.satVelEcef.velXMps,
  571. data.measurements[i].satellitePvt.satVelEcef.velYMps,
  572. data.measurements[i].satellitePvt.satVelEcef.velZMps,
  573. data.measurements[i].satellitePvt.satVelEcef.ureRateMps,
  574. data.measurements[i].satellitePvt.satClockInfo.satHardwareCodeBiasMeters,
  575. data.measurements[i].satellitePvt.satClockInfo.satTimeCorrectionMeters,
  576. data.measurements[i].satellitePvt.satClockInfo.satClkDriftMps,
  577. data.measurements[i].satellitePvt.ionoDelayMeters,
  578. data.measurements[i].satellitePvt.tropoDelayMeters
  579. );
  580. }
  581. LOC_LOGd(" Clocks Info "
  582. " gnssClockFlags: 0x%04x,"
  583. " leapSecond: %d,"
  584. " timeNs: %" PRId64
  585. " timeUncertaintyNs: %.2f,"
  586. " fullBiasNs: %" PRId64
  587. " biasNs: %.2f,"
  588. " biasUncertaintyNs: %.2f,"
  589. " driftNsps: %.2f,"
  590. " driftUncertaintyNsps: %.2f,"
  591. " hwClockDiscontinuityCount: %u,"
  592. " referenceSignalTypeForIsb.constellation: %u,"
  593. " referenceSignalTypeForIsb.carrierFrequencyHz: %.2f,"
  594. " referenceSignalTypeForIsb.codeType: %s",
  595. data.clock.gnssClockFlags,
  596. data.clock.leapSecond,
  597. data.clock.timeNs,
  598. data.clock.timeUncertaintyNs,
  599. data.clock.fullBiasNs,
  600. data.clock.biasNs,
  601. data.clock.biasUncertaintyNs,
  602. data.clock.driftNsps,
  603. data.clock.driftUncertaintyNsps,
  604. data.clock.hwClockDiscontinuityCount,
  605. data.clock.referenceSignalTypeForIsb.constellation,
  606. data.clock.referenceSignalTypeForIsb.carrierFrequencyHz,
  607. data.clock.referenceSignalTypeForIsb.codeType.c_str());
  608. LOC_LOGd(" ElapsedRealtime "
  609. " flags: 0x%08x,"
  610. " timestampNs: %" PRId64", "
  611. " timeUncertaintyNs: %.2f",
  612. data.elapsedRealtime.flags,
  613. data.elapsedRealtime.timestampNs,
  614. data.elapsedRealtime.timeUncertaintyNs);
  615. }
  616. } // namespace implementation
  617. } // namespace aidl
  618. } // namespace gnss
  619. } // namespace hardware
  620. } // namespace android