diff options
author | Bhavna Sharma <sbhavna@codeaurora.org> | 2019-10-02 16:29:38 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2019-11-06 11:46:24 -0800 |
commit | 6bfa690c483ed3f58a28062dbafc2843e0502a52 (patch) | |
tree | 446a4a3c7ba4c0381870e7cf92090f192046e36e | |
parent | 1a16cbc20ca334b0a0a2793db3aa2984a6b6b66a (diff) | |
download | gps-6bfa690c483ed3f58a28062dbafc2843e0502a52.tar.gz |
Handle SPE session TBF and nHz subscription for automotive
1. Requirement is to run SPE session only at 100ms TBF
if any nHz capable engine subscribes for nHz measurement
or nHz position reports.
2. Second requirement is to subscribe for nHz measurement
only if an an actual nHz engine subscribes for nHz measurement
CRs-Fixed: 2540001
Change-Id: I5a2c93a9d880967ab59ce6cd12cd415c98f29e6c
-rw-r--r-- | core/EngineHubProxyBase.h | 6 | ||||
-rw-r--r-- | gnss/GnssAdapter.cpp | 136 | ||||
-rw-r--r-- | gnss/GnssAdapter.h | 4 |
3 files changed, 117 insertions, 29 deletions
diff --git a/core/EngineHubProxyBase.h b/core/EngineHubProxyBase.h index ec881f6..2d30c5b 100644 --- a/core/EngineHubProxyBase.h +++ b/core/EngineHubProxyBase.h @@ -113,6 +113,9 @@ typedef std::function<void(const GnssSvNotification& svNotify, typedef std::function<void(const GnssAidingDataSvMask& svDataMask)> GnssAdapterReqAidingDataCb; +typedef std::function<void(bool nHzNeeded, bool nHzMeasNeeded)> + GnssAdapterUpdateNHzRequirementCb; + // potential parameters: message queue: MsgTask * msgTask; // callback function to report back dr and ppe position and sv report typedef EngineHubProxyBase* (getEngHubProxyFn)( @@ -120,7 +123,8 @@ typedef EngineHubProxyBase* (getEngHubProxyFn)( IOsObserver* osObserver, GnssAdapterReportEnginePositionsEventCb positionEventCb, GnssAdapterReportSvEventCb svEventCb, - GnssAdapterReqAidingDataCb reqAidingDataCb); + GnssAdapterReqAidingDataCb reqAidingDataCb, + GnssAdapterUpdateNHzRequirementCb updateNHzRequirementCb); } // namespace loc_core diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 11f6777..dee969a 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -45,7 +45,6 @@ #include <loc_nmea.h> #include <Agps.h> #include <SystemStatus.h> - #include <vector> #define RAD2DEG (180.0 / M_PI) @@ -71,6 +70,8 @@ GnssAdapter::GnssAdapter() : true, nullptr, true), mEngHubProxy(new EngineHubProxyBase()), mLocPositionMode(), + mNHzNeeded(false), + mSPEAlreadyRunningAtHighestInterval(false), mGnssSvIdUsedInPosition(), mGnssSvIdUsedInPosAvail(false), mControlCallbacks(), @@ -173,6 +174,30 @@ GnssAdapter::convertOptions(LocPosMode& out, const TrackingOptions& trackingOpti out.timeBetweenMeasurements = trackingOptions.tbm; } +bool +GnssAdapter::checkAndSetSPEToRunforNHz(TrackingOptions & out) { + // first check if NHz meas is needed at all, if not, just return false + // if a NHz capable engine is subscribed for NHz measurement or NHz positions, + // always run the SPE only session at 100ms TBF. + // If SPE session is already set to highest interval, no need to start it again. + + bool isSPERunningAtHighestInterval = false; + + if (!mNHzNeeded) { + LOC_LOGd("No nHz session needed."); + } else if (mSPEAlreadyRunningAtHighestInterval) { + LOC_LOGd("SPE is already running at highest interval."); + isSPERunningAtHighestInterval = true; + } else if (out.minInterval > MIN_TRACKING_INTERVAL) { + out.minInterval = MIN_TRACKING_INTERVAL; + LOC_LOGd("nHz session is needed, starting SPE only session at 100ms TBF."); + mSPEAlreadyRunningAtHighestInterval = true; + } + + return isSPERunningAtHighestInterval; +} + + void GnssAdapter::convertLocation(Location& out, const UlpLocation& ulpLocation, const GpsLocationExtended& locationExtended, @@ -2089,13 +2114,16 @@ GnssAdapter::updateClientsEventMask() if((1 == ContextBase::mGps_conf.EXTERNAL_DR_ENABLED) || (true == initEngHubProxy())) { mask |= LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; - mask |= LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT; mask |= LOC_API_ADAPTER_BIT_GNSS_SV_POLYNOMIAL_REPORT; mask |= LOC_API_ADAPTER_BIT_PARSED_UNPROPAGATED_POSITION_REPORT; mask |= LOC_API_ADAPTER_BIT_GNSS_SV_EPHEMERIS_REPORT; mask |= LOC_API_ADAPTER_BIT_LOC_SYSTEM_INFO; mask |= LOC_API_ADAPTER_BIT_EVENT_REPORT_INFO; + // Nhz measurement bit is set based on callback from loc eng hub + // for Nhz engines. + mask |= checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT); + LOC_LOGd("Auto usecase, Enable MEAS/POLY/EPHEMERIS - mask 0x%" PRIx64 "", mask); } @@ -2155,13 +2183,31 @@ GnssAdapter::restartSessions() // odcpi session is no longer active after restart mOdcpiRequestActive = false; + // SPE will be restarted now, so set this variable to false. + mSPEAlreadyRunningAtHighestInterval = false; + + checkAndRestartTimeBasedSession(); + + for (auto it = mDistanceBasedTrackingSessions.begin(); + it != mDistanceBasedTrackingSessions.end(); ++it) { + mLocApi->startDistanceBasedTracking(it->first.id, it->second, + new LocApiResponse(*getContext(), + [] (LocationError /*err*/) {})); + } +} + +void GnssAdapter::checkAndRestartTimeBasedSession() +{ + LOC_LOGD("%s]: ", __func__); + if (!mTimeBasedTrackingSessions.empty()) { // get the LocationOptions that has the smallest interval, which should be the active one TrackingOptions smallestIntervalOptions; // size is zero until set for the first time TrackingOptions highestPowerTrackingOptions; memset(&smallestIntervalOptions, 0, sizeof(smallestIntervalOptions)); memset(&highestPowerTrackingOptions, 0, sizeof(highestPowerTrackingOptions)); - for (auto it = mTimeBasedTrackingSessions.begin(); it != mTimeBasedTrackingSessions.end(); ++it) { + for (auto it = mTimeBasedTrackingSessions.begin(); + it != mTimeBasedTrackingSessions.end(); ++it) { // size of zero means we havent set it yet if (0 == smallestIntervalOptions.size || it->second.minInterval < smallestIntervalOptions.minInterval) { @@ -2177,14 +2223,10 @@ GnssAdapter::restartSessions() } highestPowerTrackingOptions.setLocationOptions(smallestIntervalOptions); - mLocApi->startTimeBasedTracking(highestPowerTrackingOptions, nullptr); - } - - for (auto it = mDistanceBasedTrackingSessions.begin(); - it != mDistanceBasedTrackingSessions.end(); ++it) { - mLocApi->startDistanceBasedTracking(it->first.id, it->second, - new LocApiResponse(*getContext(), - [] (LocationError /*err*/) {})); + // want to run SPE session at a fixed min interval in some automotive scenarios + if(!checkAndSetSPEToRunforNHz(highestPowerTrackingOptions)) { + mLocApi->startTimeBasedTracking(highestPowerTrackingOptions, nullptr); + } } } @@ -2491,6 +2533,7 @@ GnssAdapter::startTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t sessi multiplexedOptions.minInterval = options.minInterval; updateOptions = true; } + // if session we are starting has smaller powerMode then next smallest if (options.powerMode < multiplexedPowerMode) { multiplexedOptions.powerMode = options.powerMode; @@ -2524,15 +2567,24 @@ GnssAdapter::startTimeBasedTracking(LocationAPI* client, uint32_t sessionId, mEngHubProxy->gnssSetFixMode(locPosMode); mEngHubProxy->gnssStartFix(); - mLocApi->startTimeBasedTracking(trackingOptions, new LocApiResponse(*getContext(), - [this, client, sessionId] (LocationError err) { - if (LOCATION_ERROR_SUCCESS != err) { - eraseTrackingSession(client, sessionId); + // want to run SPE session at a fixed min interval in some automotive scenarios + // use a local copy of TrackingOptions as the TBF may get modified in the + // checkAndSetSPEToRunforNHz function + TrackingOptions tempOptions(trackingOptions); + if (!checkAndSetSPEToRunforNHz(tempOptions)) { + mLocApi->startTimeBasedTracking(tempOptions, new LocApiResponse(*getContext(), + [this, client, sessionId] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + eraseTrackingSession(client, sessionId); + } + + reportResponse(client, err, sessionId); } + )); + } else { + reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId); + } - reportResponse(client, err, sessionId); - } - )); } void @@ -2546,16 +2598,23 @@ GnssAdapter::updateTracking(LocationAPI* client, uint32_t sessionId, mEngHubProxy->gnssSetFixMode(locPosMode); mEngHubProxy->gnssStartFix(); - mLocApi->startTimeBasedTracking(updatedOptions, new LocApiResponse(*getContext(), - [this, client, sessionId, oldOptions] (LocationError err) { - if (LOCATION_ERROR_SUCCESS != err) { - // restore the old LocationOptions - saveTrackingSession(client, sessionId, oldOptions); + // want to run SPE session at a fixed min interval in some automotive scenarios + // use a local copy of TrackingOptions as the TBF may get modified in the + // checkAndSetSPEToRunforNHz function + TrackingOptions tempOptions(updatedOptions); + if(!checkAndSetSPEToRunforNHz(tempOptions)) { + mLocApi->startTimeBasedTracking(tempOptions, new LocApiResponse(*getContext(), + [this, client, sessionId, oldOptions] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + // restore the old LocationOptions + saveTrackingSession(client, sessionId, oldOptions); + } + reportResponse(client, err, sessionId); } - - reportResponse(client, err, sessionId); - } - )); + )); + } else { + reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId); + } } void @@ -2856,6 +2915,8 @@ GnssAdapter::stopTracking(LocationAPI* client, uint32_t id) [this, client, id] (LocationError err) { reportResponse(client, err, id); })); + + mSPEAlreadyRunningAtHighestInterval = false; } bool @@ -5023,11 +5084,30 @@ GnssAdapter::initEngHubProxy() { mLocApi->requestForAidingData(svDataMask); }; + GnssAdapterUpdateNHzRequirementCb updateNHzRequirementCb = + [this] (bool nHzNeeded, bool nHzMeasNeeded) { + + if (nHzMeasNeeded && + (!checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT))) { + updateEvtMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT, + LOC_REGISTRATION_MASK_ENABLED); + } else if (checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT)) { + updateEvtMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT, + LOC_REGISTRATION_MASK_DISABLED); + } + + if (mNHzNeeded != nHzNeeded) { + mNHzNeeded = nHzNeeded; + checkAndRestartTimeBasedSession(); + } + }; + getEngHubProxyFn* getter = (getEngHubProxyFn*) dlsym(handle, "getEngHubProxy"); if(getter != nullptr) { EngineHubProxyBase* hubProxy = (*getter) (mMsgTask, mSystemStatus->getOsObserver(), reportPositionEventCb, - reportSvEventCb, reqAidingDataCb); + reportSvEventCb, reqAidingDataCb, + updateNHzRequirementCb); if (hubProxy != nullptr) { mEngHubProxy = hubProxy; engHubLoadSuccessful = true; diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 3ccdd96..1bcf4b7 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -138,6 +138,8 @@ class GnssAdapter : public LocAdapterBase { /* ==== Engine Hub ===================================================================== */ EngineHubProxyBase* mEngHubProxy; + bool mNHzNeeded; + bool mSPEAlreadyRunningAtHighestInterval; /* ==== TRACKING ======================================================================= */ TrackingOptionsMap mTimeBasedTrackingSessions; @@ -228,6 +230,7 @@ public: virtual void handleEngineUpEvent(); /* ======== UTILITIES ================================================================== */ void restartSessions(); + void checkAndRestartTimeBasedSession(); /* ==== CLIENT ========================================================================= */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ @@ -265,6 +268,7 @@ public: const TrackingOptions& trackingOptions); void updateTracking(LocationAPI* client, uint32_t sessionId, const TrackingOptions& updatedOptions, const TrackingOptions& oldOptions); + bool checkAndSetSPEToRunforNHz(TrackingOptions & out); /* ==== NI ============================================================================= */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ |