• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011, Code Aurora Forum. 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 Code Aurora Forum, Inc. 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_ADAPTER_H
30 #define LOC_API_V_0_2_ADAPTER_H
31 
32 #include <LocApiAdapter.h>
33 #include "loc_api_v02_client.h"
34 #include <stdint.h>
35 #include <stdbool.h>
36 
37 /* Fix criteria structure*/
38 struct LocApiV02FixCriteria
39 {
40   LocPositionMode mode;
41   GpsPositionRecurrence recurrence;
42   uint32_t min_interval ;
43   uint32_t preferred_accuracy ;
44   uint32_t preferred_time;
45 
46   /* Constructor for the structure  */
LocApiV02FixCriteriaLocApiV02FixCriteria47   inline LocApiV02FixCriteria (LocPositionMode mode,
48                                GpsPositionRecurrence recur,
49                                uint32_t min_int,
50                                uint32_t pref_acc,
51                                uint32_t pref_time) :
52     mode(mode), recurrence(recur), min_interval(min_int),
53     preferred_accuracy(pref_acc), preferred_time(pref_time) {}
54 };
55 
56 /* This class derives from the LocApiAdapter class.
57    The members of this class are responsible for converting
58    the Loc API V02 data structures into Loc Engine data structures.
59    This class also implements some of the virtual functions that
60    handle the requests from loc engine. */
61 class LocApiV02Adapter : public LocApiAdapter {
62 
63   /* loc api v02 handle*/
64   locClientHandleType clientHandle;
65 
66   /* events the client is registered for */
67   locClientEventMaskType eventMask;
68 
69   /* current session state */
70   bool navigating;
71 
72   /* current fix criteria, for Loc aPI V02 this is
73      stored when set_position_mode is called and
74      sent out with Loc aPI V02 start message when the
75      start_fix() is called by loc engine. */
76   LocApiV02FixCriteria fixCriteria;
77 
78   /* Convert event mask from loc eng to loc_api_v02 format */
79   locClientEventMaskType convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask);
80 
81   /* Convert error from loc_api_v02 to loc eng format*/
82   enum loc_api_adapter_err convertErr(locClientStatusEnumType status);
83 
84   /* convert Ni Encoding type from QMI_LOC to loc eng format */
85   GpsNiEncodingType convertNiEncoding(
86     qmiLocNiDataCodingSchemeEnumT_v02 loc_encoding);
87 
88   /*convert NI notify verify type from QMI LOC to loc eng format*/
89   bool convertNiNotifyVerifyType (GpsNiNotification *notif,
90       qmiLocNiNotifyVerifyEnumT_v02 notif_priv);
91 
92   /* close Loc API V02 client */
93   int deInitLocClient();
94 
95   /* convert position report to loc eng format and send the converted
96      position to loc eng */
97   void reportPosition
98     (const qmiLocEventPositionReportIndMsgT_v02 *location_report_ptr);
99 
100   /* convert satellite report to loc eng format and  send the converted
101      report to loc eng */
102   void reportSv (const qmiLocEventGnssSvInfoIndMsgT_v02 *gnss_report_ptr);
103 
104   /* convert engine state report to loc eng format and send the converted
105      report to loc eng */
106   void reportEngineState (
107     const qmiLocEventEngineStateIndMsgT_v02 *engine_state_ptr);
108 
109   /* convert fix session report to loc eng format and send the converted
110      report to loc eng */
111   void reportFixSessionState (
112     const qmiLocEventFixSessionStateIndMsgT_v02 *fix_session_state_ptr);
113 
114   /* convert NMEA report to loc eng format and send the converted
115      report to loc eng */
116   void reportNmea (const qmiLocEventNmeaIndMsgT_v02 *nmea_report_ptr);
117 
118   /* convert and report an ATL request to loc engine */
119   void reportAtlRequest(
120     const qmiLocEventLocationServerConnectionReqIndMsgT_v02
121     *server_request_ptr);
122 
123   /* convert and report NI request to loc eng */
124   void reportNiRequest(
125     const qmiLocEventNiNotifyVerifyReqIndMsgT_v02 *ni_req_ptr);
126 
127 public:
128   LocApiV02Adapter(LocEng &locEng);
129   ~LocApiV02Adapter();
130 
131   /* event callback registered with the loc_api v02 interface */
132   void eventCb(locClientHandleType client_handle,
133                uint32_t loc_event_id,
134                locClientEventIndUnionType loc_event_payload);
135 
136   /* error callback, this function handles the  service unavailable
137      error */
138   void errorCb(locClientHandleType handle,
139                locClientErrorEnumType errorId);
140 
141   virtual enum loc_api_adapter_err reinit();
142 
143   virtual enum loc_api_adapter_err startFix();
144 
145   virtual enum loc_api_adapter_err stopFix();
146 
147   virtual enum loc_api_adapter_err
148     setPositionMode(LocPositionMode mode, GpsPositionRecurrence recurrence,
149                     uint32_t min_interval, uint32_t preferred_accuracy,
150                     uint32_t preferred_time);
151 
152   virtual enum loc_api_adapter_err
153     setTime(GpsUtcTime time, int64_t timeReference, int uncertainty);
154 
155   virtual enum loc_api_adapter_err
156     injectPosition(double latitude, double longitude, float accuracy);
157 
158   virtual enum loc_api_adapter_err
159     deleteAidingData(GpsAidingData f);
160 
161   virtual enum loc_api_adapter_err
162     informNiResponse(GpsUserResponseType userResponse,
163                      const void* passThroughData);
164 
165   virtual enum loc_api_adapter_err
166     setServer(const char* url, int len);
167   virtual enum loc_api_adapter_err
168     setServer(unsigned int ip, int port, LocServerType type);
169   virtual enum loc_api_adapter_err
170     setXtraData(char* data, int length);
171 #ifdef QCOM_FEATURE_IPV6
172   virtual enum loc_api_adapter_err
173     atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear,
174                    AGpsType agpsType);
175 #else
176   virtual enum loc_api_adapter_err
177     atlOpenStatus(int handle, int is_succ, char* apn,
178                    AGpsType agpsType);
179 #endif
180   virtual enum loc_api_adapter_err atlCloseStatus(int handle, int is_succ);
181   virtual enum loc_api_adapter_err setSUPLVersion(uint32_t version);
182 
183   virtual enum loc_api_adapter_err
184     setSensorControlConfig(int sensorUsage);
185 
186   virtual enum loc_api_adapter_err
187     setSensorProperties(float gyroBiasVarianceRandomWalk);
188 
189   virtual enum loc_api_adapter_err
190     setSensorPerfControlConfig(int controlMode,
191                                int accelSamplesPerBatch,
192                                int accelBatchesPerSec,
193                                int gyroSamplesPerBatch,
194                                int gyroBatchesPerSec);
195 };
196 
197 #endif //LOC_API_V_0_2_ADAPTER_H
198