blob: 4514a21bd7d0d8222d7cda06de528784fba37d8d [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 Riley3b7c4392017-10-13 06:56:42 -070054GnssLocation convertToGnssLocation(FlpLocation* flpLocation) {
Wyatt Riley8791e7b2017-01-17 12:12:25 -080055 GnssLocation gnssLocation = {};
Wyatt Riley3b7c4392017-10-13 06:56:42 -070056 if (flpLocation != nullptr) {
57 gnssLocation = {.gnssLocationFlags = 0, // clear here and set below
58 .latitudeDegrees = flpLocation->latitude,
59 .longitudeDegrees = flpLocation->longitude,
60 .altitudeMeters = flpLocation->altitude,
61 .speedMetersPerSec = flpLocation->speed,
62 .bearingDegrees = flpLocation->bearing,
63 .horizontalAccuracyMeters = flpLocation->accuracy,
64 .verticalAccuracyMeters = 0,
65 .speedAccuracyMetersPerSecond = 0,
66 .bearingAccuracyDegrees = 0,
67 .timestamp = flpLocation->timestamp};
68 // FlpLocation flags different from GnssLocation flags
69 if (flpLocation->flags & FLP_LOCATION_HAS_LAT_LONG) {
70 gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_LAT_LONG;
71 }
72 if (flpLocation->flags & FLP_LOCATION_HAS_ALTITUDE) {
73 gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_ALTITUDE;
74 }
75 if (flpLocation->flags & FLP_LOCATION_HAS_SPEED) {
76 gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_SPEED;
77 }
78 if (flpLocation->flags & FLP_LOCATION_HAS_BEARING) {
79 gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_BEARING;
80 }
81 if (flpLocation->flags & FLP_LOCATION_HAS_ACCURACY) {
82 gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_HORIZONTAL_ACCURACY;
83 }
Wyatt Riley8791e7b2017-01-17 12:12:25 -080084 }
85
86 return gnssLocation;
87}
88
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070089} // namespace implementation
90} // namespace V1_0
91} // namespace gnss
92} // namespace hardware
93} // namespace android