diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-01-09 07:03:18 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-01-09 07:03:18 +0000 |
commit | 4e5dda14794259e04580bc8d51296f49fdc7351f (patch) | |
tree | c694b598b1b0a2e58bdf28bf1acb670f6000ba4b | |
parent | 278af0ffe918fd254e7c43c6e5548258e979b75e (diff) | |
parent | ac9f22fd6e124fb59fd1e8972329443b65135341 (diff) | |
download | gps-4e5dda14794259e04580bc8d51296f49fdc7351f.tar.gz |
Merge remote-tracking branch 'goog/qcom/release/LA.UM.8.1.C9.09.00.00.518.370' into qt-qpr1-dev am: c81977c14b am: ac9f22fd6e
Change-Id: I9c5395a248bbe63684e48c12211f5485cff39807
-rw-r--r-- | android/1.0/GnssConfiguration.cpp | 3 | ||||
-rw-r--r-- | android/1.1/GnssConfiguration.cpp | 3 | ||||
-rw-r--r-- | android/2.0/GnssConfiguration.cpp | 3 | ||||
-rw-r--r-- | core/EngineHubProxyBase.h | 5 | ||||
-rw-r--r-- | core/LocApiBase.cpp | 19 | ||||
-rw-r--r-- | core/LocApiBase.h | 15 | ||||
-rw-r--r-- | core/SystemStatus.cpp | 3 | ||||
-rw-r--r-- | core/SystemStatus.h | 32 | ||||
-rw-r--r-- | etc/gps.conf | 21 | ||||
-rw-r--r-- | gnss/GnssAdapter.cpp | 297 | ||||
-rw-r--r-- | gnss/GnssAdapter.h | 33 | ||||
-rw-r--r-- | gnss/location_gnss.cpp | 57 | ||||
-rw-r--r-- | location/ILocationAPI.h | 113 | ||||
-rw-r--r-- | location/LocationAPI.cpp | 76 | ||||
-rw-r--r-- | location/LocationAPI.h | 113 | ||||
-rw-r--r-- | location/LocationDataTypes.h | 70 | ||||
-rw-r--r-- | location/location_interface.h | 6 | ||||
-rw-r--r-- | utils/Android.mk | 3 | ||||
-rw-r--r-- | utils/LogBuffer.cpp | 167 | ||||
-rw-r--r-- | utils/LogBuffer.h | 95 | ||||
-rw-r--r-- | utils/Makefile.am | 2 | ||||
-rw-r--r-- | utils/SkipList.h | 158 | ||||
-rw-r--r-- | utils/gps_extended_c.h | 21 | ||||
-rw-r--r-- | utils/loc_cfg.cpp | 10 | ||||
-rw-r--r-- | utils/loc_log.cpp | 50 | ||||
-rw-r--r-- | utils/loc_nmea.cpp | 3 | ||||
-rw-r--r-- | utils/log_util.h | 62 | ||||
-rw-r--r-- | utils/msg_q.c | 2 |
28 files changed, 1344 insertions, 98 deletions
diff --git a/android/1.0/GnssConfiguration.cpp b/android/1.0/GnssConfiguration.cpp index 0b62249..73c9d5c 100644 --- a/android/1.0/GnssConfiguration.cpp +++ b/android/1.0/GnssConfiguration.cpp @@ -65,6 +65,9 @@ Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) { config.size = sizeof(GnssConfig); config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; case 0x00020002: config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; break; diff --git a/android/1.1/GnssConfiguration.cpp b/android/1.1/GnssConfiguration.cpp index 93f9645..708e2c1 100644 --- a/android/1.1/GnssConfiguration.cpp +++ b/android/1.1/GnssConfiguration.cpp @@ -65,6 +65,9 @@ Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) { config.size = sizeof(GnssConfig); config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; case 0x00020002: config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; break; diff --git a/android/2.0/GnssConfiguration.cpp b/android/2.0/GnssConfiguration.cpp index 363d2b1..069c036 100644 --- a/android/2.0/GnssConfiguration.cpp +++ b/android/2.0/GnssConfiguration.cpp @@ -55,6 +55,9 @@ Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) { config.size = sizeof(GnssConfig); config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; case 0x00020002: config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; break; diff --git a/core/EngineHubProxyBase.h b/core/EngineHubProxyBase.h index 2d30c5b..d46bca2 100644 --- a/core/EngineHubProxyBase.h +++ b/core/EngineHubProxyBase.h @@ -101,6 +101,11 @@ public: (void) additionalSystemInfo; return false; } + + inline virtual bool configLeverArm(const LeverArmConfigInfo& configInfo) { + (void) configInfo; + return false; + } }; typedef std::function<void(int count, EngineLocationInfo* locationArr)> diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 595fa49..71abdf9 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -756,24 +756,27 @@ DEFAULT_IMPL() void LocApiBase::getBlacklistSv() DEFAULT_IMPL() -void LocApiBase::setConstellationControl(const GnssSvTypeConfig& /*config*/) +void LocApiBase::setConstellationControl(const GnssSvTypeConfig& /*config*/, + LocApiResponse* /*adapterResponse*/) DEFAULT_IMPL() void LocApiBase::getConstellationControl() DEFAULT_IMPL() -void LocApiBase::resetConstellationControl() +void LocApiBase::resetConstellationControl(LocApiResponse* /*adapterResponse*/) DEFAULT_IMPL() -LocationError LocApiBase:: +void LocApiBase:: setConstrainedTuncMode(bool /*enabled*/, float /*tuncConstraint*/, - uint32_t /*energyBudget*/) -DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + uint32_t /*energyBudget*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() -LocationError LocApiBase:: - setPositionAssistedClockEstimatorMode(bool /*enabled*/) -DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) +void LocApiBase:: + setPositionAssistedClockEstimatorMode(bool /*enabled*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() LocationError LocApiBase::getGnssEnergyConsumed() DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) diff --git a/core/LocApiBase.h b/core/LocApiBase.h index 3c85b09..9c76bab 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -260,12 +260,17 @@ public: virtual LocationError setBlacklistSvSync(const GnssSvIdConfig& config); virtual void setBlacklistSv(const GnssSvIdConfig& config); virtual void getBlacklistSv(); - virtual void setConstellationControl(const GnssSvTypeConfig& config); + virtual void setConstellationControl(const GnssSvTypeConfig& config, + LocApiResponse *adapterResponse=nullptr); virtual void getConstellationControl(); - virtual void resetConstellationControl(); - virtual LocationError setConstrainedTuncMode(bool enabled, float tuncConstraint, - uint32_t energyBudget); - virtual LocationError setPositionAssistedClockEstimatorMode(bool enabled); + virtual void resetConstellationControl(LocApiResponse *adapterResponse=nullptr); + + virtual void setConstrainedTuncMode(bool enabled, + float tuncConstraint, + uint32_t energyBudget, + LocApiResponse* adapterResponse=nullptr); + virtual void setPositionAssistedClockEstimatorMode(bool enabled, + LocApiResponse* adapterResponse=nullptr); virtual LocationError getGnssEnergyConsumed(); virtual void addGeofence(uint32_t clientId, const GeofenceOption& options, diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index 0624580..393eead 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -1346,6 +1346,9 @@ SystemStatus::SystemStatus(const MsgTask* msgTask) : template <typename TYPE_REPORT, typename TYPE_ITEM> bool SystemStatus::setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s) { + if (s.ignore()) { + return false; + } if (!report.empty() && report.back().equals(static_cast<TYPE_ITEM&>(s.collate(report.back())))) { // there is no change - just update reported timestamp report.back().mUtcReported = s.mUtcReported; diff --git a/core/SystemStatus.h b/core/SystemStatus.h index 2cfb25d..8ec85fa 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -87,6 +87,7 @@ public: return *this; } virtual void dump(void) {}; + inline virtual bool ignore() { return false; }; }; class SystemStatusLocation : public SystemStatusItemBase @@ -103,7 +104,7 @@ public: mLocation(location), mLocationEx(locationEx) {} bool equals(const SystemStatusLocation& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWM1; @@ -133,7 +134,7 @@ public: mTimeUncNs(0ULL) {} inline SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea); bool equals(const SystemStatusTimeAndClock& peer); - void dump(void); + void dump(void) override; }; class SystemStatusXoState : public SystemStatusItemBase @@ -144,7 +145,7 @@ public: mXoState(0) {} inline SystemStatusXoState(const SystemStatusPQWM1& nmea); bool equals(const SystemStatusXoState& peer); - void dump(void); + void dump(void) override; }; class SystemStatusRfAndParams : public SystemStatusItemBase @@ -191,7 +192,7 @@ public: mGalBpAmpQ(0) {} inline SystemStatusRfAndParams(const SystemStatusPQWM1& nmea); bool equals(const SystemStatusRfAndParams& peer); - void dump(void); + void dump(void) override; }; class SystemStatusErrRecovery : public SystemStatusItemBase @@ -202,7 +203,8 @@ public: mRecErrorRecovery(0) {}; inline SystemStatusErrRecovery(const SystemStatusPQWM1& nmea); bool equals(const SystemStatusErrRecovery& peer); - void dump(void); + inline bool ignore() override { return 0 == mRecErrorRecovery; }; + void dump(void) override; }; class SystemStatusPQWP1; @@ -226,7 +228,7 @@ public: mEpiSrc(0) {} inline SystemStatusInjectedPosition(const SystemStatusPQWP1& nmea); bool equals(const SystemStatusInjectedPosition& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP2; @@ -248,7 +250,7 @@ public: mBestAltUnc(0) {} inline SystemStatusBestPosition(const SystemStatusPQWP2& nmea); bool equals(const SystemStatusBestPosition& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP3; @@ -284,7 +286,7 @@ public: mNavicXtraValid(0) {} inline SystemStatusXtra(const SystemStatusPQWP3& nmea); bool equals(const SystemStatusXtra& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP4; @@ -304,7 +306,7 @@ public: mQzssEpheValid(0) {} inline SystemStatusEphemeris(const SystemStatusPQWP4& nmea); bool equals(const SystemStatusEphemeris& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP5; @@ -350,7 +352,7 @@ public: mNavicBadMask(0) {} inline SystemStatusSvHealth(const SystemStatusPQWP5& nmea); bool equals(const SystemStatusSvHealth& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP6; @@ -362,7 +364,7 @@ public: mFixInfoMask(0) {} inline SystemStatusPdr(const SystemStatusPQWP6& nmea); bool equals(const SystemStatusPdr& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWP7; @@ -386,7 +388,7 @@ public: } inline SystemStatusNavData(const SystemStatusPQWP7& nmea); bool equals(const SystemStatusNavData& peer); - void dump(void); + void dump(void) override; }; class SystemStatusPQWS1; @@ -400,7 +402,7 @@ public: mHepeLimit(0) {} inline SystemStatusPositionFailure(const SystemStatusPQWS1& nmea); bool equals(const SystemStatusPositionFailure& peer); - void dump(void); + void dump(void) override; }; /****************************************************************************** @@ -759,7 +761,7 @@ public: inline bool equals(const SystemStatusTac& peer) { return (mValue == peer.mValue); } - inline void dump(void) { + inline void dump(void) override { LOC_LOGD("Tac: value=%s", mValue.c_str()); } }; @@ -775,7 +777,7 @@ public: inline bool equals(const SystemStatusMccMnc& peer) { return (mValue == peer.mValue); } - inline void dump(void) { + inline void dump(void) override { LOC_LOGD("TacMccMnc value=%s", mValue.c_str()); } }; diff --git a/etc/gps.conf b/etc/gps.conf index 47aa8ef..1d4e233 100644 --- a/etc/gps.conf +++ b/etc/gps.conf @@ -322,3 +322,24 @@ CP_MTLR_ES=0 # and QCSR SS5 hardware receiver. # By default QTI GNSS receiver is enabled. # GNSS_DEPLOYMENT = 0 + +################################################## +## LOG BUFFER CONFIGURATION +################################################## +#LOG_BUFFER_ENABLED, 1=enable, 0=disable +#*_LEVEL_TIME_DEPTH, maximum time depth of level * +#in log buffer, unit is second +#*_LEVEL_MAX_CAPACITY, maximum numbers of level * +#log print sentences in log buffer +LOG_BUFFER_ENABLED = 0 +E_LEVEL_TIME_DEPTH = 600 +E_LEVEL_MAX_CAPACITY = 50 +W_LEVEL_TIME_DEPTH = 500 +W_LEVEL_MAX_CAPACITY = 100 +I_LEVEL_TIME_DEPTH = 400 +I_LEVEL_MAX_CAPACITY = 200 +D_LEVEL_TIME_DEPTH = 30 +D_LEVEL_MAX_CAPACITY = 300 +V_LEVEL_TIME_DEPTH = 200 +V_LEVEL_MAX_CAPACITY = 400 + diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 339f9a0..4dbd182 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -80,6 +80,7 @@ GnssAdapter::GnssAdapter() : mGnssSvIdConfig(), mGnssSvTypeConfig(), mGnssSvTypeConfigCb(nullptr), + mLocConfigInfo{}, mNiData(), mAgpsManager(), mOdcpiRequestCb(nullptr), @@ -533,6 +534,8 @@ inline uint32_t GnssAdapter::convertSuplVersion(const GnssConfigSuplVersion suplVersion) { switch (suplVersion) { + case GNSS_CONFIG_SUPL_VERSION_2_0_4: + return 0x00020004; case GNSS_CONFIG_SUPL_VERSION_2_0_0: return 0x00020000; case GNSS_CONFIG_SUPL_VERSION_2_0_2: @@ -829,12 +832,32 @@ GnssAdapter::setConfig() mLocApi->setXtraVersionCheckSync(gpsConf.XTRA_VERSION_CHECK); + // load tunc configuration from config file on first boot-up, + // e.g.: adapter.mLocConfigInfo.tuncConfigInfo.isValid is false + if (mLocConfigInfo.tuncConfigInfo.isValid == false) { + mLocConfigInfo.tuncConfigInfo.isValid = true; + mLocConfigInfo.tuncConfigInfo.enable = + (gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED == 1); + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs = + (float)gpsConf.CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD; + mLocConfigInfo.tuncConfigInfo.energyBudget = + gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET; + } + mLocApi->setConstrainedTuncMode( - gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED == 1, - (float)gpsConf.CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD, - gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET); + mLocConfigInfo.tuncConfigInfo.enable, + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs, + mLocConfigInfo.tuncConfigInfo.energyBudget); + + // load pace configuration from config file on first boot-up, + // e.g.: adapter.mLocConfigInfo.paceConfigInfo.isValid is false + if (mLocConfigInfo.paceConfigInfo.isValid == false) { + mLocConfigInfo.paceConfigInfo.isValid = true; + mLocConfigInfo.paceConfigInfo.enable = + (gpsConf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED==1); + } mLocApi->setPositionAssistedClockEstimatorMode( - gpsConf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED == 1); + mLocConfigInfo.paceConfigInfo.enable); if (sapConf.GYRO_BIAS_RANDOM_WALK_VALID || sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID || @@ -3374,10 +3397,11 @@ GnssAdapter::reportPosition(const UlpLocation& ulpLocation, } } - // if engine hub is running and the fix is from sensor, e.g.: DRE, - // inject DRE fix to modem - if ((1 == ContextBase::mGps_conf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED) && - (true == initEngHubProxy()) && (LOC_POS_TECH_MASK_SENSORS & techMask)) { + // if PACE is enabled and engine hub is running and the fix is from sensor, + // e.g.: DRE, inject DRE fix to modem + if ((true == mLocConfigInfo.paceConfigInfo.isValid && + true == mLocConfigInfo.paceConfigInfo.enable) && + (true == initEngHubProxy()) && (LOC_POS_TECH_MASK_SENSORS & techMask)) { mLocApi->injectPosition(locationInfo, false); } } @@ -5059,6 +5083,263 @@ GnssAdapter::nfwControlCommand(bool enable) { } } +// Set tunc constrained mode, use 0 session id to indicate +// that no callback is needed. Session id 0 is used for calls that +// are not invoked from the integration api, e.g.: initial configuration +// from the configure file +void +GnssAdapter::setConstrainedTunc(bool enable, float tuncConstraint, + uint32_t energyBudget, uint32_t sessionId) { + + mLocConfigInfo.tuncConfigInfo.isValid = true; + mLocConfigInfo.tuncConfigInfo.enable = enable; + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs = tuncConstraint; + mLocConfigInfo.tuncConfigInfo.energyBudget = energyBudget; + + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->setConstrainedTuncMode( + enable, tuncConstraint, energyBudget, locApiResponse); +} + +uint32_t +GnssAdapter::setConstrainedTuncCommand (bool enable, float tuncConstraint, + uint32_t energyBudget) { + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgEnableTUNC : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + bool mEnable; + float mTuncConstraint; + uint32_t mEnergyBudget; + + inline MsgEnableTUNC(GnssAdapter& adapter, + uint32_t sessionId, + bool enable, + float tuncConstraint, + uint32_t energyBudget) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEnable(enable), + mTuncConstraint(tuncConstraint), + mEnergyBudget(energyBudget) {} + inline virtual void proc() const { + mAdapter.setConstrainedTunc(mEnable, mTuncConstraint, + mEnergyBudget, mSessionId); + } + }; + + sendMsg(new MsgEnableTUNC(*this, sessionId, enable, + tuncConstraint, energyBudget)); + + return sessionId; +} + +// Set position assisted clock estimator, use 0 session id to indicate +// that no callback is needed. Session id 0 is used for calls that are +// not invoked from the integration api, e.g.: initial configuration +// from the configure file. +void +GnssAdapter::setPositionAssistedClockEstimator(bool enable, + uint32_t sessionId) { + + mLocConfigInfo.paceConfigInfo.isValid = true; + mLocConfigInfo.paceConfigInfo.enable = enable; + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->setPositionAssistedClockEstimatorMode(enable, locApiResponse); +} + +uint32_t +GnssAdapter::setPositionAssistedClockEstimatorCommand(bool enable) { + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgEnablePACE : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + bool mEnable; + inline MsgEnablePACE(GnssAdapter& adapter, + uint32_t sessionId, bool enable) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEnable(enable){} + inline virtual void proc() const { + mAdapter.setPositionAssistedClockEstimator(mEnable, mSessionId); + } + }; + + sendMsg(new MsgEnablePACE(*this, sessionId, enable)); + return sessionId; +} + +void +GnssAdapter::updateSvConfig(uint32_t sessionId, + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) { + + // check whether if any constellation is removed from the new config + GnssSvTypesMask enabledRemoved = mGnssSvTypeConfig.enabledSvTypesMask & + (mGnssSvTypeConfig.enabledSvTypesMask ^ svTypeConfig.enabledSvTypesMask); + // Send reset if any constellation is removed from the enabled list + if (enabledRemoved != 0) { + mLocApi->resetConstellationControl(); + } + + mGnssSvTypeConfig = svTypeConfig; + mGnssSvIdConfig = svIdConfig; + + // Send blacklist info + mLocApi->setBlacklistSv(mGnssSvIdConfig); + + // Send only enabled constellation config + GnssSvTypeConfig svTypeConfigCopy = {sizeof(GnssSvTypeConfig), 0, 0}; + svTypeConfigCopy.enabledSvTypesMask = mGnssSvTypeConfig.enabledSvTypesMask; + LocApiResponse* locApiResponse = new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + mLocApi->setConstellationControl(svTypeConfigCopy, locApiResponse); +} + +uint32_t GnssAdapter::gnssUpdateSvConfigCommand( + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgUpdateSvConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + GnssSvTypeConfig mSvTypeConfig; + GnssSvIdConfig mSvIdConfig; + + inline MsgUpdateSvConfig(GnssAdapter& adapter, + uint32_t sessionId, + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mSvTypeConfig(svTypeConfig), + mSvIdConfig(svIdConfig) {} + inline virtual void proc() const { + mAdapter.updateSvConfig(mSessionId, mSvTypeConfig, mSvIdConfig); + } + }; + + if (sessionId != 0) { + sendMsg(new MsgUpdateSvConfig(*this, sessionId, + svTypeConfig, svIdConfig)); + } + return sessionId; +} + +void +GnssAdapter::resetSvConfig(uint32_t sessionId) { + + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->resetConstellationControl(locApiResponse); +} + +uint32_t GnssAdapter::gnssResetSvConfigCommand() { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgResetSvConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + + inline MsgResetSvConfig(GnssAdapter& adapter, + uint32_t sessionId) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId) {} + inline virtual void proc() const { + mAdapter.resetSvConfig(mSessionId); + } + }; + + sendMsg(new MsgResetSvConfig(*this, sessionId)); + return sessionId; +} + +void +GnssAdapter::configLeverArm(uint32_t sessionId, + const LeverArmConfigInfo& configInfo) { + + LocationError err = LOCATION_ERROR_NOT_SUPPORTED; + if (true == mEngHubProxy->configLeverArm(configInfo)) { + err = LOCATION_ERROR_SUCCESS; + } + reportResponse(err, sessionId); +} + +uint32_t +GnssAdapter::configLeverArmCommand(const LeverArmConfigInfo& configInfo) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgConfigLeverArm : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + LeverArmConfigInfo mConfigInfo; + + inline MsgConfigLeverArm(GnssAdapter& adapter, + uint32_t sessionId, + const LeverArmConfigInfo& configInfo) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mConfigInfo(configInfo) {} + inline virtual void proc() const { + mAdapter.configLeverArm(mSessionId, mConfigInfo); + } + }; + + sendMsg(new MsgConfigLeverArm(*this, sessionId, configInfo)); + return sessionId; +} + /* ==== Eng Hub Proxy ================================================================= */ /* ======== UTILITIES ================================================================= */ void diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 37a4892..ff8131f 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -122,6 +122,23 @@ typedef struct { double latLonDiffThreshold; } BlockCPIInfo; +typedef struct { + bool isValid; + bool enable; + float tuncThresholdMs; // need to be specified if enable is true + uint32_t energyBudget; // need to be specified if enable is true +} TuncConfigInfo; + +typedef struct { + bool isValid; + bool enable; +} PaceConfigInfo; + +typedef struct { + TuncConfigInfo tuncConfigInfo; + PaceConfigInfo paceConfigInfo; +} LocIntegrationConfigInfo; + using namespace loc_core; namespace loc_core { @@ -158,6 +175,7 @@ class GnssAdapter : public LocAdapterBase { GnssSvTypeConfig mGnssSvTypeConfig; GnssSvTypeConfigCallback mGnssSvTypeConfigCb; bool mSupportNfwControl; + LocIntegrationConfigInfo mLocConfigInfo; /* ==== NI ============================================================================= */ NiData mNiData; @@ -270,6 +288,14 @@ public: const TrackingOptions& updatedOptions, const TrackingOptions& oldOptions); bool checkAndSetSPEToRunforNHz(TrackingOptions & out); + void setConstrainedTunc(bool enable, float tuncConstraint, + uint32_t energyBudget, uint32_t sessionId); + void setPositionAssistedClockEstimator(bool enable, uint32_t sessionId); + void updateSvConfig(uint32_t sessionId, const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig); + void resetSvConfig(uint32_t sessionId); + void configLeverArm(uint32_t sessionId, const LeverArmConfigInfo& configInfo); + /* ==== NI ============================================================================= */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ void gnssNiResponseCommand(LocationAPI* client, uint32_t id, GnssNiResponse response); @@ -329,6 +355,13 @@ public: void dataConnFailedCommand(AGpsExtType agpsType); void getGnssEnergyConsumedCommand(GnssEnergyConsumedCallback energyConsumedCb); void nfwControlCommand(bool enable); + uint32_t setConstrainedTuncCommand (bool enable, float tuncConstraint, + uint32_t energyBudget); + uint32_t setPositionAssistedClockEstimatorCommand (bool enable); + uint32_t gnssUpdateSvConfigCommand(const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig); + uint32_t gnssResetSvConfigCommand(); + uint32_t configLeverArmCommand(const LeverArmConfigInfo& configInfo); /* ========= ODCPI ===================================================================== */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ diff --git a/gnss/location_gnss.cpp b/gnss/location_gnss.cpp index 5380f05..97e99e4 100644 --- a/gnss/location_gnss.cpp +++ b/gnss/location_gnss.cpp @@ -80,6 +80,13 @@ static void blockCPI(double latitude, double longitude, float accuracy, int blockDurationMsec, double latLonDiffThreshold); static void updateBatteryStatus(bool charging); static void updateSystemPowerState(PowerStateType systemPowerState); +static uint32_t setConstrainedTunc (bool enable, float tuncConstraint, + uint32_t energyBudget); +static uint32_t setPositionAssistedClockEstimator(bool enable); +static uint32_t gnssUpdateSvConfig(const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig); +static uint32_t gnssResetSvConfig(); +static uint32_t configLeverArm(const LeverArmConfigInfo& configInfo); static const GnssInterface gGnssInterface = { sizeof(GnssInterface), @@ -119,7 +126,12 @@ static const GnssInterface gGnssInterface = { getPowerStateChanges, injectLocationExt, updateBatteryStatus, - updateSystemPowerState + updateSystemPowerState, + setConstrainedTunc, + setPositionAssistedClockEstimator, + gnssUpdateSvConfig, + gnssResetSvConfig, + configLeverArm, }; #ifndef DEBUG_X86 @@ -398,3 +410,46 @@ static void updateSystemPowerState(PowerStateType systemPowerState) { gGnssAdapter->updateSystemPowerStateCommand(systemPowerState); } } + +static uint32_t setConstrainedTunc (bool enable, float tuncConstraint, uint32_t energyBudget) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->setConstrainedTuncCommand(enable, tuncConstraint, energyBudget); + } else { + return 0; + } +} + +static uint32_t setPositionAssistedClockEstimator(bool enable) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->setPositionAssistedClockEstimatorCommand(enable); + } else { + return 0; + } +} + +static uint32_t gnssUpdateSvConfig( + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssUpdateSvConfigCommand( + svTypeConfig, svIdConfig); + } else { + return 0; + } +} + +static uint32_t gnssResetSvConfig() { + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssResetSvConfigCommand(); + } else { + return 0; + } +} + +static uint32_t configLeverArm(const LeverArmConfigInfo& configInfo){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->configLeverArmCommand(configInfo); + } else { + return 0; + } +} diff --git a/location/ILocationAPI.h b/location/ILocationAPI.h index 3df6f79..87aa99b 100644 --- a/location/ILocationAPI.h +++ b/location/ILocationAPI.h @@ -189,6 +189,119 @@ public: LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid LOCATION_ERROR_NOT_SUPPORTED if build is not userdebug */ virtual uint32_t gnssDeleteAidingData(GnssAidingData& data) = 0; + + /** @brief + Reset the constellation settings to modem default. + + @param + None + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t resetConstellationConfig() = 0; + + /** @brief + Configure the constellation to be used by the GNSS engine on + modem. + + @param + constellationConfig: specify the constellation configuration + used by GNSS engine. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellations( + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) = 0; + + /** @brief + Enable or disable the constrained time uncertainty feature. + + @param + enable: true to enable the constrained time uncertainty + feature and false to disable the constrainted time + uncertainty feature. + + @param + tuncThreshold: this specifies the time uncertainty threshold + that gps engine need to maintain, in units of milli-seconds. + Default is 0.0 meaning that modem default value of time + uncertainty threshold will be used. This parameter is + ignored when requesting to disable this feature. + + @param + energyBudget: this specifies the power budget that gps + engine is allowed to spend to maintain the time uncertainty. + Default is 0 meaning that GPS engine is not constained by + power budget and can spend as much power as needed. The + parameter need to be specified in units of 0.1 milli watt + second. This parameter is ignored requesting to disable this + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters + are invalid + */ + virtual uint32_t configConstrainedTimeUncertainty( + bool enable, float tuncThreshold = 0.0, + uint32_t energyBudget = 0) = 0; + + /** @brief + Enable or disable position assisted clock estimator feature. + + @param + enable: true to enable position assisted clock estimator and + false to disable the position assisted clock estimator + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configPositionAssistedClockEstimator(bool enable) = 0; + + /** @brief + Sets the lever arm parameters for the vehicle. + + @param + configInfo: lever arm configuration info regarding below two + types of lever arm info: + a: GNSS Antenna w.r.t the origin at the IMU e.g.: inertial + measurement unit. + b: lever arm parameters regarding the OPF (output frame) + w.r.t the origin (at the GPS Antenna). Vehicle manufacturers + prefer the position output to be tied to a specific point in + the vehicle rather than where the antenna is placed + (midpoint of the rear axle is typical). + + Caller can choose types of lever arm info to configure via the + leverMarkTypeMask. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configLeverArm(const LeverArmConfigInfo& configInfo) = 0; }; #endif /* ILOCATIONAPI_H */ diff --git a/location/LocationAPI.cpp b/location/LocationAPI.cpp index 4348c27..7c125b8 100644 --- a/location/LocationAPI.cpp +++ b/location/LocationAPI.cpp @@ -723,3 +723,79 @@ LocationControlAPI::gnssDeleteAidingData(GnssAidingData& data) pthread_mutex_unlock(&gDataMutex); return id; } + +uint32_t LocationControlAPI::resetConstellationConfig() { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->gnssResetSvConfig(); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configConstellations( + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->gnssUpdateSvConfig( + svTypeConfig, svIdConfig); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configConstrainedTimeUncertainty( + bool enable, float tuncThreshold, uint32_t energyBudget) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->setConstrainedTunc(enable, + tuncThreshold, + energyBudget); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configPositionAssistedClockEstimator(bool enable) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->setPositionAssistedClockEstimator(enable); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configLeverArm(const LeverArmConfigInfo& configInfo) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configLeverArm(configInfo); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} diff --git a/location/LocationAPI.h b/location/LocationAPI.h index 6f5987c..f70fc2f 100644 --- a/location/LocationAPI.h +++ b/location/LocationAPI.h @@ -261,6 +261,119 @@ public: LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid LOCATION_ERROR_NOT_SUPPORTED if build is not userdebug */ virtual uint32_t gnssDeleteAidingData(GnssAidingData& data) override; + + /** @brief + Reset the constellation settings to modem default. + + @param + None + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t resetConstellationConfig() override; + + /** @brief + Configure the constellation to be used by the GNSS engine on + modem. + + @param + constellationConfig: specify the constellation configuration + used by GNSS engine. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellations( + const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig) override; + + /** @brief + Enable or disable the constrained time uncertainty feature. + + @param + enable: true to enable the constrained time uncertainty + feature and false to disable the constrainted time + uncertainty feature. + + @param + tuncThreshold: this specifies the time uncertainty threshold + that gps engine need to maintain, in units of milli-seconds. + Default is 0.0 meaning that modem default value of time + uncertainty threshold will be used. This parameter is + ignored when requesting to disable this feature. + + @param + energyBudget: this specifies the power budget that gps + engine is allowed to spend to maintain the time uncertainty. + Default is 0 meaning that GPS engine is not constained by + power budget and can spend as much power as needed. The + parameter need to be specified in units of 0.1 milli watt + second. This parameter is ignored requesting to disable this + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters + are invalid + */ + virtual uint32_t configConstrainedTimeUncertainty( + bool enable, float tuncThreshold = 0.0, + uint32_t energyBudget = 0) override; + + /** @brief + Enable or disable position assisted clock estimator feature. + + @param + enable: true to enable position assisted clock estimator and + false to disable the position assisted clock estimator + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configPositionAssistedClockEstimator(bool enable) override; + + /** @brief + Sets the lever arm parameters for the vehicle. + + @param + configInfo: lever arm configuration info regarding below two + types of lever arm info: + a: GNSS Antenna w.r.t the origin at the IMU e.g.: inertial + measurement unit. + b: lever arm parameters regarding the OPF (output frame) + w.r.t the origin (at the GPS Antenna). Vehicle manufacturers + prefer the position output to be tied to a specific point in + the vehicle rather than where the antenna is placed + (midpoint of the rear axle is typical). + + Caller can choose types of lever arm info to configure via the + leverMarkTypeMask. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configLeverArm(const LeverArmConfigInfo& configInfo) override; }; #endif /* LOCATIONAPI_H */ diff --git a/location/LocationDataTypes.h b/location/LocationDataTypes.h index 956754a..65b5e13 100644 --- a/location/LocationDataTypes.h +++ b/location/LocationDataTypes.h @@ -248,6 +248,7 @@ typedef enum { GNSS_CONFIG_SUPL_VERSION_1_0_0 = 1, GNSS_CONFIG_SUPL_VERSION_2_0_0, GNSS_CONFIG_SUPL_VERSION_2_0_2, + GNSS_CONFIG_SUPL_VERSION_2_0_4, } GnssConfigSuplVersion; // LTE Positioning Profile @@ -658,6 +659,8 @@ typedef enum { DEAD_RECKONING_ENGINE = (1 << 1), PRECISE_POSITIONING_ENGINE = (1 << 2) } PositioningEngineBits; +#define POSITION_ENGINE_MASK_ALL \ + (STANDARD_POSITIONING_ENGINE|DEAD_RECKONING_ENGINE|PRECISE_POSITIONING_ENGINE) typedef uint64_t GnssDataMask; typedef enum { @@ -1186,6 +1189,13 @@ typedef struct { // GAL - SV 301 maps to bit 0 #define GNSS_SV_CONFIG_GAL_INITIAL_SV_ID 301 uint64_t galBlacklistSvMask; + + // SBAS - SV 120 to 158, maps to 0 to 38 + // SV 183 to 191, maps to 39 to 47 +#define GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID 120 +#define GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH 39 +#define GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID 183 + uint64_t sbasBlacklistSvMask; } GnssSvIdConfig; struct GnssConfig{ @@ -1313,6 +1323,66 @@ struct LocationSystemInfo { LeapSecondSystemInfo leapSecondSysInfo; }; +/* Mask indicating enabled or disabled constellations */ +typedef uint64_t GnssSvTypesMask; +typedef enum { + GNSS_SV_TYPES_MASK_GLO_BIT = (1<<0), + GNSS_SV_TYPES_MASK_BDS_BIT = (1<<1), + GNSS_SV_TYPES_MASK_QZSS_BIT = (1<<2), + GNSS_SV_TYPES_MASK_GAL_BIT = (1<<3), + GNSS_SV_TYPES_MASK_NAVIC_BIT = (1<<4), +} GnssSvTypesMaskBits; + +/* This SV Type config is injected directly to GNSS Adapter + * bypassing Location API */ +typedef struct { + uint32_t size; // set to sizeof(GnssSvTypeConfig) + // Enabled Constellations + GnssSvTypesMask enabledSvTypesMask; + // Disabled Constellations + GnssSvTypesMask blacklistedSvTypesMask; +} GnssSvTypeConfig; + +// Specify parameters related to lever arm +struct LeverArmParams { + // Offset along the vehicle forward axis + float forwardOffsetMeters; + // Offset along the vehicle starboard axis + float sidewaysOffsetMeters; + // Offset along the vehicle up axis + float upOffsetMeters; +}; + +typedef uint32_t LeverArmTypeMask; + +enum LeverArmTypeBits { + // Lever arm regarding the VRP (Vehicle Reference Point) w.r.t + // the origin (at the GPS Antenna) + LEVER_ARM_TYPE_GNSS_TO_VRP_BIT = (1<<0), + // Lever arm regarding GNSS Antenna w.r.t the origin at the IMU + // e.g.: inertial measurement unit for DR (dead reckoning + // engine) + LEVER_ARM_TYPE_DR_IMU_TO_GNSS_BIT = (1<<1), + // Lever arm regarding GNSS Antenna w.r.t the origin at the + // IMU (inertial measurement unit) for VEPP (vision enhanced + // precise positioning engine) + LEVER_ARM_TYPE_VEPP_IMU_TO_GNSS_BIT = (1<<2) +}; + +struct LeverArmConfigInfo { + // Valid mask for the types of lever arm parameters provided + LeverArmTypeMask leverArmValidMask; + // Lever arm regarding the VRP (Vehicle Reference Point) w.r.t the origin + // (at the GPS Antenna) + LeverArmParams gnssToVRP; + // Lever arm parameters regarding GNSS Antenna w.r.t the origin at the IMU + // (inertial measurement unit) for DR (dead reckoning engine) + LeverArmParams drImuToGnss; + // Lever arm regarding GNSS Antenna w.r.t the origin at the IMU + // (inertial measurement unit) for VEPP (vision enhanced precise position engine) + LeverArmParams veppImuToGnss; +}; + /* Provides the capabilities of the system capabilities callback is called once soon after createInstance is called */ typedef std::function<void( diff --git a/location/location_interface.h b/location/location_interface.h index d08dfb3..6edb911 100644 --- a/location/location_interface.h +++ b/location/location_interface.h @@ -89,6 +89,12 @@ struct GnssInterface { void (*injectLocationExt)(const GnssLocationInfoNotification &locationInfo); void (*updateBatteryStatus)(bool charging); void (*updateSystemPowerState)(PowerStateType systemPowerState); + uint32_t (*setConstrainedTunc) (bool enable, float tuncConstraint, uint32_t energyBudget); + uint32_t (*setPositionAssistedClockEstimator) (bool enable); + uint32_t (*gnssUpdateSvConfig)(const GnssSvTypeConfig& svTypeConfig, + const GnssSvIdConfig& svIdConfig); + uint32_t (*gnssResetSvConfig)(); + uint32_t (*configLeverArm)(const LeverArmConfigInfo& configInfo); }; struct BatchingInterface { diff --git a/utils/Android.mk b/utils/Android.mk index 88ad487..57d485d 100644 --- a/utils/Android.mk +++ b/utils/Android.mk @@ -27,7 +27,8 @@ LOCAL_SRC_FILES += \ MsgTask.cpp \ loc_misc_utils.cpp \ loc_nmea.cpp \ - LocIpc.cpp + LocIpc.cpp \ + LogBuffer.cpp # Flag -std=c++11 is not accepted by compiler when LOCAL_CLANG is set to true LOCAL_CFLAGS += \ diff --git a/utils/LogBuffer.cpp b/utils/LogBuffer.cpp new file mode 100644 index 0000000..1bb6f0f --- /dev/null +++ b/utils/LogBuffer.cpp @@ -0,0 +1,167 @@ +/* Copyright (c) 2019 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "LogBuffer.h" +#include <utils/Log.h> + +#define LOG_TAG "LocSvc_LogBuffer" + +namespace loc_util { + +LogBuffer* LogBuffer::mInstance; +struct sigaction LogBuffer::mOriSigAction[NSIG]; +struct sigaction LogBuffer::mNewSigAction; +mutex LogBuffer::sLock; + +LogBuffer* LogBuffer::getInstance() { + if (mInstance == nullptr) { + lock_guard<mutex> guard(sLock); + if (mInstance == nullptr) { + mInstance = new LogBuffer(); + } + } + return mInstance; +} + +LogBuffer::LogBuffer(): mLogList(TOTAL_LOG_LEVELS), + mConfigVec(TOTAL_LOG_LEVELS, ConfigsInLevel(TIME_DEPTH_THRESHOLD_MINIMAL_IN_SEC, + MAXIMUM_NUM_IN_LIST, 0)) { + loc_param_s_type log_buff_config_table[] = + { + {"E_LEVEL_TIME_DEPTH", &mConfigVec[0].mTimeDepthThres, NULL, 'n'}, + {"E_LEVEL_MAX_CAPACITY", &mConfigVec[0].mMaxNumThres, NULL, 'n'}, + {"W_LEVEL_TIME_DEPTH", &mConfigVec[1].mTimeDepthThres, NULL, 'n'}, + {"W_LEVEL_MAX_CAPACITY", &mConfigVec[1].mMaxNumThres, NULL, 'n'}, + {"I_LEVEL_TIME_DEPTH", &mConfigVec[2].mTimeDepthThres, NULL, 'n'}, + {"I_LEVEL_MAX_CAPACITY", &mConfigVec[2].mMaxNumThres, NULL, 'n'}, + {"D_LEVEL_TIME_DEPTH", &mConfigVec[3].mTimeDepthThres, NULL, 'n'}, + {"D_LEVEL_MAX_CAPACITY", &mConfigVec[3].mMaxNumThres, NULL, 'n'}, + {"V_LEVEL_TIME_DEPTH", &mConfigVec[4].mTimeDepthThres, NULL, 'n'}, + {"V_LEVEL_MAX_CAPACITY", &mConfigVec[4].mMaxNumThres, NULL, 'n'}, + }; + loc_read_conf(LOC_PATH_GPS_CONF_STR, log_buff_config_table, + sizeof(log_buff_config_table)/sizeof(log_buff_config_table[0])); + registerSignalHandler(); +} + +void LogBuffer::append(string& data, int level, uint64_t timestamp) { + lock_guard<mutex> guard(mLock); + pair<uint64_t, string> item(timestamp, data); + mLogList.append(item, level); + mConfigVec[level].mCurrentSize++; + + while ((timestamp - mLogList.front(level).first) > mConfigVec[level].mTimeDepthThres || + mConfigVec[level].mCurrentSize > mConfigVec[level].mMaxNumThres) { + mLogList.pop(level); + mConfigVec[level].mCurrentSize--; + } +} + +//Dump the log buffer of specific level, level = -1 to dump all the levels in log buffer. +void LogBuffer::dump(std::function<void(stringstream&)> log, int level) { + lock_guard<mutex> guard(mLock); + list<pair<pair<uint64_t, string>, int>> li; + if (-1 == level) { + li = mLogList.dump(); + } else { + li = mLogList.dump(level); + } + ALOGE("Begining of dump, buffer size: %d", (int)li.size()); + stringstream ln; + ln << "dump log buffer, level[" << level << "]" << ", buffer size: " << li.size() << endl; + log(ln); + for_each (li.begin(), li.end(), [&, this](const pair<pair<uint64_t, string>, int> &item){ + stringstream line; + line << "["<<item.first.first << "] "; + line << "Level " << mLevelMap[item.second] << ": "; + line << item.first.second << endl; + if (log != nullptr) { + log(line); + } + }); + ALOGE("End of dump"); +} + +void LogBuffer::dumpToAdbLogcat() { + dump([](stringstream& line){ + ALOGE("%s", line.str().c_str()); + }); +} + +void LogBuffer::dumpToLogFile(string filePath) { + ALOGE("Dump GPS log buffer to file: %s", filePath.c_str()); + fstream s; + s.open(filePath, std::fstream::out | std::fstream::app); + dump([&s](stringstream& line){ + s << line.str(); + }); + s.close(); +} + +void LogBuffer::flush() { + mLogList.flush(); +} + +void LogBuffer::registerSignalHandler() { + ALOGE("Singal handler registered"); + mNewSigAction.sa_sigaction = &LogBuffer::signalHandler; + mNewSigAction.sa_flags = SA_SIGINFO; + sigemptyset(&mNewSigAction.sa_mask); + + sigaction(SIGINT, &mNewSigAction, &mOriSigAction[SIGINT]); + sigaction(SIGKILL, &mNewSigAction, &mOriSigAction[SIGKILL]); + sigaction(SIGSEGV, &mNewSigAction, &mOriSigAction[SIGSEGV]); + sigaction(SIGABRT, &mNewSigAction, &mOriSigAction[SIGABRT]); + sigaction(SIGTRAP, &mNewSigAction, &mOriSigAction[SIGTRAP]); + sigaction(SIGUSR1, &mNewSigAction, &mOriSigAction[SIGUSR1]); +} + +void LogBuffer::signalHandler(const int code, siginfo_t *const si, void *const sc) { + ALOGE("[Gnss Log buffer]Singal handler, signal ID: %d", code); + + //Dump the log buffer to adb logcat + mInstance->dumpToAdbLogcat(); + + //Dump the log buffer to file + time_t now = time(NULL); + struct tm *curr_time = localtime(&now); + char path[50]; + snprintf(path, 50, LOG_BUFFER_FILE_PATH "gpslog_%d%d%d-%d%d%d.log", + (1900 + curr_time->tm_year), ( 1 + curr_time->tm_mon), curr_time->tm_mday, + curr_time->tm_hour, curr_time->tm_min, curr_time->tm_sec); + + mInstance->dumpToLogFile(path); + + //Process won't be terminated if SIGUSR1 is recieved + if (code != SIGUSR1) { + mOriSigAction[code].sa_sigaction(code, si, sc); + } +} + +} diff --git a/utils/LogBuffer.h b/utils/LogBuffer.h new file mode 100644 index 0000000..8d90439 --- /dev/null +++ b/utils/LogBuffer.h @@ -0,0 +1,95 @@ +/* Copyright (c) 2019 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOG_BUFFER_H +#define LOG_BUFFER_H + +#include "SkipList.h" +#include "log_util.h" +#include <loc_cfg.h> +#include <loc_pla.h> +#include <string> +#include <sstream> +#include <ostream> +#include <fstream> +#include <time.h> +#include <mutex> +#include <signal.h> +#include <thread> +#include <functional> + +//default error level time depth threshold, +#define TIME_DEPTH_THRESHOLD_MINIMAL_IN_SEC 60 +//default maximum log buffer size +#define MAXIMUM_NUM_IN_LIST 50 +//file path of dumped log buffer +#define LOG_BUFFER_FILE_PATH "/data/vendor/location/" + +namespace loc_util { + +class ConfigsInLevel{ +public: + uint32_t mTimeDepthThres; + uint32_t mMaxNumThres; + int mCurrentSize; + + ConfigsInLevel(uint32_t time, int num, int size): + mTimeDepthThres(time), mMaxNumThres(num), mCurrentSize(size) {} +}; + +class LogBuffer { +private: + static LogBuffer* mInstance; + static struct sigaction mOriSigAction[NSIG]; + static struct sigaction mNewSigAction; + static mutex sLock; + + SkipList<pair<uint64_t, string>> mLogList; + vector<ConfigsInLevel> mConfigVec; + mutex mLock; + + const vector<string> mLevelMap {"E", "W", "I", "D", "V"}; + +public: + static LogBuffer* getInstance(); + void append(string& data, int level, uint64_t timestamp); + void dump(std::function<void(stringstream&)> log, int level = -1); + void dumpToAdbLogcat(); + void dumpToLogFile(string filePath); + void flush(); +private: + LogBuffer(); + void registerSignalHandler(); + static void signalHandler(const int code, siginfo_t *const si, void *const sc); + +}; + +} + +#endif diff --git a/utils/Makefile.am b/utils/Makefile.am index 9a9c67e..72c7872 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -23,6 +23,7 @@ libgps_utils_la_h_sources = \ LocThread.h \ LocTimer.h \ LocIpc.h \ + SkipList.h\ loc_misc_utils.h \ loc_nmea.h \ gps_extended_c.h \ @@ -42,6 +43,7 @@ libgps_utils_la_c_sources = \ LocTimer.cpp \ LocThread.cpp \ LocIpc.cpp \ + LogBuffer.cpp \ MsgTask.cpp \ loc_misc_utils.cpp \ loc_nmea.cpp diff --git a/utils/SkipList.h b/utils/SkipList.h new file mode 100644 index 0000000..afaa1a6 --- /dev/null +++ b/utils/SkipList.h @@ -0,0 +1,158 @@ +/* Copyright (c) 2019 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_SKIP_LIST_H +#define LOC_SKIP_LIST_H + +#include <stdlib.h> +#include <list> +#include <vector> +#include <iostream> +#include <algorithm> + +using namespace std; + +namespace loc_util { + +template <typename T, + template<typename elem, typename Allocator = std::allocator<elem>> class container = list> +class SkipNode { +public: + typedef typename container<SkipNode<T, container>>::iterator NodeIterator; + + int mLevel; + T mData; + NodeIterator mNextInLevel; + + SkipNode(int level, T& data): mLevel(level), mData(data) {} +}; + +template <typename T> +class SkipList { + using NodeIterator = typename SkipNode<T>::NodeIterator; +private: + list<SkipNode<T>> mMainList; + vector<NodeIterator> mHeadVec; + vector<NodeIterator> mTailVec; +public: + SkipList(int totalLevels); + void append(T& data, int level); + void pop(int level); + void pop(); + T front(int level); + int size(); + void flush(); + list<pair<T, int>> dump(); + list<pair<T, int>> dump(int level); +}; + +template <typename T> +SkipList<T>::SkipList(int totalLevels): mHeadVec(totalLevels, mMainList.end()), + mTailVec(totalLevels, mMainList.end()) {} + +template <typename T> +void SkipList<T>::append(T& data, int level) { + if ( level < 0 || level >= mHeadVec.size()) { + return; + } + + SkipNode<T> node(level, data); + node.mNextInLevel = mMainList.end(); + mMainList.push_back(node); + auto iter = --mMainList.end(); + if (mHeadVec[level] == mMainList.end()) { + mHeadVec[level] = iter; + } else { + (*mTailVec[level]).mNextInLevel = iter; + } + mTailVec[level] = iter; +} + +template <typename T> +void SkipList<T>::pop(int level) { + if (mHeadVec[level] == mMainList.end()) { + return; + } + + if ((*mHeadVec[level]).mNextInLevel == mMainList.end()) { + mTailVec[level] = mMainList.end(); + } + + auto tmp_iter = (*mHeadVec[level]).mNextInLevel; + mMainList.erase(mHeadVec[level]); + mHeadVec[level] = tmp_iter; +} + +template <typename T> +void SkipList<T>::pop() { + pop(mMainList.front().mLevel); +} + +template <typename T> +T SkipList<T>::front(int level) { + return (*mHeadVec[level]).mData; +} + +template <typename T> +int SkipList<T>::size() { + return mMainList.size(); +} + +template <typename T> +void SkipList<T>::flush() { + mMainList.clear(); + for (int i = 0; i < mHeadVec.size(); i++) { + mHeadVec[i] = mMainList.end(); + mTailVec[i] = mMainList.end(); + } +} + +template <typename T> +list<pair<T, int>> SkipList<T>::dump() { + list<pair<T, int>> li; + for_each(mMainList.begin(), mMainList.end(), [&](SkipNode<T> &item) { + li.push_back(make_pair(item.mData, item.mLevel)); + }); + return li; +} + +template <typename T> +list<pair<T, int>> SkipList<T>::dump(int level) { + list<pair<T, int>> li; + auto head = mHeadVec[level]; + while (head != mMainList.end()) { + li.push_back(make_pair((*head).mData, (*head).mLevel)); + head = (*head).mNextInLevel; + } + return li; +} + +} + +#endif diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index 62985d2..f4ad524 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -2089,26 +2089,6 @@ typedef struct Gnss_Srn_MacAddr_Type macAddrType; /* SRN AP MAC Address type */ } GnssSrnDataReq; -/* Mask indicating enabled or disabled constellations */ -typedef uint64_t GnssSvTypesMask; -typedef enum { - GNSS_SV_TYPES_MASK_GLO_BIT = (1<<0), - GNSS_SV_TYPES_MASK_BDS_BIT = (1<<1), - GNSS_SV_TYPES_MASK_QZSS_BIT = (1<<2), - GNSS_SV_TYPES_MASK_GAL_BIT = (1<<3), - GNSS_SV_TYPES_MASK_NAVIC_BIT = (1<<4), -} GnssSvTypesMaskBits; - -/* This SV Type config is injected directly to GNSS Adapter - * bypassing Location API */ -typedef struct { - uint32_t size; // set to sizeof(GnssSvTypeConfig) - // Enabled Constellations - GnssSvTypesMask enabledSvTypesMask; - // Disabled Constellations - GnssSvTypesMask blacklistedSvTypesMask; -} GnssSvTypeConfig; - /* Provides the current GNSS SV Type configuration to the client. * This is fetched via direct call to GNSS Adapter bypassing * Location API */ @@ -2242,6 +2222,7 @@ enum PowerStateType { #define EAP_LOC_CLIENT_DIR "/data/vendor/location/extap_locclient/" #define LOC_CLIENT_NAME_PREFIX "toclient" +#define LOC_INTAPI_NAME_PREFIX "toIntapiClient" typedef uint64_t NetworkHandle; #define NETWORK_HANDLE_UNKNOWN ~0 diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index 8baf8ca..432095e 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -59,13 +59,15 @@ static uint32_t DEBUG_LEVEL = 0xff; static uint32_t TIMESTAMP = 0; static uint32_t DATUM_TYPE = 0; static bool sVendorEnhanced = true; +static uint32_t sLogBufferEnabled = 0; /* Parameter spec table */ static const loc_param_s_type loc_param_table[] = { - {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, - {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, - {"DATUM_TYPE", &DATUM_TYPE, NULL, 'n'}, + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, + {"DATUM_TYPE", &DATUM_TYPE, NULL, 'n'}, + {"LOG_BUFFER_ENABLED", &sLogBufferEnabled, NULL, 'n'}, }; static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); @@ -429,6 +431,7 @@ void loc_read_conf(const char* conf_file_name, const loc_param_s_type* config_ta { FILE *conf_fp = NULL; + log_buffer_init(false); if((conf_fp = fopen(conf_file_name, "r")) != NULL) { LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); @@ -441,6 +444,7 @@ void loc_read_conf(const char* conf_file_name, const loc_param_s_type* config_ta } /* Initialize logging mechanism with parsed data */ loc_logger_init(DEBUG_LEVEL, TIMESTAMP); + log_buffer_init(sLogBufferEnabled); } /*============================================================================= diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp index ab28998..2c6a3fa 100644 --- a/utils/loc_log.cpp +++ b/utils/loc_log.cpp @@ -31,11 +31,13 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <sys/time.h> #include "log_util.h" #include "loc_log.h" #include "msg_q.h" #include <loc_pla.h> +#include "LogBuffer.h" #define BUFFER_SIZE 120 @@ -179,35 +181,6 @@ char *loc_get_time(char *time_string, size_t buf_size) return time_string; } - -/*=========================================================================== -FUNCTION loc_logger_init - -DESCRIPTION - Initializes the state of DEBUG_LEVEL and TIMESTAMP - -DEPENDENCIES - N/A - -RETURN VALUE - None - -SIDE EFFECTS - N/A -===========================================================================*/ -void loc_logger_init(unsigned long debug, unsigned long timestamp) -{ - loc_logger.DEBUG_LEVEL = debug; -#ifdef TARGET_BUILD_VARIANT_USER - // force user builds to 2 or less - if (loc_logger.DEBUG_LEVEL > 2) { - loc_logger.DEBUG_LEVEL = 2; - } -#endif - loc_logger.TIMESTAMP = timestamp; -} - - /*=========================================================================== FUNCTION get_timestamp @@ -236,3 +209,22 @@ char * get_timestamp(char *str, unsigned long buf_size) return str; } +/*=========================================================================== + +FUNCTION log_buffer_insert + +DESCRIPTION + Insert a log sentence with specific level to the log buffer. + +RETURN VALUE + N/A + +===========================================================================*/ +void log_buffer_insert(char *str, unsigned long buf_size, int level) +{ + timespec tv; + clock_gettime(CLOCK_BOOTTIME, &tv); + uint64_t elapsedTime = (uint64_t)tv.tv_sec + (uint64_t)tv.tv_nsec/1000000000; + string ss = str; + loc_util::LogBuffer::getInstance()->append(ss, level, elapsedTime); +} diff --git a/utils/loc_nmea.cpp b/utils/loc_nmea.cpp index 876620f..9ee2716 100644 --- a/utils/loc_nmea.cpp +++ b/utils/loc_nmea.cpp @@ -1195,7 +1195,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, (location, locationExtended, systemInfo, utcPosTimestamp); time_t utcTime(utcPosTimestamp/1000); - tm * pTm = gmtime(&utcTime); + struct tm result; + tm * pTm = gmtime_r(&utcTime, &result); if (NULL == pTm) { LOC_LOGE("gmtime failed"); return; diff --git a/utils/log_util.h b/utils/log_util.h index 192baeb..13c08bc 100644 --- a/utils/log_util.h +++ b/utils/log_util.h @@ -30,9 +30,13 @@ #ifndef __LOG_UTIL_H__ #define __LOG_UTIL_H__ +#include <stdbool.h> + #if defined (USE_ANDROID_LOGGING) || defined (ANDROID) // Android and LE targets with logcat support #include <utils/Log.h> +#include <unistd.h> +#include <sys/syscall.h> #elif defined (USE_GLIB) // LE targets with no logcat support @@ -41,6 +45,7 @@ #include <sys/types.h> #include <sys/time.h> #include <unistd.h> +#include <sys/syscall.h> #ifndef LOG_TAG #define LOG_TAG "GPS_UTILS" @@ -90,18 +95,20 @@ typedef struct loc_logger_s { unsigned long DEBUG_LEVEL; unsigned long TIMESTAMP; + bool LOG_BUFFER_ENABLE; } loc_logger_s_type; + /*============================================================================= * * EXTERNAL DATA * *============================================================================*/ -extern loc_logger_s_type loc_logger; // Logging Improvements extern const char *loc_logger_boolStr[]; +extern loc_logger_s_type loc_logger; extern const char *boolStr[]; extern const char VOID_RET[]; extern const char FROM_AFW[]; @@ -117,8 +124,49 @@ extern const char EXIT_ERROR_TAG[]; * MODULE EXPORTED FUNCTIONS * *============================================================================*/ -extern void loc_logger_init(unsigned long debug, unsigned long timestamp); +inline void loc_logger_init(unsigned long debug, unsigned long timestamp) +{ + loc_logger.DEBUG_LEVEL = debug; +#ifdef TARGET_BUILD_VARIANT_USER + // force user builds to 2 or less + if (loc_logger.DEBUG_LEVEL > 2) { + loc_logger.DEBUG_LEVEL = 2; + } +#endif + loc_logger.TIMESTAMP = timestamp; +} + +inline void log_buffer_init(bool enabled) { + loc_logger.LOG_BUFFER_ENABLE = enabled; +} + extern char* get_timestamp(char* str, unsigned long buf_size); +extern void log_buffer_insert(char *str, unsigned long buf_size, int level); + +/*============================================================================= + * + * LOGGING BUFFER MACROS + * + *============================================================================*/ +#ifndef LOG_NDEBUG +#define LOG_NDEBUG 0 +#endif +#define TOTAL_LOG_LEVELS 5 +#define LOGGING_BUFFER_MAX_LEN 1024 +#define IF_LOG_BUFFER_ENABLE if (loc_logger.LOG_BUFFER_ENABLE) +#define INSERT_BUFFER(flag, level, format, x...) \ +{ \ + IF_LOG_BUFFER_ENABLE { \ + if (flag == 0) { \ + char timestr[32]; \ + get_timestamp(timestr, sizeof(timestr)); \ + char log_str[LOGGING_BUFFER_MAX_LEN]; \ + snprintf(log_str, LOGGING_BUFFER_MAX_LEN, "%s %d %ld %s :" format "\n", \ + timestr, getpid(), syscall(SYS_gettid), LOG_TAG==NULL ? "": LOG_TAG, ##x);\ + log_buffer_insert(log_str, sizeof(log_str), level); \ + } \ + } \ +} #ifndef DEBUG_DMN_LOC_API @@ -133,11 +181,11 @@ extern char* get_timestamp(char* str, unsigned long buf_size); #define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) #define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) -#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); } -#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); } -#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); } -#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); } -#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); } +#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 0, __VA_ARGS__);} +#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 1, __VA_ARGS__);} +#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 2, __VA_ARGS__);} +#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 3, __VA_ARGS__);} +#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 4, __VA_ARGS__);} #else /* DEBUG_DMN_LOC_API */ diff --git a/utils/msg_q.c b/utils/msg_q.c index 2d49b4a..3383960 100644 --- a/utils/msg_q.c +++ b/utils/msg_q.c @@ -26,6 +26,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// Uncomment to log verbose logs +#define LOG_NDEBUG 1 #define LOG_TAG "LocSvc_utils_q" #include <stdio.h> #include <stdlib.h> |