Merge changes from topic "gnss" into sc-v2-dev

* changes:
  Supported synchronized fixed location and measurement from device files
  Add parser to support CSV location data
This commit is contained in:
Hao Chen 2022-02-22 23:08:40 +00:00 committed by Android (Google) Code Review
commit 3870153fac
8 changed files with 164 additions and 7 deletions

View file

@ -39,6 +39,7 @@ cc_library_static {
"v2_1/GnssMeasurement.cpp",
"v2_1/GnssMeasurementCorrections.cpp",
"DeviceFileReader.cpp",
"FixLocationParser.cpp",
"GnssRawMeasurementParser.cpp",
"GnssReplayUtils.cpp",
"MockLocation.cpp",

View file

@ -22,8 +22,17 @@ namespace common {
void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) {
char inputBuffer[INPUT_BUFFER_SIZE];
int mGnssFd = open(ReplayUtils::getGnssPath().c_str(),
O_RDWR | O_NONBLOCK);
std::string deviceFilePath = "";
if (command == CMD_GET_LOCATION) {
deviceFilePath = ReplayUtils::getFixedLocationPath();
} else if (command == CMD_GET_RAWMEASUREMENT) {
deviceFilePath = ReplayUtils::getGnssPath();
} else {
// Invalid command
return;
}
int mGnssFd = open(deviceFilePath.c_str(), O_RDWR | O_NONBLOCK);
if (mGnssFd == -1) {
return;
@ -68,10 +77,13 @@ void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMi
}
// Cache the injected data.
if (ReplayUtils::isGnssRawMeasurement(inputStr)) {
data_[CMD_GET_RAWMEASUREMENT] = inputStr;
} else if (ReplayUtils::isNMEA(inputStr)) {
if (command == CMD_GET_LOCATION) {
// TODO validate data
data_[CMD_GET_LOCATION] = inputStr;
} else if (command == CMD_GET_RAWMEASUREMENT) {
if (ReplayUtils::isGnssRawMeasurement(inputStr)) {
data_[CMD_GET_RAWMEASUREMENT] = inputStr;
}
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (C) 2022 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 "FixLocationParser.h"
#include <android/hardware/gnss/1.0/IGnss.h>
namespace android {
namespace hardware {
namespace gnss {
namespace common {
std::unique_ptr<V2_0::GnssLocation> FixLocationParser::getLocationFromInputStr(
const std::string& locationStr) {
/*
* Fix,Provider,LatitudeDegrees,LongitudeDegrees,AltitudeMeters,SpeedMps,
* AccuracyMeters,BearingDegrees,UnixTimeMillis,SpeedAccuracyMps,BearingAccuracyDegrees,
* elapsedRealtimeNanos
*/
if (locationStr.empty()) {
return nullptr;
}
std::vector<std::string> locationStrRecords;
ParseUtils::splitStr(locationStr, LINE_SEPARATOR, locationStrRecords);
if (locationStrRecords.empty()) {
return nullptr;
}
std::vector<std::string> locationValues;
ParseUtils::splitStr(locationStrRecords[0], COMMA_SEPARATOR, locationValues);
if (locationValues.size() < 12) {
return nullptr;
}
V2_0::ElapsedRealtime elapsedRealtime = {
.flags = V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS |
V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS,
.timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()),
// This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
// In an actual implementation provide an estimate of the synchronization uncertainty
// or don't set the field.
.timeUncertaintyNs = 1020400};
V1_0::GnssLocation locationV1 = {
.gnssLocationFlags = 0xFF,
.latitudeDegrees = ParseUtils::tryParseDouble(locationValues[2], 0),
.longitudeDegrees = ParseUtils::tryParseDouble(locationValues[3], 0),
.altitudeMeters = ParseUtils::tryParseDouble(locationValues[4], 0),
.speedMetersPerSec = ParseUtils::tryParsefloat(locationValues[5], 0),
.bearingDegrees = ParseUtils::tryParsefloat(locationValues[7], 0),
.horizontalAccuracyMeters = ParseUtils::tryParsefloat(locationValues[6], 0),
.verticalAccuracyMeters = ParseUtils::tryParsefloat(locationValues[6], 0),
.speedAccuracyMetersPerSecond = ParseUtils::tryParsefloat(locationValues[9], 0),
.bearingAccuracyDegrees = ParseUtils::tryParsefloat(locationValues[10], 0),
.timestamp = ParseUtils::tryParseLongLong(locationValues[8], 0)};
V2_0::GnssLocation locationV2 = {.v1_0 = locationV1, .elapsedRealtime = elapsedRealtime};
return std::make_unique<V2_0::GnssLocation>(locationV2);
}
} // namespace common
} // namespace gnss
} // namespace hardware
} // namespace android

View file

@ -29,11 +29,24 @@ std::string ReplayUtils::getGnssPath() {
return GNSS_PATH;
}
std::string ReplayUtils::getFixedLocationPath() {
char devname_value[PROPERTY_VALUE_MAX] = "";
if (property_get("debug.location.fixedlocation.devname", devname_value, NULL) > 0) {
return devname_value;
}
return FIXED_LOCATION_PATH;
}
bool ReplayUtils::hasGnssDeviceFile() {
struct stat sb;
return stat(getGnssPath().c_str(), &sb) != -1;
}
bool ReplayUtils::hasFixedLocationDeviceFile() {
struct stat sb;
return stat(getFixedLocationPath().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);

View file

@ -36,6 +36,7 @@ const float kIrnssL5FreqHz = 1176.45 * 1e6;
// Location replay constants
constexpr char GNSS_PATH[] = "/dev/gnss0";
constexpr char FIXED_LOCATION_PATH[] = "/dev/gnss1";
constexpr int INPUT_BUFFER_SIZE = 256;
constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION";
constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT";

View file

@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 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_default_FixLocationParser_H_
#define android_hardware_gnss_common_default_FixLocationParser_H_
#include <android/hardware/gnss/2.0/IGnss.h>
#include <utils/SystemClock.h>
#include <string>
#include <vector>
#include <Constants.h>
#include <Utils.h>
#include <log/log.h>
#include "Constants.h"
#include "ParseUtils.h"
namespace android {
namespace hardware {
namespace gnss {
namespace common {
struct FixLocationParser {
public:
static std::unique_ptr<V2_0::GnssLocation> getLocationFromInputStr(const std::string& inputStr);
};
} // namespace common
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // android_hardware_gnss_common_default_FixLocationParser_H_

View file

@ -37,10 +37,14 @@ namespace common {
struct ReplayUtils {
static std::string getGnssPath();
static std::string getFixedLocationPath();
static std::string getDataFromDeviceFile(const std::string& command, int mMinIntervalMs);
static bool hasGnssDeviceFile();
static bool hasFixedLocationDeviceFile();
static bool isGnssRawMeasurement(const std::string& inputStr);
static bool isNMEA(const std::string& inputStr);

View file

@ -31,6 +31,7 @@
#include <cutils/properties.h>
#include "DeviceFileReader.h"
#include "FixLocationParser.h"
#include "GnssAntennaInfo.h"
#include "GnssConfiguration.h"
#include "GnssDebug.h"
@ -38,7 +39,6 @@
#include "GnssMeasurementCorrections.h"
#include "GnssReplayUtils.h"
#include "MockLocation.h"
#include "NmeaFixInfo.h"
#include "Utils.h"
namespace android::hardware::gnss::common::implementation {
@ -162,9 +162,12 @@ GnssTemplate<T_IGnss>::~GnssTemplate() {
template <class T_IGnss>
std::unique_ptr<V2_0::GnssLocation> GnssTemplate<T_IGnss>::getLocationFromHW() {
mHardwareModeChecked = true;
if (!ReplayUtils::hasFixedLocationDeviceFile()) {
return nullptr;
}
std::string inputStr =
::android::hardware::gnss::common::DeviceFileReader::Instance().getLocationData();
return NmeaFixInfo::getLocationFromInputStr(inputStr);
return FixLocationParser::getLocationFromInputStr(inputStr);
}
template <class T_IGnss>