QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSReceiverDetector.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <chrono>
5#include <cstdint>
6#include <functional>
7#include <optional>
8#include <span>
9#include <vector>
10
11#include <QtCore/QLatin1StringView>
12#include <QtCore/QString>
13
14#include "GPSFamilyProtocol.h"
15#include "GPSProtocolRuntime.h"
16#include "GPSStreamDemux.h"
17
21{
22public:
23 struct Match
24 {
25 const GPSReceiverFamily* family = nullptr;
27 QLatin1StringView evidence{};
28 };
29
30 explicit GPSReceiverSignatures(std::span<const GPSReceiverFamily* const> families);
31
32 void push(std::span<const uint8_t> bytes);
33
35 void reset();
36
38 [[nodiscard]] const std::optional<Match>& match() const { return _match; }
39
41 [[nodiscard]] bool framedTraffic() const { return _framedTraffic; }
42
43private:
44 void frame(const GPSFrame& frame) override;
45
46 std::span<const GPSReceiverFamily* const> _families;
47 GPSStreamDemux _demux;
48 std::optional<Match> _match;
49 bool _framedTraffic = false;
50};
51
54{
56 const GPSReceiverFamily* family = nullptr;
58 unsigned baud = 0;
60 QString evidence;
63 QString errorDetail;
64
65 [[nodiscard]] bool found() const { return family != nullptr; }
66};
67
79{
80public:
81 static constexpr std::chrono::milliseconds LISTEN_WINDOW{1000};
84 static constexpr std::chrono::milliseconds TIMEOUT{45000};
85 static constexpr std::array<unsigned, 8> BAUD_PRIORITY{115200, 38400, 460800, 9600, 230400, 921600, 57600, 19200};
86
89 GPSReceiverDetector(std::span<const GPSReceiverFamily* const> families, GPSRuntimeIO io,
90 std::function<void(const GPSConfigurationEvidence&)> commandFinished = {});
91
92 Q_DISABLE_COPY(GPSReceiverDetector)
93
94
95 [[nodiscard]] static std::vector<unsigned> baudCandidates(std::span<const GPSReceiverFamily* const> families);
96
98 [[nodiscard]] GPSReceiverDetection detect(unsigned baud = 0);
99
100private:
101 enum class Listen : uint8_t
102 {
103 Identified,
104 Quiet,
105 Failed,
106 };
107
108 Listen _listen(unsigned baud, uint64_t untilUs, GPSReceiverDetection& result);
109 bool _stopped(GPSReceiverDetection& result) const;
110 GPSReceiverDetection _identified(const GPSReceiverFamily& family, unsigned baud, QString evidence) const;
111
112 std::span<const GPSReceiverFamily* const> _families;
113 GPSReceiverSignatures _signatures;
114 GPSRuntimeIO _io;
115 std::function<void(const GPSConfigurationEvidence&)> _commandFinished;
116};
GPSProtocolError
Sticky failure of the current receiver session; I/O and control stop until the next configure().
Definition GPSCommand.h:23
static constexpr std::chrono::milliseconds TIMEOUT
static constexpr std::chrono::milliseconds LISTEN_WINDOW
GPSReceiverDetection detect(unsigned baud=0)
Identifies the receiver at baud, which then every family is probed at, or else at each baudCandidates...
static std::vector< unsigned > baudCandidates(std::span< const GPSReceiverFamily *const > families)
The rates detection tries without a fixed rate: every candidate rate of families, in likelihood order...
static constexpr std::array< unsigned, 8 > BAUD_PRIORITY
void push(std::span< const uint8_t > bytes)
const std::optional< Match > & match() const
The first family signature since the last reset.
void reset()
Forgets partial frames and findings, as after a rate change.
bool framedTraffic() const
Standard NMEA sentences or RTCM3 frames arrived, so the link runs at the receiver's rate.
Evidence from one configuration command, not a claim of physical receiver operation.
Definition GPSCommand.h:46
The receiver detection found, or why it found none.
const GPSReceiverFamily * family
Null when no family was identified.
GPSProtocolError error
Protocol when nothing was identified; Cancelled or Transport when the link ended detection.
unsigned baud
The rate the receiver answered at.
QString evidence
What identified it: a signature such as "UBX frames", or "identity query".
const GPSReceiverFamily * family
QLatin1StringView evidence
What identified the family, such as "UBX frames".