SystemStatus.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. #ifndef __SYSTEM_STATUS__
  30. #define __SYSTEM_STATUS__
  31. #include <stdint.h>
  32. #include <sys/time.h>
  33. #include <vector>
  34. #include <algorithm>
  35. #include <iterator>
  36. #include <loc_pla.h>
  37. #include <log_util.h>
  38. #include <MsgTask.h>
  39. #include <IDataItemCore.h>
  40. #include <IOsObserver.h>
  41. #include <DataItemConcreteTypes.h>
  42. #include <SystemStatusOsObserver.h>
  43. #include <gps_extended_c.h>
  44. #define GPS_MIN (1) //1-32
  45. #define SBAS_MIN (33)
  46. #define GLO_MIN (65) //65-88
  47. #define QZSS_MIN (193) //193-197
  48. #define BDS_MIN (201) //201-237
  49. #define GAL_MIN (301) //301-336
  50. #define NAVIC_MIN (401) //401-414
  51. #define GPS_NUM (32)
  52. #define SBAS_NUM (32)
  53. #define GLO_NUM (24)
  54. #define QZSS_NUM (5)
  55. #define BDS_NUM (37)
  56. #define GAL_NUM (36)
  57. #define NAVIC_NUM (14)
  58. #define SV_ALL_NUM_MIN (GPS_NUM + GLO_NUM + QZSS_NUM + BDS_NUM + GAL_NUM) //=134
  59. #define SV_ALL_NUM (SV_ALL_NUM_MIN + NAVIC_NUM) //=148
  60. namespace loc_core
  61. {
  62. /******************************************************************************
  63. SystemStatus report data structure
  64. ******************************************************************************/
  65. class SystemStatusItemBase
  66. {
  67. public:
  68. timespec mUtcTime;
  69. timespec mUtcReported;
  70. static const uint32_t maxItem = 5;
  71. SystemStatusItemBase() {
  72. timeval tv;
  73. gettimeofday(&tv, NULL);
  74. mUtcTime.tv_sec = tv.tv_sec;
  75. mUtcTime.tv_nsec = tv.tv_usec*1000ULL;
  76. mUtcReported = mUtcTime;
  77. };
  78. virtual ~SystemStatusItemBase() {};
  79. inline virtual SystemStatusItemBase& collate(SystemStatusItemBase&) {
  80. return *this;
  81. }
  82. virtual void dump(void) {};
  83. inline virtual bool ignore() { return false; };
  84. virtual bool equals(const SystemStatusItemBase& peer) { return false; }
  85. };
  86. class SystemStatusLocation : public SystemStatusItemBase
  87. {
  88. public:
  89. bool mValid;
  90. UlpLocation mLocation;
  91. GpsLocationExtended mLocationEx;
  92. inline SystemStatusLocation() :
  93. mValid(false) {}
  94. inline SystemStatusLocation(const UlpLocation& location,
  95. const GpsLocationExtended& locationEx) :
  96. mValid(true),
  97. mLocation(location),
  98. mLocationEx(locationEx) {}
  99. bool equals(const SystemStatusItemBase& peer) override;
  100. void dump(void) override;
  101. };
  102. class SystemStatusPQWM1;
  103. class SystemStatusTimeAndClock : public SystemStatusItemBase
  104. {
  105. public:
  106. uint16_t mGpsWeek;
  107. uint32_t mGpsTowMs;
  108. uint8_t mTimeValid;
  109. uint8_t mTimeSource;
  110. int32_t mTimeUnc;
  111. int32_t mClockFreqBias;
  112. int32_t mClockFreqBiasUnc;
  113. int32_t mLeapSeconds;
  114. int32_t mLeapSecUnc;
  115. uint64_t mTimeUncNs;
  116. inline SystemStatusTimeAndClock() :
  117. mGpsWeek(0),
  118. mGpsTowMs(0),
  119. mTimeValid(0),
  120. mTimeSource(0),
  121. mTimeUnc(0),
  122. mClockFreqBias(0),
  123. mClockFreqBiasUnc(0),
  124. mLeapSeconds(0),
  125. mLeapSecUnc(0),
  126. mTimeUncNs(0ULL) {}
  127. inline SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea);
  128. bool equals(const SystemStatusItemBase& peer) override;
  129. void dump(void) override;
  130. };
  131. class SystemStatusXoState : public SystemStatusItemBase
  132. {
  133. public:
  134. uint8_t mXoState;
  135. inline SystemStatusXoState() :
  136. mXoState(0) {}
  137. inline SystemStatusXoState(const SystemStatusPQWM1& nmea);
  138. bool equals(const SystemStatusItemBase& peer) override;
  139. void dump(void) override;
  140. };
  141. class SystemStatusRfAndParams : public SystemStatusItemBase
  142. {
  143. public:
  144. int32_t mPgaGain;
  145. uint32_t mGpsBpAmpI;
  146. uint32_t mGpsBpAmpQ;
  147. uint32_t mAdcI;
  148. uint32_t mAdcQ;
  149. uint32_t mJammerGps;
  150. uint32_t mJammerGlo;
  151. uint32_t mJammerBds;
  152. uint32_t mJammerGal;
  153. double mAgcGps;
  154. double mAgcGlo;
  155. double mAgcBds;
  156. double mAgcGal;
  157. uint32_t mGloBpAmpI;
  158. uint32_t mGloBpAmpQ;
  159. uint32_t mBdsBpAmpI;
  160. uint32_t mBdsBpAmpQ;
  161. uint32_t mGalBpAmpI;
  162. uint32_t mGalBpAmpQ;
  163. inline SystemStatusRfAndParams() :
  164. mPgaGain(0),
  165. mGpsBpAmpI(0),
  166. mGpsBpAmpQ(0),
  167. mAdcI(0),
  168. mAdcQ(0),
  169. mJammerGps(0),
  170. mJammerGlo(0),
  171. mJammerBds(0),
  172. mJammerGal(0),
  173. mAgcGps(0),
  174. mAgcGlo(0),
  175. mAgcBds(0),
  176. mAgcGal(0),
  177. mGloBpAmpI(0),
  178. mGloBpAmpQ(0),
  179. mBdsBpAmpI(0),
  180. mBdsBpAmpQ(0),
  181. mGalBpAmpI(0),
  182. mGalBpAmpQ(0) {}
  183. inline SystemStatusRfAndParams(const SystemStatusPQWM1& nmea);
  184. bool equals(const SystemStatusItemBase& peer) override;
  185. void dump(void) override;
  186. };
  187. class SystemStatusErrRecovery : public SystemStatusItemBase
  188. {
  189. public:
  190. uint32_t mRecErrorRecovery;
  191. inline SystemStatusErrRecovery() :
  192. mRecErrorRecovery(0) {};
  193. inline SystemStatusErrRecovery(const SystemStatusPQWM1& nmea);
  194. bool equals(const SystemStatusItemBase& peer) override;
  195. inline bool ignore() override { return 0 == mRecErrorRecovery; };
  196. void dump(void) override;
  197. };
  198. class SystemStatusPQWP1;
  199. class SystemStatusInjectedPosition : public SystemStatusItemBase
  200. {
  201. public:
  202. uint8_t mEpiValidity;
  203. float mEpiLat;
  204. float mEpiLon;
  205. float mEpiAlt;
  206. float mEpiHepe;
  207. float mEpiAltUnc;
  208. uint8_t mEpiSrc;
  209. inline SystemStatusInjectedPosition() :
  210. mEpiValidity(0),
  211. mEpiLat(0),
  212. mEpiLon(0),
  213. mEpiAlt(0),
  214. mEpiHepe(0),
  215. mEpiAltUnc(0),
  216. mEpiSrc(0) {}
  217. inline SystemStatusInjectedPosition(const SystemStatusPQWP1& nmea);
  218. bool equals(const SystemStatusItemBase& peer) override;
  219. void dump(void) override;
  220. };
  221. class SystemStatusPQWP2;
  222. class SystemStatusBestPosition : public SystemStatusItemBase
  223. {
  224. public:
  225. bool mValid;
  226. float mBestLat;
  227. float mBestLon;
  228. float mBestAlt;
  229. float mBestHepe;
  230. float mBestAltUnc;
  231. inline SystemStatusBestPosition() :
  232. mValid(false),
  233. mBestLat(0),
  234. mBestLon(0),
  235. mBestAlt(0),
  236. mBestHepe(0),
  237. mBestAltUnc(0) {}
  238. inline SystemStatusBestPosition(const SystemStatusPQWP2& nmea);
  239. bool equals(const SystemStatusItemBase& peer) override;
  240. void dump(void) override;
  241. };
  242. class SystemStatusPQWP3;
  243. class SystemStatusXtra : public SystemStatusItemBase
  244. {
  245. public:
  246. uint8_t mXtraValidMask;
  247. uint32_t mGpsXtraAge;
  248. uint32_t mGloXtraAge;
  249. uint32_t mBdsXtraAge;
  250. uint32_t mGalXtraAge;
  251. uint32_t mQzssXtraAge;
  252. uint32_t mNavicXtraAge;
  253. uint32_t mGpsXtraValid;
  254. uint32_t mGloXtraValid;
  255. uint64_t mBdsXtraValid;
  256. uint64_t mGalXtraValid;
  257. uint8_t mQzssXtraValid;
  258. uint32_t mNavicXtraValid;
  259. inline SystemStatusXtra() :
  260. mXtraValidMask(0),
  261. mGpsXtraAge(0),
  262. mGloXtraAge(0),
  263. mBdsXtraAge(0),
  264. mGalXtraAge(0),
  265. mQzssXtraAge(0),
  266. mNavicXtraAge(0),
  267. mGpsXtraValid(0),
  268. mGloXtraValid(0),
  269. mBdsXtraValid(0ULL),
  270. mGalXtraValid(0ULL),
  271. mQzssXtraValid(0),
  272. mNavicXtraValid(0) {}
  273. inline SystemStatusXtra(const SystemStatusPQWP3& nmea);
  274. bool equals(const SystemStatusItemBase& peer) override;
  275. void dump(void) override;
  276. };
  277. class SystemStatusPQWP4;
  278. class SystemStatusEphemeris : public SystemStatusItemBase
  279. {
  280. public:
  281. uint32_t mGpsEpheValid;
  282. uint32_t mGloEpheValid;
  283. uint64_t mBdsEpheValid;
  284. uint64_t mGalEpheValid;
  285. uint8_t mQzssEpheValid;
  286. inline SystemStatusEphemeris() :
  287. mGpsEpheValid(0),
  288. mGloEpheValid(0),
  289. mBdsEpheValid(0ULL),
  290. mGalEpheValid(0ULL),
  291. mQzssEpheValid(0) {}
  292. inline SystemStatusEphemeris(const SystemStatusPQWP4& nmea);
  293. bool equals(const SystemStatusItemBase& peer) override;
  294. void dump(void) override;
  295. };
  296. class SystemStatusPQWP5;
  297. class SystemStatusSvHealth : public SystemStatusItemBase
  298. {
  299. public:
  300. uint32_t mGpsUnknownMask;
  301. uint32_t mGloUnknownMask;
  302. uint64_t mBdsUnknownMask;
  303. uint64_t mGalUnknownMask;
  304. uint8_t mQzssUnknownMask;
  305. uint32_t mNavicUnknownMask;
  306. uint32_t mGpsGoodMask;
  307. uint32_t mGloGoodMask;
  308. uint64_t mBdsGoodMask;
  309. uint64_t mGalGoodMask;
  310. uint8_t mQzssGoodMask;
  311. uint32_t mNavicGoodMask;
  312. uint32_t mGpsBadMask;
  313. uint32_t mGloBadMask;
  314. uint64_t mBdsBadMask;
  315. uint64_t mGalBadMask;
  316. uint8_t mQzssBadMask;
  317. uint32_t mNavicBadMask;
  318. inline SystemStatusSvHealth() :
  319. mGpsUnknownMask(0),
  320. mGloUnknownMask(0),
  321. mBdsUnknownMask(0ULL),
  322. mGalUnknownMask(0ULL),
  323. mQzssUnknownMask(0),
  324. mNavicUnknownMask(0),
  325. mGpsGoodMask(0),
  326. mGloGoodMask(0),
  327. mBdsGoodMask(0ULL),
  328. mGalGoodMask(0ULL),
  329. mQzssGoodMask(0),
  330. mNavicGoodMask(0),
  331. mGpsBadMask(0),
  332. mGloBadMask(0),
  333. mBdsBadMask(0ULL),
  334. mGalBadMask(0ULL),
  335. mQzssBadMask(0),
  336. mNavicBadMask(0) {}
  337. inline SystemStatusSvHealth(const SystemStatusPQWP5& nmea);
  338. bool equals(const SystemStatusItemBase& peer) override;
  339. void dump(void) override;
  340. };
  341. class SystemStatusPQWP6;
  342. class SystemStatusPdr : public SystemStatusItemBase
  343. {
  344. public:
  345. uint32_t mFixInfoMask;
  346. inline SystemStatusPdr() :
  347. mFixInfoMask(0) {}
  348. inline SystemStatusPdr(const SystemStatusPQWP6& nmea);
  349. bool equals(const SystemStatusItemBase& peer) override;
  350. void dump(void) override;
  351. };
  352. class SystemStatusPQWP7;
  353. struct SystemStatusNav
  354. {
  355. GnssEphemerisType mType;
  356. GnssEphemerisSource mSource;
  357. int32_t mAgeSec;
  358. };
  359. class SystemStatusNavData : public SystemStatusItemBase
  360. {
  361. public:
  362. SystemStatusNav mNav[SV_ALL_NUM];
  363. inline SystemStatusNavData() {
  364. for (uint32_t i=0; i<SV_ALL_NUM; i++) {
  365. mNav[i].mType = GNSS_EPH_TYPE_UNKNOWN;
  366. mNav[i].mSource = GNSS_EPH_SOURCE_UNKNOWN;
  367. mNav[i].mAgeSec = 0;
  368. }
  369. }
  370. inline SystemStatusNavData(const SystemStatusPQWP7& nmea);
  371. bool equals(const SystemStatusItemBase& peer) override;
  372. void dump(void) override;
  373. };
  374. class SystemStatusPQWS1;
  375. class SystemStatusPositionFailure : public SystemStatusItemBase
  376. {
  377. public:
  378. uint32_t mFixInfoMask;
  379. uint32_t mHepeLimit;
  380. inline SystemStatusPositionFailure() :
  381. mFixInfoMask(0),
  382. mHepeLimit(0) {}
  383. inline SystemStatusPositionFailure(const SystemStatusPQWS1& nmea);
  384. bool equals(const SystemStatusItemBase& peer) override;
  385. void dump(void) override;
  386. };
  387. /******************************************************************************
  388. SystemStatus report data structure - from DataItem observer
  389. ******************************************************************************/
  390. class SystemStatusAirplaneMode : public SystemStatusItemBase {
  391. public:
  392. AirplaneModeDataItem mDataItem;
  393. inline SystemStatusAirplaneMode(bool mode=false): mDataItem(mode) {}
  394. inline SystemStatusAirplaneMode(const AirplaneModeDataItem& itemBase):
  395. mDataItem(itemBase) {}
  396. inline bool equals(const SystemStatusItemBase& peer) override {
  397. return mDataItem.mMode == ((const SystemStatusAirplaneMode&)peer).mDataItem.mMode;
  398. }
  399. };
  400. class SystemStatusENH : public SystemStatusItemBase {
  401. public:
  402. ENHDataItem mDataItem;
  403. inline SystemStatusENH(bool enabled=false): mDataItem(enabled) {}
  404. inline SystemStatusENH(const ENHDataItem& itemBase): mDataItem(itemBase) {}
  405. inline bool equals(const SystemStatusItemBase& peer) override {
  406. return mDataItem.mEnabled == ((const SystemStatusENH&)peer).mDataItem.mEnabled;
  407. }
  408. };
  409. class SystemStatusGpsState : public SystemStatusItemBase {
  410. public:
  411. GPSStateDataItem mDataItem;
  412. inline SystemStatusGpsState(bool enabled=false): mDataItem(enabled) {}
  413. inline SystemStatusGpsState(const GPSStateDataItem& itemBase): mDataItem(itemBase) {}
  414. inline bool equals(const SystemStatusItemBase& peer) override {
  415. return mDataItem.mEnabled == ((const SystemStatusGpsState&)peer).mDataItem.mEnabled;
  416. }
  417. inline void dump(void) override {
  418. LOC_LOGD("GpsState: state=%u", mDataItem.mEnabled);
  419. }
  420. };
  421. class SystemStatusNLPStatus : public SystemStatusItemBase {
  422. public:
  423. NLPStatusDataItem mDataItem;
  424. inline SystemStatusNLPStatus(bool enabled=false): mDataItem(enabled) {}
  425. inline SystemStatusNLPStatus(const NLPStatusDataItem& itemBase): mDataItem(itemBase) {}
  426. inline bool equals(const SystemStatusItemBase& peer) override {
  427. return mDataItem.mEnabled == ((const SystemStatusNLPStatus&)peer).mDataItem.mEnabled;
  428. }
  429. };
  430. class SystemStatusWifiHardwareState : public SystemStatusItemBase {
  431. public:
  432. WifiHardwareStateDataItem mDataItem;
  433. inline SystemStatusWifiHardwareState(bool enabled=false): mDataItem(enabled) {}
  434. inline SystemStatusWifiHardwareState(const WifiHardwareStateDataItem& itemBase):
  435. mDataItem(itemBase) {}
  436. inline bool equals(const SystemStatusItemBase& peer) override {
  437. return mDataItem.mEnabled == ((const SystemStatusWifiHardwareState&)peer).mDataItem.mEnabled;
  438. }
  439. };
  440. class SystemStatusNetworkInfo : public SystemStatusItemBase {
  441. public:
  442. NetworkInfoDataItem mDataItem;
  443. inline SystemStatusNetworkInfo(int32_t type=0, std::string typeName="", string subTypeName="",
  444. bool connected=false, bool roaming=false,
  445. uint64_t networkHandle=NETWORK_HANDLE_UNKNOWN, string apn = "") :
  446. mDataItem((NetworkType)type, type, typeName, subTypeName, connected && (!roaming),
  447. connected, roaming, networkHandle, apn) {}
  448. inline SystemStatusNetworkInfo(const NetworkInfoDataItem& itemBase): mDataItem(itemBase) {}
  449. inline bool equals(const SystemStatusItemBase& peer) override {
  450. const NetworkInfoDataItem peerDI = ((const SystemStatusNetworkInfo&)peer).mDataItem;
  451. bool rtv = (mDataItem.mAllTypes == peerDI.mAllTypes) &&
  452. (mDataItem.mConnected == peerDI.mConnected);
  453. for (uint8_t i = 0; rtv && i < MAX_NETWORK_HANDLES; ++i) {
  454. rtv = (mDataItem.mAllNetworkHandles[i] == peerDI.mAllNetworkHandles[i]) && rtv;
  455. }
  456. rtv = rtv && !peerDI.mApn.compare(mDataItem.mApn);
  457. LOC_LOGv("NetworkInfoDataItem quals: %d", rtv);
  458. return rtv;
  459. }
  460. inline virtual SystemStatusItemBase& collate(SystemStatusItemBase& curInfo) {
  461. LOC_LOGv("NetworkInfo: mAllTypes=%" PRIx64 " connected=%u mType=%x mApn=%s",
  462. mDataItem.mAllTypes, mDataItem.mConnected, mDataItem.mType,
  463. mDataItem.mApn.c_str());
  464. uint64_t allTypes = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mDataItem.mAllTypes;
  465. string& apn = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mDataItem.mApn;
  466. // Replace current with cached table for now and then update
  467. memcpy(mDataItem.mAllNetworkHandles,
  468. static_cast<SystemStatusNetworkInfo&>(curInfo).mDataItem.getNetworkHandle(),
  469. sizeof(mDataItem.mAllNetworkHandles));
  470. // Update the apn for non-mobile type connections.
  471. if (TYPE_MOBILE != mDataItem.mType && apn.compare("") != 0) {
  472. mDataItem.mApn = apn;
  473. }
  474. if (mDataItem.mConnected) {
  475. mDataItem.mAllTypes |= allTypes;
  476. for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) {
  477. if (mDataItem.mNetworkHandle ==
  478. mDataItem.mAllNetworkHandles[i].networkHandle) {
  479. LOC_LOGD("collate duplicate detected, not updating");
  480. break;
  481. }
  482. if (NETWORK_HANDLE_UNKNOWN ==
  483. mDataItem.mAllNetworkHandles[i].networkHandle) {
  484. mDataItem.mAllNetworkHandles[i].networkHandle =
  485. mDataItem.mNetworkHandle;
  486. mDataItem.mAllNetworkHandles[i].networkType =
  487. (loc_core::NetworkType) mDataItem.mType;
  488. break;
  489. }
  490. }
  491. } else if (0 != mDataItem.mAllTypes) {
  492. uint8_t deletedIndex = MAX_NETWORK_HANDLES;
  493. uint8_t lastValidIndex = 0;
  494. uint8_t typeCount = 0;
  495. for (; lastValidIndex < MAX_NETWORK_HANDLES && NETWORK_HANDLE_UNKNOWN !=
  496. mDataItem.mAllNetworkHandles[lastValidIndex].networkHandle;
  497. ++lastValidIndex) {
  498. // Maintain count for number of network handles still
  499. // connected for given type
  500. if (mDataItem.mType ==
  501. mDataItem.mAllNetworkHandles[lastValidIndex].networkType) {
  502. if (mDataItem.mNetworkHandle ==
  503. mDataItem.mAllNetworkHandles[lastValidIndex].networkHandle) {
  504. deletedIndex = lastValidIndex;
  505. } else {
  506. typeCount++;
  507. }
  508. }
  509. }
  510. if (lastValidIndex > 0) {
  511. --lastValidIndex;
  512. }
  513. if (MAX_NETWORK_HANDLES != deletedIndex) {
  514. LOC_LOGd("deletedIndex:%u, lastValidIndex:%u, typeCount:%u",
  515. deletedIndex, lastValidIndex, typeCount);
  516. mDataItem.mAllNetworkHandles[deletedIndex] =
  517. mDataItem.mAllNetworkHandles[lastValidIndex];
  518. mDataItem.mAllNetworkHandles[lastValidIndex].networkHandle =
  519. NETWORK_HANDLE_UNKNOWN;
  520. mDataItem.mAllNetworkHandles[lastValidIndex].networkType = TYPE_UNKNOWN;
  521. }
  522. // If no more handles of given type, set bitmask
  523. if (0 == typeCount) {
  524. mDataItem.mAllTypes = (allTypes & (~mDataItem.mAllTypes));
  525. LOC_LOGD("mAllTypes:%" PRIx64, mDataItem.mAllTypes);
  526. }
  527. } // else (mDataItem.mConnected == false && mDataItem.mAllTypes == 0)
  528. // we keep mDataItem->mAllTypes as 0, which means no more connections.
  529. return *this;
  530. }
  531. inline void dump(void) override {
  532. LOC_LOGD("NetworkInfo: mAllTypes=%" PRIx64 " connected=%u mType=%x mApn=%s",
  533. mDataItem.mAllTypes, mDataItem.mConnected, mDataItem.mType,
  534. mDataItem.mApn.c_str());
  535. }
  536. };
  537. class SystemStatusServiceInfo : public SystemStatusItemBase {
  538. public:
  539. RilServiceInfoDataItem mDataItem;
  540. inline SystemStatusServiceInfo(): mDataItem() {}
  541. inline SystemStatusServiceInfo(const RilServiceInfoDataItem& itemBase):
  542. mDataItem(itemBase) {}
  543. inline bool equals(const SystemStatusItemBase& peer) override {
  544. return ((const SystemStatusServiceInfo&)peer).mDataItem == mDataItem;
  545. }
  546. };
  547. class SystemStatusRilCellInfo : public SystemStatusItemBase {
  548. public:
  549. RilCellInfoDataItem mDataItem;
  550. inline SystemStatusRilCellInfo(): mDataItem() {}
  551. inline SystemStatusRilCellInfo(const RilCellInfoDataItem& itemBase): mDataItem(itemBase) {}
  552. inline bool equals(const SystemStatusItemBase& peer) override {
  553. return ((const SystemStatusRilCellInfo&)peer).mDataItem == mDataItem;
  554. }
  555. };
  556. class SystemStatusServiceStatus : public SystemStatusItemBase {
  557. public:
  558. ServiceStatusDataItem mDataItem;
  559. inline SystemStatusServiceStatus(int32_t mServiceState=0): mDataItem(mServiceState) {}
  560. inline SystemStatusServiceStatus(const ServiceStatusDataItem& itemBase):
  561. mDataItem(itemBase) {}
  562. inline bool equals(const SystemStatusItemBase& peer) override {
  563. return mDataItem.mServiceState ==
  564. ((const SystemStatusServiceStatus&)peer).mDataItem.mServiceState;
  565. }
  566. };
  567. class SystemStatusModel : public SystemStatusItemBase {
  568. public:
  569. ModelDataItem mDataItem;
  570. inline SystemStatusModel(string name=""): mDataItem(name) {}
  571. inline SystemStatusModel(const ModelDataItem& itemBase): mDataItem(itemBase) {}
  572. inline bool equals(const SystemStatusItemBase& peer) override {
  573. return mDataItem.mModel == ((const SystemStatusModel&)peer).mDataItem.mModel;
  574. }
  575. };
  576. class SystemStatusManufacturer : public SystemStatusItemBase {
  577. public:
  578. ManufacturerDataItem mDataItem;
  579. inline SystemStatusManufacturer(string name=""): mDataItem(name) {}
  580. inline SystemStatusManufacturer(const ManufacturerDataItem& itemBase): mDataItem(itemBase) {}
  581. inline bool equals(const SystemStatusItemBase& peer) override {
  582. return mDataItem.mManufacturer ==
  583. ((const SystemStatusManufacturer&)peer).mDataItem.mManufacturer;
  584. }
  585. };
  586. class SystemStatusAssistedGps : public SystemStatusItemBase {
  587. public:
  588. AssistedGpsDataItem mDataItem;
  589. inline SystemStatusAssistedGps(bool enabled=false): mDataItem(enabled) {}
  590. inline SystemStatusAssistedGps(const AssistedGpsDataItem& itemBase): mDataItem(itemBase) {}
  591. inline bool equals(const SystemStatusItemBase& peer) override {
  592. return mDataItem.mEnabled == ((const SystemStatusAssistedGps&)peer).mDataItem.mEnabled;
  593. }
  594. };
  595. class SystemStatusScreenState : public SystemStatusItemBase {
  596. public:
  597. ScreenStateDataItem mDataItem;
  598. inline SystemStatusScreenState(bool state=false): mDataItem(state) {}
  599. inline SystemStatusScreenState(const ScreenStateDataItem& itemBase): mDataItem(itemBase) {}
  600. inline bool equals(const SystemStatusItemBase& peer) override {
  601. return mDataItem.mState == ((const SystemStatusScreenState&)peer).mDataItem.mState;
  602. }
  603. };
  604. class SystemStatusPowerConnectState : public SystemStatusItemBase {
  605. public:
  606. PowerConnectStateDataItem mDataItem;
  607. inline SystemStatusPowerConnectState(bool state=false): mDataItem(state) {}
  608. inline SystemStatusPowerConnectState(const PowerConnectStateDataItem& itemBase):
  609. mDataItem(itemBase) {}
  610. inline bool equals(const SystemStatusItemBase& peer) override {
  611. return mDataItem.mState == ((const SystemStatusPowerConnectState&)peer).mDataItem.mState;
  612. }
  613. };
  614. class SystemStatusTimeZoneChange : public SystemStatusItemBase {
  615. public:
  616. TimeZoneChangeDataItem mDataItem;
  617. inline SystemStatusTimeZoneChange(int64_t currTimeMillis=0ULL, int32_t rawOffset=0,
  618. int32_t dstOffset=0): mDataItem(currTimeMillis, rawOffset, dstOffset) {}
  619. inline SystemStatusTimeZoneChange(const TimeZoneChangeDataItem& itemBase):
  620. mDataItem(itemBase) {}
  621. inline bool equals(const SystemStatusItemBase& peer) override {
  622. return mDataItem.mCurrTimeMillis ==
  623. ((const SystemStatusTimeZoneChange&)peer).mDataItem.mCurrTimeMillis &&
  624. mDataItem.mRawOffsetTZ ==
  625. ((const SystemStatusTimeZoneChange&)peer).mDataItem.mRawOffsetTZ &&
  626. mDataItem.mDstOffsetTZ ==
  627. ((const SystemStatusTimeZoneChange&)peer).mDataItem.mDstOffsetTZ;
  628. }
  629. };
  630. class SystemStatusTimeChange : public SystemStatusItemBase {
  631. public:
  632. TimeChangeDataItem mDataItem;
  633. inline SystemStatusTimeChange(
  634. int64_t currTimeMillis=0ULL, int32_t rawOffset=0, int32_t dstOffset=0):
  635. mDataItem(currTimeMillis, rawOffset, dstOffset) {}
  636. inline SystemStatusTimeChange(const TimeChangeDataItem& itemBase): mDataItem(itemBase) {}
  637. inline bool equals(const SystemStatusItemBase& peer) override {
  638. return mDataItem.mCurrTimeMillis ==
  639. ((const SystemStatusTimeChange&)peer).mDataItem.mCurrTimeMillis &&
  640. mDataItem.mRawOffsetTZ ==
  641. ((const SystemStatusTimeChange&)peer).mDataItem.mRawOffsetTZ &&
  642. mDataItem.mDstOffsetTZ ==
  643. ((const SystemStatusTimeChange&)peer).mDataItem.mDstOffsetTZ;
  644. }
  645. };
  646. class SystemStatusWifiSupplicantStatus : public SystemStatusItemBase {
  647. public:
  648. WifiSupplicantStatusDataItem mDataItem;
  649. inline SystemStatusWifiSupplicantStatus(): mDataItem() {}
  650. inline SystemStatusWifiSupplicantStatus(const WifiSupplicantStatusDataItem& itemBase):
  651. mDataItem(itemBase) {}
  652. inline bool equals(const SystemStatusItemBase& peer) override {
  653. return mDataItem.mState ==
  654. ((const SystemStatusWifiSupplicantStatus&)peer).mDataItem.mState &&
  655. mDataItem.mApMacAddressValid ==
  656. ((const SystemStatusWifiSupplicantStatus&)peer).mDataItem.mApMacAddressValid &&
  657. mDataItem.mWifiApSsidValid ==
  658. ((const SystemStatusWifiSupplicantStatus&)peer).mDataItem.mWifiApSsidValid &&
  659. mDataItem.mWifiApSsid ==
  660. ((const SystemStatusWifiSupplicantStatus&)peer).mDataItem.mWifiApSsid;
  661. }
  662. };
  663. class SystemStatusShutdownState : public SystemStatusItemBase {
  664. public:
  665. ShutdownStateDataItem mDataItem;
  666. inline SystemStatusShutdownState(bool state=false): mDataItem(state) {}
  667. inline SystemStatusShutdownState(const ShutdownStateDataItem& itemBase):
  668. mDataItem(itemBase) {}
  669. inline bool equals(const SystemStatusItemBase& peer) override {
  670. return mDataItem.mState == ((const SystemStatusShutdownState&)peer).mDataItem.mState;
  671. }
  672. };
  673. class SystemStatusTac : public SystemStatusItemBase {
  674. public:
  675. TacDataItem mDataItem;
  676. inline SystemStatusTac(std::string value=""): mDataItem(value) {}
  677. inline SystemStatusTac(const TacDataItem& itemBase): mDataItem(itemBase) {}
  678. inline bool equals(const SystemStatusItemBase& peer) override {
  679. return mDataItem.mValue == ((const SystemStatusTac&)peer).mDataItem.mValue;
  680. }
  681. inline void dump(void) override {
  682. LOC_LOGD("Tac: value=%s", mDataItem.mValue.c_str());
  683. }
  684. };
  685. class SystemStatusMccMnc : public SystemStatusItemBase {
  686. public:
  687. MccmncDataItem mDataItem;
  688. inline SystemStatusMccMnc(std::string value=""): mDataItem(value) {}
  689. inline SystemStatusMccMnc(const MccmncDataItem& itemBase): mDataItem(itemBase) {}
  690. inline bool equals(const SystemStatusItemBase& peer) override {
  691. return mDataItem.mValue == ((const SystemStatusMccMnc&)peer).mDataItem.mValue;
  692. }
  693. inline void dump(void) override {
  694. LOC_LOGD("TacMccMnc value=%s", mDataItem.mValue.c_str());
  695. }
  696. };
  697. class SystemStatusBtDeviceScanDetail : public SystemStatusItemBase {
  698. public:
  699. BtDeviceScanDetailsDataItem mDataItem;
  700. inline SystemStatusBtDeviceScanDetail(): mDataItem() {}
  701. inline SystemStatusBtDeviceScanDetail(const BtDeviceScanDetailsDataItem& itemBase):
  702. mDataItem(itemBase) {}
  703. inline bool equals(const SystemStatusItemBase& peer) override {
  704. return mDataItem.mApSrnRssi ==
  705. ((const SystemStatusBtDeviceScanDetail&)peer).mDataItem.mApSrnRssi &&
  706. memcmp(mDataItem.mApSrnMacAddress,
  707. ((const SystemStatusBtDeviceScanDetail&)peer).mDataItem.mApSrnMacAddress,
  708. sizeof(mDataItem.mApSrnMacAddress)) == 0 &&
  709. mDataItem.mApSrnTimestamp ==
  710. ((const SystemStatusBtDeviceScanDetail&)peer).mDataItem.mApSrnTimestamp &&
  711. mDataItem.mRequestTimestamp ==
  712. ((const SystemStatusBtDeviceScanDetail&)peer).mDataItem.mRequestTimestamp &&
  713. mDataItem.mReceiveTimestamp ==
  714. ((const SystemStatusBtDeviceScanDetail&)peer).mDataItem.mReceiveTimestamp;
  715. }
  716. };
  717. class SystemStatusBtleDeviceScanDetail : public SystemStatusItemBase {
  718. public:
  719. BtLeDeviceScanDetailsDataItem mDataItem;
  720. inline SystemStatusBtleDeviceScanDetail(): mDataItem() {}
  721. inline SystemStatusBtleDeviceScanDetail(const BtLeDeviceScanDetailsDataItem& itemBase):
  722. mDataItem(itemBase) {}
  723. inline bool equals(const SystemStatusItemBase& peer) override {
  724. return mDataItem.mApSrnRssi ==
  725. ((const SystemStatusBtleDeviceScanDetail&)peer).mDataItem.mApSrnRssi &&
  726. memcmp(mDataItem.mApSrnMacAddress,
  727. ((const SystemStatusBtleDeviceScanDetail&)peer).mDataItem.mApSrnMacAddress,
  728. sizeof(mDataItem.mApSrnMacAddress)) == 0 &&
  729. mDataItem.mApSrnTimestamp ==
  730. ((const SystemStatusBtleDeviceScanDetail&)peer).mDataItem.mApSrnTimestamp &&
  731. mDataItem.mRequestTimestamp ==
  732. ((const SystemStatusBtleDeviceScanDetail&)peer).mDataItem.mRequestTimestamp &&
  733. mDataItem.mReceiveTimestamp ==
  734. ((const SystemStatusBtleDeviceScanDetail&)peer).mDataItem.mReceiveTimestamp;
  735. }
  736. };
  737. class SystemStatusInEmergencyCall : public SystemStatusItemBase {
  738. public:
  739. InEmergencyCallDataItem mDataItem;
  740. inline SystemStatusInEmergencyCall(bool value = false): mDataItem(value) {}
  741. inline SystemStatusInEmergencyCall(const InEmergencyCallDataItem& itemBase):
  742. mDataItem(itemBase) {}
  743. inline bool equals(const SystemStatusItemBase& peer) override {
  744. return mDataItem.mIsEmergency ==
  745. ((const SystemStatusInEmergencyCall&)peer).mDataItem.mIsEmergency;
  746. }
  747. inline void dump(void) override {
  748. LOC_LOGd("In Emergency Call: %d", mDataItem.mIsEmergency);
  749. }
  750. };
  751. /******************************************************************************
  752. SystemStatusReports
  753. ******************************************************************************/
  754. class SystemStatusReports
  755. {
  756. public:
  757. // from QMI_LOC indication
  758. std::vector<SystemStatusLocation> mLocation;
  759. // from ME debug NMEA
  760. std::vector<SystemStatusTimeAndClock> mTimeAndClock;
  761. std::vector<SystemStatusXoState> mXoState;
  762. std::vector<SystemStatusRfAndParams> mRfAndParams;
  763. std::vector<SystemStatusErrRecovery> mErrRecovery;
  764. // from PE debug NMEA
  765. std::vector<SystemStatusInjectedPosition> mInjectedPosition;
  766. std::vector<SystemStatusBestPosition> mBestPosition;
  767. std::vector<SystemStatusXtra> mXtra;
  768. std::vector<SystemStatusEphemeris> mEphemeris;
  769. std::vector<SystemStatusSvHealth> mSvHealth;
  770. std::vector<SystemStatusPdr> mPdr;
  771. std::vector<SystemStatusNavData> mNavData;
  772. // from SM debug NMEA
  773. std::vector<SystemStatusPositionFailure> mPositionFailure;
  774. // from dataitems observer
  775. std::vector<SystemStatusAirplaneMode> mAirplaneMode;
  776. std::vector<SystemStatusENH> mENH;
  777. std::vector<SystemStatusGpsState> mGPSState;
  778. std::vector<SystemStatusNLPStatus> mNLPStatus;
  779. std::vector<SystemStatusWifiHardwareState> mWifiHardwareState;
  780. std::vector<SystemStatusNetworkInfo> mNetworkInfo;
  781. std::vector<SystemStatusServiceInfo> mRilServiceInfo;
  782. std::vector<SystemStatusRilCellInfo> mRilCellInfo;
  783. std::vector<SystemStatusServiceStatus> mServiceStatus;
  784. std::vector<SystemStatusModel> mModel;
  785. std::vector<SystemStatusManufacturer> mManufacturer;
  786. std::vector<SystemStatusInEmergencyCall> mInEmergencyCall;
  787. std::vector<SystemStatusAssistedGps> mAssistedGps;
  788. std::vector<SystemStatusScreenState> mScreenState;
  789. std::vector<SystemStatusPowerConnectState> mPowerConnectState;
  790. std::vector<SystemStatusTimeZoneChange> mTimeZoneChange;
  791. std::vector<SystemStatusTimeChange> mTimeChange;
  792. std::vector<SystemStatusWifiSupplicantStatus> mWifiSupplicantStatus;
  793. std::vector<SystemStatusShutdownState> mShutdownState;
  794. std::vector<SystemStatusTac> mTac;
  795. std::vector<SystemStatusMccMnc> mMccMnc;
  796. std::vector<SystemStatusBtDeviceScanDetail> mBtDeviceScanDetail;
  797. std::vector<SystemStatusBtleDeviceScanDetail> mBtLeDeviceScanDetail;
  798. };
  799. /******************************************************************************
  800. SystemStatus
  801. ******************************************************************************/
  802. class SystemStatus
  803. {
  804. private:
  805. static SystemStatus *mInstance;
  806. SystemStatusOsObserver mSysStatusObsvr;
  807. // ctor
  808. SystemStatus(const MsgTask* msgTask);
  809. // dtor
  810. inline ~SystemStatus() {}
  811. // Data members
  812. static pthread_mutex_t mMutexSystemStatus;
  813. SystemStatusReports mCache;
  814. bool mTracking;
  815. template <typename TYPE_REPORT, typename TYPE_ITEM>
  816. bool setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s);
  817. // set default dataitem derived item in report cache
  818. template <typename TYPE_REPORT, typename TYPE_ITEM>
  819. void setDefaultIteminReport(TYPE_REPORT& report, const TYPE_ITEM& s);
  820. template <typename TYPE_REPORT, typename TYPE_ITEM>
  821. void getIteminReport(TYPE_REPORT& reportout, const TYPE_ITEM& c) const;
  822. public:
  823. // Static methods
  824. static SystemStatus* getInstance(const MsgTask* msgTask);
  825. static void destroyInstance();
  826. IOsObserver* getOsObserver();
  827. // Helpers
  828. bool eventPosition(const UlpLocation& location,const GpsLocationExtended& locationEx);
  829. bool eventDataItemNotify(IDataItemCore* dataitem);
  830. bool setNmeaString(const char *data, uint32_t len);
  831. bool getReport(SystemStatusReports& reports, bool isLatestonly = false) const;
  832. bool setDefaultGnssEngineStates(void);
  833. bool eventConnectionStatus(bool connected, int8_t type,
  834. bool roaming, NetworkHandle networkHandle, string& apn);
  835. bool updatePowerConnectState(bool charging);
  836. void resetNetworkInfo();
  837. bool eventOptInStatus(bool userConsent);
  838. bool eventInEmergencyCall(bool isEmergency);
  839. void setTracking(bool tracking);
  840. };
  841. } // namespace loc_core
  842. #endif //__SYSTEM_STATUS__