QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSInputMonitor.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5
7#include "GPSDriver.h"
8#include "MonotonicClock.h"
9
12{
13public:
14 GPSInputMonitor(uint64_t startUs, std::chrono::milliseconds window)
15 : _window(window)
16 , _positionAtUs(startUs)
17 {}
18
21 bool update(const GPSReceiveResult& result, bool identified, uint64_t nowUs)
22 {
23 if (result.liveness != GPSReceiveLiveness::Idle) {
24 _bytesAtUs = nowUs;
25 }
26 if (result.liveness == GPSReceiveLiveness::Data) {
27 _dataAtUs = nowUs;
28 }
29 if (result.updates.testFlag(GPSReceiveUpdate::Position)) {
30 _positionAtUs = nowUs;
31 }
32 const auto recent = [this, nowUs](uint64_t atUs) { return MonotonicClock::fresh(atUs, nowUs, _window); };
33 GPSInputProblem current = GPSInputProblem::NotGNSS;
34 if (recent(_positionAtUs)) {
35 current = GPSInputProblem::None;
36 } else if (!recent(_bytesAtUs)) {
37 current = GPSInputProblem::NoData;
38 } else if (identified) {
39 current = GPSInputProblem::NoPositions;
40 } else if (recent(_dataAtUs)) {
41 current = GPSInputProblem::CorrectionsOnly;
42 }
43 const bool changed = current != _problem;
44 _problem = current;
45 return changed;
46 }
47
48 [[nodiscard]] GPSInputProblem problem() const { return _problem; }
49
50private:
51 std::chrono::milliseconds _window;
52 uint64_t _positionAtUs;
53 uint64_t _bytesAtUs = 0;
54 uint64_t _dataAtUs = 0;
55 GPSInputProblem _problem = GPSInputProblem::None;
56};
@ Data
Useful reports, even without a registered sink.
Classifies why a session that stays connected delivers no position, from the receive cycles of the la...
GPSInputMonitor(uint64_t startUs, std::chrono::milliseconds window)
GPSInputProblem problem() const
bool update(const GPSReceiveResult &result, bool identified, uint64_t nowUs)
GPSInputProblem
Why a receiver that stays connected while silent reports no position.
constexpr bool fresh(uint64_t timestampUs, uint64_t nowUs, std::chrono::microseconds lifetime)
Whether a receipt is younger than lifetime.
GPSReceiveLiveness liveness
Definition GPSDriver.h:54
GPSReceiveUpdates updates
Position and satellite reports published to the sinks.
Definition GPSDriver.h:56