QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSReceiverWorker.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <functional>
6#include <memory>
7
8#include <QtCore/QByteArray>
9#include <QtCore/QDeadlineTimer>
10#include <QtCore/QObject>
11#include <QtCore/QString>
12#include <QtCore/QThread>
13
14#include "GPSCancellation.h"
15#include "GPSClock.h"
16#include "GPSConnectionErrors.h"
17#include "GPSReceiverConfig.h"
18#include "GPSReceiverReports.h"
19#include "GPSType.h"
20
21class GPSTransport;
22
25class GPSReceiverWorker : public QObject
26{
27 Q_OBJECT
28
30 friend class GPSReceiverTest;
31
32public:
34 using TransportFactory = std::function<std::unique_ptr<GPSTransport>(GPSCancelToken)>;
35
38 QObject* parent = nullptr, GPSClock clock = {});
39 ~GPSReceiverWorker() override;
40
42 // Virtual so the receiver suites' scripted worker can emit signals without a worker thread.
43 virtual void start();
44
47 virtual void stop();
48
50 bool wait(QDeadlineTimer deadline = QDeadlineTimer(QDeadlineTimer::Forever));
51
54 void setEndsWhenIdle(bool endsWhenIdle);
55
57 static constexpr std::chrono::milliseconds RECEIVE_TIMEOUT{1200};
60 static constexpr std::chrono::milliseconds USEFUL_DATA_TIMEOUT = 3 * RECEIVE_TIMEOUT;
61
62signals:
66 void rtcmDataReceived(const QByteArray& message, qint64 receivedAtMs);
69 void connectionError(GPSConnectionError error, const QString& detail = {});
77 void receiverReady(const QString& identity = {});
79 void finished();
80
81private:
82 void _runSession();
83
84 std::unique_ptr<QThread> _thread;
85 TransportFactory _transportFactory;
86 GPSType _type;
87 GPSCancelSource _cancelSource;
88 bool _endsWhenIdle = true;
89 GPSReceiverConfig _config{};
90 GPSClock _clock;
91};
Config config
Error error
Issues tokens and cancels them all at once. Copies share the cancellation.
static constexpr std::chrono::milliseconds RECEIVE_TIMEOUT
Longest wait for one read before the session re-checks cancellation.
void inputProblem(GPSInputProblem problem)
virtual void start()
Starts the session once; later calls are ignored.
void connectionError(GPSConnectionError error, const QString &detail={})
detail is the transport's or the protocol's diagnostic, or empty when it gave none.
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
Waits for the worker to exit; returns true at once when the session never started.
void finished()
Delivered on this object's thread once the session thread has finished.
friend class GPSReceiverTest
void receiverReady(const QString &identity={})
identity is the receiver model and firmware, or empty when the family does not report them.
void satelliteInfoUpdated(const GPSSatelliteReport &message)
void surveyInStatusUpdated(const GPSSurveyReport &report)
~GPSReceiverWorker() override
void receiverDetected(GPSType type)
void setEndsWhenIdle(bool endsWhenIdle)
std::function< std::unique_ptr< GPSTransport >(GPSCancelToken)> TransportFactory
Consumed on the worker thread, so transport construction, I/O and destruction share that thread.
static constexpr std::chrono::milliseconds USEFUL_DATA_TIMEOUT
friend class GPSReceiverWorkerTest
void rtcmDataReceived(const QByteArray &message, qint64 receivedAtMs)
RTCM output the receiver sent, stamped with the steady clock when it was read.
void positionUpdated(const GPSPositionReport &report)
GPSInputProblem
Why a receiver that stays connected while silent reports no position.
The monotonic clock receiver sessions run on: the steady clock unless tests inject a virtual one.
Definition GPSClock.h:11