QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4SerialPortsComponent.cc
Go to the documentation of this file.
2
3#include "Fact.h"
5#include "ParameterManager.h"
6#include "Vehicle.h"
7
9 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
10 , _name(tr("Ports"))
11{}
12
14{
15 QList<Fact*> facts;
16
17 if (!parameterManager) {
18 return facts;
19 }
20 for (const QString& name : parameterManager->parameterNames(ParameterManager::defaultComponentId)) {
21 Fact* const fact = parameterManager->getParameter(ParameterManager::defaultComponentId, name);
23 facts.append(fact);
24 }
25 }
26
27 return facts;
28}
29
31{
32 return tr("Assign functions such as MAVLink telemetry, GPS and RC input to the vehicle's serial ports.");
33}
34
36{
37 return QStringLiteral("/InstrumentValueIcons/link.svg");
38}
39
41{
42 return QUrl::fromUserInput(
43 QStringLiteral("qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/PX4SerialPortsComponent.qml"));
44}
45
47{
48 QStringList triggers;
49 for (const Fact* const fact : functionFacts(_vehicle->parameterManager())) {
50 triggers.append(fact->name());
51 }
52
53 return triggers;
54}
55
56QList<VehicleSummaryItem> PX4SerialPortsComponent::summaryItems() const
57{
58 QList<PX4SerialPortConfig::Function> functions;
59 for (const Fact* const fact : functionFacts(_vehicle->parameterManager())) {
60 functions.append(PX4SerialPortConfig::makeFunction(fact->name(), fact->shortDescription(), fact->enumValues(),
61 fact->enumStrings(), fact->rawValue().toInt()));
62 }
63
64 QList<VehicleSummaryItem> items;
65 for (const PX4SerialPortConfig::Port& port : PX4SerialPortConfig::ports(functions)) {
66 QStringList labels;
67 for (const PX4SerialPortConfig::Function& function : functions) {
68 if (function.currentPortId == port.id) {
69 labels.append(function.label);
70 }
71 }
72 if (!labels.isEmpty()) {
73 items.append({port.label, labels.join(QStringLiteral(", "))});
74 }
75 }
76
77 return items;
78}
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
A Fact is used to hold a single value within the system.
Definition Fact.h:15
QVariantList enumValues() const
Definition Fact.cc:304
static QList< Fact * > functionFacts(ParameterManager *parameterManager)
Parameters which select the serial port a function runs on. The page is only shown when there are som...
QList< VehicleSummaryItem > summaryItems() const final
Values for this component's card on the Summary page. A component with none falls back to summaryQmlS...
QString iconResource() const final
QStringList summaryChangedTriggerList() const final
Parameters whose change emits summaryItemsChanged, besides those that change setupComplete.
PX4SerialPortsComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
QString description() const final
Fact * getParameter(int componentId, const QString &paramName)
static constexpr int defaultComponentId
QStringList parameterNames(int componentId) const
Returns all parameter names.
VehicleComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent, QObject *parent=nullptr)
bool isFunctionParam(const QVariantList &enumValues)
true: the enum values are a PX4 serial port selection, which makes the parameter a port function
Function makeFunction(const QString &paramName, const QString &shortDescription, const QVariantList &enumValues, const QStringList &enumStrings, int value)
value is the function parameter's value. currentPortId is defaultPortId when it is Disabled.
QList< Port > ports(const QList< Function > &functions)
Every port any function can run on, in port id order.