QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSReceiverConnectionPolicy.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <optional>
5
6#include <QtCore/QCoreApplication>
7#include <QtCore/QString>
8
11#ifndef QGC_NO_SERIAL_LINK
12#include "SerialPortManager.h"
13#endif
14
16
31
41{
42 Q_DECLARE_TR_FUNCTIONS(GPSReceiverConnectionPolicy)
43
45
46public:
50 RuntimeScheduler* scheduler);
51
54
56 bool connectConfigured(bool allowPersistentChanges);
60 void update();
62 void reset();
63
65 bool reconnecting() const { return _keepConnected && !_receiver.hasReceiver(); }
66
67 void receiverReady();
68 [[nodiscard]] GPSReceiverSessionOutcome sessionEnded(bool portRemoved);
69
70private:
71 enum class Owner
72 {
73 None,
74 Saved,
75 Discovered,
76 };
77
78 bool _hasSavedReceiver() const;
79 bool _discoveryEnabled() const;
80 bool _connectConfigured(bool allowPersistentChanges);
81 void _updateSaved();
82 void _attemptSaved();
83 void _scheduleRetry();
84 void _cancelRetries();
85 bool _serialDeviceAvailable(const QString& device) const;
86 void _updateDiscovery();
87#ifndef QGC_NO_SERIAL_LINK
90 void _connectDiscovered(const QString& device);
91#endif
92
93 GPSReceiverConnector& _receiver;
94 const GPSReceiverConfiguration& _configuration;
95 RuntimeScheduler* const _scheduler;
96 Owner _owner = Owner::None;
98 bool _startPending = true;
100 bool _keepConnected = false;
102 bool _paused = false;
103 bool _waitingForPort = false;
104 QString _autoPort;
105#ifndef QGC_NO_SERIAL_LINK
106 SerialPortSettleTracker _waitingPorts;
107#endif
108 std::optional<quint64> _retryDeadlineUs;
109 ExponentialBackoff _retryBackoff{std::chrono::seconds(1), 2, std::chrono::seconds(30)};
110};
GPSReceiverSessionOutcome
What the policy does after a receiver session ends; the receiver words the message for it.
@ Unplugged
A discovered receiver was unplugged; discovery connects it again when it returns.
@ None
Nothing reconnects; the receiver's own message for the error applies.
@ AutoRetrying
A discovered receiver failed or was lost; discovery retries it.
@ WaitingForPort
The saved receiver was unplugged; it reconnects when its port returns.
@ Retrying
The saved receiver's connection was lost; a retry is scheduled.
Retry delays that start at an initial value and grow by a factor per attempt, up to a cap.
void disconnectConfigured()
Disconnects at the user's request and pauses automatic connection.
bool reconnecting() const
The saved receiver is being connected automatically and is not connected yet.
GPSReceiverSessionOutcome sessionEnded(bool portRemoved)
void reset()
Forgets connection ownership and pending retries, before another connection replaces it.
void update()
Periodic tick: due automatic connections and USB discovery.
void configurationChanged(const GPSReceiverConfiguration &previous)
The receiver's configuration changed from previous.
bool connectConfigured(bool allowPersistentChanges)
Connects the saved receiver at the user's request and resumes automatic connection.
virtual bool hasReceiver() const =0
The receiver configuration the application's settings binding supplies as values.