rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace gnss { |
| 22 | namespace V1_0 { |
| 23 | namespace implementation { |
| 24 | |
| 25 | using android::hardware::gnss::V1_0::GnssLocation; |
| 26 | |
| 27 | GnssLocation convertToGnssLocation(GpsLocation_ext* location) { |
| 28 | GnssLocation gnssLocation = {}; |
| 29 | if (location != nullptr) { |
| 30 | gnssLocation = { |
| 31 | .gnssLocationFlags = static_cast<uint16_t>(location->legacyLocation.flags & 0xff), |
| 32 | .latitudeDegrees = location->legacyLocation.latitude, |
| 33 | .longitudeDegrees = location->legacyLocation.longitude, |
| 34 | .altitudeMeters = location->legacyLocation.altitude, |
| 35 | .speedMetersPerSec = location->legacyLocation.speed, |
| 36 | .bearingDegrees = location->legacyLocation.bearing, |
| 37 | .horizontalAccuracyMeters = location->horizontalAccuracyMeters, |
| 38 | .verticalAccuracyMeters = location->verticalAccuracyMeters, |
| 39 | .speedAccuracyMetersPerSecond = location->speedAccuracyMetersPerSecond, |
| 40 | .bearingAccuracyDegrees = location->bearingAccuracyDegrees, |
| 41 | .timestamp = location->legacyLocation.timestamp |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | return gnssLocation; |
| 46 | } |
| 47 | |
| 48 | GnssLocation convertToGnssLocation(FlpLocation* flpLocation) { |
| 49 | GnssLocation gnssLocation = {}; |
| 50 | if (flpLocation != nullptr) { |
| 51 | gnssLocation = {.gnssLocationFlags = 0, // clear here and set below |
| 52 | .latitudeDegrees = flpLocation->latitude, |
| 53 | .longitudeDegrees = flpLocation->longitude, |
| 54 | .altitudeMeters = flpLocation->altitude, |
| 55 | .speedMetersPerSec = flpLocation->speed, |
| 56 | .bearingDegrees = flpLocation->bearing, |
| 57 | .horizontalAccuracyMeters = flpLocation->accuracy, |
| 58 | .verticalAccuracyMeters = 0, |
| 59 | .speedAccuracyMetersPerSecond = 0, |
| 60 | .bearingAccuracyDegrees = 0, |
| 61 | .timestamp = flpLocation->timestamp}; |
| 62 | // FlpLocation flags different from GnssLocation flags |
| 63 | if (flpLocation->flags & FLP_LOCATION_HAS_LAT_LONG) { |
| 64 | gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_LAT_LONG; |
| 65 | } |
| 66 | if (flpLocation->flags & FLP_LOCATION_HAS_ALTITUDE) { |
| 67 | gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_ALTITUDE; |
| 68 | } |
| 69 | if (flpLocation->flags & FLP_LOCATION_HAS_SPEED) { |
| 70 | gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_SPEED; |
| 71 | } |
| 72 | if (flpLocation->flags & FLP_LOCATION_HAS_BEARING) { |
| 73 | gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_BEARING; |
| 74 | } |
| 75 | if (flpLocation->flags & FLP_LOCATION_HAS_ACCURACY) { |
| 76 | gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_HORIZONTAL_ACCURACY; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return gnssLocation; |
| 81 | } |
| 82 | |
| 83 | } // namespace implementation |
| 84 | } // namespace V1_0 |
| 85 | } // namespace gnss |
| 86 | } // namespace hardware |
| 87 | } // namespace android |