Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80451ef0 authored by Yipeng Cao's avatar Yipeng Cao
Browse files

Fix gnss replay

Change the /dev/gnss0 read logic, will send the  CMD_GET_LOCATION to
/dev/gnss0 first.
launch_cvd   --start_gnss_proxy --gnss_file_path=xxx

Test: Manually

Change-Id: Ic493790e80ceb6fd4d890b31e596b5c08addee40
parent 1be70235
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -202,8 +202,15 @@ std::unique_ptr<V2_0::GnssLocation> NmeaFixInfo::getLocationFromInputStr(
    uint32_t fixId = 0;
    double lastTimeStamp = 0;
    for (const auto& line : nmeaRecords) {
        if (line.compare(0, strlen(GPGA_RECORD_TAG), GPGA_RECORD_TAG) != 0 &&
            line.compare(0, strlen(GPRMC_RECORD_TAG), GPRMC_RECORD_TAG) != 0) {
            continue;
        }
        std::vector<std::string> sentenceValues;
        splitStr(line, COMMA_SEPARATOR, sentenceValues);
        if (sentenceValues.size() < MIN_COL_NUM) {
            continue;
        }
        double currentTimeStamp = std::stof(sentenceValues[1]);
        // If see a new timestamp, report correct location.
        if ((currentTimeStamp - lastTimeStamp) > TIMESTAMP_EPSILON &&
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ 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 {
+9 −2
Original line number Diff line number Diff line
@@ -196,6 +196,7 @@ std::unique_ptr<V2_0::GnssLocation> GnssTemplate<T_IGnss>::getLocationFromHW() {
        return nullptr;
    }
    while (true) {
        memset(inputBuffer, 0, INPUT_BUFFER_SIZE);
        bytes_read = read(mGnssFd, &inputBuffer, INPUT_BUFFER_SIZE);
        if (bytes_read <= 0) {
            break;
@@ -218,9 +219,14 @@ Return<bool> GnssTemplate<T_IGnss>::start() {
            auto svStatus = filterBlocklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
            this->reportSvStatus(svStatus);
            auto currentLocation = getLocationFromHW();
            if (mGnssFd != -1 && currentLocation != nullptr) {
            if (mGnssFd != -1) {
                // Only report location if the return from hardware is valid
                // note that we can not merge these two "if" together, if didn't
                // get location from hardware, we shouldn't report location, not
                // report the "default" one.
                if (currentLocation != nullptr) {
                    this->reportLocation(*currentLocation);
                }
            } else {
                if (sGnssCallback_2_1 != nullptr || sGnssCallback_2_0 != nullptr) {
                    const auto location = Utils::getMockLocationV2_0();
@@ -259,6 +265,7 @@ Return<bool> GnssTemplate<T_IGnss>::stop() {
    if (mGnssFd != -1) {
        close(mGnssFd);
        mGnssFd = -1;
        mHardwareModeChecked = false;
    }
    return true;
}