Loading gnss/common/utils/default/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ cc_library_static { "v2_1/GnssMeasurement.cpp", "v2_1/GnssMeasurement.cpp", "v2_1/GnssMeasurementCorrections.cpp", "v2_1/GnssMeasurementCorrections.cpp", "DeviceFileReader.cpp", "DeviceFileReader.cpp", "FixLocationParser.cpp", "GnssRawMeasurementParser.cpp", "GnssRawMeasurementParser.cpp", "GnssReplayUtils.cpp", "GnssReplayUtils.cpp", "MockLocation.cpp", "MockLocation.cpp", Loading gnss/common/utils/default/DeviceFileReader.cpp +17 −5 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,17 @@ namespace common { void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) { void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) { char inputBuffer[INPUT_BUFFER_SIZE]; char inputBuffer[INPUT_BUFFER_SIZE]; int mGnssFd = open(ReplayUtils::getGnssPath().c_str(), std::string deviceFilePath = ""; O_RDWR | O_NONBLOCK); 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) { if (mGnssFd == -1) { return; return; Loading Loading @@ -68,10 +77,13 @@ void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMi } } // Cache the injected data. // Cache the injected data. if (command == CMD_GET_LOCATION) { // TODO validate data data_[CMD_GET_LOCATION] = inputStr; } else if (command == CMD_GET_RAWMEASUREMENT) { if (ReplayUtils::isGnssRawMeasurement(inputStr)) { if (ReplayUtils::isGnssRawMeasurement(inputStr)) { data_[CMD_GET_RAWMEASUREMENT] = inputStr; data_[CMD_GET_RAWMEASUREMENT] = inputStr; } else if (ReplayUtils::isNMEA(inputStr)) { } data_[CMD_GET_LOCATION] = inputStr; } } } } Loading gnss/common/utils/default/FixLocationParser.cpp 0 → 100644 +76 −0 Original line number Original line Diff line number Diff line /* * 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 gnss/common/utils/default/GnssReplayUtils.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -29,11 +29,24 @@ std::string ReplayUtils::getGnssPath() { return GNSS_PATH; 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() { bool ReplayUtils::hasGnssDeviceFile() { struct stat sb; struct stat sb; return stat(getGnssPath().c_str(), &sb) != -1; 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) { bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { // TODO: add more logic check to by pass invalid data. // TODO: add more logic check to by pass invalid data. return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); Loading gnss/common/utils/default/include/Constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,7 @@ const float kIrnssL5FreqHz = 1176.45 * 1e6; // Location replay constants // Location replay constants constexpr char GNSS_PATH[] = "/dev/gnss0"; constexpr char GNSS_PATH[] = "/dev/gnss0"; constexpr char FIXED_LOCATION_PATH[] = "/dev/gnss1"; constexpr int INPUT_BUFFER_SIZE = 256; constexpr int INPUT_BUFFER_SIZE = 256; constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT"; constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT"; Loading Loading
gnss/common/utils/default/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ cc_library_static { "v2_1/GnssMeasurement.cpp", "v2_1/GnssMeasurement.cpp", "v2_1/GnssMeasurementCorrections.cpp", "v2_1/GnssMeasurementCorrections.cpp", "DeviceFileReader.cpp", "DeviceFileReader.cpp", "FixLocationParser.cpp", "GnssRawMeasurementParser.cpp", "GnssRawMeasurementParser.cpp", "GnssReplayUtils.cpp", "GnssReplayUtils.cpp", "MockLocation.cpp", "MockLocation.cpp", Loading
gnss/common/utils/default/DeviceFileReader.cpp +17 −5 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,17 @@ namespace common { void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) { void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) { char inputBuffer[INPUT_BUFFER_SIZE]; char inputBuffer[INPUT_BUFFER_SIZE]; int mGnssFd = open(ReplayUtils::getGnssPath().c_str(), std::string deviceFilePath = ""; O_RDWR | O_NONBLOCK); 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) { if (mGnssFd == -1) { return; return; Loading Loading @@ -68,10 +77,13 @@ void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMi } } // Cache the injected data. // Cache the injected data. if (command == CMD_GET_LOCATION) { // TODO validate data data_[CMD_GET_LOCATION] = inputStr; } else if (command == CMD_GET_RAWMEASUREMENT) { if (ReplayUtils::isGnssRawMeasurement(inputStr)) { if (ReplayUtils::isGnssRawMeasurement(inputStr)) { data_[CMD_GET_RAWMEASUREMENT] = inputStr; data_[CMD_GET_RAWMEASUREMENT] = inputStr; } else if (ReplayUtils::isNMEA(inputStr)) { } data_[CMD_GET_LOCATION] = inputStr; } } } } Loading
gnss/common/utils/default/FixLocationParser.cpp 0 → 100644 +76 −0 Original line number Original line Diff line number Diff line /* * 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
gnss/common/utils/default/GnssReplayUtils.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -29,11 +29,24 @@ std::string ReplayUtils::getGnssPath() { return GNSS_PATH; 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() { bool ReplayUtils::hasGnssDeviceFile() { struct stat sb; struct stat sb; return stat(getGnssPath().c_str(), &sb) != -1; 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) { bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { // TODO: add more logic check to by pass invalid data. // TODO: add more logic check to by pass invalid data. return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos); Loading
gnss/common/utils/default/include/Constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,7 @@ const float kIrnssL5FreqHz = 1176.45 * 1e6; // Location replay constants // Location replay constants constexpr char GNSS_PATH[] = "/dev/gnss0"; constexpr char GNSS_PATH[] = "/dev/gnss0"; constexpr char FIXED_LOCATION_PATH[] = "/dev/gnss1"; constexpr int INPUT_BUFFER_SIZE = 256; constexpr int INPUT_BUFFER_SIZE = 256; constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT"; constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT"; Loading