QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSSurveyClock.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <optional>
6
7#include "GPSFamilyProtocol.h"
8
11{
12public:
13 void start(uint64_t nowUs)
14 {
15 _startedUs = nowUs;
16 _seconds = 0;
17 }
18
19 void reset()
20 {
21 _startedUs.reset();
22 _seconds = 0;
23 }
24
26 void stop(uint64_t nowUs)
27 {
28 (void) update(nowUs);
29 _startedUs.reset();
30 }
31
32 bool running() const { return _startedUs.has_value(); }
33
35 bool update(uint64_t nowUs)
36 {
37 if (!_startedUs || nowUs < *_startedUs) {
38 return false;
39 }
40 const auto seconds = static_cast<uint32_t>((nowUs - *_startedUs) / 1000000);
41 if (seconds == _seconds) {
42 return false;
43 }
44 _seconds = seconds;
45 return true;
46 }
47
48 std::chrono::seconds duration() const { return std::chrono::seconds(_seconds); }
49
51 void start(GPSDecodeContext& context)
52 {
53 start(context.nowUs());
54 context.publishSurvey(true, false, duration());
55 }
56
59 {
60 if (update(context.nowUs())) {
61 context.publishSurvey(true, false, duration());
62 }
63 }
64
66 void finish(GPSDecodeContext& context, bool valid, const GPSEllipsoidPosition& position = {})
67 {
68 stop(context.nowUs());
69 context.publishSurvey(false, valid, duration(), position);
70 }
71
72private:
73 std::optional<uint64_t> _startedUs;
74 uint32_t _seconds = 0;
75};
uint64_t nowUs() const
void publishSurvey(GPSSurveyReport &status)
Stamps status with the receipt time and publishes a copy. Survey progress is not an update flag.
Host-timed survey-in duration for receivers that report completion but not elapsed time.
bool running() const
bool update(uint64_t nowUs)
void start(GPSDecodeContext &context)
Starts timing and publishes the survey as active.
void stop(uint64_t nowUs)
Freezes the duration at its final value.
void start(uint64_t nowUs)
std::chrono::seconds duration() const
void finish(GPSDecodeContext &context, bool valid, const GPSEllipsoidPosition &position={})
Stops timing and publishes the finished survey, valid at position or failed.
void publishProgress(GPSDecodeContext &context)
Publishes the active survey when its whole-second duration advanced.
WGS84 geodetic position with ellipsoid height, not mean-sea-level altitude.