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 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace gnss { |
| 22 | namespace common { |
| 23 | |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 24 | std::string ReplayUtils::getGnssPath() { |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 25 | char devname_value[PROPERTY_VALUE_MAX] = ""; |
| 26 | if (property_get("debug.location.gnss.devname", devname_value, NULL) > 0) { |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 27 | return devname_value; |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 28 | } |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 29 | return GNSS_PATH; |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame^] | 32 | std::string ReplayUtils::getFixedLocationPath() { |
| 33 | char devname_value[PROPERTY_VALUE_MAX] = ""; |
| 34 | if (property_get("debug.location.fixedlocation.devname", devname_value, NULL) > 0) { |
| 35 | return devname_value; |
| 36 | } |
| 37 | return FIXED_LOCATION_PATH; |
| 38 | } |
| 39 | |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 40 | bool ReplayUtils::hasGnssDeviceFile() { |
| 41 | struct stat sb; |
George Burgess IV | f2493a3 | 2021-07-07 09:59:32 -0700 | [diff] [blame] | 42 | return stat(getGnssPath().c_str(), &sb) != -1; |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Yuchen He | 090f16c | 2022-01-20 22:57:09 +0000 | [diff] [blame^] | 45 | bool ReplayUtils::hasFixedLocationDeviceFile() { |
| 46 | struct stat sb; |
| 47 | return stat(getFixedLocationPath().c_str(), &sb) != -1; |
| 48 | } |
| 49 | |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 50 | bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { |
| 51 | // TODO: add more logic check to by pass invalid data. |
| 52 | return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); |
| 53 | } |
| 54 | |
| 55 | bool ReplayUtils::isNMEA(const std::string& inputStr) { |
Yuchen He | 3cbf5f3 | 2021-08-30 22:20:30 +0000 | [diff] [blame] | 56 | return !inputStr.empty() && (inputStr.find("$GPRMC,", 0) != std::string::npos || |
Yuchen He | 42b2d0a | 2022-01-12 04:39:37 +0000 | [diff] [blame] | 57 | inputStr.find("$GPGGA,", 0) != std::string::npos); |
Yuchen He | 14a3018 | 2021-06-10 17:10:15 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace common |
| 61 | } // namespace gnss |
| 62 | } // namespace hardware |
| 63 | } // namespace android |