QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4SerialPortsController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QHash>
4#include <QtCore/QObject>
5#include <QtCore/QPointer>
6#include <QtCore/QSet>
7#include <QtCore/QStringList>
8#include <QtCore/QVariantList>
9#include <QtQmlIntegration/QtQmlIntegration>
10
11#include "FactPanelController.h"
12#include "PX4SerialPortConfig.h"
13
14class Fact;
17
19class PX4SerialPortRow : public QObject
20{
21 Q_OBJECT
22 QML_ELEMENT
23 QML_UNCREATABLE("Created by PX4SerialPortsController")
24 Q_MOC_INCLUDE("Fact.h")
25 Q_PROPERTY(int portId READ portId CONSTANT)
26 Q_PROPERTY(QString label READ label CONSTANT)
29 Q_PROPERTY(QStringList functionLabels READ functionLabels NOTIFY functionLabelsChanged)
31 Q_PROPERTY(bool shared READ shared CONSTANT)
33 Q_PROPERTY(int functionIndex READ functionIndex NOTIFY functionIndexChanged)
35 Q_PROPERTY(QVariantList functionEnabled READ functionEnabled NOTIFY functionEnabledChanged)
36 Q_PROPERTY(QString conflictText READ conflictText NOTIFY conflictTextChanged)
38 Q_PROPERTY(QStringList assignments READ assignments NOTIFY assignmentsChanged)
41 Q_PROPERTY(Fact* baudFact READ baudFact NOTIFY baudFactChanged)
43 Q_PROPERTY(bool baudLoading READ baudLoading NOTIFY baudLoadingChanged)
44 Q_PROPERTY(QVariantList optionFacts READ optionFacts NOTIFY optionFactsChanged)
46 Q_PROPERTY(bool optionsLoading READ optionsLoading NOTIFY optionsLoadingChanged)
47 Q_PROPERTY(bool rebootRequired READ rebootRequired NOTIFY rebootRequiredChanged)
48
49public:
50 PX4SerialPortRow(int portId, const QString& label, const QStringList& functionParamNames,
51 const QStringList& functionLabels, QObject* parent = nullptr);
52
53 int portId() const { return _portId; }
54
55 QString label() const { return _label; }
56
57 QStringList functionLabels() const { return _noneAvailable ? _functionLabels : _functionLabels.mid(1); }
58
59 bool shared() const { return _shared; }
60
61 int functionIndex() const { return _functionIndex; }
62
63 QVariantList functionEnabled() const { return _functionEnabled; }
64
65 QString conflictText() const { return _conflictText; }
66
67 QStringList assignments() const { return _assignments; }
68
69 bool defaultFunctionOnPort() const { return !_noneAvailable; }
70
71 Fact* baudFact() const { return _baudFact; }
72
73 bool baudLoading() const { return _baudLoading; }
74
75 QVariantList optionFacts() const { return _optionFacts; }
76
77 bool optionsLoading() const { return _optionsLoading; }
78
79 bool rebootRequired() const { return _rebootRequired; }
80
82 QString functionParamName(int functionIndex) const;
83 int functionIndexOf(const QString& functionParamName) const;
84
85 void setNoneAvailable(bool noneAvailable);
87 void setFunctionEnabled(const QVariantList& functionEnabled);
88 void setConflictText(const QString& conflictText);
89 void setAssignments(const QStringList& assignments);
91 void setBaudLoading(bool baudLoading);
92 void setOptionFacts(const QVariantList& optionFacts);
95
96signals:
108
109private:
110 const int _portId;
111 const QString _label;
112 const QStringList _functionParamNames;
113 const QStringList _functionLabels;
114 bool _noneAvailable = true;
115 const bool _shared;
116 int _functionIndex = 0;
117 QVariantList _functionEnabled;
118 QString _conflictText;
119 QStringList _assignments;
120 Fact* _baudFact = nullptr;
121 bool _baudLoading = false;
122 QVariantList _optionFacts;
123 bool _optionsLoading = false;
124 bool _rebootRequired = false;
125};
126
130{
131 Q_OBJECT
132 QML_ELEMENT
133 Q_MOC_INCLUDE("QmlObjectListModel.h")
134 Q_PROPERTY(QmlObjectListModel* ports READ ports CONSTANT)
136
137public:
138 explicit PX4SerialPortsController(QObject* parent = nullptr);
139
140 QmlObjectListModel* ports() const { return _ports; }
141
142 int changedPortCount() const { return _changedPortCount; }
143
146 Q_INVOKABLE void setPortFunction(int portId, int functionIndex);
147
149 Q_INVOKABLE void setPortFunctionEnabled(int portId, int functionIndex, bool enabled);
150
152 Q_INVOKABLE void revertChanges();
153
154signals:
156
157private slots:
158 void _update();
159 void _factAdded(int componentId, Fact* fact);
160 void _parameterReadFailed(int componentId, const QString& paramName);
161
162private:
163 Fact* _fact(const QString& paramName);
164 void _watchFact(Fact* fact);
165 void _requestParameter(const QString& paramName);
166 bool _differsFromInitial(const QString& paramName) const;
167 void _writeParams(const QList<PX4SerialPortConfig::ParamWrite>& writes);
168 PX4SerialPortRow* _row(int portId) const;
169
170 QPointer<ParameterManager> _parameterManager;
171 QmlObjectListModel* _ports = nullptr;
172 QList<Fact*> _functionFacts;
173 QHash<QString, QVariant> _initialValues;
174 QSet<QString> _requestedParams;
175 QSet<QString> _pendingParams;
176 QSet<Fact*> _watchedFacts;
177 QHash<QString, int> _optionParamPorts;
179 int _changedPortCount = 0;
180};
FactPanelController(QObject *parent=nullptr)
A Fact is used to hold a single value within the system.
Definition Fact.h:15
One serial port row on the PX4 Ports page.
void setFunctionIndex(int functionIndex)
void assignmentsChanged()
void setRebootRequired(bool rebootRequired)
void optionsLoadingChanged()
QString functionParamName(int functionIndex) const
Function parameter for an index into functionLabels, empty for "None".
QVariantList optionFacts() const
void defaultFunctionOnPortChanged()
void baudLoadingChanged()
void optionFactsChanged()
void setOptionFacts(const QVariantList &optionFacts)
PX4SerialPortRow(int portId, const QString &label, const QStringList &functionParamNames, const QStringList &functionLabels, QObject *parent=nullptr)
true: several functions can run on the port at once, so each one is turned on or off separately
void rebootRequiredChanged()
QVariantList functionEnabled() const
int functionIndexOf(const QString &functionParamName) const
void setFunctionEnabled(const QVariantList &functionEnabled)
void functionLabelsChanged()
QStringList assignments() const
void setConflictText(const QString &conflictText)
QStringList functionLabels() const
void setNoneAvailable(bool noneAvailable)
void setBaudFact(Fact *baudFact)
void baudFactChanged()
void setBaudLoading(bool baudLoading)
void functionEnabledChanged()
void setOptionsLoading(bool optionsLoading)
void conflictTextChanged()
void setAssignments(const QStringList &assignments)
void functionIndexChanged()
Q_INVOKABLE void setPortFunctionEnabled(int portId, int functionIndex, bool enabled)
Turns the function at functionIndex on or off on a shared port, leaving the port's other functions al...
PX4SerialPortsController(QObject *parent=nullptr)
Q_INVOKABLE void revertChanges()
Writes back the values each parameter had when the page opened. Ignored while parameter writes are pe...
Q_INVOKABLE void setPortFunction(int portId, int functionIndex)
QmlObjectListModel * ports() const