Home | History | Annotate | Download | only in default
      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* location) {
     28     GnssLocation gnssLocation = {};
     29     if (location != nullptr) {
     30         gnssLocation = {
     31             // 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),
     35             .latitudeDegrees = location->latitude,
     36             .longitudeDegrees = location->longitude,
     37             .altitudeMeters = location->altitude,
     38             .speedMetersPerSec = location->speed,
     39             .bearingDegrees = location->bearing,
     40             .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,
     47             .timestamp = location->timestamp
     48         };
     49     }
     50 
     51     return gnssLocation;
     52 }
     53 
     54 GnssLocation 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 
     76 }  // namespace implementation
     77 }  // namespace V1_0
     78 }  // namespace gnss
     79 }  // namespace hardware
     80 }  // namespace android
     81