QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RTKSettings.cc
Go to the documentation of this file.
1#include "RTKSettings.h"
2
3#include <QtCore/QSettings>
4
6
7namespace {
8// Values persisted before receivers had roles.
9constexpr int kLegacyPassiveManufacturer = 7;
10constexpr QLatin1StringView kManufacturerMigrated("manufacturerMigrated");
11
12enum LegacyNmeaSource
13{
14 NmeaDisabled = 0,
15 NmeaUdp = 1,
16 NmeaSerial = 2,
17};
18
21LegacyNmeaSource legacyNmeaSourceFromPort(const QString& port)
22{
23 if (port.isEmpty() || port == QLatin1String("Disabled") || port == QLatin1String("Serial <none available>")) {
24 return NmeaDisabled;
25 }
26 return port == QLatin1String("UDP Port") ? NmeaUdp : NmeaSerial;
27}
28
30void migrateLegacySettings()
31{
32 QSettings settings;
33 settings.beginGroup(RTKSettings::settingsGroup);
34 // Before receivers had roles, the manufacturer only filtered the settings shown and auto-connect chose the family
35 // by board name, so a saved value falls back to Detect automatically. Old and new values share the key, so a marker
36 // keeps a manufacturer chosen later. Only the legacy passive choice stores a role; otherwise the default applies.
37 if (!settings.contains(kManufacturerMigrated)) {
38 if (!settings.contains(RTKSettings::receiverRoleName)) {
39 if (settings.value(RTKSettings::baseReceiverManufacturersName).toInt() == kLegacyPassiveManufacturer) {
40 settings.setValue(RTKSettings::receiverRoleName, RTKSettings::Passive);
41 }
42 settings.remove(RTKSettings::baseReceiverManufacturersName);
43 }
44 settings.setValue(kManufacturerMigrated, true);
45 }
46 const bool receiverConfigured = !settings.value(RTKSettings::serialDeviceName).toString().trimmed().isEmpty();
47 settings.endGroup();
48
49 // Receiver auto-connect moved here from the AutoConnect group.
50 settings.beginGroup(AutoConnectSettings::settingsGroup);
51 const QVariant autoConnect = settings.value(QStringLiteral("autoConnectRTKGPS"));
52 settings.remove(QStringLiteral("autoConnectRTKGPS"));
53 settings.endGroup();
54 settings.beginGroup(RTKSettings::settingsGroup);
55 if (autoConnect.isValid() && !settings.contains(RTKSettings::autoConnectName)) {
56 settings.setValue(RTKSettings::autoConnectName, autoConnect);
57 }
58 settings.endGroup();
59
60 // The separate NMEA GPS input became a passive receiver that forwards no RTCM. Only one receiver remains: the input
61 // replaces neither a configured receiver nor RTK auto-connect the user turned on, since that setting is saved only
62 // when changed. Left at its default, the input the user chose wins over a base that may not exist.
63 settings.beginGroup(AutoConnectSettings::settingsGroup);
64 const QString nmeaPort = settings.value(QStringLiteral("autoConnectNmeaPort")).toString().trimmed();
65 const int nmeaSource = settings.contains(QStringLiteral("nmeaSource"))
66 ? settings.value(QStringLiteral("nmeaSource")).toInt()
67 : legacyNmeaSourceFromPort(nmeaPort);
68 const QVariant nmeaBaud = settings.value(QStringLiteral("autoConnectNmeaBaud"), 4800);
69 const QVariant nmeaUdpPort = settings.value(QStringLiteral("nmeaUdpPort"));
70 for (const auto* key : {"nmeaSource", "autoConnectNmeaPort", "autoConnectNmeaBaud", "nmeaUdpPort"}) {
71 settings.remove(QLatin1String(key));
72 }
73 settings.endGroup();
74 const bool nmeaInput = nmeaSource == NmeaUdp || (nmeaSource == NmeaSerial && !nmeaPort.isEmpty());
75 const bool baseChosen = autoConnect.isValid() && autoConnect.toBool();
76 if (receiverConfigured || baseChosen || !nmeaInput) {
77 return;
78 }
79 settings.beginGroup(RTKSettings::settingsGroup);
80 settings.setValue(RTKSettings::receiverRoleName, RTKSettings::Passive);
81 settings.setValue(RTKSettings::forwardReceiverRtcmName, false);
82 // The NMEA input always connected at startup.
83 settings.setValue(RTKSettings::autoConnectName, true);
84 if (nmeaSource == NmeaUdp) {
85 settings.setValue(RTKSettings::connectionTypeName, RTKSettings::Udp);
86 if (nmeaUdpPort.isValid()) {
87 settings.setValue(RTKSettings::udpPortName, nmeaUdpPort);
88 }
89 } else {
90 settings.setValue(RTKSettings::connectionTypeName, RTKSettings::Serial);
91 settings.setValue(RTKSettings::serialDeviceName, nmeaPort);
92 settings.setValue(RTKSettings::serialBaudRateName, nmeaBaud);
93 }
94 settings.endGroup();
95}
96
97} // namespace
98
100{
101 migrateLegacySettings();
102}
103
105DECLARE_SETTINGSFACT(RTKSettings, forwardReceiverRtcm)
106DECLARE_SETTINGSFACT(RTKSettings, baseReceiverManufacturers)
107DECLARE_SETTINGSFACT(RTKSettings, surveyInAccuracyLimit)
108DECLARE_SETTINGSFACT(RTKSettings, surveyInMinObservationDuration)
109DECLARE_SETTINGSFACT(RTKSettings, receiverAveragingDuration)
110DECLARE_SETTINGSFACT(RTKSettings, connectionType)
115DECLARE_SETTINGSFACT(RTKSettings, gcsPositionSource)
117DECLARE_SETTINGSFACT(RTKSettings, serialBaudRate)
118DECLARE_SETTINGSFACT(RTKSettings, useFixedBasePosition)
119DECLARE_SETTINGSFACT(RTKSettings, fixedBasePositionLatitude)
120DECLARE_SETTINGSFACT(RTKSettings, fixedBasePositionLongitude)
121DECLARE_SETTINGSFACT(RTKSettings, fixedBasePositionAltitude)
122DECLARE_SETTINGSFACT(RTKSettings, fixedBasePositionAccuracy)
123DECLARE_SETTINGSFACT(RTKSettings, compactRtcmCorrections)
#define DECLARE_SETTINGSFACT(CLASS, NAME)
#define DECLARE_SETTINGGROUP(NAME, GROUP)
QString settingsGroup() const
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