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