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 #include <array>
20
21 namespace android {
22 namespace hardware {
23 namespace gnss {
24 namespace common {
25
getGnssPath()26 std::string ReplayUtils::getGnssPath() {
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();
32 }
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
39 return GNSS_PATH;
40 }
41
getFixedLocationPath()42 std::string ReplayUtils::getFixedLocationPath() {
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();
48 }
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
55 return FIXED_LOCATION_PATH;
56 }
57
hasGnssDeviceFile()58 bool ReplayUtils::hasGnssDeviceFile() {
59 struct stat sb;
60 return stat(getGnssPath().c_str(), &sb) != -1;
61 }
62
hasFixedLocationDeviceFile()63 bool ReplayUtils::hasFixedLocationDeviceFile() {
64 struct stat sb;
65 return stat(getFixedLocationPath().c_str(), &sb) != -1;
66 }
67
isGnssRawMeasurement(const std::string & inputStr)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
isNMEA(const std::string & inputStr)73 bool ReplayUtils::isNMEA(const std::string& inputStr) {
74 return !inputStr.empty() && (inputStr.find("$GPRMC,", 0) != std::string::npos ||
75 inputStr.find("$GPGGA,", 0) != std::string::npos);
76 }
77
78 } // namespace common
79 } // namespace gnss
80 } // namespace hardware
81 } // namespace android
82