blob: d9956d63826a6bacb0dd7838e323275c09c373fc [file] [log] [blame]
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "GnssUtils.h"
18
19namespace android {
20namespace hardware {
21namespace gnss {
22namespace V1_0 {
23namespace implementation {
24
25using android::hardware::gnss::V1_0::GnssLocation;
26
27GnssLocation convertToGnssLocation(GpsLocation* location) {
28 GnssLocation gnssLocation = {};
29 if (location != nullptr) {
30 gnssLocation = {
gomocf6b4d32017-01-15 20:08:59 -080031 // Bit operation AND with 1f below is needed to clear vertical accuracy,
32 // speed accuracy and bearing accuracy flags as some vendors are found
33 // to be setting these bits in pre-Android-O devices
34 .gnssLocationFlags = static_cast<uint16_t>(location->flags & 0x1f),
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070035 .latitudeDegrees = location->latitude,
36 .longitudeDegrees = location->longitude,
37 .altitudeMeters = location->altitude,
38 .speedMetersPerSec = location->speed,
39 .bearingDegrees = location->bearing,
gomoc3d92782017-01-11 14:04:21 -080040 .horizontalAccuracyMeters = location->accuracy,
41 // Older chipsets do not provide the following 3 fields, hence the flags
42 // HAS_VERTICAL_ACCURACY, HAS_SPEED_ACCURACY and HAS_BEARING_ACCURACY are
43 // not set and the field are set to zeros.
44 .verticalAccuracyMeters = 0,
45 .speedAccuracyMetersPerSecond = 0,
46 .bearingAccuracyDegrees = 0,
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070047 .timestamp = location->timestamp
48 };
49 }
50
51 return gnssLocation;
52}
53
Wyatt Riley8791e7b2017-01-17 12:12:25 -080054GnssLocation convertToGnssLocation(FlpLocation* location) {
55 GnssLocation gnssLocation = {};
56 if (location != nullptr) {
57 gnssLocation = {
58 // Bit mask applied (and 0's below) for same reason as above with GpsLocation
59 .gnssLocationFlags = static_cast<uint16_t>(location->flags & 0x1f),
60 .latitudeDegrees = location->latitude,
61 .longitudeDegrees = location->longitude,
62 .altitudeMeters = location->altitude,
63 .speedMetersPerSec = location->speed,
64 .bearingDegrees = location->bearing,
65 .horizontalAccuracyMeters = location->accuracy,
66 .verticalAccuracyMeters = 0,
67 .speedAccuracyMetersPerSecond = 0,
68 .bearingAccuracyDegrees = 0,
69 .timestamp = location->timestamp
70 };
71 }
72
73 return gnssLocation;
74}
75
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070076} // namespace implementation
77} // namespace V1_0
78} // namespace gnss
79} // namespace hardware
80} // namespace android