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