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_V_0_2_H 30 #define LOC_API_V_0_2_H 31 32 #include <stdint.h> 33 #include <stdbool.h> 34 #include "ds_client.h" 35 #include <LocApiBase.h> 36 #include <loc_api_v02_client.h> 37 38 using namespace loc_core; 39 40 /* This class derives from the LocApiBase class. 41 The members of this class are responsible for converting 42 the Loc API V02 data structures into Loc Adapter data structures. 43 This class also implements some of the virtual functions that 44 handle the requests from loc engine. */ 45 class LocApiV02 : public LocApiBase { 46 enum supported_status { 47 sup_unknown, 48 sup_yes, 49 sup_no 50 }; 51 protected: 52 /* loc api v02 handle*/ 53 locClientHandleType clientHandle; 54 55 private: 56 /*ds client handle*/ 57 dsClientHandleType dsClientHandle; 58 enum supported_status mGnssMeasurementSupported; 59 locClientEventMaskType mQmiMask; 60 bool mInSession; 61 bool mEngineOn; 62 63 /* Convert event mask from loc eng to loc_api_v02 format */ 64 static locClientEventMaskType convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask); 65 66 /* Convert GPS LOCK mask from gps.conf definition */ 67 static qmiLocLockEnumT_v02 convertGpsLockMask(LOC_GPS_LOCK_MASK lockMask); 68 69 /* Convert error from loc_api_v02 to loc eng format*/ 70 static enum loc_api_adapter_err convertErr(locClientStatusEnumType status); 71 72 /* convert Ni Encoding type from QMI_LOC to loc eng format */ 73 static GpsNiEncodingType convertNiEncoding( 74 qmiLocNiDataCodingSchemeEnumT_v02 loc_encoding); 75 76 /*convert NI notify verify type from QMI LOC to loc eng format*/ 77 static bool convertNiNotifyVerifyType (GpsNiNotification *notif, 78 qmiLocNiNotifyVerifyEnumT_v02 notif_priv); 79 80 /*convert GpsMeasurement type from QMI LOC to loc eng format*/ 81 static void convertGpsMeasurements (GpsMeasurement& gpsMeasurement, 82 const qmiLocSVMeasurementStructT_v02& gnss_measurement_info); 83 84 /*convert GpsClock type from QMI LOC to loc eng format*/ 85 static void convertGpsClock (GpsClock& gpsClock, 86 const qmiLocEventGnssSvMeasInfoIndMsgT_v02& gnss_measurement_info); 87 88 /* convert position report to loc eng format and send the converted 89 position to loc eng */ 90 void reportPosition 91 (const qmiLocEventPositionReportIndMsgT_v02 *location_report_ptr); 92 93 /* convert satellite report to loc eng format and send the converted 94 report to loc eng */ 95 void reportSv (const qmiLocEventGnssSvInfoIndMsgT_v02 *gnss_report_ptr); 96 97 /* convert engine state report to loc eng format and send the converted 98 report to loc eng */ 99 void reportEngineState ( 100 const qmiLocEventEngineStateIndMsgT_v02 *engine_state_ptr); 101 102 /* convert fix session report to loc eng format and send the converted 103 report to loc eng */ 104 void reportFixSessionState ( 105 const qmiLocEventFixSessionStateIndMsgT_v02 *fix_session_state_ptr); 106 107 /* convert NMEA report to loc eng format and send the converted 108 report to loc eng */ 109 void reportNmea (const qmiLocEventNmeaIndMsgT_v02 *nmea_report_ptr); 110 111 /* convert and report an ATL request to loc engine */ 112 void reportAtlRequest( 113 const qmiLocEventLocationServerConnectionReqIndMsgT_v02 114 *server_request_ptr); 115 116 /* convert and report NI request to loc eng */ 117 void reportNiRequest( 118 const qmiLocEventNiNotifyVerifyReqIndMsgT_v02 *ni_req_ptr); 119 120 /* report the xtra server info */ 121 void reportXtraServerUrl( 122 const qmiLocEventInjectPredictedOrbitsReqIndMsgT_v02* server_request_ptr); 123 124 /* convert and report GNSS measurement data to loc eng */ 125 void reportGnssMeasurementData( 126 const qmiLocEventGnssSvMeasInfoIndMsgT_v02& gnss_measurement_report_ptr); 127 128 bool registerEventMask(locClientEventMaskType qmiMask); 129 locClientEventMaskType adjustMaskForNoSession(locClientEventMaskType qmiMask); 130 void cacheGnssMeasurementSupport(); 131 132 protected: 133 virtual enum loc_api_adapter_err 134 open(LOC_API_ADAPTER_EVENT_MASK_T mask); 135 virtual enum loc_api_adapter_err 136 close(); 137 138 public: 139 LocApiV02(const MsgTask* msgTask, 140 LOC_API_ADAPTER_EVENT_MASK_T exMask, 141 ContextBase *context = NULL); 142 ~LocApiV02(); 143 144 /* event callback registered with the loc_api v02 interface */ 145 virtual void eventCb(locClientHandleType client_handle, 146 uint32_t loc_event_id, 147 locClientEventIndUnionType loc_event_payload); 148 149 /* error callback, this function handles the service unavailable 150 error */ 151 void errorCb(locClientHandleType handle, 152 locClientErrorEnumType errorId); 153 154 void ds_client_event_cb(ds_client_status_enum_type result); 155 156 virtual enum loc_api_adapter_err startFix(const LocPosMode& posMode); 157 158 virtual enum loc_api_adapter_err stopFix(); 159 160 virtual enum loc_api_adapter_err 161 setPositionMode(const LocPosMode& mode); 162 163 virtual enum loc_api_adapter_err 164 setTime(GpsUtcTime time, int64_t timeReference, int uncertainty); 165 166 virtual enum loc_api_adapter_err 167 injectPosition(double latitude, double longitude, float accuracy); 168 169 virtual enum loc_api_adapter_err 170 deleteAidingData(GpsAidingData f); 171 172 virtual enum loc_api_adapter_err 173 informNiResponse(GpsUserResponseType userResponse, 174 const void* passThroughData); 175 176 virtual enum loc_api_adapter_err 177 setServer(const char* url, int len); 178 virtual enum loc_api_adapter_err 179 setServer(unsigned int ip, int port, LocServerType type); 180 virtual enum loc_api_adapter_err 181 setXtraData(char* data, int length); 182 virtual enum loc_api_adapter_err 183 requestXtraServer(); 184 virtual enum loc_api_adapter_err 185 atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, 186 AGpsType agpsType); 187 virtual enum loc_api_adapter_err atlCloseStatus(int handle, int is_succ); 188 virtual enum loc_api_adapter_err setSUPLVersion(uint32_t version); 189 virtual enum loc_api_adapter_err setLPPConfig(uint32_t profile); 190 191 virtual enum loc_api_adapter_err 192 setSensorControlConfig(int sensorUsage, int sensorProvider); 193 194 virtual enum loc_api_adapter_err 195 setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, 196 bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk, 197 bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk, 198 bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk, 199 bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk); 200 201 virtual enum loc_api_adapter_err 202 setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec, 203 int gyroSamplesPerBatch, int gyroBatchesPerSec, 204 int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh, 205 int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig); 206 virtual enum loc_api_adapter_err setExtPowerConfig(int isBatteryCharging); 207 virtual enum loc_api_adapter_err setAGLONASSProtocol(unsigned long aGlonassProtocol); 208 virtual enum loc_api_adapter_err 209 getWwanZppFix(GpsLocation & zppLoc); 210 virtual enum loc_api_adapter_err 211 getBestAvailableZppFix(GpsLocation & zppLoc); 212 virtual enum loc_api_adapter_err 213 getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask); 214 virtual int initDataServiceClient(); 215 virtual int openAndStartDataCall(); 216 virtual void stopDataCall(); 217 virtual void closeDataCall(); 218 virtual int setGpsLock(LOC_GPS_LOCK_MASK lock); 219 220 /* 221 Returns 222 Current value of GPS Lock on success 223 -1 on failure 224 */ 225 virtual int getGpsLock(void); 226 227 virtual void installAGpsCert(const DerEncodedCertificate* pData, 228 size_t length, 229 uint32_t slotBitMask); 230 /* 231 Update Registration Mask 232 */ 233 virtual int updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event, 234 loc_registration_mask_status isEnabled); 235 /* 236 Set Gnss Constellation Config 237 */ 238 virtual bool gnssConstellationConfig(); 239 }; 240 241 extern "C" LocApiBase* getLocApi(const MsgTask* msgTask, 242 LOC_API_ADAPTER_EVENT_MASK_T exMask, 243 ContextBase* context); 244 #endif //LOC_API_V_0_2_H 245