1 /* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation, nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #define LOG_NDEBUG 0
31 #define LOG_TAG "LocSvc_MeasurementAPIClient"
32
33 #include <log_util.h>
34 #include <loc_cfg.h>
35 #include <inttypes.h>
36
37 #include "LocationUtil.h"
38 #include "MeasurementAPIClient.h"
39 #include <loc_misc_utils.h>
40
41 namespace android {
42 namespace hardware {
43 namespace gnss {
44 namespace V2_0 {
45 namespace implementation {
46
47 using ::android::hardware::gnss::V1_0::IGnssMeasurement;
48 using ::android::hardware::gnss::V2_0::IGnssMeasurementCallback;
49
50 static void convertGnssData(GnssMeasurementsNotification& in,
51 V1_0::IGnssMeasurementCallback::GnssData& out);
52 static void convertGnssData_1_1(GnssMeasurementsNotification& in,
53 V1_1::IGnssMeasurementCallback::GnssData& out);
54 static void convertGnssData_2_0(GnssMeasurementsNotification& in,
55 V2_0::IGnssMeasurementCallback::GnssData& out);
56 static void convertGnssMeasurement(GnssMeasurementsData& in,
57 V1_0::IGnssMeasurementCallback::GnssMeasurement& out);
58 static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out);
59 static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in,
60 ::android::hardware::hidl_string& out);
61 static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in,
62 ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtimeNanos);
63
MeasurementAPIClient()64 MeasurementAPIClient::MeasurementAPIClient() :
65 mGnssMeasurementCbIface(nullptr),
66 mGnssMeasurementCbIface_1_1(nullptr),
67 mGnssMeasurementCbIface_2_0(nullptr),
68 mTracking(false)
69 {
70 LOC_LOGD("%s]: ()", __FUNCTION__);
71 }
72
~MeasurementAPIClient()73 MeasurementAPIClient::~MeasurementAPIClient()
74 {
75 LOC_LOGD("%s]: ()", __FUNCTION__);
76 }
77
clearInterfaces()78 void MeasurementAPIClient::clearInterfaces()
79 {
80 mGnssMeasurementCbIface = nullptr;
81 mGnssMeasurementCbIface_1_1 = nullptr;
82 mGnssMeasurementCbIface_2_0 = nullptr;
83 }
84
85 Return<IGnssMeasurement::GnssMeasurementStatus>
startTracking(GnssPowerMode powerMode,uint32_t timeBetweenMeasurement)86 MeasurementAPIClient::startTracking(
87 GnssPowerMode powerMode, uint32_t timeBetweenMeasurement)
88 {
89 LocationCallbacks locationCallbacks;
90 memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
91 locationCallbacks.size = sizeof(LocationCallbacks);
92
93 if (mGnssMeasurementCbIface_2_0 != nullptr ||
94 mGnssMeasurementCbIface_1_1 != nullptr ||
95 mGnssMeasurementCbIface != nullptr) {
96 locationCallbacks.gnssMeasurementsCb =
97 [this](GnssMeasurementsNotification gnssMeasurementsNotification) {
98 onGnssMeasurementsCb(gnssMeasurementsNotification);
99 };
100 }
101
102 locAPISetCallbacks(locationCallbacks);
103
104 TrackingOptions options = {};
105 memset(&options, 0, sizeof(TrackingOptions));
106 options.size = sizeof(TrackingOptions);
107 options.minInterval = 1000;
108 options.mode = GNSS_SUPL_MODE_STANDALONE;
109 if (GNSS_POWER_MODE_INVALID != powerMode) {
110 options.powerMode = powerMode;
111 options.tbm = timeBetweenMeasurement;
112 }
113
114 mTracking = true;
115 LOC_LOGd("(powermode: %d) (tbm %d)", (int)powerMode, timeBetweenMeasurement);
116 locAPIStartTracking(options);
117 return IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
118 }
119
120 // for GpsMeasurementInterface
measurementClose()121 void MeasurementAPIClient::measurementClose() {
122 LOC_LOGD("%s]: ()", __FUNCTION__);
123 mTracking = false;
124 clearInterfaces();
125 locAPIStopTracking();
126 }
127
128 // callbacks
onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification)129 void MeasurementAPIClient::onGnssMeasurementsCb(
130 GnssMeasurementsNotification gnssMeasurementsNotification)
131 {
132 LOC_LOGD("%s]: (count: %u active: %d)",
133 __FUNCTION__, gnssMeasurementsNotification.count, mTracking);
134 if (mTracking) {
135 mMutex.lock();
136 sp<V1_0::IGnssMeasurementCallback> gnssMeasurementCbIface = nullptr;
137 sp<V1_1::IGnssMeasurementCallback> gnssMeasurementCbIface_1_1 = nullptr;
138 sp<V2_0::IGnssMeasurementCallback> gnssMeasurementCbIface_2_0 = nullptr;
139 if (mGnssMeasurementCbIface_2_0 != nullptr) {
140 gnssMeasurementCbIface_2_0 = mGnssMeasurementCbIface_2_0;
141 } else if (mGnssMeasurementCbIface_1_1 != nullptr) {
142 gnssMeasurementCbIface_1_1 = mGnssMeasurementCbIface_1_1;
143 } else if (mGnssMeasurementCbIface != nullptr) {
144 gnssMeasurementCbIface = mGnssMeasurementCbIface;
145 }
146 mMutex.unlock();
147
148 if (gnssMeasurementCbIface_2_0 != nullptr) {
149 V2_0::IGnssMeasurementCallback::GnssData gnssData;
150 convertGnssData_2_0(gnssMeasurementsNotification, gnssData);
151 auto r = gnssMeasurementCbIface_2_0->gnssMeasurementCb_2_0(gnssData);
152 if (!r.isOk()) {
153 LOC_LOGE("%s] Error from gnssMeasurementCb description=%s",
154 __func__, r.description().c_str());
155 }
156 } else if (gnssMeasurementCbIface_1_1 != nullptr) {
157 V1_1::IGnssMeasurementCallback::GnssData gnssData;
158 convertGnssData_1_1(gnssMeasurementsNotification, gnssData);
159 auto r = gnssMeasurementCbIface_1_1->gnssMeasurementCb(gnssData);
160 if (!r.isOk()) {
161 LOC_LOGE("%s] Error from gnssMeasurementCb description=%s",
162 __func__, r.description().c_str());
163 }
164 } else if (gnssMeasurementCbIface != nullptr) {
165 V1_0::IGnssMeasurementCallback::GnssData gnssData;
166 convertGnssData(gnssMeasurementsNotification, gnssData);
167 auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData);
168 if (!r.isOk()) {
169 LOC_LOGE("%s] Error from GnssMeasurementCb description=%s",
170 __func__, r.description().c_str());
171 }
172 }
173 }
174 }
175
convertGnssMeasurement(GnssMeasurementsData & in,V1_0::IGnssMeasurementCallback::GnssMeasurement & out)176 static void convertGnssMeasurement(GnssMeasurementsData& in,
177 V1_0::IGnssMeasurementCallback::GnssMeasurement& out)
178 {
179 memset(&out, 0, sizeof(out));
180 if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
181 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR;
182 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
183 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY;
184 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
185 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES;
186 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
187 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE;
188 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
189 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY;
190 if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT)
191 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL;
192 convertGnssSvid(in, out.svid);
193 convertGnssConstellationType(in.svType, out.constellation);
194 out.timeOffsetNs = in.timeOffsetNs;
195 if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
196 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
197 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
198 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
199 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
200 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
201 if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
202 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
203 if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
204 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
205 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
206 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
207 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
208 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
209 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
210 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
211 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
212 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
213 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
214 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
215 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
216 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
217 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
218 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
219 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
220 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
221 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
222 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
223 out.receivedSvTimeInNs = in.receivedSvTimeNs;
224 out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
225 out.cN0DbHz = in.carrierToNoiseDbHz;
226 out.pseudorangeRateMps = in.pseudorangeRateMps;
227 out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
228 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
229 out.accumulatedDeltaRangeState |=
230 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
231 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
232 out.accumulatedDeltaRangeState |=
233 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
234 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
235 out.accumulatedDeltaRangeState |=
236 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
237 out.accumulatedDeltaRangeM = in.adrMeters;
238 out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
239 out.carrierFrequencyHz = in.carrierFrequencyHz;
240 out.carrierCycles = in.carrierCycles;
241 out.carrierPhase = in.carrierPhase;
242 out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
243 uint8_t indicator =
244 static_cast<uint8_t>(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN);
245 if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT)
246 indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT;
247 if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT)
248 indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT;
249 out.multipathIndicator =
250 static_cast<IGnssMeasurementCallback::GnssMultipathIndicator>(indicator);
251 out.snrDb = in.signalToNoiseRatioDb;
252 out.agcLevelDb = in.agcLevelDb;
253 }
254
convertGnssClock(GnssMeasurementsClock & in,IGnssMeasurementCallback::GnssClock & out)255 static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out)
256 {
257 memset(&out, 0, sizeof(out));
258 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
259 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND;
260 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
261 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY;
262 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
263 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS;
264 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
265 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS;
266 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
267 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY;
268 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
269 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT;
270 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
271 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY;
272 out.leapSecond = in.leapSecond;
273 out.timeNs = in.timeNs;
274 out.timeUncertaintyNs = in.timeUncertaintyNs;
275 out.fullBiasNs = in.fullBiasNs;
276 out.biasNs = in.biasNs;
277 out.biasUncertaintyNs = in.biasUncertaintyNs;
278 out.driftNsps = in.driftNsps;
279 out.driftUncertaintyNsps = in.driftUncertaintyNsps;
280 out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
281 }
282
convertGnssData(GnssMeasurementsNotification & in,V1_0::IGnssMeasurementCallback::GnssData & out)283 static void convertGnssData(GnssMeasurementsNotification& in,
284 V1_0::IGnssMeasurementCallback::GnssData& out)
285 {
286 memset(&out, 0, sizeof(out));
287 out.measurementCount = in.count;
288 if (out.measurementCount > static_cast<uint32_t>(V1_0::GnssMax::SVS_COUNT)) {
289 LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.",
290 __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT);
291 out.measurementCount = static_cast<uint32_t>(V1_0::GnssMax::SVS_COUNT);
292 }
293 for (size_t i = 0; i < out.measurementCount; i++) {
294 convertGnssMeasurement(in.measurements[i], out.measurements[i]);
295 }
296 convertGnssClock(in.clock, out.clock);
297 }
298
convertGnssData_1_1(GnssMeasurementsNotification & in,V1_1::IGnssMeasurementCallback::GnssData & out)299 static void convertGnssData_1_1(GnssMeasurementsNotification& in,
300 V1_1::IGnssMeasurementCallback::GnssData& out)
301 {
302 memset(&out, 0, sizeof(out));
303 out.measurements.resize(in.count);
304 for (size_t i = 0; i < in.count; i++) {
305 convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_0);
306 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
307 out.measurements[i].accumulatedDeltaRangeState |=
308 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
309 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
310 out.measurements[i].accumulatedDeltaRangeState |=
311 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
312 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
313 out.measurements[i].accumulatedDeltaRangeState |=
314 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
315 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
316 out.measurements[i].accumulatedDeltaRangeState |=
317 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED;
318 }
319 convertGnssClock(in.clock, out.clock);
320 }
321
convertGnssData_2_0(GnssMeasurementsNotification & in,V2_0::IGnssMeasurementCallback::GnssData & out)322 static void convertGnssData_2_0(GnssMeasurementsNotification& in,
323 V2_0::IGnssMeasurementCallback::GnssData& out)
324 {
325 memset(&out, 0, sizeof(out));
326 out.measurements.resize(in.count);
327 for (size_t i = 0; i < in.count; i++) {
328 convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_1.v1_0);
329 convertGnssConstellationType(in.measurements[i].svType, out.measurements[i].constellation);
330 convertGnssMeasurementsCodeType(in.measurements[i].codeType, out.measurements[i].codeType);
331 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
332 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
333 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
334 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
335 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
336 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
337 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
338 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
339 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
340 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
341 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
342 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED;
343 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
344 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
345 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
346 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
347 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
348 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
349 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
350 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
351 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
352 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
353 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
354 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
355 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
356 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
357 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
358 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
359 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
360 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
361 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
362 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
363 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
364 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
365 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
366 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
367 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
368 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
369 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
370 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
371 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT)
372 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_KNOWN;
373 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT)
374 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_KNOWN;
375 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT)
376 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_2ND_CODE_LOCK;
377 }
378 convertGnssClock(in.clock, out.clock);
379 convertElapsedRealtimeNanos(in, out.elapsedRealtime);
380 }
381
convertElapsedRealtimeNanos(GnssMeasurementsNotification & in,::android::hardware::gnss::V2_0::ElapsedRealtime & elapsedRealtime)382 static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in,
383 ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtime)
384 {
385 if (in.clock.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT) {
386 elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS;
387 elapsedRealtime.timestampNs = in.clock.elapsedRealTime;
388 elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS;
389 elapsedRealtime.timeUncertaintyNs = in.clock.elapsedRealTimeUnc;
390 LOC_LOGd("elapsedRealtime.timestampNs=%" PRIi64 ""
391 " elapsedRealtime.timeUncertaintyNs=%" PRIi64 " elapsedRealtime.flags=0x%X",
392 elapsedRealtime.timestampNs,
393 elapsedRealtime.timeUncertaintyNs, elapsedRealtime.flags);
394 }
395 }
396
convertGnssMeasurementsCodeType(GnssMeasurementsCodeType & in,::android::hardware::hidl_string & out)397 static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in,
398 ::android::hardware::hidl_string& out)
399 {
400 switch(in) {
401 case GNSS_MEASUREMENTS_CODE_TYPE_A:
402 out = "A";
403 break;
404 case GNSS_MEASUREMENTS_CODE_TYPE_B:
405 out = "B";
406 break;
407 case GNSS_MEASUREMENTS_CODE_TYPE_C:
408 out = "C";
409 break;
410 case GNSS_MEASUREMENTS_CODE_TYPE_I:
411 out = "I";
412 break;
413 case GNSS_MEASUREMENTS_CODE_TYPE_L:
414 out = "L";
415 break;
416 case GNSS_MEASUREMENTS_CODE_TYPE_M:
417 out = "M";
418 break;
419 case GNSS_MEASUREMENTS_CODE_TYPE_P:
420 out = "P";
421 break;
422 case GNSS_MEASUREMENTS_CODE_TYPE_Q:
423 out = "Q";
424 break;
425 case GNSS_MEASUREMENTS_CODE_TYPE_S:
426 out = "S";
427 break;
428 case GNSS_MEASUREMENTS_CODE_TYPE_W:
429 out = "W";
430 break;
431 case GNSS_MEASUREMENTS_CODE_TYPE_X:
432 out = "X";
433 break;
434 case GNSS_MEASUREMENTS_CODE_TYPE_Y:
435 out = "Y";
436 break;
437 case GNSS_MEASUREMENTS_CODE_TYPE_Z:
438 out = "Z";
439 break;
440 case GNSS_MEASUREMENTS_CODE_TYPE_N:
441 out = "N";
442 break;
443 default:
444 out = "UNKNOWN";
445 }
446 }
447
448 } // namespace implementation
449 } // namespace V2_0
450 } // namespace gnss
451 } // namespace hardware
452 } // namespace android
453