Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 "GnssReplayUtils.h" |
| 18 | |
Enrico Granata | 9447139 | 2022-02-23 10:50:35 -0700 | [diff] [blame] | 19 | #include <array> |
| 20 | |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace gnss { |
| 24 | namespace common { |
| 25 | |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 26 | std::string ReplayUtils::getGnssPath() { |
Enrico Granata | 9447139 | 2022-02-23 10:50:35 -0700 | [diff] [blame] | 27 | std::array<char, PROPERTY_VALUE_MAX> devname_value; |
| 28 | |
| 29 | devname_value.fill(0); |
| 30 | if (property_get("debug.location.gnss.devname", devname_value.begin(), NULL) > 0) { |
| 31 | return devname_value.begin(); |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 32 | } |
Enrico Granata | 9447139 | 2022-02-23 10:50:35 -0700 | [diff] [blame] | 33 | |
| 34 | devname_value.fill(0); |
| 35 | if (property_get("vendor.ser.gnss-uart", devname_value.begin(), NULL) > 0) { |
| 36 | return devname_value.begin(); |
| 37 | } |
| 38 | |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 39 | return GNSS_PATH; |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame] | 42 | std::string ReplayUtils::getFixedLocationPath() { |
Enrico Granata | 9447139 | 2022-02-23 10:50:35 -0700 | [diff] [blame] | 43 | std::array<char, PROPERTY_VALUE_MAX> devname_value; |
| 44 | |
| 45 | devname_value.fill(0); |
| 46 | if (property_get("debug.location.fixedlocation.devname", devname_value.begin(), NULL) > 0) { |
| 47 | return devname_value.begin(); |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame] | 48 | } |
Enrico Granata | 9447139 | 2022-02-23 10:50:35 -0700 | [diff] [blame] | 49 | |
| 50 | devname_value.fill(0); |
| 51 | if (property_get("vendor.ser.gnss-uart", devname_value.begin(), NULL) > 0) { |
| 52 | return devname_value.begin(); |
| 53 | } |
| 54 | |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame] | 55 | return FIXED_LOCATION_PATH; |
| 56 | } |
| 57 | |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 58 | bool ReplayUtils::hasGnssDeviceFile() { |
| 59 | struct stat sb; |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 60 | return stat(getGnssPath().c_str(), &sb) != -1; |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame] | 63 | bool ReplayUtils::hasFixedLocationDeviceFile() { |
| 64 | struct stat sb; |
| 65 | return stat(getFixedLocationPath().c_str(), &sb) != -1; |
| 66 | } |
| 67 | |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 68 | bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { |
| 69 | // TODO: add more logic check to by pass invalid data. |
| 70 | return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); |
| 71 | } |
| 72 | |
| 73 | bool ReplayUtils::isNMEA(const std::string& inputStr) { |
Yuchen He | 3cbf5f3 | 2021-08-30 22:20:30 +0000 | [diff] [blame] | 74 | return !inputStr.empty() && (inputStr.find("$GPRMC,", 0) != std::string::npos || |
Yuchen He | 42b2d0a | 2022-01-12 04:39:37 +0000 | [diff] [blame] | 75 | inputStr.find("$GPGGA,", 0) != std::string::npos); |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace common |
| 79 | } // namespace gnss |
| 80 | } // namespace hardware |
| 81 | } // namespace android |