Skip to content

Commit eff16bd

Browse files
committed
RemoteIDManager: Evaluate GCS GPS health deterministically
The gcsGPSGood checks flipped the flag relative to its previous value across separate conditionals (and early-returned in the FAA no-altitude case), so it oscillated green/red at the send rate whenever a condition sat near its boundary - e.g. in FAA when the altitude was momentarily missing. Compute the health from the current fix each cycle (valid, altitude-if-FAA, fresh) and emit only on change. Also keep sending the SYSTEM message with an UNKNOWN location instead of going silent when the fix isn't usable.
1 parent 2c1c20d commit eff16bd

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

src/Vehicle/RemoteIDManager.cc

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -295,33 +295,30 @@ void RemoteIDManager::_sendSystem()
295295
gcsPosition = QGCPositionManager::instance()->gcsPosition();
296296
geoPositionInfo = QGCPositionManager::instance()->geoPositionInfo();
297297

298-
// GPS position needs to be valid before checking other stuff
299-
if (geoPositionInfo.isValid()) {
300-
// If we dont have altitude for FAA then the GPS data is no good
301-
if ((_settings->region()->rawValue().toInt() == Region::FAA) && !(gcsPosition.altitude() >= 0) && _gcsGPSGood) {
302-
_gcsGPSGood = false;
303-
emit gcsGPSGoodChanged();
304-
qCDebug(RemoteIDManagerLog) << "GCS GPS data error (no altitude): Altitude data is mandatory for GCS GPS data in FAA regions.";
305-
return;
306-
}
298+
// Determine GPS health deterministically from the current data every cycle. The
299+
// previous code flipped _gcsGPSGood relative to its prior value across separate
300+
// checks, which made it oscillate green/red at the send rate (e.g. in FAA when the
301+
// altitude was momentarily missing).
302+
bool good = true;
303+
const char* reason = nullptr;
304+
if (!geoPositionInfo.isValid()) {
305+
good = false;
306+
reason = "GCS GPS data is not valid.";
307+
} else if ((_settings->region()->rawValue().toInt() == Region::FAA) && !(gcsPosition.altitude() >= 0)) {
308+
// FAA mandates an operator altitude
309+
good = false;
310+
reason = "GCS GPS data error (no altitude): Altitude data is mandatory for GCS GPS data in FAA regions.";
311+
} else if (_lastGeoPositionTimeStamp.msecsTo(QDateTime::currentDateTimeUtc()) > ALLOWED_GPS_DELAY) {
312+
good = false;
313+
reason = "GCS GPS data is older than 5 seconds";
314+
}
307315

308-
// If the GPS data is older than ALLOWED_GPS_DELAY we cannot use this data
309-
if (_lastGeoPositionTimeStamp.msecsTo(QDateTime::currentDateTime().currentDateTimeUtc()) > ALLOWED_GPS_DELAY) {
310-
if (_gcsGPSGood) {
311-
_gcsGPSGood = false;
312-
emit gcsGPSGoodChanged();
313-
qCDebug(RemoteIDManagerLog) << "GCS GPS data is older than 5 seconds";
314-
}
315-
} else {
316-
if (!_gcsGPSGood) {
317-
_gcsGPSGood = true;
318-
emit gcsGPSGoodChanged();
319-
}
320-
}
321-
} else {
322-
_gcsGPSGood = false;
316+
if (good != _gcsGPSGood) {
317+
_gcsGPSGood = good;
323318
emit gcsGPSGoodChanged();
324-
qCDebug(RemoteIDManagerLog) << "GCS GPS data is not valid.";
319+
if (reason) {
320+
qCDebug(RemoteIDManagerLog) << reason;
321+
}
325322
}
326323

327324
}

0 commit comments

Comments
 (0)