diff options
Diffstat (limited to 'gps/gnss')
-rw-r--r-- | gps/gnss/Agps.cpp | 2 | ||||
-rw-r--r-- | gps/gnss/Agps.h | 20 | ||||
-rw-r--r-- | gps/gnss/Android.mk | 1 | ||||
-rw-r--r-- | gps/gnss/GnssAdapter.cpp | 546 | ||||
-rw-r--r-- | gps/gnss/GnssAdapter.h | 56 | ||||
-rw-r--r-- | gps/gnss/Makefile.am | 84 | ||||
-rw-r--r-- | gps/gnss/XtraSystemStatusObserver.cpp | 146 | ||||
-rw-r--r-- | gps/gnss/XtraSystemStatusObserver.h | 44 | ||||
-rw-r--r-- | gps/gnss/location_gnss.cpp | 33 |
9 files changed, 587 insertions, 345 deletions
diff --git a/gps/gnss/Agps.cpp b/gps/gnss/Agps.cpp index 72ce293..6ce0c34 100644 --- a/gps/gnss/Agps.cpp +++ b/gps/gnss/Agps.cpp @@ -30,7 +30,7 @@ #define LOG_TAG "LocSvc_Agps" #include <Agps.h> -#include <platform_lib_includes.h> +#include <loc_pla.h> #include <ContextBase.h> #include <loc_timer.h> diff --git a/gps/gnss/Agps.h b/gps/gnss/Agps.h index 2f89c8c..703a475 100644 --- a/gps/gnss/Agps.h +++ b/gps/gnss/Agps.h @@ -34,7 +34,8 @@ #include <list> #include <MsgTask.h> #include <gps_extended_c.h> -#include <platform_lib_log_util.h> +#include <loc_pla.h> +#include <log_util.h> /* ATL callback function pointers * Passed in by Adapter to AgpsManager */ @@ -277,34 +278,29 @@ public: mAgnssNif(NULL), mInternetNif(NULL), mDsNif(NULL) {} /* Register callbacks */ - void registerCallbacks( - AgnssStatusIpV4Cb frameworkStatusV4Cb, - - AgpsAtlOpenStatusCb atlOpenStatusCb, + inline void registerATLCallbacks(AgpsAtlOpenStatusCb atlOpenStatusCb, AgpsAtlCloseStatusCb atlCloseStatusCb, - AgpsDSClientInitFn dsClientInitFn, AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn, AgpsDSClientStopDataCallFn dsClientStopDataCallFn, AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn, AgpsDSClientReleaseFn dsClientReleaseFn, - - SendMsgToAdapterMsgQueueFn sendMsgToAdapterQueueFn ){ - - mFrameworkStatusV4Cb = frameworkStatusV4Cb; + SendMsgToAdapterMsgQueueFn sendMsgToAdapterQueueFn) { mAtlOpenStatusCb = atlOpenStatusCb; mAtlCloseStatusCb = atlCloseStatusCb; - mDSClientInitFn = dsClientInitFn; mDSClientOpenAndStartDataCallFn = dsClientOpenAndStartDataCallFn; mDSClientStopDataCallFn = dsClientStopDataCallFn; mDSClientCloseDataCallFn = dsClientCloseDataCallFn; mDSClientReleaseFn = dsClientReleaseFn; - mSendMsgToAdapterQueueFn = sendMsgToAdapterQueueFn; } + inline void registerFrameworkStatusCallback(AgnssStatusIpV4Cb frameworkStatusV4Cb) { + mFrameworkStatusV4Cb = frameworkStatusV4Cb; + } + /* Create all AGPS state machines */ void createAgpsStateMachines(); diff --git a/gps/gnss/Android.mk b/gps/gnss/Android.mk index e5b9dcc..d809bc2 100644 --- a/gps/gnss/Android.mk +++ b/gps/gnss/Android.mk @@ -7,7 +7,6 @@ include $(CLEAR_VARS) LOCAL_MODULE := libgnss LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_OWNER := qti LOCAL_MODULE_TAGS := optional LOCAL_SHARED_LIBRARIES := \ diff --git a/gps/gnss/GnssAdapter.cpp b/gps/gnss/GnssAdapter.cpp index cdda01d..751c148 100644 --- a/gps/gnss/GnssAdapter.cpp +++ b/gps/gnss/GnssAdapter.cpp @@ -74,12 +74,79 @@ GnssAdapter::GnssAdapter() : mNiData(), mAgpsManager(), mAgpsCbInfo(), + mOdcpiRequestCb(nullptr), + mOdcpiRequestActive(false), + mOdcpiTimer(this), + mOdcpiRequest(), mSystemStatus(SystemStatus::getInstance(mMsgTask)), - mServerUrl(""), + mServerUrl(":"), mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask) { LOC_LOGD("%s]: Constructor %p", __func__, this); mUlpPositionMode.mode = LOC_POSITION_MODE_INVALID; + + pthread_condattr_t condAttr; + pthread_condattr_init(&condAttr); + pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC); + pthread_cond_init(&mNiData.session.tCond, &condAttr); + pthread_cond_init(&mNiData.sessionEs.tCond, &condAttr); + pthread_condattr_destroy(&condAttr); + + /* Set ATL open/close callbacks */ + AgpsAtlOpenStatusCb atlOpenStatusCb = + [this](int handle, int isSuccess, char* apn, + AGpsBearerType bearerType, AGpsExtType agpsType) { + + mLocApi->atlOpenStatus( + handle, isSuccess, apn, bearerType, agpsType); + }; + AgpsAtlCloseStatusCb atlCloseStatusCb = + [this](int handle, int isSuccess) { + + mLocApi->atlCloseStatus(handle, isSuccess); + }; + + /* Register DS Client APIs */ + AgpsDSClientInitFn dsClientInitFn = + [this](bool isDueToSSR) { + + return mLocApi->initDataServiceClient(isDueToSSR); + }; + + AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn = + [this] { + + return mLocApi->openAndStartDataCall(); + }; + + AgpsDSClientStopDataCallFn dsClientStopDataCallFn = + [this] { + + mLocApi->stopDataCall(); + }; + + AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn = + [this] { + + mLocApi->closeDataCall(); + }; + + AgpsDSClientReleaseFn dsClientReleaseFn = + [this] { + + mLocApi->releaseDataServiceClient(); + }; + + /* Send Msg function */ + SendMsgToAdapterMsgQueueFn sendMsgFn = + [this](LocMsg* msg) { + + sendMsg(msg); + }; + mAgpsManager.registerATLCallbacks(atlOpenStatusCb, atlCloseStatusCb, + dsClientInitFn, dsClientOpenAndStartDataCallFn, dsClientStopDataCallFn, + dsClientCloseDataCallFn, dsClientReleaseFn, sendMsgFn); + readConfigCommand(); setConfigCommand(); initDefaultAgpsCommand(); @@ -522,6 +589,38 @@ GnssAdapter::readConfigCommand() } } +LocationError +GnssAdapter::setSuplHostServer(const char* server, int port) +{ + LocationError locErr = LOCATION_ERROR_SUCCESS; + if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) { + char serverUrl[MAX_URL_LEN] = {}; + int32_t length = -1; + const char noHost[] = "NONE"; + + locErr = LOCATION_ERROR_INVALID_PARAMETER; + + if ((NULL == server) || (server[0] == 0) || + (strncasecmp(noHost, server, sizeof(noHost)) == 0)) { + serverUrl[0] = '\0'; + length = 0; + } else if (port > 0) { + length = snprintf(serverUrl, sizeof(serverUrl), "%s:%u", server, port); + } + + if (length >= 0 && strncasecmp(getServerUrl().c_str(), + serverUrl, sizeof(serverUrl)) != 0) { + setServerUrl(serverUrl); + locErr = mLocApi->setServer(serverUrl, length); + if (locErr != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s]:Error while setting SUPL_HOST server:%s", + __func__, serverUrl); + } + } + } + return locErr; +} + void GnssAdapter::setConfigCommand() { @@ -541,6 +640,8 @@ GnssAdapter::setConfigCommand() mApi.setLPPConfig(mAdapter.convertLppProfile(ContextBase::mGps_conf.LPP_PROFILE)); mApi.setAGLONASSProtocol(ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT); } + mAdapter.setSuplHostServer(ContextBase::mGps_conf.SUPL_HOST, + ContextBase::mGps_conf.SUPL_PORT); mApi.setSensorControlConfig(ContextBase::mSap_conf.SENSOR_USAGE, ContextBase::mSap_conf.SENSOR_PROVIDER); mApi.setLPPeProtocolCp( @@ -683,30 +784,8 @@ GnssAdapter::gnssUpdateConfigCommand(GnssConfig config) } if (mConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { if (GNSS_ASSISTANCE_TYPE_SUPL == mConfig.assistanceServer.type) { - if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) { - char serverUrl[MAX_URL_LEN] = {}; - int32_t length = 0; - const char noHost[] = "NONE"; - if (NULL == mConfig.assistanceServer.hostName || - strncasecmp(noHost, - mConfig.assistanceServer.hostName, - sizeof(noHost)) == 0) { - err = LOCATION_ERROR_INVALID_PARAMETER; - } else { - length = snprintf(serverUrl, sizeof(serverUrl), "%s:%u", - mConfig.assistanceServer.hostName, - mConfig.assistanceServer.port); - } - - if (length > 0 && strncasecmp(mAdapter.getServerUrl().c_str(), - serverUrl, sizeof(serverUrl)) != 0) { - mAdapter.setServerUrl(serverUrl); - err = mApi.setServer(serverUrl, length); - } - - } else { - err = LOCATION_ERROR_SUCCESS; - } + err = mAdapter.setSuplHostServer(mConfig.assistanceServer.hostName, + mConfig.assistanceServer.port); } else if (GNSS_ASSISTANCE_TYPE_C2K == mConfig.assistanceServer.type) { if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) { struct in_addr addr; @@ -859,7 +938,7 @@ GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data) mAdapter.reportResponse(err, mSessionId); SystemStatus* s = mAdapter.getSystemStatus(); if ((nullptr != s) && (mData.deleteAll)) { - s->setDefaultReport(); + s->setDefaultGnssEngineStates(); } } }; @@ -869,6 +948,26 @@ GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data) } void +GnssAdapter::gnssUpdateXtraThrottleCommand(const bool enabled) +{ + LOC_LOGD("%s] enabled:%d", __func__, enabled); + + struct UpdateXtraThrottleMsg : public LocMsg { + GnssAdapter& mAdapter; + const bool mEnabled; + inline UpdateXtraThrottleMsg(GnssAdapter& adapter, const bool enabled) : + LocMsg(), + mAdapter(adapter), + mEnabled(enabled) {} + inline virtual void proc() const { + mAdapter.mXtraObserver.updateXtraThrottle(mEnabled); + } + }; + + sendMsg(new UpdateXtraThrottleMsg(*this, enabled)); +} + +void GnssAdapter::injectLocationCommand(double latitude, double longitude, float accuracy) { LOC_LOGD("%s]: latitude %8.4f longitude %8.4f accuracy %8.4f", @@ -1077,7 +1176,16 @@ GnssAdapter::updateClientsEventMask() mask |= LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; mask |= LOC_API_ADAPTER_BIT_GNSS_SV_POLYNOMIAL_REPORT; - LOC_LOGD("%s]: Auto usecase, Enable MEAS/POLY - mask 0x%x", __func__, mask); + LOC_LOGD("%s]: Auto usecase, Enable MEAS/POLY - mask 0x%" PRIu64 "", __func__, mask); + } + + if (mAgpsCbInfo.statusV4Cb != NULL) { + mask |= LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST; + } + + // Add ODCPI handling + if (nullptr != mOdcpiRequestCb) { + mask |= LOC_API_ADAPTER_BIT_REQUEST_WIFI; } updateEvtMask(mask, LOC_REGISTRATION_MASK_SET); @@ -1105,6 +1213,9 @@ GnssAdapter::restartSessions() { LOC_LOGD("%s]: ", __func__); + // odcpi session is no longer active after restart + mOdcpiRequestActive = false; + if (mTrackingSessions.empty()) { return; } @@ -1943,7 +2054,8 @@ GnssAdapter::reportPositionEvent(const UlpLocation& ulpLocation, inline virtual void proc() const { // extract bug report info - this returns true if consumed by systemstatus SystemStatus* s = mAdapter.getSystemStatus(); - if ((nullptr != s) && (LOC_SESS_SUCCESS == mStatus)){ + if ((nullptr != s) && + ((LOC_SESS_SUCCESS == mStatus) || (LOC_SESS_INTERMEDIATE == mStatus))){ s->eventPosition(mUlpLocation, mLocationExtended); } mAdapter.reportPosition(mUlpLocation, mLocationExtended, mStatus, mTechMask); @@ -1953,34 +2065,41 @@ GnssAdapter::reportPositionEvent(const UlpLocation& ulpLocation, sendMsg(new MsgReportPosition(*this, ulpLocation, locationExtended, status, techMask)); } +bool +GnssAdapter::needReport(const UlpLocation& ulpLocation, + enum loc_sess_status status, + LocPosTechMask techMask) { + bool reported = false; + if (LOC_SESS_SUCCESS == status) { + // this is a final fix + LocPosTechMask mask = + LOC_POS_TECH_MASK_SATELLITE | LOC_POS_TECH_MASK_SENSORS | LOC_POS_TECH_MASK_HYBRID; + // it is a Satellite fix or a sensor fix + reported = (mask & techMask); + } else if (LOC_SESS_INTERMEDIATE == status && + LOC_SESS_INTERMEDIATE == ContextBase::mGps_conf.INTERMEDIATE_POS) { + // this is a intermediate fix and we accepte intermediate + + // it is NOT the case that + // there is inaccuracy; and + // we care about inaccuracy; and + // the inaccuracy exceeds our tolerance + reported = !((ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ACCURACY) && + (ContextBase::mGps_conf.ACCURACY_THRES != 0) && + (ulpLocation.gpsLocation.accuracy > ContextBase::mGps_conf.ACCURACY_THRES)); + } + + return reported; +} + void GnssAdapter::reportPosition(const UlpLocation& ulpLocation, const GpsLocationExtended& locationExtended, enum loc_sess_status status, LocPosTechMask techMask) { - bool reported = false; - // what's in the if is... (line by line) - // 1. this is a final fix; and - // 1.1 it is a Satellite fix; or - // 1.2 it is a sensor fix - // 2. (must be intermediate fix... implicit) - // 2.1 we accepte intermediate; and - // 2.2 it is NOT the case that - // 2.2.1 there is inaccuracy; and - // 2.2.2 we care about inaccuracy; and - // 2.2.3 the inaccuracy exceeds our tolerance - if ((LOC_SESS_SUCCESS == status && - ((LOC_POS_TECH_MASK_SATELLITE | - LOC_POS_TECH_MASK_SENSORS | - LOC_POS_TECH_MASK_HYBRID) & - techMask)) || - (LOC_SESS_INTERMEDIATE == ContextBase::mGps_conf.INTERMEDIATE_POS && - !((ulpLocation.gpsLocation.flags & - LOC_GPS_LOCATION_HAS_ACCURACY) && - (ContextBase::mGps_conf.ACCURACY_THRES != 0) && - (ulpLocation.gpsLocation.accuracy > - ContextBase::mGps_conf.ACCURACY_THRES)))) { + bool reported = needReport(ulpLocation, status, techMask); + if (reported) { if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA) { mGnssSvIdUsedInPosAvail = true; mGnssSvIdUsedInPosition = locationExtended.gnss_sv_used_ids; @@ -1997,7 +2116,6 @@ GnssAdapter::reportPosition(const UlpLocation& ulpLocation, it->second.gnssLocationInfoCb(locationInfo); } } - reported = true; } if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && !mTrackingSessions.empty()) { @@ -2224,14 +2342,14 @@ static void* niThreadProc(void *args) NiSession* pSession = (NiSession*)args; int rc = 0; /* return code from pthread calls */ - struct timeval present_time; + struct timespec present_time; struct timespec expire_time; pthread_mutex_lock(&pSession->tLock); /* Calculate absolute expire time */ - gettimeofday(&present_time, NULL); + clock_gettime(CLOCK_MONOTONIC, &present_time); expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft; - expire_time.tv_nsec = present_time.tv_usec * 1000; + expire_time.tv_nsec = present_time.tv_nsec; LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec", __func__, (long)expire_time.tv_sec, pSession->respTimeLeft); @@ -2356,7 +2474,7 @@ void GnssAdapter::reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements, int msInWeek) { - LOC_LOGD("%s]: ", __func__); + LOC_LOGD("%s]: msInWeek=%d", __func__, msInWeek); struct MsgReportGnssMeasurementData : public LocMsg { GnssAdapter& mAdapter; @@ -2407,19 +2525,170 @@ GnssAdapter::reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial) mUlpProxy->reportSvPolynomial(svPolynomial); } -void GnssAdapter::initDefaultAgps() { - LOC_LOGD("%s]: ", __func__); +bool +GnssAdapter::reportOdcpiRequestEvent(OdcpiRequestInfo& request) +{ + struct MsgReportOdcpiRequest : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestInfo mOdcpiRequest; + inline MsgReportOdcpiRequest(GnssAdapter& adapter, OdcpiRequestInfo& request) : + LocMsg(), + mAdapter(adapter), + mOdcpiRequest(request) {} + inline virtual void proc() const { + mAdapter.reportOdcpiRequest(mOdcpiRequest); + } + }; - LocationCapabilitiesMask mask = getCapabilities(); - if (!(mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) && - !(mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)) { - LOC_LOGI("%s]: Target does not support MSB and MSA.", __func__); - return; + sendMsg(new MsgReportOdcpiRequest(*this, request)); + return true; +} + +void GnssAdapter::reportOdcpiRequest(const OdcpiRequestInfo& request) +{ + if (nullptr != mOdcpiRequestCb) { + LOC_LOGd("request: type %d, tbf %d, isEmergency %d" + " requestActive: %d timerActive: %d", + request.type, request.tbfMillis, request.isEmergencyMode, + mOdcpiRequestActive, mOdcpiTimer.isActive()); + // ODCPI START and ODCPI STOP from modem can come in quick succession + // so the mOdcpiTimer helps avoid spamming the framework as well as + // extending the odcpi session past 30 seconds if needed + if (ODCPI_REQUEST_TYPE_START == request.type) { + if (false == mOdcpiRequestActive && false == mOdcpiTimer.isActive()) { + mOdcpiRequestCb(request); + mOdcpiRequestActive = true; + mOdcpiTimer.start(); + // if the current active odcpi session is non-emergency, and the new + // odcpi request is emergency, replace the odcpi request with new request + // and restart the timer + } else if (false == mOdcpiRequest.isEmergencyMode && + true == request.isEmergencyMode) { + mOdcpiRequestCb(request); + mOdcpiRequestActive = true; + if (true == mOdcpiTimer.isActive()) { + mOdcpiTimer.restart(); + } else { + mOdcpiTimer.start(); + } + // if ODCPI request is not active but the timer is active, then + // just update the active state and wait for timer to expire + // before requesting new ODCPI to avoid spamming ODCPI requests + } else if (false == mOdcpiRequestActive && true == mOdcpiTimer.isActive()) { + mOdcpiRequestActive = true; + } + mOdcpiRequest = request; + // the request is being stopped, but allow timer to expire first + // before stopping the timer just in case more ODCPI requests come + // to avoid spamming more odcpi requests to the framework + } else { + mOdcpiRequestActive = false; + } + } else { + LOC_LOGw("ODCPI request not supported"); + } +} + +void GnssAdapter::initOdcpiCommand(const OdcpiRequestCallback& callback) +{ + struct MsgInitOdcpi : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestCallback mOdcpiCb; + inline MsgInitOdcpi(GnssAdapter& adapter, + const OdcpiRequestCallback& callback) : + LocMsg(), + mAdapter(adapter), + mOdcpiCb(callback) {} + inline virtual void proc() const { + mAdapter.initOdcpi(mOdcpiCb); + } + }; + + sendMsg(new MsgInitOdcpi(*this, callback)); +} + +void GnssAdapter::initOdcpi(const OdcpiRequestCallback& callback) +{ + mOdcpiRequestCb = callback; + + /* Register for WIFI request */ + updateEvtMask(LOC_API_ADAPTER_BIT_REQUEST_WIFI, + LOC_REGISTRATION_MASK_ENABLED); +} + +void GnssAdapter::injectOdcpiCommand(const Location& location) +{ + struct MsgInjectOdcpi : public LocMsg { + GnssAdapter& mAdapter; + Location mLocation; + inline MsgInjectOdcpi(GnssAdapter& adapter, const Location& location) : + LocMsg(), + mAdapter(adapter), + mLocation(location) {} + inline virtual void proc() const { + mAdapter.injectOdcpi(mLocation); + } + }; + + sendMsg(new MsgInjectOdcpi(*this, location)); +} + +void GnssAdapter::injectOdcpi(const Location& location) +{ + LOC_LOGd("ODCPI Injection: requestActive: %d timerActive: %d" + "lat %.7f long %.7f", + mOdcpiRequestActive, mOdcpiTimer.isActive(), + location.latitude, location.longitude); + + loc_api_adapter_err err = mLocApi->injectPosition(location); + if (LOC_API_ADAPTER_ERR_SUCCESS != err) { + LOC_LOGe("Inject Position API error %d", err); + } +} + +// Called in the context of LocTimer thread +void OdcpiTimer::timeOutCallback() +{ + if (nullptr != mAdapter) { + mAdapter->odcpiTimerExpireEvent(); + } +} + +// Called in the context of LocTimer thread +void GnssAdapter::odcpiTimerExpireEvent() +{ + struct MsgOdcpiTimerExpire : public LocMsg { + GnssAdapter& mAdapter; + inline MsgOdcpiTimerExpire(GnssAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + inline virtual void proc() const { + mAdapter.odcpiTimerExpire(); + } + }; + sendMsg(new MsgOdcpiTimerExpire(*this)); +} +void GnssAdapter::odcpiTimerExpire() +{ + LOC_LOGd("requestActive: %d timerActive: %d", + mOdcpiRequestActive, mOdcpiTimer.isActive()); + + // if ODCPI request is still active after timer + // expires, request again and restart timer + if (mOdcpiRequestActive) { + mOdcpiRequestCb(mOdcpiRequest); + mOdcpiTimer.restart(); + } else { + mOdcpiTimer.stop(); } +} + +void GnssAdapter::initDefaultAgps() { + LOC_LOGD("%s]: ", __func__); void *handle = nullptr; if ((handle = dlopen("libloc_net_iface.so", RTLD_NOW)) == nullptr) { - LOC_LOGE("%s]: libloc_net_iface.so not found !", __func__); + LOC_LOGD("%s]: libloc_net_iface.so not found !", __func__); return; } @@ -2437,7 +2706,7 @@ void GnssAdapter::initDefaultAgps() { return; } - initAgpsCommand(cbInfo); + initAgps(cbInfo); } void GnssAdapter::initDefaultAgpsCommand() { @@ -2448,7 +2717,6 @@ void GnssAdapter::initDefaultAgpsCommand() { inline MsgInitDefaultAgps(GnssAdapter& adapter) : LocMsg(), mAdapter(adapter) { - LOC_LOGV("MsgInitDefaultAgps"); } inline virtual void proc() const { mAdapter.initDefaultAgps(); @@ -2459,141 +2727,53 @@ void GnssAdapter::initDefaultAgpsCommand() { } /* INIT LOC AGPS MANAGER */ -void GnssAdapter::initAgpsCommand(const AgpsCbInfo& cbInfo){ - LOC_LOGI("GnssAdapter::initAgpsCommand"); +void GnssAdapter::initAgps(const AgpsCbInfo& cbInfo) { + LOC_LOGD("%s]: mAgpsCbInfo.cbPriority - %d; cbInfo.cbPriority - %d", + __func__, mAgpsCbInfo.cbPriority, cbInfo.cbPriority) - /* Set ATL open/close callbacks */ - AgpsAtlOpenStatusCb atlOpenStatusCb = - [this](int handle, int isSuccess, char* apn, - AGpsBearerType bearerType, AGpsExtType agpsType) { - - mLocApi->atlOpenStatus( - handle, isSuccess, apn, bearerType, agpsType); - }; - AgpsAtlCloseStatusCb atlCloseStatusCb = - [this](int handle, int isSuccess) { - - mLocApi->atlCloseStatus(handle, isSuccess); - }; - - /* Register DS Client APIs */ - AgpsDSClientInitFn dsClientInitFn = - [this](bool isDueToSSR) { - - return mLocApi->initDataServiceClient(isDueToSSR); - }; - - AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn = - [this] { - - return mLocApi->openAndStartDataCall(); - }; - - AgpsDSClientStopDataCallFn dsClientStopDataCallFn = - [this] { - - mLocApi->stopDataCall(); - }; - - AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn = - [this] { + if (!((ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSB) || + (ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSA))) { + return; + } - mLocApi->closeDataCall(); - }; + if (mAgpsCbInfo.cbPriority > cbInfo.cbPriority) { + return; + } else { + mAgpsCbInfo = cbInfo; - AgpsDSClientReleaseFn dsClientReleaseFn = - [this] { + mAgpsManager.registerFrameworkStatusCallback((AgnssStatusIpV4Cb)cbInfo.statusV4Cb); - mLocApi->releaseDataServiceClient(); - }; + mAgpsManager.createAgpsStateMachines(); - /* Send Msg function */ - SendMsgToAdapterMsgQueueFn sendMsgFn = - [this](LocMsg* msg) { + /* Register for AGPS event mask */ + updateEvtMask(LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST, + LOC_REGISTRATION_MASK_ENABLED); + } +} - sendMsg(msg); - }; +void GnssAdapter::initAgpsCommand(const AgpsCbInfo& cbInfo){ + LOC_LOGI("GnssAdapter::initAgpsCommand"); /* Message to initialize AGPS module */ struct AgpsMsgInit: public LocMsg { - - AgpsManager* mAgpsManager; - - AgnssStatusIpV4Cb mFrameworkStatusV4Cb; - - AgpsAtlOpenStatusCb mAtlOpenStatusCb; - AgpsAtlCloseStatusCb mAtlCloseStatusCb; - - AgpsDSClientInitFn mDSClientInitFn; - AgpsDSClientOpenAndStartDataCallFn mDSClientOpenAndStartDataCallFn; - AgpsDSClientStopDataCallFn mDSClientStopDataCallFn; - AgpsDSClientCloseDataCallFn mDSClientCloseDataCallFn; - AgpsDSClientReleaseFn mDSClientReleaseFn; - - SendMsgToAdapterMsgQueueFn mSendMsgFn; + const AgpsCbInfo mCbInfo; GnssAdapter& mAdapter; - inline AgpsMsgInit(AgpsManager* agpsManager, - AgnssStatusIpV4Cb frameworkStatusV4Cb, - AgpsAtlOpenStatusCb atlOpenStatusCb, - AgpsAtlCloseStatusCb atlCloseStatusCb, - AgpsDSClientInitFn dsClientInitFn, - AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn, - AgpsDSClientStopDataCallFn dsClientStopDataCallFn, - AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn, - AgpsDSClientReleaseFn dsClientReleaseFn, - SendMsgToAdapterMsgQueueFn sendMsgFn, + inline AgpsMsgInit(const AgpsCbInfo& cbInfo, GnssAdapter& adapter) : - LocMsg(), mAgpsManager(agpsManager), mFrameworkStatusV4Cb( - frameworkStatusV4Cb), mAtlOpenStatusCb(atlOpenStatusCb), mAtlCloseStatusCb( - atlCloseStatusCb), mDSClientInitFn(dsClientInitFn), mDSClientOpenAndStartDataCallFn( - dsClientOpenAndStartDataCallFn), mDSClientStopDataCallFn( - dsClientStopDataCallFn), mDSClientCloseDataCallFn( - dsClientCloseDataCallFn), mDSClientReleaseFn( - dsClientReleaseFn), mSendMsgFn(sendMsgFn), - mAdapter(adapter) { - + LocMsg(), mCbInfo(cbInfo), mAdapter(adapter) { LOC_LOGV("AgpsMsgInit"); } inline virtual void proc() const { - LOC_LOGV("AgpsMsgInit::proc()"); - - mAgpsManager->registerCallbacks(mFrameworkStatusV4Cb, mAtlOpenStatusCb, - mAtlCloseStatusCb, mDSClientInitFn, - mDSClientOpenAndStartDataCallFn, mDSClientStopDataCallFn, - mDSClientCloseDataCallFn, mDSClientReleaseFn, mSendMsgFn); - - mAgpsManager->createAgpsStateMachines(); - - /* Register for AGPS event mask */ - mAdapter.updateEvtMask(LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST, - LOC_REGISTRATION_MASK_ENABLED); + mAdapter.initAgps(mCbInfo); } }; - if (mAgpsCbInfo.cbPriority > cbInfo.cbPriority) { - LOC_LOGI("Higher priority AGPS CB already registered (%d > %d) !", - mAgpsCbInfo.cbPriority, cbInfo.cbPriority); - return; - } else { - mAgpsCbInfo = cbInfo; - LOC_LOGI("Registering AGPS CB %p with priority %d", - mAgpsCbInfo.statusV4Cb, mAgpsCbInfo.cbPriority); - } - /* Send message to initialize AGPS Manager */ - sendMsg(new AgpsMsgInit( - &mAgpsManager, - (AgnssStatusIpV4Cb)cbInfo.statusV4Cb, - atlOpenStatusCb, atlCloseStatusCb, - dsClientInitFn, dsClientOpenAndStartDataCallFn, - dsClientStopDataCallFn, dsClientCloseDataCallFn, - dsClientReleaseFn, - sendMsgFn, - *this)); + sendMsg(new AgpsMsgInit(cbInfo, *this)); } /* GnssAdapter::requestATL @@ -2993,6 +3173,9 @@ bool GnssAdapter::getDebugReport(GnssDebugReport& r) r.mLocation.mLocation.longitude = (double)(reports.mBestPosition.back().mBestLon) * RAD2DEG; r.mLocation.mLocation.altitude = reports.mBestPosition.back().mBestAlt; + r.mLocation.mLocation.accuracy = + (double)(reports.mBestPosition.back().mBestHepe); + r.mLocation.mUtcReported = reports.mBestPosition.back().mUtcReported; } else { @@ -3018,8 +3201,8 @@ bool GnssAdapter::getDebugReport(GnssDebugReport& r) (int64_t)(reports.mTimeAndClock.back().mGpsTowMs); r.mTime.timeUncertaintyNs = - (float)((reports.mTimeAndClock.back().mTimeUnc + - reports.mTimeAndClock.back().mLeapSecUnc)*1000); + ((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", @@ -3052,12 +3235,12 @@ GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int m systemstatus->getReport(reports, true); if ((!reports.mRfAndParams.empty()) && (!reports.mTimeAndClock.empty()) && - reports.mTimeAndClock.back().mTimeValid && (abs(msInWeek - (int)reports.mTimeAndClock.back().mGpsTowMs) < 2000)) { for (size_t i = 0; i < measurements.count; i++) { switch (measurements.measurements[i].svType) { case GNSS_SV_TYPE_GPS: + case GNSS_SV_TYPE_QZSS: measurements.measurements[i].agcLevelDb = reports.mRfAndParams.back().mAgcGps; measurements.measurements[i].flags |= @@ -3085,7 +3268,6 @@ GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int m GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; break; - case GNSS_SV_TYPE_QZSS: case GNSS_SV_TYPE_SBAS: case GNSS_SV_TYPE_UNKNOWN: default: diff --git a/gps/gnss/GnssAdapter.h b/gps/gnss/GnssAdapter.h index e7605f9..0609e6d 100644 --- a/gps/gnss/GnssAdapter.h +++ b/gps/gnss/GnssAdapter.h @@ -43,9 +43,39 @@ #define MAX_SATELLITES_IN_USE 12 #define LOC_NI_NO_RESPONSE_TIME 20 #define LOC_GPS_NI_RESPONSE_IGNORE 4 +#define ODCPI_EXPECTED_INJECTION_TIME_MS 10000 class GnssAdapter; +class OdcpiTimer : public LocTimer { +public: + OdcpiTimer(GnssAdapter* adapter) : + LocTimer(), mAdapter(adapter), mActive(false) {} + + inline void start() { + mActive = true; + LocTimer::start(ODCPI_EXPECTED_INJECTION_TIME_MS, false); + } + inline void stop() { + mActive = false; + LocTimer::stop(); + } + inline void restart() { + stop(); + start(); + } + inline bool isActive() { + return mActive; + } + +private: + // Override + virtual void timeOutCallback() override; + + GnssAdapter* mAdapter; + bool mActive; +}; + typedef struct { pthread_t thread; /* NI thread */ uint32_t respTimeLeft; /* examine time for NI response */ @@ -81,6 +111,7 @@ namespace loc_core { } class GnssAdapter : public LocAdapterBase { + /* ==== ULP ============================================================================ */ UlpProxyBase* mUlpProxy; @@ -102,10 +133,18 @@ class GnssAdapter : public LocAdapterBase { /* ==== NI ============================================================================= */ NiData mNiData; - /* ==== AGPS ========================================================*/ + /* ==== AGPS =========================================================================== */ // This must be initialized via initAgps() AgpsManager mAgpsManager; AgpsCbInfo mAgpsCbInfo; + void initAgps(const AgpsCbInfo& cbInfo); + + /* ==== ODCPI ========================================================================== */ + OdcpiRequestCallback mOdcpiRequestCb; + bool mOdcpiRequestActive; + OdcpiTimer mOdcpiTimer; + OdcpiRequestInfo mOdcpiRequest; + void odcpiTimerExpire(); /* === SystemStatus ===================================================================== */ SystemStatus* mSystemStatus; @@ -151,6 +190,7 @@ public: LocationCallbacks getClientCallbacks(LocationAPI* client); LocationCapabilitiesMask getCapabilities(); void broadcastCapabilities(LocationCapabilitiesMask); + LocationError setSuplHostServer(const char* server, int port); /* ==== TRACKING ======================================================================= */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ @@ -198,6 +238,7 @@ public: void setConfigCommand(); uint32_t* gnssUpdateConfigCommand(GnssConfig config); uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data); + void gnssUpdateXtraThrottleCommand(const bool enabled); void initDefaultAgpsCommand(); void initAgpsCommand(const AgpsCbInfo& cbInfo); @@ -206,6 +247,15 @@ public: void dataConnClosedCommand(AGpsExtType agpsType); void dataConnFailedCommand(AGpsExtType agpsType); + /* ========= ODCPI ===================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void initOdcpiCommand(const OdcpiRequestCallback& callback); + void injectOdcpiCommand(const Location& location); + /* ======== UTILITIES ================================================================== */ + void initOdcpi(const OdcpiRequestCallback& callback); + void injectOdcpi(const Location& location); + void odcpiTimerExpireEvent(); + /* ======== RESPONSES ================================================================== */ void reportResponse(LocationError err, uint32_t sessionId); void reportResponse(size_t count, LocationError* errs, uint32_t* ids); @@ -239,8 +289,11 @@ public: virtual bool requestSuplES(int connHandle); virtual bool reportDataCallOpened(); virtual bool reportDataCallClosed(); + virtual bool reportOdcpiRequestEvent(OdcpiRequestInfo& request); /* ======== UTILITIES ================================================================= */ + bool needReport(const UlpLocation& ulpLocation, + enum loc_sess_status status, LocPosTechMask techMask); void reportPosition(const UlpLocation &ulpLocation, const GpsLocationExtended &locationExtended, enum loc_sess_status status, @@ -249,6 +302,7 @@ public: void reportNmea(const char* nmea, size_t length); bool requestNiNotify(const GnssNiNotification& notify, const void* data); void reportGnssMeasurementData(const GnssMeasurementsNotification& measurements); + void reportOdcpiRequest(const OdcpiRequestInfo& request); /*======== GNSSDEBUG ================================================================*/ bool getDebugReport(GnssDebugReport& report); diff --git a/gps/gnss/Makefile.am b/gps/gnss/Makefile.am index 3afdcd7..c818cae 100644 --- a/gps/gnss/Makefile.am +++ b/gps/gnss/Makefile.am @@ -1,99 +1,31 @@ AM_CFLAGS = \ $(LOCPLA_CFLAGS) \ $(LOCHAL_CFLAGS) \ + $(GPSUTILS_CFLAGS) \ + $(LOCCORE_CFLAGS) \ -I./ \ -I../utils \ - -I../core \ + -I$(WORKSPACE)/hardware/qcom/gps/core/data-items \ -I../location \ -std=c++11 libgnss_la_SOURCES = \ location_gnss.cpp \ GnssAdapter.cpp \ + XtraSystemStatusObserver.cpp \ Agps.cpp if USE_GLIB libgnss_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ -libgnss_la_LDFLAGS = -lstdc++ -lpthread @GLIB_LIBS@ -shared -avoid-version +libgnss_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -avoid-version libgnss_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ else libgnss_la_CFLAGS = $(AM_CFLAGS) -libgnss_la_LDFLAGS = -lpthread -shared -version-info 1:0:0 +libgnss_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0 libgnss_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) endif -libgnss_la_LIBADD = -lstdc++ $(LOCPLA_LIBS) $(LOCHAL_LIBS) - - -#Create and Install libraries -#lib_LTLIBRARIES = libgnss.la - -#library_includedir = $(pkgincludedir) -#pkgconfigdir = $(libdir)/pkgconfig -#pkgconfig_DATA = location-api.pc -#EXTRA_DIST = $(pkgconfig_DATA) - - -libloc_ds_api_CFLAGS = \ - $(QMIF_CFLAGS) \ - $(QMI_CFLAGS) \ - $(DATA_CFLAGS) \ - $(GPSUTILS_CFLAGS) \ - -I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api - -libloc_ds_api_la_SOURCES = \ - $(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.c - -if USE_GLIB -libloc_ds_api_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) @GLIB_CFLAGS@ -libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 -libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic -libloc_ds_api_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ -else -libloc_ds_api_la_CFLAGS = $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) -libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -Wl,--export-dynamic -shared -version-info 1:0:0 -libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic -libloc_ds_api_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_ds_api_CFLAGS) -endif - -libloc_ds_api_la_LIBADD = -lstdc++ $(QMIF_LIBS) -lqmiservices -ldsi_netctrl $(GPSUTILS_LIBS) $(LOCPLA_LIBS) - -libloc_api_v02_CFLAGS = \ - $(QMIF_CFLAGS) \ - $(GPSUTILS_CFLAGS) \ - -I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api \ - -I$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02 - -libloc_api_v02_la_SOURCES = \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.cpp \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.c \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.c \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.c \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.c - -if USE_GLIB -libloc_api_v02_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) @GLIB_CFLAGS@ -libloc_api_v02_la_LDFLAGS = -lstdc++ -g -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 -libloc_api_v02_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ -else -libloc_api_v02_la_CFLAGS = $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) -libloc_api_v02_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -shared -version-info 1:0:0 -libloc_api_v02_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_api_v02_CFLAGS) -endif - -libloc_api_v02_la_CXXFLAGS = -std=c++0x -libloc_api_v02_la_LIBADD = -lstdc++ -lqmi_cci -lqmi_common_so $(QMIF_LIBS) $(GPSUTILS_LIBS) $(LOCPLA_LIBS) ../core/libloc_core.la libloc_ds_api.la - -library_include_HEADERS = \ - $(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.h \ - $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_util_log.h - -library_includedir = $(pkgincludedir) +libgnss_la_LIBADD = -lstdc++ $(GPSUTILS_LIBS) $(LOCCORE_LIBS) #Create and Install libraries -lib_LTLIBRARIES = libgnss.la libloc_ds_api.la libloc_api_v02.la +lib_LTLIBRARIES = libgnss.la diff --git a/gps/gnss/XtraSystemStatusObserver.cpp b/gps/gnss/XtraSystemStatusObserver.cpp index e27e698..91c395f 100644 --- a/gps/gnss/XtraSystemStatusObserver.cpp +++ b/gps/gnss/XtraSystemStatusObserver.cpp @@ -52,94 +52,121 @@ using namespace loc_core; -#define XTRA_HAL_SOCKET_NAME "/data/vendor/location/xtra/socket_hal_xtra" +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LocSvc_XSSO" bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) { + mGpsLock = lock; + + if (!mReqStatusReceived) { + return true; + } + stringstream ss; ss << "gpslock"; ss << " " << lock; - ss << "\n"; // append seperator - return ( sendEvent(ss) ); + return ( send(LOC_IPC_XTRA, ss.str()) ); } -bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, uint32_t type) { +bool XtraSystemStatusObserver::updateConnections(uint64_t allConnections) { + mIsConnectivityStatusKnown = true; + mConnections = allConnections; + + if (!mReqStatusReceived) { + return true; + } + stringstream ss; ss << "connection"; - ss << " " << (connected ? "1" : "0"); - ss << " " << (int)type; - ss << "\n"; // append seperator - return ( sendEvent(ss) ); + ss << " " << mConnections; + return ( send(LOC_IPC_XTRA, ss.str()) ); } + bool XtraSystemStatusObserver::updateTac(const string& tac) { + mTac = tac; + + if (!mReqStatusReceived) { + return true; + } + stringstream ss; ss << "tac"; ss << " " << tac.c_str(); - ss << "\n"; // append seperator - return ( sendEvent(ss) ); + return ( send(LOC_IPC_XTRA, ss.str()) ); } bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) { + mMccmnc = mccmnc; + + if (!mReqStatusReceived) { + return true; + } + stringstream ss; ss << "mncmcc"; ss << " " << mccmnc.c_str(); - ss << "\n"; // append seperator - return ( sendEvent(ss) ); + return ( send(LOC_IPC_XTRA, ss.str()) ); } -bool XtraSystemStatusObserver::sendEvent(const stringstream& event) { - int socketFd = createSocket(); - if (socketFd < 0) { - LOC_LOGe("XTRA unreachable. sending failed."); - return false; - } +bool XtraSystemStatusObserver::updateXtraThrottle(const bool enabled) { + mXtraThrottle = enabled; - const string& data = event.str(); - int remain = data.length(); - ssize_t sent = 0; - while (remain > 0 && - (sent = ::send(socketFd, data.c_str() + (data.length() - remain), - remain, MSG_NOSIGNAL)) > 0) { - remain -= sent; + if (!mReqStatusReceived) { + return true; } - if (sent < 0) { - LOC_LOGe("sending error. reason:%s", strerror(errno)); + stringstream ss; + ss << "xtrathrottle"; + ss << " " << (enabled ? 1 : 0); + return ( send(LOC_IPC_XTRA, ss.str()) ); +} + +inline bool XtraSystemStatusObserver::onStatusRequested(int32_t xtraStatusUpdated) { + mReqStatusReceived = true; + + if (xtraStatusUpdated) { + return true; } - closeSocket(socketFd); + stringstream ss; - return (remain == 0); -} + ss << "respondStatus" << endl; + (mGpsLock == -1 ? ss : ss << mGpsLock) << endl << mConnections << endl + << mTac << endl << mMccmnc << endl << mIsConnectivityStatusKnown; + return ( send(LOC_IPC_XTRA, ss.str()) ); +} -int XtraSystemStatusObserver::createSocket() { - int socketFd = -1; +void XtraSystemStatusObserver::onReceive(const std::string& data) { + if (!strncmp(data.c_str(), "ping", sizeof("ping") - 1)) { + LOC_LOGd("ping received"); - if ((socketFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - LOC_LOGe("create socket error. reason:%s", strerror(errno)); +#ifdef USE_GLIB + } else if (!strncmp(data.c_str(), "connectBackhaul", sizeof("connectBackhaul") - 1)) { + mSystemStatusObsrvr->connectBackhaul(); - } else { - const char* socketPath = XTRA_HAL_SOCKET_NAME ; - struct sockaddr_un addr = { .sun_family = AF_UNIX }; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath); + } else if (!strncmp(data.c_str(), "disconnectBackhaul", sizeof("disconnectBackhaul") - 1)) { + mSystemStatusObsrvr->disconnectBackhaul(); +#endif - if (::connect(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - LOC_LOGe("cannot connect to XTRA. reason:%s", strerror(errno)); - if (::close(socketFd)) { - LOC_LOGe("close socket error. reason:%s", strerror(errno)); - } - socketFd = -1; - } - } + } else if (!strncmp(data.c_str(), "requestStatus", sizeof("requestStatus") - 1)) { + int32_t xtraStatusUpdated = 0; + sscanf(data.c_str(), "%*s %d", &xtraStatusUpdated); - return socketFd; -} + struct HandleStatusRequestMsg : public LocMsg { + XtraSystemStatusObserver& mXSSO; + int32_t mXtraStatusUpdated; + inline HandleStatusRequestMsg(XtraSystemStatusObserver& xsso, + int32_t xtraStatusUpdated) : + mXSSO(xsso), mXtraStatusUpdated(xtraStatusUpdated) {} + inline void proc() const override { mXSSO.onStatusRequested(mXtraStatusUpdated); } + }; + mMsgTask->sendMsg(new (nothrow) HandleStatusRequestMsg(*this, xtraStatusUpdated)); -void XtraSystemStatusObserver::closeSocket(const int socketFd) { - if (socketFd >= 0) { - if(::close(socketFd)) { - LOC_LOGe("close socket error. reason:%s", strerror(errno)); - } + } else { + LOC_LOGw("unknown event: %s", data.c_str()); } } @@ -171,11 +198,11 @@ void XtraSystemStatusObserver::getName(string& name) void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist) { - struct handleOsObserverUpdateMsg : public LocMsg { + struct HandleOsObserverUpdateMsg : public LocMsg { XtraSystemStatusObserver* mXtraSysStatObj; list <IDataItemCore*> mDataItemList; - inline handleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs, + inline HandleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs, const list<IDataItemCore*>& dataItemList) : mXtraSysStatObj(xtraSysStatObs) { for (auto eachItem : dataItemList) { @@ -191,7 +218,7 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist) } } - inline ~handleOsObserverUpdateMsg() { + inline ~HandleOsObserverUpdateMsg() { for (auto each : mDataItemList) { delete each; } @@ -205,8 +232,7 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist) { NetworkInfoDataItemBase* networkInfo = static_cast<NetworkInfoDataItemBase*>(each); - mXtraSysStatObj->updateConnectionStatus(networkInfo->mConnected, - networkInfo->mType); + mXtraSysStatObj->updateConnections(networkInfo->getAllTypes()); } break; @@ -232,7 +258,5 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist) } } }; - mMsgTask->sendMsg(new (nothrow) handleOsObserverUpdateMsg(this, dlist)); + mMsgTask->sendMsg(new (nothrow) HandleOsObserverUpdateMsg(this, dlist)); } - - diff --git a/gps/gnss/XtraSystemStatusObserver.h b/gps/gnss/XtraSystemStatusObserver.h index 42f49b5..af0789b 100644 --- a/gps/gnss/XtraSystemStatusObserver.h +++ b/gps/gnss/XtraSystemStatusObserver.h @@ -31,41 +31,67 @@ #include <cinttypes> #include <MsgTask.h> +#include <LocIpc.h> +#include <LocTimer.h> using namespace std; using loc_core::IOsObserver; using loc_core::IDataItemObserver; using loc_core::IDataItemCore; +using loc_util::LocIpc; - -class XtraSystemStatusObserver : public IDataItemObserver { +class XtraSystemStatusObserver : public IDataItemObserver, public LocIpc{ public : // constructor & destructor inline XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask): - mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask) { + mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask), + mGpsLock(-1), mConnections(0), mXtraThrottle(true), mReqStatusReceived(false), + mDelayLocTimer(*this), mIsConnectivityStatusKnown (false) { subscribe(true); + startListeningNonBlocking(LOC_IPC_HAL); + mDelayLocTimer.start(100 /*.1 sec*/, false); + } + inline virtual ~XtraSystemStatusObserver() { + subscribe(false); + stopListening(); } - inline XtraSystemStatusObserver() {}; - inline virtual ~XtraSystemStatusObserver() { subscribe(false); } // IDataItemObserver overrides inline virtual void getName(string& name); virtual void notify(const list<IDataItemCore*>& dlist); bool updateLockStatus(uint32_t lock); - bool updateConnectionStatus(bool connected, uint32_t type); + bool updateConnections(uint64_t allConnections); bool updateTac(const string& tac); bool updateMccMnc(const string& mccmnc); + bool updateXtraThrottle(const bool enabled); inline const MsgTask* getMsgTask() { return mMsgTask; } void subscribe(bool yes); +protected: + void onReceive(const std::string& data) override; + private: - int createSocket(); - void closeSocket(const int32_t socketFd); - bool sendEvent(const stringstream& event); IOsObserver* mSystemStatusObsrvr; const MsgTask* mMsgTask; + int32_t mGpsLock; + uint64_t mConnections; + string mTac; + string mMccmnc; + bool mXtraThrottle; + bool mReqStatusReceived; + bool mIsConnectivityStatusKnown; + + class DelayLocTimer : public LocTimer { + XtraSystemStatusObserver& mXSSO; + public: + DelayLocTimer(XtraSystemStatusObserver& xsso) : mXSSO(xsso) {} + void timeOutCallback() override { + mXSSO.send(LOC_IPC_XTRA, "halinit"); + } + } mDelayLocTimer; + bool onStatusRequested(int32_t xtraStatusUpdated); }; #endif diff --git a/gps/gnss/location_gnss.cpp b/gps/gnss/location_gnss.cpp index b5623e1..21763dd 100644 --- a/gps/gnss/location_gnss.cpp +++ b/gps/gnss/location_gnss.cpp @@ -45,6 +45,7 @@ static void stopTracking(LocationAPI* client, uint32_t id); static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response); static uint32_t gnssDeleteAidingData(GnssAidingData& data); +static void gnssUpdateXtraThrottle(const bool enabled); static void setControlCallbacks(LocationControlCallbacks& controlCallbacks); static uint32_t enable(LocationTechnologyType techType); @@ -59,7 +60,10 @@ static void agpsDataConnOpen(AGpsExtType agpsType, const char* apnName, int apnL static void agpsDataConnClosed(AGpsExtType agpsType); static void agpsDataConnFailed(AGpsExtType agpsType); static void getDebugReport(GnssDebugReport& report); -static void updateConnectionStatus(bool connected, uint8_t type); +static void updateConnectionStatus(bool connected, int8_t type); + +static void odcpiInit(const OdcpiRequestCallback& callback); +static void odcpiInject(const Location& location); static const GnssInterface gGnssInterface = { sizeof(GnssInterface), @@ -77,6 +81,7 @@ static const GnssInterface gGnssInterface = { disable, gnssUpdateConfig, gnssDeleteAidingData, + gnssUpdateXtraThrottle, injectLocation, injectTime, agpsInit, @@ -85,6 +90,8 @@ static const GnssInterface gGnssInterface = { agpsDataConnFailed, getDebugReport, updateConnectionStatus, + odcpiInit, + odcpiInject, }; #ifndef DEBUG_X86 @@ -203,6 +210,13 @@ static uint32_t gnssDeleteAidingData(GnssAidingData& data) } } +static void gnssUpdateXtraThrottle(const bool enabled) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssUpdateXtraThrottleCommand(enabled); + } +} + static void injectLocation(double latitude, double longitude, float accuracy) { if (NULL != gGnssAdapter) { @@ -251,8 +265,23 @@ static void getDebugReport(GnssDebugReport& report) { } } -static void updateConnectionStatus(bool connected, uint8_t type) { +static void updateConnectionStatus(bool connected, int8_t type) { if (NULL != gGnssAdapter) { gGnssAdapter->getSystemStatus()->eventConnectionStatus(connected, type); } } + +static void odcpiInit(const OdcpiRequestCallback& callback) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->initOdcpiCommand(callback); + } +} + +static void odcpiInject(const Location& location) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectOdcpiCommand(location); + } +} + |