15VehicleGPSAggregateFactGroup::VehicleGPSAggregateFactGroup(QObject *parent)
16 :
FactGroup(1000,
":/json/Vehicle/GPSFact.json", parent)
18 _addFact(&_spoofingStateFact);
19 _addFact(&_jammingStateFact);
20 _addFact(&_authenticationStateFact);
21 _addFact(&_isStaleFact);
23 _spoofingStateFact.setRawValue(255);
24 _jammingStateFact.setRawValue(255);
25 _authenticationStateFact.setRawValue(255);
26 _isStaleFact.setRawValue(
true);
28 _staleTimer.setSingleShot(
true);
29 _staleTimer.setInterval(GNSS_INTEGRITY_STALE_TIMEOUT_MS);
30 connect(&_staleTimer, &QTimer::timeout,
this, &VehicleGPSAggregateFactGroup::_onStaleTimeout);
48void VehicleGPSAggregateFactGroup::_updateAggregates()
50 updateFromGps(_gps1, _gps2);
53void VehicleGPSAggregateFactGroup::_onIntegrityUpdated()
55 _isStaleFact.setRawValue(
false);
60void VehicleGPSAggregateFactGroup::_onStaleTimeout()
62 _spoofingStateFact.setRawValue(255);
63 _jammingStateFact.setRawValue(255);
64 _authenticationStateFact.setRawValue(255);
65 _isStaleFact.setRawValue(
true);
68void VehicleGPSAggregateFactGroup::_clearConnections()
70 for (
const auto& c : _connections) {
71 QObject::disconnect(c);
76int VehicleGPSAggregateFactGroup::_valueOrInvalid(
Fact* fact)
81 const QVariant v = fact->rawValue();
86 const int val = v.toInt(&ok);
90 return (val == 255) ? -1 : val;
93int VehicleGPSAggregateFactGroup::_mergeWorst(
int a,
int b)
98int VehicleGPSAggregateFactGroup::_mergeAuthentication(
int a,
int b)
101 auto getWeight = [](
int val) {
103 case AUTH_INVALID:
return -1;
104 case AUTH_UNKNOWN:
return 0;
105 case AUTH_DISABLED:
return 1;
106 case AUTH_INITIALIZING:
return 2;
107 case AUTH_OK:
return 3;
108 case AUTH_ERROR:
return 4;
113 return (getWeight(a) >= getWeight(b)) ? a : b;
118 const int spoof1 = _valueOrInvalid(gps1 ? gps1->spoofingState() : nullptr);
119 const int spoof2 = _valueOrInvalid(gps2 ? gps2->spoofingState() : nullptr);
120 const int jam1 = _valueOrInvalid(gps1 ? gps1->jammingState() : nullptr);
121 const int jam2 = _valueOrInvalid(gps2 ? gps2->jammingState() : nullptr);
122 const int auth1 = _valueOrInvalid(gps1 ? gps1->authenticationState() : nullptr);
123 const int auth2 = _valueOrInvalid(gps2 ? gps2->authenticationState() : nullptr);
125 const int spoofMerged = _mergeWorst(spoof1, spoof2);
126 const int jamMerged = _mergeWorst(jam1, jam2);
127 const int authMerged = _mergeAuthentication(auth1, auth2);
129 _spoofingStateFact.setRawValue(spoofMerged == -1 ? 255 : spoofMerged);
130 _jammingStateFact.setRawValue(jamMerged == -1 ? 255 : jamMerged);
131 _authenticationStateFact.setRawValue(authMerged == -1 ? 255 : authMerged);
Used to group Facts together into an object hierarachy.
A Fact is used to hold a single value within the system.
void gnssIntegrityReceived()