129dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju/* 229dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * Copyright (C) 2016 The Android Open Source Project 329dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * 429dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * Licensed under the Apache License, Version 2.0 (the "License"); 529dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * you may not use this file except in compliance with the License. 629dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * You may obtain a copy of the License at 729dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * 829dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * http://www.apache.org/licenses/LICENSE-2.0 929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * 1029dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * Unless required by applicable law or agreed to in writing, software 1129dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * distributed under the License is distributed on an "AS IS" BASIS, 1229dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1329dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * See the License for the specific language governing permissions and 1429dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju * limitations under the License. 1529dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju */ 1629dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 1729dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju#include "GnssUtils.h" 1829dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 1929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajunamespace android { 2029dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajunamespace hardware { 2129dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajunamespace gnss { 2229dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajunamespace V1_0 { 2329dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajunamespace implementation { 2429dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 2529dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsarajuusing android::hardware::gnss::V1_0::GnssLocation; 2629dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 2729dc1e0c724283413fdd13d68ac9751591baa3c5Hridya ValsarajuGnssLocation convertToGnssLocation(GpsLocation* location) { 2829dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju GnssLocation gnssLocation = {}; 2929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju if (location != nullptr) { 3029dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju gnssLocation = { 31cf6b4d32e45694df60a7ffa5beac70e0be5a7902gomo // Bit operation AND with 1f below is needed to clear vertical accuracy, 32cf6b4d32e45694df60a7ffa5beac70e0be5a7902gomo // speed accuracy and bearing accuracy flags as some vendors are found 33cf6b4d32e45694df60a7ffa5beac70e0be5a7902gomo // to be setting these bits in pre-Android-O devices 34cf6b4d32e45694df60a7ffa5beac70e0be5a7902gomo .gnssLocationFlags = static_cast<uint16_t>(location->flags & 0x1f), 3529dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .latitudeDegrees = location->latitude, 3629dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .longitudeDegrees = location->longitude, 3729dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .altitudeMeters = location->altitude, 3829dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .speedMetersPerSec = location->speed, 3929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .bearingDegrees = location->bearing, 40c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo .horizontalAccuracyMeters = location->accuracy, 41c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo // Older chipsets do not provide the following 3 fields, hence the flags 42c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo // HAS_VERTICAL_ACCURACY, HAS_SPEED_ACCURACY and HAS_BEARING_ACCURACY are 43c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo // not set and the field are set to zeros. 44c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo .verticalAccuracyMeters = 0, 45c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo .speedAccuracyMetersPerSecond = 0, 46c3d9278327d03d76ac2edbfc6f5d15d29a688090gomo .bearingAccuracyDegrees = 0, 4729dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju .timestamp = location->timestamp 4829dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju }; 4929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju } 5029dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 5129dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju return gnssLocation; 5229dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} 5329dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju 543b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt RileyGnssLocation convertToGnssLocation(FlpLocation* flpLocation) { 558791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley GnssLocation gnssLocation = {}; 563b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation != nullptr) { 573b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation = {.gnssLocationFlags = 0, // clear here and set below 583b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .latitudeDegrees = flpLocation->latitude, 593b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .longitudeDegrees = flpLocation->longitude, 603b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .altitudeMeters = flpLocation->altitude, 613b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .speedMetersPerSec = flpLocation->speed, 623b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .bearingDegrees = flpLocation->bearing, 633b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .horizontalAccuracyMeters = flpLocation->accuracy, 643b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .verticalAccuracyMeters = 0, 653b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .speedAccuracyMetersPerSecond = 0, 663b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .bearingAccuracyDegrees = 0, 673b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley .timestamp = flpLocation->timestamp}; 683b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley // FlpLocation flags different from GnssLocation flags 693b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation->flags & FLP_LOCATION_HAS_LAT_LONG) { 703b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_LAT_LONG; 713b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley } 723b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation->flags & FLP_LOCATION_HAS_ALTITUDE) { 733b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_ALTITUDE; 743b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley } 753b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation->flags & FLP_LOCATION_HAS_SPEED) { 763b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_SPEED; 773b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley } 783b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation->flags & FLP_LOCATION_HAS_BEARING) { 793b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_BEARING; 803b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley } 813b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley if (flpLocation->flags & FLP_LOCATION_HAS_ACCURACY) { 823b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley gnssLocation.gnssLocationFlags |= GPS_LOCATION_HAS_HORIZONTAL_ACCURACY; 833b7c4396ca89a2f90947ed96cb4c978569fdeee6Wyatt Riley } 848791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley } 858791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley 868791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley return gnssLocation; 878791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley} 888791e7bf2c3872f7ef5af509b79b655a6165ef9dWyatt Riley 8929dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} // namespace implementation 9029dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} // namespace V1_0 9129dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} // namespace gnss 9229dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} // namespace hardware 9329dc1e0c724283413fdd13d68ac9751591baa3c5Hridya Valsaraju} // namespace android 94