12#include <QtCore/QByteArrayView>
13#include <QtCore/QString>
54[[nodiscard]] QString
gpsRateList(std::span<const unsigned> rates);
71 void _limitUntil(uint64_t untilUs);
94 [[nodiscard]] uint64_t
nowUs()
const;
111 [[nodiscard]]
const QString&
errorDetail()
const {
return _errorDetail; }
149 int read(std::span<uint8_t> buffer, std::chrono::milliseconds timeout);
154 bool write(QByteArrayView bytes);
161 void wait(std::chrono::microseconds duration);
175 return _transact(std::move(step), bytes, std::monostate{});
181 return _transact(std::move(step), bytes, std::move(reply));
187 return _transact(std::move(step), bytes, std::move(reply));
210 GPSReceiveUpdates
receiveCycle(std::chrono::milliseconds timeout);
213 void receiveFor(std::chrono::milliseconds duration);
217 bool receiveUntil(std::function<
bool()> done, std::chrono::milliseconds duration);
225 GPSReceiveUpdates
flush();
240 using ReplyMatcher = std::variant<std::monostate, GPSRawAckMatcher*, GPSTextMatcher, GPSFrameMatcher>;
250 if (_replyPending()) {
262 GPSReceiveUpdates _readAndDecode(std::chrono::milliseconds timeout);
264 [[nodiscard]] QString _commandFailure(
const QByteArray& label,
GPSCommandOutcome outcome)
const;
266 void _describeFailure();
270 void _offerText(std::string_view reply);
271 void _offerFrame(
const GPSFrame& frame);
272 void _offerRaw(std::span<const uint8_t> bytes);
276 QString _errorDetail;
278 bool _commandCompleted =
true;
281 std::optional<GPSCommandOutcome> _reply;
282 ReplyMatcher _replyMatcher;
283 unsigned _detectedBaud = 0;
284 bool _servicingControls =
false;
@ Stop
The receiver answered but is not usable, so no other rate is tried.
QString gpsRateList(std::span< const unsigned > rates)
rates as a diagnostic names them, such as "38400, 9600".
GPSBaudStatus
How the link answered a baud rate change.
std::function< GPSBaudProbe()> GPSBaudProbeFunction
Probes the receiver at the rate the link was just set to.
std::function< GPSCommandOutcome(const GPSFrame &frame)> GPSFrameMatcher
Resolves the outstanding command from each dispatched frame, after the family decoded it; Pending kee...
std::function< GPSCommandOutcome()> GPSReplyPoll
Polled after each decoded chunk, for replies a family tracks in its own decoder state; Pending keeps ...
GPSProtocolError
Sticky failure of the current receiver session; I/O and control stop until the next configure().
@ Protocol
The receiver violated or rejected the control protocol.
std::function< GPSCommandOutcome(std::string_view reply)> GPSTextMatcher
Resolves the outstanding command from one text reply a decoder offers; Pending keeps waiting.
const QLoggingCategory &(*)() GPSLogCategory
A family's logging category function, as declared by Q_DECLARE_LOGGING_CATEGORY; usable as qCWarning(...
void wait(std::chrono::microseconds duration)
Waits for duration, capped by the operation deadline.
void beginCommand(GPSConfigurationStep step)
void setErrorDetail(const QString &detail)
void serviceControls()
Runs the family's streaming services once under SERVICE_TIMEOUT, then flushes. Nested calls do nothin...
GPSLogCategory logCategory() const
GPSBaudDetection detectBaud(std::span< const unsigned > candidates, unsigned baud, GPSBaudProbeFunction probe)
GPSReceiveUpdates receiveCycle(std::chrono::milliseconds timeout)
int read(std::span< uint8_t > buffer, std::chrono::milliseconds timeout)
Reads raw bytes without decoding them.
void receiveFor(std::chrono::milliseconds duration)
Repeats the family's full streaming receive until duration has passed or I/O fails.
GPSDeadline operationDeadline() const
GPSDecodeContext & context()
bool setBaudrate(unsigned baudrate)
GPSConfigurationEvidence transact(GPSConfigurationStep step, QByteArrayView bytes, GPSFrameMatcher reply)
As above, also resolved by reply from each dispatched frame.
GPSConfigurationEvidence transact(GPSConfigurationStep step, QByteArrayView bytes, GPSTextMatcher reply)
As above, also resolved by reply from each text reply a decoder offers.
void failSequence(const GPSCommandSequence::Result &result)
GPSDeadline commandDeadline() const
Deadline of the current command attempt, set by beginCommand().
void failControl(GPSProtocolError failure=GPSProtocolError::Protocol)
GPSDeadlineScope deadlineScope(std::chrono::milliseconds timeout)
bool receiveUntil(std::function< bool()> done, std::chrono::milliseconds duration)
static constexpr std::chrono::milliseconds SERVICE_TIMEOUT
Budget of the streaming services that run after each receive.
const QString & errorDetail() const
const GPSConfigurationEvidence & currentCommand() const
GPSDeadlineScope deadlineScope(GPSDeadline deadline)
static constexpr size_t READ_CHUNK_SIZE
Bytes requested by each receive or reply read.
GPSConfigurationEvidence completeCommand(GPSCommandOutcome outcome)
Retires the current attempt and reports it; repeated completion returns the retained evidence unchang...
GPSReceiveUpdates flush()
Flushes decoder state and delivers the resulting batch.
GPSStreamDemux & stream()
bool write(QByteArrayView bytes)
bool runRequired(const GPSCommandSequence &sequence)
Runs sequence and fails control over a failed step as failSequence() does.
GPSCommandSequence::Result runSequence(const GPSCommandSequence &sequence)
Runs sequence in order until a required step fails or I/O fails; failed attempts retry up to their co...
GPSConfigurationEvidence awaitReply(GPSReplyPoll reply)
Decodes received traffic until reply resolves the current command, its deadline expires,...
GPSProtocolError error() const
void failNoAnswer(std::span< const unsigned > rates)
bool writeCommand(GPSConfigurationStep step, QByteArrayView bytes)
Starts one command attempt under its own deadline scope and writes it; awaitReply() waits for its rep...
GPSConfigurationEvidence transact(GPSConfigurationStep step, QByteArrayView bytes)
GPSCommandOutcome failureOutcome() const
The command outcome that reports the sticky failure; Pending while healthy.
void finishCommand(GPSCommandOutcome outcome)
std::vector< unsigned > probed
The rates the link ran at while probing, in order.
unsigned baud
The rate that was found, or the last rate attempted.
bool linkFailed
The link could not be set to the last rate attempted.
Evidence from one configuration command, not a claim of physical receiver operation.