QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QuectelPlan.cc
Go to the documentation of this file.
2
3#include <utility>
4#include <variant>
5
6#include "NMEASentence.h"
8
9namespace Quectel::Plan {
10
11namespace {
12
14
15GPSTextMatcher rateReadback(const MessageRate& rate)
16{
17 return [message = rate.message, value = rate.rate, version = rate.version](std::string_view body) {
18 Fields reply(body);
19 // V1.0 documents an empty optional version after standard NMEA rates.
20 if (version.empty() && reply.size() == 5 && reply.back().empty()) {
21 reply.pop_back();
22 }
23 unsigned read = 0;
24 return QuectelCodec::readback(reply, "PQTMCFGMSGRATE",
25 reply.size() == (version.empty() ? 4 : 5) && reply[2] == message &&
26 QuectelCodec::number(reply[3], read) && read == value &&
27 (version.empty() || reply[4] == version));
28 };
29}
30
31} // namespace
32
33QByteArray writeBase(const GPSBaseStationConfig::Mode& mode, const GPSProtocolMath::Ecef& position, bool distanceField)
34{
35 QByteArray body = "PQTMCFGSVIN,W,";
36 if (std::holds_alternative<GPSBaseStationConfig::Fixed>(mode)) {
37 body += "2,0,0," + gpsFixedDecimal(position.x, 4) + ',' + gpsFixedDecimal(position.y, 4) + ',' +
38 gpsFixedDecimal(position.z, 4);
39 } else {
40 const auto& survey = std::get<GPSBaseStationConfig::SurveyIn>(mode);
41 body += "1," + QByteArray::number(static_cast<qint64>(survey.duration.count())) + ',' +
42 gpsFixedDecimal(survey.accuracyMeters, 9) + ",0,0,0";
43 }
44 if (distanceField) {
45 body += ",0";
46 }
47 return body;
48}
49
50GPSCommandSequence::Command command(QByteArrayView body, GPSTextMatcher reply, std::chrono::milliseconds timeout)
51{
52 return gpsCommand(NMEAUtils::frame(body), timeout, std::move(reply), {.label = body.toByteArray()});
53}
54
55GPSTextMatcher acknowledgement(QByteArrayView body)
56{
57 const qsizetype comma = body.indexOf(',');
58 return [name = body.first(comma < 0 ? body.size() : comma).toByteArray()](std::string_view reply) {
59 return QuectelCodec::acknowledgement(Fields(reply), QByteArrayView(name));
60 };
61}
62
63GPSCommandSequence messageRates(std::span<const MessageRate> rates)
64{
65 GPSCommandSequence sequence;
66 for (const auto& rate : rates) {
67 const QByteArray message = QByteArrayView(rate.message).toByteArray();
68 QByteArray suffix;
69 if (!rate.version.empty()) {
70 suffix = ',' + QByteArrayView(rate.version).toByteArray();
71 }
72 const QByteArray write = "PQTMCFGMSGRATE,W," + message + ',' + QByteArray::number(rate.rate) + suffix;
73 const QByteArray read = "PQTMCFGMSGRATE,R," + message + suffix;
74 sequence.steps.emplace_back(command(write, acknowledgement(write)));
75 sequence.steps.emplace_back(command(read, rateReadback(rate)));
76 }
77 return sequence;
78}
79
80} // namespace Quectel::Plan
GPSCommandSequence::Command gpsCommand(QByteArray wire, std::chrono::milliseconds timeout, std::variant< GPSTextMatcher, GPSCommandSequence::RawReply > reply, GPSCommandOptions options={})
Definition GPSCommand.h:162
std::function< GPSCommandOutcome(std::string_view reply)> GPSTextMatcher
Resolves the outstanding command from one text reply a decoder offers; Pending keeps waiting.
Definition GPSCommand.h:69
QByteArray gpsFixedDecimal(double value, int decimals)
Borrowed fields for the largest supported PQTM reply, including empty trailing fields.
QByteArray frame(QByteArrayView body)
body as one "$<body>*hh\r\n" sentence, with uppercase checksum digits.
GPSCommandOutcome acknowledgement(const Fields &reply, std::string_view command)
"<command>,OK" acknowledges and "<command>,ERROR,<code>" rejects a setting.
GPSCommandOutcome readback(const Fields &reply, std::string_view command, bool matches)
bool number(std::string_view text, T &result)
GPSCommandSequence::Command command(QByteArrayView body, GPSTextMatcher reply, std::chrono::milliseconds timeout)
body labelled by its text, framed as a sentence, and completed by reply within timeout.
GPSTextMatcher acknowledgement(QByteArrayView body)
Completes the setting body with its "<name>,OK" acknowledgement.
QByteArray writeBase(const GPSBaseStationConfig::Mode &mode, const GPSProtocolMath::Ecef &position, bool distanceField)
GPSCommandSequence messageRates(std::span< const MessageRate > rates)
PQTMCFGMSGRATE,W for each of rates, each followed by its PQTMCFGMSGRATE,R readback.
std::variant< SurveyIn, Fixed, ReceiverAveraging > Mode
std::vector< Command > steps
Definition GPSCommand.h:150
std::string_view message
Definition QuectelPlan.h:71
std::string_view version
Message version; standard NMEA messages have none.
Definition QuectelPlan.h:74