QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SBFPlan.cc
Go to the documentation of this file.
1#include "SBF/SBFPlan.h"
2
3#include <chrono>
4#include <utility>
5#include <variant>
6
7#include "GPSProtocolMath.h"
8
9namespace {
10
11constexpr std::chrono::milliseconds COMMAND_TIMEOUT{1000};
12
14void add(GPSCommandSequence& sequence, const QByteArray& command, GPSCommandOptions options = {})
15{
16 sequence.steps.emplace_back(
17 gpsCommand(command + '\n', COMMAND_TIMEOUT,
18 GPSCommandSequence::RawReply{.accepted = "$R: " + command, .rejected = "$R?"}, std::move(options)));
19}
20
21} // namespace
22
23namespace SBF::Plan {
24
26{
27 GPSCommandSequence result;
28 for (const char* port : {"COM1", "COM2", "USB1", "USB2", "USB3", "USB4"}) {
29 add(result, "setDataInOut," + QByteArray(port) + ",,-RTCMv3-RTCMv2-CMRv2", {.required = false});
30 }
31 return result;
32}
33
34GPSCommandSequence port(QByteArrayView port, unsigned baud)
35{
36 const QByteArray name = port.toByteArray();
37 GPSCommandSequence result;
38 add(result, "setSBFOutput, Stream1, " + name + ", none, off");
39 // COM ports have a baud rate; USB and IP connections do not.
40 if (port.startsWith("COM")) {
41 add(result, "setCOMSettings, " + name + ", baud" + QByteArray::number(baud));
42 }
43 add(result, "setDataInOut, " + name + ", Auto, SBF");
44 // WGS84 selects the global datum except when external corrections supply a datum.
45 add(result, "setGeodeticDatum, WGS84");
46 return result;
47}
48
50{
51 const QByteArray name = port.toByteArray();
52 GPSCommandSequence result;
53 add(result, "setDataInOut, " + name + ", Auto, RTCMv3+SBF");
54 if (const auto* fixed = std::get_if<GPSBaseStationConfig::Fixed>(&base.mode)) {
55 const auto& position = fixed->position;
56 add(result,
57 "setStaticPosGeodetic, Geodetic1, " + gpsFixedDecimal(position.latitudeDegrees, 9) + ", " +
58 gpsFixedDecimal(position.longitudeDegrees, 9) + ", " + gpsFixedDecimal(position.altitudeMeters, 4) +
59 ", WGS84",
60 {.label = "setStaticPosGeodetic (fixed position)"});
61 add(result, "setAntennaOffset, Main, 0.000000, 0.000000, 0.000000");
62 add(result, "setReceiverDynamics, Low, Static");
63 add(result, "setPVTMode, Static, , Geodetic1");
64 } else {
65 add(result, "setPVTMode, Static, All, auto");
66 }
67 add(result, "setSBFOutput, Stream1, " + name + ", +PVTGeodetic, msec500");
68 return result;
69}
70
71} // namespace SBF::Plan
GPSCommandSequence::Command gpsCommand(QByteArray wire, std::chrono::milliseconds timeout, std::variant< GPSTextMatcher, GPSCommandSequence::RawReply > reply, GPSCommandOptions options={})
Definition GPSCommand.h:162
QByteArray gpsFixedDecimal(double value, int decimals)
GPSCommandSequence sequence(std::span< const Setting > settings, char port)
settings for port, each acknowledged by an ACK.
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.
constexpr std::chrono::milliseconds COMMAND_TIMEOUT
Per attempt, unless a command gives its own.
Definition QuectelPlan.h:26
GPSCommandSequence base(QByteArrayView port, const GPSBaseStationConfig &base)
Streams RTCM3 corrections and the PVTGeodetic survey status over port in the mode base selects.
Definition SBFPlan.cc:49
GPSCommandSequence port(QByteArrayView port, unsigned baud)
Clears the SBF output of port, keeps a serial port at the link's baud, and selects SBF and the WGS84 ...
Definition SBFPlan.cc:34
GPSCommandSequence silenceCorrectionOutput()
Definition SBFPlan.cc:25
Configuration used only by the RTK base-station role.
Matched in the raw received bytes, for replies that need not be complete frames (see GPSRawAckMatcher...
Definition GPSCommand.h:125
std::vector< Command > steps
Definition GPSCommand.h:150