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