1 /* Copyright (c) 2017-2019, 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
36 #include "LocationUtil.h"
37 #include "MeasurementAPIClient.h"
38
39 namespace android {
40 namespace hardware {
41 namespace gnss {
42 namespace V2_0 {
43 namespace implementation {
44
45 using ::android::hardware::gnss::V1_0::IGnssMeasurement;
46 using ::android::hardware::gnss::V2_0::IGnssMeasurementCallback;
47
48 static void convertGnssData(GnssMeasurementsNotification& in,
49 V1_0::IGnssMeasurementCallback::GnssData& out);
50 static void convertGnssData_1_1(GnssMeasurementsNotification& in,
51 V1_1::IGnssMeasurementCallback::GnssData& out);
52 static void convertGnssData_2_0(GnssMeasurementsNotification& in,
53 V2_0::IGnssMeasurementCallback::GnssData& out);
54 static void convertGnssMeasurement(GnssMeasurementsData& in,
55 V1_0::IGnssMeasurementCallback::GnssMeasurement& out);
56 static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out);
57 static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in,
58 ::android::hardware::hidl_string& out);
59
MeasurementAPIClient()60 MeasurementAPIClient::MeasurementAPIClient() :
61 mGnssMeasurementCbIface(nullptr),
62 mGnssMeasurementCbIface_1_1(nullptr),
63 mGnssMeasurementCbIface_2_0(nullptr),
64 mTracking(false)
65 {
66 LOC_LOGD("%s]: ()", __FUNCTION__);
67 }
68
~MeasurementAPIClient()69 MeasurementAPIClient::~MeasurementAPIClient()
70 {
71 LOC_LOGD("%s]: ()", __FUNCTION__);
72 }
73
74 // for GpsInterface
75 Return<IGnssMeasurement::GnssMeasurementStatus>
measurementSetCallback(const sp<V1_0::IGnssMeasurementCallback> & callback)76 MeasurementAPIClient::measurementSetCallback(const sp<V1_0::IGnssMeasurementCallback>& callback)
77 {
78 LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
79
80 mMutex.lock();
81 mGnssMeasurementCbIface = callback;
82 mMutex.unlock();
83
84 return startTracking();
85 }
86
87 Return<IGnssMeasurement::GnssMeasurementStatus>
measurementSetCallback_1_1(const sp<V1_1::IGnssMeasurementCallback> & callback,GnssPowerMode powerMode,uint32_t timeBetweenMeasurement)88 MeasurementAPIClient::measurementSetCallback_1_1(
89 const sp<V1_1::IGnssMeasurementCallback>& callback,
90 GnssPowerMode powerMode, uint32_t timeBetweenMeasurement)
91 {
92 LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)",
93 __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement);
94
95 mMutex.lock();
96 mGnssMeasurementCbIface_1_1 = callback;
97 mMutex.unlock();
98
99 return startTracking(powerMode, timeBetweenMeasurement);
100 }
101
102 Return<IGnssMeasurement::GnssMeasurementStatus>
measurementSetCallback_2_0(const sp<V2_0::IGnssMeasurementCallback> & callback,GnssPowerMode powerMode,uint32_t timeBetweenMeasurement)103 MeasurementAPIClient::measurementSetCallback_2_0(
104 const sp<V2_0::IGnssMeasurementCallback>& callback,
105 GnssPowerMode powerMode, uint32_t timeBetweenMeasurement)
106 {
107 LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)",
108 __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement);
109
110 mMutex.lock();
111 mGnssMeasurementCbIface_2_0 = callback;
112 mMutex.unlock();
113
114 return startTracking(powerMode, timeBetweenMeasurement);
115 }
116
117 Return<IGnssMeasurement::GnssMeasurementStatus>
startTracking(GnssPowerMode powerMode,uint32_t timeBetweenMeasurement)118 MeasurementAPIClient::startTracking(
119 GnssPowerMode powerMode, uint32_t timeBetweenMeasurement)
120 {
121 LocationCallbacks locationCallbacks;
122 memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
123 locationCallbacks.size = sizeof(LocationCallbacks);
124
125 locationCallbacks.trackingCb = nullptr;
126 locationCallbacks.batchingCb = nullptr;
127 locationCallbacks.geofenceBreachCb = nullptr;
128 locationCallbacks.geofenceStatusCb = nullptr;
129 locationCallbacks.gnssLocationInfoCb = nullptr;
130 locationCallbacks.gnssNiCb = nullptr;
131 locationCallbacks.gnssSvCb = nullptr;
132 locationCallbacks.gnssNmeaCb = nullptr;
133
134 locationCallbacks.gnssMeasurementsCb = nullptr;
135 if (mGnssMeasurementCbIface_2_0 != nullptr ||
136 mGnssMeasurementCbIface_1_1 != nullptr ||
137 mGnssMeasurementCbIface != nullptr) {
138 locationCallbacks.gnssMeasurementsCb =
139 [this](GnssMeasurementsNotification gnssMeasurementsNotification) {
140 onGnssMeasurementsCb(gnssMeasurementsNotification);
141 };
142 }
143
144 locAPISetCallbacks(locationCallbacks);
145
146 TrackingOptions options = {};
147 memset(&options, 0, sizeof(TrackingOptions));
148 options.size = sizeof(TrackingOptions);
149 options.minInterval = 1000;
150 options.mode = GNSS_SUPL_MODE_STANDALONE;
151 if (GNSS_POWER_MODE_INVALID != powerMode) {
152 options.powerMode = powerMode;
153 options.tbm = timeBetweenMeasurement;
154 }
155
156 mTracking = true;
157 LOC_LOGD("%s]: start tracking session", __FUNCTION__);
158 locAPIStartTracking(options);
159 return IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
160 }
161
162 // for GpsMeasurementInterface
measurementClose()163 void MeasurementAPIClient::measurementClose() {
164 LOC_LOGD("%s]: ()", __FUNCTION__);
165 mTracking = false;
166 locAPIStopTracking();
167 }
168
169 // callbacks
onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification)170 void MeasurementAPIClient::onGnssMeasurementsCb(
171 GnssMeasurementsNotification gnssMeasurementsNotification)
172 {
173 LOC_LOGD("%s]: (count: %u active: %d)",
174 __FUNCTION__, gnssMeasurementsNotification.count, mTracking);
175 if (mTracking) {
176 mMutex.lock();
177 sp<V1_0::IGnssMeasurementCallback> gnssMeasurementCbIface = nullptr;
178 sp<V1_1::IGnssMeasurementCallback> gnssMeasurementCbIface_1_1 = nullptr;
179 sp<V2_0::IGnssMeasurementCallback> gnssMeasurementCbIface_2_0 = nullptr;
180 if (mGnssMeasurementCbIface_2_0 != nullptr) {
181 gnssMeasurementCbIface_2_0 = mGnssMeasurementCbIface_2_0;
182 } else if (mGnssMeasurementCbIface_1_1 != nullptr) {
183 gnssMeasurementCbIface_1_1 = mGnssMeasurementCbIface_1_1;
184 } else if (mGnssMeasurementCbIface != nullptr) {
185 gnssMeasurementCbIface = mGnssMeasurementCbIface;
186 }
187 mMutex.unlock();
188
189 if (gnssMeasurementCbIface_2_0 != nullptr) {
190 V2_0::IGnssMeasurementCallback::GnssData gnssData;
191 convertGnssData_2_0(gnssMeasurementsNotification, gnssData);
192 auto r = gnssMeasurementCbIface_2_0->gnssMeasurementCb_2_0(gnssData);
193 if (!r.isOk()) {
194 LOC_LOGE("%s] Error from gnssMeasurementCb description=%s",
195 __func__, r.description().c_str());
196 }
197 } else if (gnssMeasurementCbIface_1_1 != nullptr) {
198 V1_1::IGnssMeasurementCallback::GnssData gnssData;
199 convertGnssData_1_1(gnssMeasurementsNotification, gnssData);
200 auto r = gnssMeasurementCbIface_1_1->gnssMeasurementCb(gnssData);
201 if (!r.isOk()) {
202 LOC_LOGE("%s] Error from gnssMeasurementCb description=%s",
203 __func__, r.description().c_str());
204 }
205 } else if (gnssMeasurementCbIface != nullptr) {
206 V1_0::IGnssMeasurementCallback::GnssData gnssData;
207 convertGnssData(gnssMeasurementsNotification, gnssData);
208 auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData);
209 if (!r.isOk()) {
210 LOC_LOGE("%s] Error from GnssMeasurementCb description=%s",
211 __func__, r.description().c_str());
212 }
213 }
214 }
215 }
216
convertGnssMeasurement(GnssMeasurementsData & in,V1_0::IGnssMeasurementCallback::GnssMeasurement & out)217 static void convertGnssMeasurement(GnssMeasurementsData& in,
218 V1_0::IGnssMeasurementCallback::GnssMeasurement& out)
219 {
220 memset(&out, 0, sizeof(out));
221 if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
222 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR;
223 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
224 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY;
225 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
226 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES;
227 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
228 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE;
229 if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
230 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY;
231 if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT)
232 out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL;
233 out.svid = in.svId;
234 convertGnssConstellationType(in.svType, out.constellation);
235 out.timeOffsetNs = in.timeOffsetNs;
236 if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
237 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
238 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
239 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
240 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
241 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
242 if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
243 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
244 if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
245 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
246 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
247 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
248 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
249 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
250 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
251 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
252 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
253 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
254 if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
255 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
256 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
257 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
258 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
259 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
260 if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
261 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
262 if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
263 out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
264 out.receivedSvTimeInNs = in.receivedSvTimeNs;
265 out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
266 out.cN0DbHz = in.carrierToNoiseDbHz;
267 out.pseudorangeRateMps = in.pseudorangeRateMps;
268 out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
269 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
270 out.accumulatedDeltaRangeState |=
271 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
272 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
273 out.accumulatedDeltaRangeState |=
274 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
275 if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
276 out.accumulatedDeltaRangeState |=
277 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
278 out.accumulatedDeltaRangeM = in.adrMeters;
279 out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
280 out.carrierFrequencyHz = in.carrierFrequencyHz;
281 out.carrierCycles = in.carrierCycles;
282 out.carrierPhase = in.carrierPhase;
283 out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
284 uint8_t indicator =
285 static_cast<uint8_t>(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN);
286 if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT)
287 indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT;
288 if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT)
289 indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT;
290 out.multipathIndicator =
291 static_cast<IGnssMeasurementCallback::GnssMultipathIndicator>(indicator);
292 out.snrDb = in.signalToNoiseRatioDb;
293 out.agcLevelDb = in.agcLevelDb;
294 }
295
convertGnssClock(GnssMeasurementsClock & in,IGnssMeasurementCallback::GnssClock & out)296 static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out)
297 {
298 memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssClock));
299 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
300 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND;
301 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
302 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY;
303 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
304 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS;
305 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
306 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS;
307 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
308 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY;
309 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
310 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT;
311 if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
312 out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY;
313 out.leapSecond = in.leapSecond;
314 out.timeNs = in.timeNs;
315 out.timeUncertaintyNs = in.timeUncertaintyNs;
316 out.fullBiasNs = in.fullBiasNs;
317 out.biasNs = in.biasNs;
318 out.biasUncertaintyNs = in.biasUncertaintyNs;
319 out.driftNsps = in.driftNsps;
320 out.driftUncertaintyNsps = in.driftUncertaintyNsps;
321 out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
322 }
323
convertGnssData(GnssMeasurementsNotification & in,V1_0::IGnssMeasurementCallback::GnssData & out)324 static void convertGnssData(GnssMeasurementsNotification& in,
325 V1_0::IGnssMeasurementCallback::GnssData& out)
326 {
327 out.measurementCount = in.count;
328 if (out.measurementCount > static_cast<uint32_t>(V1_0::GnssMax::SVS_COUNT)) {
329 LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.",
330 __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT);
331 out.measurementCount = static_cast<uint32_t>(V1_0::GnssMax::SVS_COUNT);
332 }
333 for (size_t i = 0; i < out.measurementCount; i++) {
334 convertGnssMeasurement(in.measurements[i], out.measurements[i]);
335 }
336 convertGnssClock(in.clock, out.clock);
337 }
338
convertGnssData_1_1(GnssMeasurementsNotification & in,V1_1::IGnssMeasurementCallback::GnssData & out)339 static void convertGnssData_1_1(GnssMeasurementsNotification& in,
340 V1_1::IGnssMeasurementCallback::GnssData& out)
341 {
342 out.measurements.resize(in.count);
343 for (size_t i = 0; i < in.count; i++) {
344 convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_0);
345 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
346 out.measurements[i].accumulatedDeltaRangeState |=
347 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
348 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
349 out.measurements[i].accumulatedDeltaRangeState |=
350 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
351 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
352 out.measurements[i].accumulatedDeltaRangeState |=
353 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
354 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
355 out.measurements[i].accumulatedDeltaRangeState |=
356 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED;
357 }
358 convertGnssClock(in.clock, out.clock);
359 }
360
convertGnssData_2_0(GnssMeasurementsNotification & in,V2_0::IGnssMeasurementCallback::GnssData & out)361 static void convertGnssData_2_0(GnssMeasurementsNotification& in,
362 V2_0::IGnssMeasurementCallback::GnssData& out)
363 {
364 out.measurements.resize(in.count);
365 for (size_t i = 0; i < in.count; i++) {
366 convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_1.v1_0);
367 convertGnssConstellationType(in.measurements[i].svType, out.measurements[i].constellation);
368 convertGnssMeasurementsCodeType(in.measurements[i].codeType, out.measurements[i].codeType);
369 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
370 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
371 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
372 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
373 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
374 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
375 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
376 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
377 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
378 if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
379 out.measurements[i].v1_1.accumulatedDeltaRangeState |=
380 IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED;
381 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
382 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
383 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
384 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
385 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
386 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
387 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
388 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
389 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
390 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
391 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
392 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
393 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
394 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
395 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
396 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
397 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
398 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
399 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
400 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
401 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
402 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
403 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
404 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
405 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
406 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
407 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
408 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
409 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT)
410 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_KNOWN;
411 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT)
412 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_KNOWN;
413 if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT)
414 out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_2ND_CODE_LOCK;
415 }
416 convertGnssClock(in.clock, out.clock);
417 }
418
convertGnssMeasurementsCodeType(GnssMeasurementsCodeType & in,::android::hardware::hidl_string & out)419 static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in,
420 ::android::hardware::hidl_string& out)
421 {
422 switch(in) {
423 case GNSS_MEASUREMENTS_CODE_TYPE_A:
424 out = "A";
425 break;
426 case GNSS_MEASUREMENTS_CODE_TYPE_B:
427 out = "B";
428 break;
429 case GNSS_MEASUREMENTS_CODE_TYPE_C:
430 out = "C";
431 break;
432 case GNSS_MEASUREMENTS_CODE_TYPE_I:
433 out = "I";
434 break;
435 case GNSS_MEASUREMENTS_CODE_TYPE_L:
436 out = "L";
437 break;
438 case GNSS_MEASUREMENTS_CODE_TYPE_M:
439 out = "M";
440 break;
441 case GNSS_MEASUREMENTS_CODE_TYPE_P:
442 out = "P";
443 break;
444 case GNSS_MEASUREMENTS_CODE_TYPE_Q:
445 out = "Q";
446 break;
447 case GNSS_MEASUREMENTS_CODE_TYPE_S:
448 out = "S";
449 break;
450 case GNSS_MEASUREMENTS_CODE_TYPE_W:
451 out = "W";
452 break;
453 case GNSS_MEASUREMENTS_CODE_TYPE_X:
454 out = "X";
455 break;
456 case GNSS_MEASUREMENTS_CODE_TYPE_Y:
457 out = "Y";
458 break;
459 case GNSS_MEASUREMENTS_CODE_TYPE_Z:
460 out = "Z";
461 break;
462 case GNSS_MEASUREMENTS_CODE_TYPE_N:
463 out = "N";
464 break;
465 default:
466 out = "UNKNOWN";
467 }
468 }
469
470 } // namespace implementation
471 } // namespace V2_0
472 } // namespace gnss
473 } // namespace hardware
474 } // namespace android
475