Home | History | Annotate | Download | only in libloc_api_50001
      1 /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation, nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  */
     29 #ifndef LOC_API_ENG_ADAPTER_H
     30 #define LOC_API_ENG_ADAPTER_H
     31 
     32 #include <ctype.h>
     33 #include <hardware/gps.h>
     34 #include <loc.h>
     35 #include <loc_eng_log.h>
     36 #include <log_util.h>
     37 #include <LocAdapterBase.h>
     38 #include <LocDualContext.h>
     39 #include <UlpProxyBase.h>
     40 #include <platform_lib_includes.h>
     41 
     42 #define MAX_URL_LEN 256
     43 
     44 using namespace loc_core;
     45 
     46 class LocEngAdapter;
     47 
     48 class LocInternalAdapter : public LocAdapterBase {
     49     LocEngAdapter* mLocEngAdapter;
     50 public:
     51     LocInternalAdapter(LocEngAdapter* adapter);
     52 
     53     virtual void reportPosition(UlpLocation &location,
     54                                 GpsLocationExtended &locationExtended,
     55                                 void* locationExt,
     56                                 enum loc_sess_status status,
     57                                 LocPosTechMask loc_technology_mask);
     58     virtual void reportSv(GpsSvStatus &svStatus,
     59                           GpsLocationExtended &locationExtended,
     60                           void* svExt);
     61     virtual void reportStatus(GpsStatusValue status);
     62     virtual void setPositionModeInt(LocPosMode& posMode);
     63     virtual void startFixInt();
     64     virtual void stopFixInt();
     65     virtual void getZppInt();
     66     virtual void setUlpProxy(UlpProxyBase* ulp);
     67     virtual void shutdown();
     68 };
     69 
     70 typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp);
     71 
     72 class LocEngAdapter : public LocAdapterBase {
     73     void* mOwner;
     74     LocInternalAdapter* mInternalAdapter;
     75     UlpProxyBase* mUlp;
     76     LocPosMode mFixCriteria;
     77     bool mNavigating;
     78     // mPowerVote is encoded as
     79     // mPowerVote & 0x20 -- powerVoteRight
     80     // mPowerVote & 0x10 -- power On / Off
     81     unsigned int mPowerVote;
     82     static const unsigned int POWER_VOTE_RIGHT = 0x20;
     83     static const unsigned int POWER_VOTE_VALUE = 0x10;
     84 
     85 public:
     86     bool mSupportsAgpsRequests;
     87     bool mSupportsPositionInjection;
     88 
     89     LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask,
     90                   void* owner, ContextBase* context,
     91                   MsgTask::tCreate tCreator);
     92     virtual ~LocEngAdapter();
     93 
     94     virtual void setUlpProxy(UlpProxyBase* ulp);
     95     inline void requestUlp(unsigned long capabilities) {
     96         mContext->requestUlp(mInternalAdapter, capabilities);
     97     }
     98     inline LocInternalAdapter* getInternalAdapter() { return mInternalAdapter; }
     99     inline UlpProxyBase* getUlpProxy() { return mUlp; }
    100     inline void* getOwner() { return mOwner; }
    101     inline bool hasAgpsExtendedCapabilities() {
    102         return mContext->hasAgpsExtendedCapabilities();
    103     }
    104     inline bool hasCPIExtendedCapabilities() {
    105         return mContext->hasCPIExtendedCapabilities();
    106     }
    107     inline const MsgTask* getMsgTask() { return mMsgTask; }
    108 
    109     inline enum loc_api_adapter_err
    110         startFix()
    111     {
    112         return mLocApi->startFix(mFixCriteria);
    113     }
    114     inline enum loc_api_adapter_err
    115         stopFix()
    116     {
    117         return mLocApi->stopFix();
    118     }
    119     inline enum loc_api_adapter_err
    120         deleteAidingData(GpsAidingData f)
    121     {
    122         return mLocApi->deleteAidingData(f);
    123     }
    124     inline enum loc_api_adapter_err
    125         enableData(int enable)
    126     {
    127         return mLocApi->enableData(enable);
    128     }
    129     inline enum loc_api_adapter_err
    130         setAPN(char* apn, int len)
    131     {
    132         return mLocApi->setAPN(apn, len);
    133     }
    134     inline enum loc_api_adapter_err
    135         injectPosition(double latitude, double longitude, float accuracy)
    136     {
    137         return mLocApi->injectPosition(latitude, longitude, accuracy);
    138     }
    139     inline enum loc_api_adapter_err
    140         setTime(GpsUtcTime time, int64_t timeReference, int uncertainty)
    141     {
    142         return mLocApi->setTime(time, timeReference, uncertainty);
    143     }
    144     inline enum loc_api_adapter_err
    145         setXtraData(char* data, int length)
    146     {
    147         return mLocApi->setXtraData(data, length);
    148     }
    149     inline enum loc_api_adapter_err
    150         requestXtraServer()
    151     {
    152         return mLocApi->requestXtraServer();
    153     }
    154     inline enum loc_api_adapter_err
    155         atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType)
    156     {
    157         return mLocApi->atlOpenStatus(handle, is_succ, apn, bearer, agpsType);
    158     }
    159     inline enum loc_api_adapter_err
    160         atlCloseStatus(int handle, int is_succ)
    161     {
    162         return mLocApi->atlCloseStatus(handle, is_succ);
    163     }
    164     inline enum loc_api_adapter_err
    165         setPositionMode(const LocPosMode *posMode)
    166     {
    167         if (NULL != posMode) {
    168             mFixCriteria = *posMode;
    169         }
    170         return mLocApi->setPositionMode(mFixCriteria);
    171     }
    172     inline enum loc_api_adapter_err
    173         setServer(const char* url, int len)
    174     {
    175         return mLocApi->setServer(url, len);
    176     }
    177     inline enum loc_api_adapter_err
    178         setServer(unsigned int ip, int port,
    179                   LocServerType type)
    180     {
    181         return mLocApi->setServer(ip, port, type);
    182     }
    183     inline enum loc_api_adapter_err
    184         informNiResponse(GpsUserResponseType userResponse, const void* passThroughData)
    185     {
    186         return mLocApi->informNiResponse(userResponse, passThroughData);
    187     }
    188     inline enum loc_api_adapter_err
    189         setSUPLVersion(uint32_t version)
    190     {
    191         return mLocApi->setSUPLVersion(version);
    192     }
    193     inline enum loc_api_adapter_err
    194         setLPPConfig(uint32_t profile)
    195     {
    196         return mLocApi->setLPPConfig(profile);
    197     }
    198     inline enum loc_api_adapter_err
    199         setSensorControlConfig(int sensorUsage, int sensorProvider)
    200     {
    201         return mLocApi->setSensorControlConfig(sensorUsage, sensorProvider);
    202     }
    203     inline enum loc_api_adapter_err
    204         setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk,
    205                             bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk,
    206                             bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk,
    207                             bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk,
    208                             bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk)
    209     {
    210         return mLocApi->setSensorProperties(gyroBiasVarianceRandomWalk_valid, gyroBiasVarianceRandomWalk,
    211                                            accelBiasVarianceRandomWalk_valid, accelBiasVarianceRandomWalk,
    212                                            angleBiasVarianceRandomWalk_valid, angleBiasVarianceRandomWalk,
    213                                            rateBiasVarianceRandomWalk_valid, rateBiasVarianceRandomWalk,
    214                                            velocityBiasVarianceRandomWalk_valid, velocityBiasVarianceRandomWalk);
    215     }
    216     inline virtual enum loc_api_adapter_err
    217         setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec,
    218                             int gyroSamplesPerBatch, int gyroBatchesPerSec,
    219                             int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh,
    220                             int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig)
    221     {
    222         return mLocApi->setSensorPerfControlConfig(controlMode, accelSamplesPerBatch, accelBatchesPerSec,
    223                                                   gyroSamplesPerBatch, gyroBatchesPerSec,
    224                                                   accelSamplesPerBatchHigh, accelBatchesPerSecHigh,
    225                                                   gyroSamplesPerBatchHigh, gyroBatchesPerSecHigh,
    226                                                   algorithmConfig);
    227     }
    228     inline virtual enum loc_api_adapter_err
    229         setExtPowerConfig(int isBatteryCharging)
    230     {
    231         return mLocApi->setExtPowerConfig(isBatteryCharging);
    232     }
    233     inline virtual enum loc_api_adapter_err
    234         setAGLONASSProtocol(unsigned long aGlonassProtocol)
    235     {
    236         return mLocApi->setAGLONASSProtocol(aGlonassProtocol);
    237     }
    238     inline virtual int initDataServiceClient()
    239     {
    240         return mLocApi->initDataServiceClient();
    241     }
    242     inline virtual int openAndStartDataCall()
    243     {
    244         return mLocApi->openAndStartDataCall();
    245     }
    246     inline virtual void stopDataCall()
    247     {
    248         mLocApi->stopDataCall();
    249     }
    250     inline virtual void closeDataCall()
    251     {
    252         mLocApi->closeDataCall();
    253     }
    254     inline enum loc_api_adapter_err
    255         getZpp(GpsLocation &zppLoc, LocPosTechMask &tech_mask)
    256     {
    257         return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask);
    258     }
    259 
    260     inline virtual void installAGpsCert(const DerEncodedCertificate* pData,
    261                                         size_t length,
    262                                         uint32_t slotBitMask)
    263     {
    264         mLocApi->installAGpsCert(pData, length, slotBitMask);
    265     }
    266 
    267     virtual void handleEngineDownEvent();
    268     virtual void handleEngineUpEvent();
    269     virtual void reportPosition(UlpLocation &location,
    270                                 GpsLocationExtended &locationExtended,
    271                                 void* locationExt,
    272                                 enum loc_sess_status status,
    273                                 LocPosTechMask loc_technology_mask);
    274     virtual void reportSv(GpsSvStatus &svStatus,
    275                           GpsLocationExtended &locationExtended,
    276                           void* svExt);
    277     virtual void reportStatus(GpsStatusValue status);
    278     virtual void reportNmea(const char* nmea, int length);
    279     virtual bool reportXtraServer(const char* url1, const char* url2,
    280                                   const char* url3, const int maxlength);
    281     virtual bool requestXtraData();
    282     virtual bool requestTime();
    283     virtual bool requestATL(int connHandle, AGpsType agps_type);
    284     virtual bool releaseATL(int connHandle);
    285     virtual bool requestNiNotify(GpsNiNotification &notify, const void* data);
    286     virtual bool requestSuplES(int connHandle);
    287     virtual bool reportDataCallOpened();
    288     virtual bool reportDataCallClosed();
    289     virtual void reportGpsMeasurementData(GpsData &gpsMeasurementData);
    290 
    291     inline const LocPosMode& getPositionMode() const
    292     {return mFixCriteria;}
    293     inline virtual bool isInSession()
    294     { return mNavigating; }
    295     void setInSession(bool inSession);
    296 
    297     // Permit/prohibit power voting
    298     inline void setPowerVoteRight(bool powerVoteRight) {
    299         mPowerVote = powerVoteRight ? (mPowerVote | POWER_VOTE_RIGHT) :
    300                                       (mPowerVote & ~POWER_VOTE_RIGHT);
    301     }
    302     inline bool getPowerVoteRight() const {
    303         return (mPowerVote & POWER_VOTE_RIGHT) != 0 ;
    304     }
    305     // Set the power voting up/down and do actual operation if permitted
    306     inline void setPowerVote(bool powerOn) {
    307         mPowerVote = powerOn ? (mPowerVote | POWER_VOTE_VALUE) :
    308                                (mPowerVote & ~POWER_VOTE_VALUE);
    309         requestPowerVote();
    310     }
    311     inline bool getPowerVote() const {
    312         return (mPowerVote & POWER_VOTE_VALUE) != 0 ;
    313     }
    314     // Do power voting according to last settings if permitted
    315     void requestPowerVote();
    316 
    317     /*Values for lock
    318       1 = Do not lock any position sessions
    319       2 = Lock MI position sessions
    320       3 = Lock MT position sessions
    321       4 = Lock all position sessions
    322     */
    323     inline int setGpsLock(LOC_GPS_LOCK_MASK lock)
    324     {
    325         return mLocApi->setGpsLock(lock);
    326     }
    327 
    328     int setGpsLockMsg(LOC_GPS_LOCK_MASK lock);
    329 
    330     /*
    331       Returns
    332       Current value of GPS lock on success
    333       -1 on failure
    334      */
    335     inline int getGpsLock()
    336     {
    337         return mLocApi->getGpsLock();
    338     }
    339 
    340     /*
    341       Update Registration Mask
    342      */
    343     void updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event,
    344                                 loc_registration_mask_status isEnabled);
    345 
    346     /*
    347       Set Gnss Constellation Config
    348      */
    349     bool gnssConstellationConfig();
    350 };
    351 
    352 #endif //LOC_API_ENG_ADAPTER_H
    353