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