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
42{
43 Q_DECLARE_TR_FUNCTIONS(GPSReceiverConnectionPolicy)
44
46
47public:
51 RuntimeScheduler* scheduler);
52
55
57 bool connectConfigured(bool allowPersistentChanges);
61 void update();
63 void reset();
64
66 bool reconnecting() const { return _keepConnected && !_receiver.hasReceiver(); }
67
68 void receiverReady();
69 [[nodiscard]] GPSReceiverSessionOutcome sessionEnded(bool portRemoved);
70
71private:
72 enum class Owner
73 {
74 None,
75 Saved,
76 Discovered,
77 };
78
79 bool _hasSavedReceiver() const;
80 bool _discoveryEnabled() const;
81 bool _connectConfigured(bool allowPersistentChanges);
82 void _updateSaved();
83 void _attemptSaved();
84 void _scheduleRetry();
85 void _cancelRetries();
86 bool _serialDeviceAvailable(const QString& device) const;
87 QString _serialDeviceLabel(const QString& device) const;
88 void _updateDiscovery();
89#ifndef QGC_NO_SERIAL_LINK
92 void _connectDiscovered(const QString& device);
93#endif
94
95 GPSReceiverConnector& _receiver;
96 const GPSReceiverConfiguration& _configuration;
97 RuntimeScheduler* const _scheduler;
98 Owner _owner = Owner::None;
100 bool _startPending = true;
102 bool _keepConnected = false;
104 bool _paused = false;
105 bool _waitingForPort = false;
106 QString _autoPort;
107#ifndef QGC_NO_SERIAL_LINK
108 SerialPortSettleTracker _waitingPorts;
109#endif
110 std::optional<quint64> _retryDeadlineUs;
111 ExponentialBackoff _retryBackoff{std::chrono::seconds(1), 2, std::chrono::seconds(30)};
112};
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.
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.
GPSReceiverConnectionPolicy(GPSReceiverConnector &receiver, const GPSReceiverConfiguration &configuration, RuntimeScheduler *scheduler)
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.
The receiver configuration the application's settings binding supplies as values.