From 2c71ec9e02ea234106d520717fc36eb4f3ad7c48 Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Fri, 11 May 2018 14:59:44 -0700 Subject: [PATCH] feat: Add timeuncNs in PQWM1 message Add timeuncNs field in PQWM1 of debug NMEA message generated by modem. SystemStaus to parse it. GnssDebug adds this value in timeunc when it generates GNSS debug report. Change-Id: I649915f95730dc8db22e8b4cb88008edc6d8b9d0 CRs-Fixed: 2236950 --- android/1.1/GnssDebug.cpp | 10 ++++++---- android/2.0/GnssDebug.cpp | 18 +++++++++++------- core/SystemStatus.cpp | 19 ++++++++++++++----- core/SystemStatus.h | 4 +++- gnss/GnssAdapter.cpp | 15 ++++++++++++--- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/android/1.1/GnssDebug.cpp b/android/1.1/GnssDebug.cpp index ce394767..f164c544 100644 --- a/android/1.1/GnssDebug.cpp +++ b/android/1.1/GnssDebug.cpp @@ -36,7 +36,8 @@ using ::android::hardware::hidl_vec; #define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) #define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT -#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns #define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) @@ -125,9 +126,10 @@ Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; } - if (data.time.timeUncertaintyNs <= 0 || - data.time.timeUncertaintyNs > (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC) { - data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC; + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; } if (data.time.frequencyUncertaintyNsPerSec <= 0 || data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { diff --git a/android/2.0/GnssDebug.cpp b/android/2.0/GnssDebug.cpp index b6b9bfed..dc0d9f4d 100644 --- a/android/2.0/GnssDebug.cpp +++ b/android/2.0/GnssDebug.cpp @@ -41,7 +41,8 @@ using ::android::hardware::gnss::V2_0::IGnssDebug; #define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) #define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT -#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns #define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) @@ -130,9 +131,10 @@ Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; } - if (data.time.timeUncertaintyNs <= 0 || - data.time.timeUncertaintyNs > (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC) { - data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC; + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; } if (data.time.frequencyUncertaintyNsPerSec <= 0 || data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { @@ -247,9 +249,11 @@ Return GnssDebug::getDebugData_2_0(getDebugData_2_0_cb _hidl_cb) if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; } - if (data.time.timeUncertaintyNs <= 0 || - data.time.timeUncertaintyNs > (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC) { - data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC; + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } + else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; } if (data.time.frequencyUncertaintyNsPerSec <= 0 || data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index 6ef49935..524963bd 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -126,6 +126,7 @@ public: uint32_t mBdsBpAmpQ; // x1C uint32_t mGalBpAmpI; // x1D uint32_t mGalBpAmpQ; // x1E + uint64_t mTimeUncNs; // x1F }; // parser @@ -157,7 +158,6 @@ private: eAgcGlo = 20, eAgcBds = 21, eAgcGal = 22, - eMax0 = eAgcGal, eLeapSeconds = 23, eLeapSecUnc = 24, eGloBpAmpI = 25, @@ -166,6 +166,8 @@ private: eBdsBpAmpQ = 28, eGalBpAmpI = 29, eGalBpAmpQ = 30, + eMax0 = eGalBpAmpQ, + eTimeUncNs = 31, eMax }; SystemStatusPQWM1 mM1; @@ -201,6 +203,7 @@ public: inline uint32_t getBdsBpAmpQ() { return mM1.mBdsBpAmpQ; } inline uint32_t getGalBpAmpI() { return mM1.mGalBpAmpI; } inline uint32_t getGalBpAmpQ() { return mM1.mGalBpAmpQ; } + inline uint64_t getTimeUncNs() { return mM1.mTimeUncNs; } SystemStatusPQWM1parser(const char *str_in, uint32_t len_in) : SystemStatusNmeaBase(str_in, len_in) @@ -245,6 +248,9 @@ public: mM1.mGalBpAmpI = atoi(mField[eGalBpAmpI].c_str()); mM1.mGalBpAmpQ = atoi(mField[eGalBpAmpQ].c_str()); } + if (mField.size() > eTimeUncNs) { + mM1.mTimeUncNs = strtoull(mField[eTimeUncNs].c_str(), nullptr, 10); + } } inline SystemStatusPQWM1& get() { return mM1;} //getparser @@ -715,7 +721,8 @@ SystemStatusTimeAndClock::SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea mClockFreqBias(nmea.mClockFreqBias), mClockFreqBiasUnc(nmea.mClockFreqBiasUnc), mLeapSeconds(nmea.mLeapSeconds), - mLeapSecUnc(nmea.mLeapSecUnc) + mLeapSecUnc(nmea.mLeapSecUnc), + mTimeUncNs(nmea.mTimeUncNs) { } @@ -729,7 +736,8 @@ bool SystemStatusTimeAndClock::equals(const SystemStatusTimeAndClock& peer) (mClockFreqBias != peer.mClockFreqBias) || (mClockFreqBiasUnc != peer.mClockFreqBiasUnc) || (mLeapSeconds != peer.mLeapSeconds) || - (mLeapSecUnc != peer.mLeapSecUnc)) { + (mLeapSecUnc != peer.mLeapSecUnc) || + (mTimeUncNs != peer.mTimeUncNs)) { return false; } return true; @@ -737,7 +745,7 @@ bool SystemStatusTimeAndClock::equals(const SystemStatusTimeAndClock& peer) void SystemStatusTimeAndClock::dump() { - LOC_LOGV("TimeAndClock: u=%ld:%ld g=%d:%d v=%d ts=%d tu=%d b=%d bu=%d ls=%d lu=%d", + LOC_LOGV("TimeAndClock: u=%ld:%ld g=%d:%d v=%d ts=%d tu=%d b=%d bu=%d ls=%d lu=%d un=%" PRIu64, mUtcTime.tv_sec, mUtcTime.tv_nsec, mGpsWeek, mGpsTowMs, @@ -747,7 +755,8 @@ void SystemStatusTimeAndClock::dump() mClockFreqBias, mClockFreqBiasUnc, mLeapSeconds, - mLeapSecUnc); + mLeapSecUnc, + mTimeUncNs); return; } diff --git a/core/SystemStatus.h b/core/SystemStatus.h index 73a220a0..399a6c49 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -116,6 +116,7 @@ public: int32_t mClockFreqBiasUnc; int32_t mLeapSeconds; int32_t mLeapSecUnc; + uint64_t mTimeUncNs; inline SystemStatusTimeAndClock() : mGpsWeek(0), mGpsTowMs(0), @@ -125,7 +126,8 @@ public: mClockFreqBias(0), mClockFreqBiasUnc(0), mLeapSeconds(0), - mLeapSecUnc(0) {} + mLeapSecUnc(0), + mTimeUncNs(0ULL) {} inline SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea); bool equals(const SystemStatusTimeAndClock& peer); void dump(void); diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 5253a1b4..1a6bdd9f 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -4340,9 +4340,18 @@ bool GnssAdapter::getDebugReport(GnssDebugReport& r) (int64_t)(reports.mTimeAndClock.back().mLeapSeconds))*1000ULL + (int64_t)(reports.mTimeAndClock.back().mGpsTowMs); - r.mTime.timeUncertaintyNs = - ((float)(reports.mTimeAndClock.back().mTimeUnc) + - (float)(reports.mTimeAndClock.back().mLeapSecUnc))*1000.0f; + if (reports.mTimeAndClock.back().mTimeUncNs > 0) { + // TimeUncNs value is available + r.mTime.timeUncertaintyNs = + (float)(reports.mTimeAndClock.back().mLeapSecUnc)*1000.0f + + (float)(reports.mTimeAndClock.back().mTimeUncNs); + } else { + // fall back to legacy TimeUnc + r.mTime.timeUncertaintyNs = + ((float)(reports.mTimeAndClock.back().mTimeUnc) + + (float)(reports.mTimeAndClock.back().mLeapSecUnc))*1000.0f; + } + r.mTime.frequencyUncertaintyNsPerSec = (float)(reports.mTimeAndClock.back().mClockFreqBiasUnc); LOC_LOGV("getDebugReport - timeestimate=%" PRIu64 " unc=%f frequnc=%f",