Merge changes from topics "presubmit-am-4fee2b7578f94a34b28ec502594c100c", "presubmit-am-e0c94944d7344b3d975421d4c0812104", "presubmit-am-e106eae8e71e41a6a6d95a2472dd22fe" into sc-v2-dev-plus-aosp
* changes:
[automerged blank] Merge fix to AOSP: Report default location when location is not available in /dev/gnss0 2p: d20063ad90
Merge fix to AOSP: Report default location when location is not available in /dev/gnss0
Read GNSS measurement from device file when available
Add raw measurement parser
diff --git a/gnss/aidl/default/GnssMeasurementInterface.cpp b/gnss/aidl/default/GnssMeasurementInterface.cpp
index 0e489c5..fcc1f98 100644
--- a/gnss/aidl/default/GnssMeasurementInterface.cpp
+++ b/gnss/aidl/default/GnssMeasurementInterface.cpp
@@ -19,13 +19,11 @@
#include "GnssMeasurementInterface.h"
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <log/log.h>
-#include "GnssReplayUtils.h"
#include "Utils.h"
namespace aidl::android::hardware::gnss {
using Utils = ::android::hardware::gnss::common::Utils;
-using ReplayUtils = ::android::hardware::gnss::common::ReplayUtils;
std::shared_ptr<IGnssMeasurementCallback> GnssMeasurementInterface::sCallback = nullptr;
@@ -65,22 +63,9 @@
mIsActive = true;
mThread = std::thread([this, enableCorrVecOutputs]() {
while (mIsActive == true) {
- std::string rawMeasurementStr = "";
- if (ReplayUtils::hasGnssDeviceFile() &&
- ReplayUtils::isGnssRawMeasurement(
- rawMeasurementStr = ReplayUtils::getDataFromDeviceFile(
- std::string(
- ::android::hardware::gnss::common::CMD_GET_RAWMEASUREMENT),
- mMinIntervalMillis))) {
- // TODO: implement rawMeasurementStr parser and report measurement.
- ALOGD("rawMeasurementStr(size: %zu) from device file: %s", rawMeasurementStr.size(),
- rawMeasurementStr.c_str());
- auto measurement = Utils::getMockMeasurement(enableCorrVecOutputs);
- this->reportMeasurement(measurement);
- } else {
- auto measurement = Utils::getMockMeasurement(enableCorrVecOutputs);
- this->reportMeasurement(measurement);
- }
+ auto measurement = Utils::getMockMeasurement(enableCorrVecOutputs);
+ this->reportMeasurement(measurement);
+
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
}
});
diff --git a/gnss/common/utils/default/Android.bp b/gnss/common/utils/default/Android.bp
index ac94cc1..a1d3123 100644
--- a/gnss/common/utils/default/Android.bp
+++ b/gnss/common/utils/default/Android.bp
@@ -41,7 +41,6 @@
"MockLocation.cpp",
"Utils.cpp",
"NmeaFixInfo.cpp",
- "GnssReplayUtils.cpp",
],
export_include_dirs: ["include"],
shared_libs: [
diff --git a/gnss/common/utils/default/GnssReplayUtils.cpp b/gnss/common/utils/default/GnssReplayUtils.cpp
deleted file mode 100644
index fc4c477..0000000
--- a/gnss/common/utils/default/GnssReplayUtils.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "GnssReplayUtils.h"
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace common {
-
-std::string ReplayUtils::getGnssPath() {
- char devname_value[PROPERTY_VALUE_MAX] = "";
- if (property_get("debug.location.gnss.devname", devname_value, NULL) > 0) {
- return devname_value;
- }
- return GNSS_PATH;
-}
-
-bool ReplayUtils::hasGnssDeviceFile() {
- struct stat sb;
- return stat(getGnssPath().c_str(), &sb) != -1;
-}
-
-bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) {
- // TODO: add more logic check to by pass invalid data.
- return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos);
-}
-
-bool ReplayUtils::isNMEA(const std::string& inputStr) {
- return !inputStr.empty() &&
- (inputStr.rfind("$GPRMC,", 0) == 0 || inputStr.rfind("$GPRMA,", 0) == 0);
-}
-
-std::string ReplayUtils::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) {
- char inputBuffer[INPUT_BUFFER_SIZE];
- int mGnssFd = open(getGnssPath().c_str(), O_RDWR | O_NONBLOCK);
-
- if (mGnssFd == -1) {
- return "";
- }
-
- int bytes_write = write(mGnssFd, command.c_str(), command.size());
- if (bytes_write <= 0) {
- return "";
- }
-
- struct epoll_event ev, events[1];
- ev.data.fd = mGnssFd;
- ev.events = EPOLLIN;
- int epoll_fd = epoll_create1(0);
- epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mGnssFd, &ev);
- int bytes_read = -1;
- std::string inputStr = "";
- int epoll_ret = epoll_wait(epoll_fd, events, 1, mMinIntervalMs);
-
- if (epoll_ret == -1) {
- return "";
- }
- while (true) {
- memset(inputBuffer, 0, INPUT_BUFFER_SIZE);
- bytes_read = read(mGnssFd, &inputBuffer, INPUT_BUFFER_SIZE);
- if (bytes_read <= 0) {
- break;
- }
- inputStr += std::string(inputBuffer, bytes_read);
- }
-
- return inputStr;
-}
-
-} // namespace common
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/common/utils/default/include/Constants.h b/gnss/common/utils/default/include/Constants.h
index f205ba6..22afee1 100644
--- a/gnss/common/utils/default/include/Constants.h
+++ b/gnss/common/utils/default/include/Constants.h
@@ -34,18 +34,6 @@
const float kGloG1FreqHz = 1602.0 * 1e6;
const float kIrnssL5FreqHz = 1176.45 * 1e6;
-// Location replay constants
-constexpr char GNSS_PATH[] = "/dev/gnss0";
-constexpr int INPUT_BUFFER_SIZE = 256;
-constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION";
-constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT";
-constexpr char LINE_SEPARATOR = '\n';
-constexpr char COMMA_SEPARATOR = ',';
-constexpr char GPGA_RECORD_TAG[] = "$GPGGA";
-constexpr char GPRMC_RECORD_TAG[] = "$GPRMC";
-constexpr double TIMESTAMP_EPSILON = 0.001;
-constexpr int MIN_COL_NUM = 13;
-
} // namespace common
} // namespace gnss
} // namespace hardware
diff --git a/gnss/common/utils/default/include/GnssReplayUtils.h b/gnss/common/utils/default/include/GnssReplayUtils.h
deleted file mode 100644
index 32c0e58..0000000
--- a/gnss/common/utils/default/include/GnssReplayUtils.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef android_hardware_gnss_common_GnssReplayUtils_H_
-#define android_hardware_gnss_common_GnssReplayUtils_H_
-
-#include <cutils/properties.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <log/log.h>
-#include <sys/epoll.h>
-#include <sys/stat.h>
-#include <chrono>
-#include <string>
-#include <thread>
-
-#include "Constants.h"
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace common {
-
-struct ReplayUtils {
- static std::string getGnssPath();
-
- static std::string getDataFromDeviceFile(const std::string& command, int mMinIntervalMs);
-
- static bool hasGnssDeviceFile();
-
- static bool isGnssRawMeasurement(const std::string& inputStr);
-
- static bool isNMEA(const std::string& inputStr);
-};
-
-} // namespace common
-} // namespace gnss
-} // namespace hardware
-} // namespace android
-
-#endif // android_hardware_gnss_common_GnssReplayUtils_H_
diff --git a/gnss/common/utils/default/include/NmeaFixInfo.h b/gnss/common/utils/default/include/NmeaFixInfo.h
index 5c27045..c96eece 100644
--- a/gnss/common/utils/default/include/NmeaFixInfo.h
+++ b/gnss/common/utils/default/include/NmeaFixInfo.h
@@ -27,6 +27,13 @@
namespace gnss {
namespace common {
+constexpr char GPGA_RECORD_TAG[] = "$GPGGA";
+constexpr char GPRMC_RECORD_TAG[] = "$GPRMC";
+constexpr char LINE_SEPARATOR = '\n';
+constexpr char COMMA_SEPARATOR = ',';
+constexpr double TIMESTAMP_EPSILON = 0.001;
+constexpr int MIN_COL_NUM = 13;
+
/** Helper class to parse and store the GNSS fix details information. */
class NmeaFixInfo {
private:
diff --git a/gnss/common/utils/default/include/v2_1/GnssTemplate.h b/gnss/common/utils/default/include/v2_1/GnssTemplate.h
index b834a1f..48cab99 100644
--- a/gnss/common/utils/default/include/v2_1/GnssTemplate.h
+++ b/gnss/common/utils/default/include/v2_1/GnssTemplate.h
@@ -35,7 +35,6 @@
#include "GnssDebug.h"
#include "GnssMeasurement.h"
#include "GnssMeasurementCorrections.h"
-#include "GnssReplayUtils.h"
#include "MockLocation.h"
#include "NmeaFixInfo.h"
#include "Utils.h"
@@ -160,19 +159,52 @@
template <class T_IGnss>
std::unique_ptr<V2_0::GnssLocation> GnssTemplate<T_IGnss>::getLocationFromHW() {
+ char inputBuffer[INPUT_BUFFER_SIZE];
if (!mHardwareModeChecked) {
- // default using /dev/gnss0
- std::string gnss_dev_path = ReplayUtils::getGnssPath();
+ // default using gnss0
+ const char * gnss_dev_path = GNSS_PATH;
+ char devname_value[PROPERTY_VALUE_MAX] = "";
+ if (property_get("debug.location.gnss.devname", devname_value, NULL) > 0) {
+ gnss_dev_path = devname_value;
+ ALOGD("using %s instead of the default %s", gnss_dev_path, GNSS_PATH);
+ }
- mGnssFd = open(gnss_dev_path.c_str(), O_RDWR | O_NONBLOCK);
+ mGnssFd = open(gnss_dev_path, O_RDWR | O_NONBLOCK);
if (mGnssFd == -1) {
- ALOGW("Failed to open %s errno: %d", gnss_dev_path.c_str(), errno);
+ ALOGW("Failed to open %s errno: %d", gnss_dev_path, errno);
}
mHardwareModeChecked = true;
}
- std::string inputStr = ::android::hardware::gnss::common::ReplayUtils::getDataFromDeviceFile(
- CMD_GET_LOCATION, mMinIntervalMs);
+ if (mGnssFd == -1) {
+ return nullptr;
+ }
+
+ int bytes_write = write(mGnssFd, CMD_GET_LOCATION, strlen(CMD_GET_LOCATION));
+ if (bytes_write <= 0) {
+ return nullptr;
+ }
+
+ struct epoll_event ev, events[1];
+ ev.data.fd = mGnssFd;
+ ev.events = EPOLLIN;
+ int epoll_fd = epoll_create1(0);
+ epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mGnssFd, &ev);
+ int bytes_read = -1;
+ std::string inputStr = "";
+ int epoll_ret = epoll_wait(epoll_fd, events, 1, mMinIntervalMs);
+
+ if (epoll_ret == -1) {
+ return nullptr;
+ }
+ while (true) {
+ memset(inputBuffer, 0, INPUT_BUFFER_SIZE);
+ bytes_read = read(mGnssFd, &inputBuffer, INPUT_BUFFER_SIZE);
+ if (bytes_read <= 0) {
+ break;
+ }
+ inputStr += std::string(inputBuffer, bytes_read);
+ }
return NmeaFixInfo::getLocationFromInputStr(inputStr);
}