QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSProtocolRuntime.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#include <span>
8
9#include <QtCore/QString>
10
11#include "GPSClock.h"
12#include "GPSCommand.h"
13#include "GPSCommandChannel.h"
14#include "GPSDeadline.h"
15#include "GPSFamilyProtocol.h"
16#include "GPSProtocolEvent.h"
17#include "GPSStreamDemux.h"
18#include "GPSTransport.h"
19
24{
25 std::function<GPSReadResult(std::span<uint8_t>, GPSDeadline)> read{};
26 std::function<GPSWriteResult(std::span<const uint8_t>, GPSDeadline)> write{};
27 std::function<GPSBaudStatus(unsigned)> setBaudrate{};
32};
33
36{
38 std::function<void(const GPSEventBatch&)> decoded{};
40 std::function<void(const GPSConfigurationEvidence&)> commandFinished{};
41};
42
48{
49public:
53 GPSProtocolRuntime(const GPSReceiverFamily& family, std::unique_ptr<GPSFamilyProtocol> protocol, GPSRuntimeIO io,
54 GPSRuntimeObserver observer = {});
56
57 Q_DISABLE_COPY(GPSProtocolRuntime)
58
59
64 [[nodiscard]] bool configure(const GPSConfig& config, unsigned& baud);
65
69 [[nodiscard]] bool probe(std::chrono::milliseconds budget);
70
73 GPSReceiveUpdates receive(std::chrono::milliseconds timeout);
74
78 [[nodiscard]] bool armDecodeOnly(const GPSConfig& config);
79
83
85 [[nodiscard]] GPSEventBatch decode(std::span<const uint8_t> bytes);
86
88 GPSReceiveUpdates consume(std::span<const uint8_t> bytes);
89
91 GPSReceiveUpdates consumeFrame(const GPSFrame& frame);
92
93 [[nodiscard]] bool receiverReady() const;
94
96 [[nodiscard]] QString identity() const;
97
98 [[nodiscard]] GPSProtocolError error() const { return _channel.error(); }
99
100 [[nodiscard]] const QString& errorDetail() const { return _channel.errorDetail(); }
101
102 [[nodiscard]] const GPSReceiverFamily& family() const { return _family; }
103
104 [[nodiscard]] GPSFamilyProtocol& protocol() { return *_protocol; }
105
106 [[nodiscard]] GPSStreamDemux& stream() { return _demux; }
107
109 [[nodiscard]] GPSLogCategory logCategory() const;
110
111private:
112 friend class GPSCommandChannel;
113
114 void frame(const GPSFrame& frame) override;
115
116 [[nodiscard]] uint64_t nowUs() const { return _io.clock.nowUs(); }
117
118 GPSReceiveUpdates _deliver(GPSEventBatch batch);
119
120 void _commandFinished(const GPSConfigurationEvidence& result);
121
122 const GPSReceiverFamily& _family;
123 GPSRuntimeIO _io;
124 GPSRuntimeObserver _observer;
125 GPSStreamDemux _demux;
126 std::unique_ptr<GPSFamilyProtocol> _protocol;
127 GPSCommandChannel _channel;
128 GPSDecodeContext _context;
129};
GPSBaudStatus
How the link answered a baud rate change.
GPSProtocolError
Sticky failure of the current receiver session; I/O and control stop until the next configure().
Definition GPSCommand.h:23
const QLoggingCategory &(*)() GPSLogCategory
A family's logging category function, as declared by Q_DECLARE_LOGGING_CATEGORY; usable as qCWarning(...
Config config
const QString & errorDetail() const
GPSProtocolError error() const
GPSProtocolError error() const
GPSEventBatch decode(std::span< const uint8_t > bytes)
Decodes bytes without I/O or observer callbacks.
GPSFamilyProtocol & protocol()
const GPSReceiverFamily & family() const
bool armDecodeOnly(const GPSConfig &config)
GPSReceiveUpdates consume(std::span< const uint8_t > bytes)
Decodes bytes and delivers their batch to the observer. An empty span flushes.
GPSReceiveUpdates receive(std::chrono::milliseconds timeout)
bool armNavigationDecode(GPSNavigationDecode decode={})
GPSReceiveUpdates consumeFrame(const GPSFrame &frame)
Decodes one frame another stream framed and delivers its batch to the observer, without flushing.
QString identity() const
Model and firmware reported during configuration, trimmed; empty when unknown.
bool probe(std::chrono::milliseconds budget)
GPSStreamDemux & stream()
GPSLogCategory logCategory() const
The family's logging category, or the runtime's when the family has none.
const QString & errorDetail() const
bool configure(const GPSConfig &config, unsigned &baud)
The monotonic clock receiver sessions run on: the steady clock unless tests inject a virtual one.
Definition GPSClock.h:11
std::function< uint64_t()> nowUs
Definition GPSClock.h:12
The receiver configuration requested for one configure() attempt.
Evidence from one configuration command, not a claim of physical receiver operation.
Definition GPSCommand.h:46
Events decoded from one span of received bytes, in publication order.
What a decode-only runtime decodes from a receiver configured elsewhere (GPSFamilyProtocol::armNaviga...
std::function< GPSReadResult(std::span< uint8_t >, GPSDeadline)> read
GPSCancelToken cancelToken
Checked before each write and baud change; reads observe it in the transport.
std::function< GPSWriteResult(std::span< const uint8_t >, GPSDeadline)> write
GPSClock clock
Without a wait, the runtime sleeps in short slices until the duration elapses or cancelToken is cance...
std::function< GPSBaudStatus(unsigned)> setBaudrate
Observers of runtime output, invoked synchronously on the runtime thread.
std::function< void(const GPSConfigurationEvidence &)> commandFinished
Every completed command, during configuration and streaming alike.
std::function< void(const GPSEventBatch &)> decoded
Borrowed for the callback; it may decode nested input through GPSProtocolRuntime::consume().