blob: d7b42757a170cdf939e8423e69523a57796b5f2f [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/* Copyright (c) 2017-2020 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 GNSS_ADAPTER_H
30#define GNSS_ADAPTER_H
31
32#include <LocAdapterBase.h>
33#include <LocContext.h>
34#include <IOsObserver.h>
35#include <EngineHubProxyBase.h>
36#include <LocationAPI.h>
37#include <Agps.h>
38#include <SystemStatus.h>
39#include <XtraSystemStatusObserver.h>
40#include <map>
41#include <functional>
42#include <loc_misc_utils.h>
43#include <queue>
44#include <NativeAgpsHandler.h>
45
46#define MAX_URL_LEN 256
47#define NMEA_SENTENCE_MAX_LENGTH 200
48#define GLONASS_SV_ID_OFFSET 64
49#define MAX_SATELLITES_IN_USE 12
50#define LOC_NI_NO_RESPONSE_TIME 20
51#define LOC_GPS_NI_RESPONSE_IGNORE 4
52#define ODCPI_EXPECTED_INJECTION_TIME_MS 10000
53#define DELETE_AIDING_DATA_EXPECTED_TIME_MS 5000
54
55class GnssAdapter;
56
57typedef std::map<LocationSessionKey, LocationOptions> LocationSessionMap;
58typedef std::map<LocationSessionKey, TrackingOptions> TrackingOptionsMap;
59
60class OdcpiTimer : public LocTimer {
61public:
62 OdcpiTimer(GnssAdapter* adapter) :
63 LocTimer(), mAdapter(adapter), mActive(false) {}
64
65 inline void start() {
66 mActive = true;
67 LocTimer::start(ODCPI_EXPECTED_INJECTION_TIME_MS, false);
68 }
69 inline void stop() {
70 mActive = false;
71 LocTimer::stop();
72 }
73 inline void restart() {
74 stop();
75 start();
76 }
77 inline bool isActive() {
78 return mActive;
79 }
80
81private:
82 // Override
83 virtual void timeOutCallback() override;
84
85 GnssAdapter* mAdapter;
86 bool mActive;
87};
88
89typedef struct {
90 pthread_t thread; /* NI thread */
91 uint32_t respTimeLeft; /* examine time for NI response */
92 bool respRecvd; /* NI User reponse received or not from Java layer*/
93 void* rawRequest;
94 uint32_t reqID; /* ID to check against response */
95 GnssNiResponse resp;
96 pthread_cond_t tCond;
97 pthread_mutex_t tLock;
98 GnssAdapter* adapter;
99} NiSession;
100typedef struct {
101 NiSession session; /* SUPL NI Session */
102 NiSession sessionEs; /* Emergency SUPL NI Session */
103 uint32_t reqIDCounter;
104} NiData;
105
106typedef enum {
107 NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA
108 NMEA_PROVIDER_MP // Modem Processor Provider of NMEA
109} NmeaProviderType;
110typedef struct {
111 GnssSvType svType;
112 const char* talker;
113 uint64_t mask;
114 uint32_t svIdOffset;
115} NmeaSvMeta;
116
117typedef struct {
118 double latitude;
119 double longitude;
120 float accuracy;
121 // the CPI will be blocked until the boot time
122 // specified in blockedTillTsMs
123 int64_t blockedTillTsMs;
124 // CPIs whose both latitude and longitude differ
125 // no more than latLonThreshold will be blocked
126 // in units of degree
127 double latLonDiffThreshold;
128} BlockCPIInfo;
129
130typedef struct {
131 bool isValid;
132 bool enable;
133 float tuncThresholdMs; // need to be specified if enable is true
134 uint32_t energyBudget; // need to be specified if enable is true
135} TuncConfigInfo;
136
137typedef struct {
138 bool isValid;
139 bool enable;
140} PaceConfigInfo;
141
142typedef struct {
143 bool isValid;
144 bool enable;
145 bool enableFor911;
146} RobustLocationConfigInfo;
147
148typedef struct {
149 TuncConfigInfo tuncConfigInfo;
150 PaceConfigInfo paceConfigInfo;
151 RobustLocationConfigInfo robustLocationConfigInfo;
152 LeverArmConfigInfo leverArmConfigInfo;
153} LocIntegrationConfigInfo;
154
155using namespace loc_core;
156
157namespace loc_core {
158 class SystemStatus;
159}
160
161typedef std::function<void(
162 uint64_t gnssEnergyConsumedFromFirstBoot
163)> GnssEnergyConsumedCallback;
164
165typedef void* QDgnssListenerHDL;
166typedef std::function<void(
167 bool sessionActive
168)> QDgnssSessionActiveCb;
169
170struct CdfwInterface {
171 void (*startDgnssApiService)(const MsgTask& msgTask);
172 QDgnssListenerHDL (*createUsableReporter)(
173 QDgnssSessionActiveCb sessionActiveCb);
174 void (*destroyUsableReporter)(QDgnssListenerHDL handle);
175 void (*reportUsable)(QDgnssListenerHDL handle, bool usable);
176};
177
178typedef uint16_t DGnssStateBitMask;
179#define DGNSS_STATE_ENABLE_NTRIP_COMMAND 0X01
180#define DGNSS_STATE_NO_NMEA_PENDING 0X02
181#define DGNSS_STATE_NTRIP_SESSION_STARTED 0X04
182
183class GnssReportLoggerUtil {
184public:
185 typedef void (*LogGnssLatency)(const GnssLatencyInfo& gnssLatencyMeasInfo);
186
187 GnssReportLoggerUtil() : mLogLatency(nullptr) {
188 const char* libname = "liblocdiagiface.so";
189 void* libHandle = nullptr;
190 mLogLatency = (LogGnssLatency)dlGetSymFromLib(libHandle, libname, "LogGnssLatency");
191 }
192
193 bool isLogEnabled();
194 void log(const GnssLatencyInfo& gnssLatencyMeasInfo);
195
196private:
197 LogGnssLatency mLogLatency;
198};
199
200class GnssAdapter : public LocAdapterBase {
201
202 /* ==== Engine Hub ===================================================================== */
203 EngineHubProxyBase* mEngHubProxy;
204 bool mNHzNeeded;
205 bool mSPEAlreadyRunningAtHighestInterval;
206
207 /* ==== TRACKING ======================================================================= */
208 TrackingOptionsMap mTimeBasedTrackingSessions;
209 LocationSessionMap mDistanceBasedTrackingSessions;
210 LocPosMode mLocPositionMode;
211 GnssSvUsedInPosition mGnssSvIdUsedInPosition;
212 bool mGnssSvIdUsedInPosAvail;
213 GnssSvMbUsedInPosition mGnssMbSvIdUsedInPosition;
214 bool mGnssMbSvIdUsedInPosAvail;
215
216 /* ==== CONTROL ======================================================================== */
217 LocationControlCallbacks mControlCallbacks;
218 uint32_t mAfwControlId;
219 uint32_t mNmeaMask;
220 uint64_t mPrevNmeaRptTimeNsec;
221 GnssSvIdConfig mGnssSvIdConfig;
222 GnssSvTypeConfig mGnssSeconaryBandConfig;
223 GnssSvTypeConfig mGnssSvTypeConfig;
224 GnssSvTypeConfigCallback mGnssSvTypeConfigCb;
225 bool mSupportNfwControl;
226 LocIntegrationConfigInfo mLocConfigInfo;
227
228 /* ==== NI ============================================================================= */
229 NiData mNiData;
230
231 /* ==== AGPS =========================================================================== */
232 // This must be initialized via initAgps()
233 AgpsManager mAgpsManager;
234 void initAgps(const AgpsCbInfo& cbInfo);
235
236 /* ==== NFW =========================================================================== */
237 NfwStatusCb mNfwCb;
238 IsInEmergencySession mIsE911Session;
239 inline void initNfw(const NfwCbInfo& cbInfo) {
240 mNfwCb = (NfwStatusCb)cbInfo.visibilityControlCb;
241 mIsE911Session = (IsInEmergencySession)cbInfo.isInEmergencySession;
242 }
243
244 /* ==== Measurement Corrections========================================================= */
245 bool mIsMeasCorrInterfaceOpen;
246 measCorrSetCapabilitiesCb mMeasCorrSetCapabilitiesCb;
247 bool initMeasCorr(bool bSendCbWhenNotSupported);
248 bool mIsAntennaInfoInterfaceOpened;
249
250 /* ==== DGNSS Data Usable Report======================================================== */
251 QDgnssListenerHDL mQDgnssListenerHDL;
252 const CdfwInterface* mCdfwInterface;
253 bool mDGnssNeedReport;
254 bool mDGnssDataUsage;
255 void reportDGnssDataUsable(const GnssSvMeasurementSet &svMeasurementSet);
256
257 /* ==== ODCPI ========================================================================== */
258 OdcpiRequestCallback mOdcpiRequestCb;
259 bool mOdcpiRequestActive;
260 OdcpiPrioritytype mCallbackPriority;
261 OdcpiTimer mOdcpiTimer;
262 OdcpiRequestInfo mOdcpiRequest;
263 void odcpiTimerExpire();
264
265 /* ==== DELETEAIDINGDATA =============================================================== */
266 int64_t mLastDeleteAidingDataTime;
267
268 /* === SystemStatus ===================================================================== */
269 SystemStatus* mSystemStatus;
270 std::string mServerUrl;
271 std::string mMoServerUrl;
272 XtraSystemStatusObserver mXtraObserver;
273 LocationSystemInfo mLocSystemInfo;
274 std::vector<GnssSvIdSource> mBlacklistedSvIds;
275 PowerStateType mSystemPowerState;
276
277 /* === Misc ===================================================================== */
278 BlockCPIInfo mBlockCPIInfo;
279 bool mPowerOn;
280 uint32_t mAllowFlpNetworkFixes;
281 std::queue<GnssLatencyInfo> mGnssLatencyInfoQueue;
282 GnssReportLoggerUtil mLogger;
283 bool mDreIntEnabled;
284
285 /* === NativeAgpsHandler ======================================================== */
286 NativeAgpsHandler mNativeAgpsHandler;
287
288 /* === Misc callback from QMI LOC API ============================================== */
289 GnssEnergyConsumedCallback mGnssEnergyConsumedCb;
290 std::function<void(bool)> mPowerStateCb;
291
292 /*==== CONVERSION ===================================================================*/
293 static void convertOptions(LocPosMode& out, const TrackingOptions& trackingOptions);
294 static void convertLocation(Location& out, const UlpLocation& ulpLocation,
295 const GpsLocationExtended& locationExtended);
296 static void convertLocationInfo(GnssLocationInfoNotification& out,
297 const GpsLocationExtended& locationExtended,
298 loc_sess_status status);
299 static uint16_t getNumSvUsed(uint64_t svUsedIdsMask,
300 int totalSvCntInThisConstellation);
301
302 /* ======== UTILITIES ================================================================== */
303 inline void initOdcpi(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority);
304 inline void injectOdcpi(const Location& location);
305 static bool isFlpClient(LocationCallbacks& locationCallbacks);
306
307 /*==== DGnss Ntrip Source ==========================================================*/
308 StartDgnssNtripParams mStartDgnssNtripParams;
309 bool mSendNmeaConsent;
310 DGnssStateBitMask mDgnssState;
311 void checkUpdateDgnssNtrip(bool isLocationValid);
312 void stopDgnssNtrip();
313 uint64_t mDgnssLastNmeaBootTimeMilli;
314
315protected:
316
317 /* ==== CLIENT ========================================================================= */
318 virtual void updateClientsEventMask();
319 virtual void stopClientSessions(LocationAPI* client);
320 inline void setNmeaReportRateConfig();
321 void logLatencyInfo();
322
323public:
324 GnssAdapter();
325 virtual inline ~GnssAdapter() { }
326
327 /* ==== SSR ============================================================================ */
328 /* ======== EVENTS ====(Called from QMI Thread)========================================= */
329 virtual void handleEngineUpEvent();
330 /* ======== UTILITIES ================================================================== */
331 void restartSessions(bool modemSSR = false);
332 void checkAndRestartTimeBasedSession();
333 void checkAndRestartSPESession();
334 void suspendSessions();
335
336 /* ==== CLIENT ========================================================================= */
337 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
338 virtual void addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks);
339
340 /* ==== TRACKING ======================================================================= */
341 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
342 uint32_t startTrackingCommand(
343 LocationAPI* client, TrackingOptions& trackingOptions);
344 void updateTrackingOptionsCommand(
345 LocationAPI* client, uint32_t id, TrackingOptions& trackingOptions);
346 void stopTrackingCommand(LocationAPI* client, uint32_t id);
347 /* ======== RESPONSES ================================================================== */
348 void reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId);
349 /* ======== UTILITIES ================================================================== */
350 bool isTimeBasedTrackingSession(LocationAPI* client, uint32_t sessionId);
351 bool isDistanceBasedTrackingSession(LocationAPI* client, uint32_t sessionId);
352 bool hasCallbacksToStartTracking(LocationAPI* client);
353 bool isTrackingSession(LocationAPI* client, uint32_t sessionId);
354 void saveTrackingSession(LocationAPI* client, uint32_t sessionId,
355 const TrackingOptions& trackingOptions);
356 void eraseTrackingSession(LocationAPI* client, uint32_t sessionId);
357
358 bool setLocPositionMode(const LocPosMode& mode);
359 LocPosMode& getLocPositionMode() { return mLocPositionMode; }
360
361 bool startTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t sessionId,
362 const TrackingOptions& trackingOptions);
363 void startTimeBasedTracking(LocationAPI* client, uint32_t sessionId,
364 const TrackingOptions& trackingOptions);
365 bool stopTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t id);
366 void stopTracking(LocationAPI* client, uint32_t id);
367 bool updateTrackingMultiplex(LocationAPI* client, uint32_t id,
368 const TrackingOptions& trackingOptions);
369 void updateTracking(LocationAPI* client, uint32_t sessionId,
370 const TrackingOptions& updatedOptions, const TrackingOptions& oldOptions);
371 bool checkAndSetSPEToRunforNHz(TrackingOptions & out);
372
373 void setConstrainedTunc(bool enable, float tuncConstraint,
374 uint32_t energyBudget, uint32_t sessionId);
375 void setPositionAssistedClockEstimator(bool enable, uint32_t sessionId);
376 void gnssUpdateSvConfig(uint32_t sessionId,
377 const GnssSvTypeConfig& constellationEnablementConfig,
378 const GnssSvIdConfig& blacklistSvConfig);
379
380 void gnssUpdateSecondaryBandConfig(
381 uint32_t sessionId, const GnssSvTypeConfig& secondaryBandConfig);
382 void gnssGetSecondaryBandConfig(uint32_t sessionId);
383 void resetSvConfig(uint32_t sessionId);
384 void configLeverArm(uint32_t sessionId, const LeverArmConfigInfo& configInfo);
385 void configRobustLocation(uint32_t sessionId, bool enable, bool enableForE911);
386 void configMinGpsWeek(uint32_t sessionId, uint16_t minGpsWeek);
387
388 /* ==== NI ============================================================================= */
389 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
390 void gnssNiResponseCommand(LocationAPI* client, uint32_t id, GnssNiResponse response);
391 /* ======================(Called from NI Thread)======================================== */
392 void gnssNiResponseCommand(GnssNiResponse response, void* rawRequest);
393 /* ======== UTILITIES ================================================================== */
394 bool hasNiNotifyCallback(LocationAPI* client);
395 NiData& getNiData() { return mNiData; }
396
397 /* ==== CONTROL CLIENT ================================================================= */
398 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
399 uint32_t enableCommand(LocationTechnologyType techType);
400 void disableCommand(uint32_t id);
401 void setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks);
402 void readConfigCommand();
403 void requestUlpCommand();
404 void initEngHubProxyCommand();
405 uint32_t* gnssUpdateConfigCommand(const GnssConfig& config);
406 uint32_t* gnssGetConfigCommand(GnssConfigFlagsMask mask);
407 uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data);
408 void deleteAidingData(const GnssAidingData &data, uint32_t sessionId);
409 void gnssUpdateXtraThrottleCommand(const bool enabled);
410 std::vector<LocationError> gnssUpdateConfig(const std::string& oldMoServerUrl,
411 const std::string& moServerUrl,
412 const std::string& serverUrl,
413 GnssConfig& gnssConfigRequested,
414 GnssConfig& gnssConfigNeedEngineUpdate, size_t count = 0);
415
416 /* ==== GNSS SV TYPE CONFIG ============================================================ */
417 /* ==== COMMANDS ====(Called from Client Thread)======================================== */
418 /* ==== These commands are received directly from client bypassing Location API ======== */
419 void gnssUpdateSvTypeConfigCommand(GnssSvTypeConfig config);
420 void gnssGetSvTypeConfigCommand(GnssSvTypeConfigCallback callback);
421 void gnssResetSvTypeConfigCommand();
422
423 /* ==== UTILITIES ====================================================================== */
424 LocationError gnssSvIdConfigUpdateSync(const std::vector<GnssSvIdSource>& blacklistedSvIds);
425 LocationError gnssSvIdConfigUpdateSync();
426 void gnssSvIdConfigUpdate(const std::vector<GnssSvIdSource>& blacklistedSvIds);
427 void gnssSvIdConfigUpdate();
428 void gnssSvTypeConfigUpdate(const GnssSvTypeConfig& config);
429 void gnssSvTypeConfigUpdate(bool sendReset = false);
430 inline void gnssSetSvTypeConfig(const GnssSvTypeConfig& config)
431 { mGnssSvTypeConfig = config; }
432 inline void gnssSetSvTypeConfigCallback(GnssSvTypeConfigCallback callback)
433 { mGnssSvTypeConfigCb = callback; }
434 inline GnssSvTypeConfigCallback gnssGetSvTypeConfigCallback()
435 { return mGnssSvTypeConfigCb; }
436 void setConfig();
437 void gnssSecondaryBandConfigUpdate(LocApiResponse* locApiResponse= nullptr);
438
439 /* ========= AGPS ====================================================================== */
440 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
441 void initDefaultAgpsCommand();
442 void initAgpsCommand(const AgpsCbInfo& cbInfo);
443 void initNfwCommand(const NfwCbInfo& cbInfo);
444 void dataConnOpenCommand(AGpsExtType agpsType,
445 const char* apnName, int apnLen, AGpsBearerType bearerType);
446 void dataConnClosedCommand(AGpsExtType agpsType);
447 void dataConnFailedCommand(AGpsExtType agpsType);
448 void getGnssEnergyConsumedCommand(GnssEnergyConsumedCallback energyConsumedCb);
449 void nfwControlCommand(bool enable);
450 uint32_t setConstrainedTuncCommand (bool enable, float tuncConstraint,
451 uint32_t energyBudget);
452 uint32_t setPositionAssistedClockEstimatorCommand (bool enable);
453 uint32_t gnssUpdateSvConfigCommand(const GnssSvTypeConfig& constellationEnablementConfig,
454 const GnssSvIdConfig& blacklistSvConfig);
455 uint32_t gnssUpdateSecondaryBandConfigCommand(
456 const GnssSvTypeConfig& secondaryBandConfig);
457 uint32_t gnssGetSecondaryBandConfigCommand();
458 uint32_t configLeverArmCommand(const LeverArmConfigInfo& configInfo);
459 uint32_t configRobustLocationCommand(bool enable, bool enableForE911);
460 bool openMeasCorrCommand(const measCorrSetCapabilitiesCb setCapabilitiesCb);
461 bool measCorrSetCorrectionsCommand(const GnssMeasurementCorrections gnssMeasCorr);
462 inline void closeMeasCorrCommand() { mIsMeasCorrInterfaceOpen = false; }
463 uint32_t antennaInfoInitCommand(const antennaInfoCb antennaInfoCallback);
464 inline void antennaInfoCloseCommand() { mIsAntennaInfoInterfaceOpened = false; }
465 uint32_t configMinGpsWeekCommand(uint16_t minGpsWeek);
466 uint32_t configDeadReckoningEngineParamsCommand(const DeadReckoningEngineConfig& dreConfig);
467 uint32_t configEngineRunStateCommand(PositioningEngineMask engType,
468 LocEngineRunState engState);
469
470 /* ========= ODCPI ===================================================================== */
471 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
472 void initOdcpiCommand(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority);
473 void injectOdcpiCommand(const Location& location);
474 /* ======== RESPONSES ================================================================== */
475 void reportResponse(LocationError err, uint32_t sessionId);
476 void reportResponse(size_t count, LocationError* errs, uint32_t* ids);
477 /* ======== UTILITIES ================================================================== */
478 LocationControlCallbacks& getControlCallbacks() { return mControlCallbacks; }
479 void setControlCallbacks(const LocationControlCallbacks& controlCallbacks)
480 { mControlCallbacks = controlCallbacks; }
481 void setAfwControlId(uint32_t id) { mAfwControlId = id; }
482 uint32_t getAfwControlId() { return mAfwControlId; }
483 virtual bool isInSession() { return !mTimeBasedTrackingSessions.empty(); }
484 void initDefaultAgps();
485 bool initEngHubProxy();
486 void initCDFWService();
487 void odcpiTimerExpireEvent();
488
489 /* ==== REPORTS ======================================================================== */
490 /* ======== EVENTS ====(Called from QMI/EngineHub Thread)===================================== */
491 virtual void reportPositionEvent(const UlpLocation& ulpLocation,
492 const GpsLocationExtended& locationExtended,
493 enum loc_sess_status status,
494 LocPosTechMask techMask,
495 GnssDataNotification* pDataNotify = nullptr,
496 int msInWeek = -1);
497 virtual void reportEnginePositionsEvent(unsigned int count,
498 EngineLocationInfo* locationArr);
499
500 virtual void reportSvEvent(const GnssSvNotification& svNotify,
501 bool fromEngineHub=false);
502 virtual void reportNmeaEvent(const char* nmea, size_t length);
503 virtual void reportDataEvent(const GnssDataNotification& dataNotify, int msInWeek);
504 virtual bool requestNiNotifyEvent(const GnssNiNotification& notify, const void* data,
505 const LocInEmergency emergencyState);
506 virtual void reportGnssMeasurementsEvent(const GnssMeasurements& gnssMeasurements,
507 int msInWeek);
508 virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
509 virtual void reportSvEphemerisEvent(GnssSvEphemerisReport & svEphemeris);
510 virtual void reportGnssSvIdConfigEvent(const GnssSvIdConfig& config);
511 virtual void reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& config);
512 virtual void reportGnssConfigEvent(uint32_t sessionId, const GnssConfig& gnssConfig);
513 virtual bool reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot);
514 virtual void reportLocationSystemInfoEvent(const LocationSystemInfo& locationSystemInfo);
515
516 virtual bool requestATL(int connHandle, LocAGpsType agps_type, LocApnTypeMask apn_type_mask);
517 virtual bool releaseATL(int connHandle);
518 virtual bool requestOdcpiEvent(OdcpiRequestInfo& request);
519 virtual bool reportDeleteAidingDataEvent(GnssAidingData& aidingData);
520 virtual bool reportKlobucharIonoModelEvent(GnssKlobucharIonoModel& ionoModel);
521 virtual bool reportGnssAdditionalSystemInfoEvent(
522 GnssAdditionalSystemInfo& additionalSystemInfo);
523 virtual void reportNfwNotificationEvent(GnssNfwNotification& notification);
524 virtual void reportLatencyInfoEvent(const GnssLatencyInfo& gnssLatencyInfo);
525 virtual bool reportQwesCapabilities
526 (
527 const std::unordered_map<LocationQwesFeatureType, bool> &featureMap
528 );
529 void reportPdnTypeFromWds(int pdnType, AGpsExtType agpsType, std::string apnName,
530 AGpsBearerType bearerType);
531
532 /* ======== UTILITIES ================================================================= */
533 bool needReportForGnssClient(const UlpLocation& ulpLocation,
534 enum loc_sess_status status, LocPosTechMask techMask);
535 bool needReportForFlpClient(enum loc_sess_status status, LocPosTechMask techMask);
536 bool needToGenerateNmeaReport(const uint32_t &gpsTimeOfWeekMs,
537 const struct timespec32_t &apTimeStamp);
538 void reportPosition(const UlpLocation &ulpLocation,
539 const GpsLocationExtended &locationExtended,
540 enum loc_sess_status status,
541 LocPosTechMask techMask);
542 void reportEnginePositions(unsigned int count,
543 const EngineLocationInfo* locationArr);
544 void reportSv(GnssSvNotification& svNotify);
545 void reportNmea(const char* nmea, size_t length);
546 void reportData(GnssDataNotification& dataNotify);
547 bool requestNiNotify(const GnssNiNotification& notify, const void* data,
548 const bool bInformNiAccept);
549 void reportGnssMeasurementData(const GnssMeasurementsNotification& measurements);
550 void reportGnssSvIdConfig(const GnssSvIdConfig& config);
551 void reportGnssSvTypeConfig(const GnssSvTypeConfig& config);
552 void reportGnssConfig(uint32_t sessionId, const GnssConfig& gnssConfig);
553 void requestOdcpi(const OdcpiRequestInfo& request);
554 void invokeGnssEnergyConsumedCallback(uint64_t energyConsumedSinceFirstBoot);
555 void saveGnssEnergyConsumedCallback(GnssEnergyConsumedCallback energyConsumedCb);
556 void reportLocationSystemInfo(const LocationSystemInfo & locationSystemInfo);
557 inline void reportNfwNotification(const GnssNfwNotification& notification) {
558 if (NULL != mNfwCb) {
559 mNfwCb(notification);
560 }
561 }
562 inline bool getE911State(void) {
563 if (NULL != mIsE911Session) {
564 return mIsE911Session();
565 }
566 return false;
567 }
568
569 void updateSystemPowerState(PowerStateType systemPowerState);
570 void reportSvPolynomial(const GnssSvPolynomial &svPolynomial);
571
572
573 std::vector<double> parseDoublesString(char* dString);
574 void reportGnssAntennaInformation(const antennaInfoCb antennaInfoCallback);
575
576 /*======== GNSSDEBUG ================================================================*/
577 bool getDebugReport(GnssDebugReport& report);
578 /* get AGC information from system status and fill it */
579 void getAgcInformation(GnssMeasurementsNotification& measurements, int msInWeek);
580 /* get Data information from system status and fill it */
581 void getDataInformation(GnssDataNotification& data, int msInWeek);
582
583 /*==== SYSTEM STATUS ================================================================*/
584 inline SystemStatus* getSystemStatus(void) { return mSystemStatus; }
585 std::string& getServerUrl(void) { return mServerUrl; }
586 std::string& getMoServerUrl(void) { return mMoServerUrl; }
587
588 /*==== CONVERSION ===================================================================*/
589 static uint32_t convertSuplVersion(const GnssConfigSuplVersion suplVersion);
590 static uint32_t convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl);
591 static uint32_t convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices);
592 static uint32_t convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask);
593 static uint32_t convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask);
594 static uint32_t convertAGloProt(const GnssConfigAGlonassPositionProtocolMask);
595 static uint32_t convertSuplMode(const GnssConfigSuplModeMask suplModeMask);
596 static void convertSatelliteInfo(std::vector<GnssDebugSatelliteInfo>& out,
597 const GnssSvType& in_constellation,
598 const SystemStatusReports& in);
599 static bool convertToGnssSvIdConfig(
600 const std::vector<GnssSvIdSource>& blacklistedSvIds, GnssSvIdConfig& config);
601 static void convertFromGnssSvIdConfig(
602 const GnssSvIdConfig& svConfig, std::vector<GnssSvIdSource>& blacklistedSvIds);
603 static void convertGnssSvIdMaskToList(
604 uint64_t svIdMask, std::vector<GnssSvIdSource>& svIds,
605 GnssSvId initialSvId, GnssSvType svType);
606 static void computeVRPBasedLla(const UlpLocation& loc, GpsLocationExtended& locExt,
607 const LeverArmConfigInfo& leverArmConfigInfo);
608
609 void injectLocationCommand(double latitude, double longitude, float accuracy);
610 void injectLocationExtCommand(const GnssLocationInfoNotification &locationInfo);
611
612 void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty);
613 void blockCPICommand(double latitude, double longitude, float accuracy,
614 int blockDurationMsec, double latLonDiffThreshold);
615
616 /* ==== MISCELLANEOUS ================================================================== */
617 /* ======== COMMANDS ====(Called from Client Thread)==================================== */
618 void getPowerStateChangesCommand(std::function<void(bool)> powerStateCb);
619 /* ======== UTILITIES ================================================================== */
620 void reportPowerStateIfChanged();
621 void savePowerStateCallback(std::function<void(bool)> powerStateCb){
622 mPowerStateCb = powerStateCb; }
623 bool getPowerState() { return mPowerOn; }
624 inline PowerStateType getSystemPowerState() { return mSystemPowerState; }
625
626 void setAllowFlpNetworkFixes(uint32_t allow) { mAllowFlpNetworkFixes = allow; }
627 uint32_t getAllowFlpNetworkFixes() { return mAllowFlpNetworkFixes; }
628 void setSuplHostServer(const char* server, int port, LocServerType type);
629 void notifyClientOfCachedLocationSystemInfo(LocationAPI* client,
630 const LocationCallbacks& callbacks);
631 LocationCapabilitiesMask getCapabilities();
632 void updateSystemPowerStateCommand(PowerStateType systemPowerState);
633
634 /*==== DGnss Usable Report Flag ====================================================*/
635 inline void setDGnssUsableFLag(bool dGnssNeedReport) { mDGnssNeedReport = dGnssNeedReport;}
636 inline bool isNMEAPrintEnabled() {
637 return ((mContext != NULL) && (0 != mContext->mGps_conf.ENABLE_NMEA_PRINT));
638 }
639
640 /*==== DGnss Ntrip Source ==========================================================*/
641 void updateNTRIPGGAConsentCommand(bool consentAccepted) { mSendNmeaConsent = consentAccepted; }
642 void enablePPENtripStreamCommand(const GnssNtripConnectionParams& params, bool enableRTKEngine);
643 void disablePPENtripStreamCommand();
644 void handleEnablePPENtrip(const GnssNtripConnectionParams& params);
645 void handleDisablePPENtrip();
646 void reportGGAToNtrip(const char* nmea);
647 inline bool isDgnssNmeaRequired() { return mSendNmeaConsent &&
648 mStartDgnssNtripParams.ntripParams.requiresNmeaLocation;}
649};
650
651#endif //GNSS_ADAPTER_H