GnssMeasurementInterface.cpp 29 KB

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