blob: 6caf313a040abbdd65e2f39c8bfdbcafd83ca992 [file] [log] [blame]
Yuchen He14a30182021-06-10 17:10:15 -07001/*
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 Granata94471392022-02-23 10:50:35 -070019#include <array>
20
Yuchen He14a30182021-06-10 17:10:15 -070021namespace android {
22namespace hardware {
23namespace gnss {
24namespace common {
25
George Burgess IVf2493a32021-07-07 09:59:32 -070026std::string ReplayUtils::getGnssPath() {
Enrico Granata94471392022-02-23 10:50:35 -070027 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 He14a30182021-06-10 17:10:15 -070032 }
Enrico Granata94471392022-02-23 10:50:35 -070033
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 IVf2493a32021-07-07 09:59:32 -070039 return GNSS_PATH;
Yuchen He14a30182021-06-10 17:10:15 -070040}
41
Yuchen He090f16c2022-01-20 22:57:09 +000042std::string ReplayUtils::getFixedLocationPath() {
Enrico Granata94471392022-02-23 10:50:35 -070043 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 He090f16c2022-01-20 22:57:09 +000048 }
Enrico Granata94471392022-02-23 10:50:35 -070049
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 He090f16c2022-01-20 22:57:09 +000055 return FIXED_LOCATION_PATH;
56}
57
Yuchen He14a30182021-06-10 17:10:15 -070058bool ReplayUtils::hasGnssDeviceFile() {
59 struct stat sb;
George Burgess IVf2493a32021-07-07 09:59:32 -070060 return stat(getGnssPath().c_str(), &sb) != -1;
Yuchen He14a30182021-06-10 17:10:15 -070061}
62
Yuchen He090f16c2022-01-20 22:57:09 +000063bool ReplayUtils::hasFixedLocationDeviceFile() {
64 struct stat sb;
65 return stat(getFixedLocationPath().c_str(), &sb) != -1;
66}
67
Yuchen He14a30182021-06-10 17:10:15 -070068bool 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
73bool ReplayUtils::isNMEA(const std::string& inputStr) {
Yuchen He3cbf5f32021-08-30 22:20:30 +000074 return !inputStr.empty() && (inputStr.find("$GPRMC,", 0) != std::string::npos ||
Yuchen He42b2d0a2022-01-12 04:39:37 +000075 inputStr.find("$GPGGA,", 0) != std::string::npos);
Yuchen He14a30182021-06-10 17:10:15 -070076}
77
78} // namespace common
79} // namespace gnss
80} // namespace hardware
81} // namespace android