GnssAdapter.h 35 KB

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