6import QGroundControl.Controls
7import QGroundControl.FactControls
11 pageComponent: pageComponent
13 property real _margins: ScreenTools.defaultFontPixelHeight * 0.5
14 property real _cellPadding: ScreenTools.defaultFontPixelWidth * 1.5
15 property bool _showInUseOnly: false
17 readonly property int _rowsPerPort: 3 // separator, port settings, conflict warning
18 // Reverting or rebooting before earlier writes finish could undo the revert or apply only part of a change
19 readonly property bool _pendingWrites: controller.vehicle ? controller.vehicle.parameterManager.pendingWrites : false
20 readonly property int _shownPortCount: {
22 for (let i = 0; i < controller.ports.count; i++) {
23 if (_portShown(controller.ports.get(i))) {
30 // shared: several functions' options are shown together, so name the function instance
31 function _optionLabel(paramName, shared) {
34 "RATE": qsTr("Send rate"),
35 "FORWARD": qsTr("Forwarding"),
36 "FLOW_CTRL": qsTr("Flow control"),
37 "UDP_PRT": qsTr("UDP port"),
38 "REMOTE_PRT": qsTr("Remote port"),
39 "BROADCAST": qsTr("Broadcast"),
40 "PROTOCOL": qsTr("Protocol")
42 const suffix = paramName.replace(/^[A-Z]+_\d_/, "")
43 const label = labels[suffix] !== undefined ? labels[suffix] : paramName
44 const instance = paramName.match(/^[A-Z]+_(\d)_/)
45 return (shared && instance) ? qsTr("%1 (instance %2)").arg(label).arg(instance[1]) : label
48 // Ethernet is the only shared port. PX4 has no baud rate there, so a rate of 0 is a fixed value.
49 function _optionNote(paramName, ethernet) {
51 "RATE": ethernet ? qsTr("0 uses 100000 bytes/s.") : qsTr("0 uses half the link bandwidth.")
53 const note = notes[paramName.replace(/^[A-Z]+_\d_/, "")]
54 return note !== undefined ? note : ""
57 // A port whose function was just removed stays shown until the change is reverted or applied
58 function _portShown(port) {
59 return !_showInUseOnly || port.assignments.length > 0 || port.rebootRequired
62 PX4SerialPortsController {
74 width: Math.max(availableWidth, implicitWidth)
78 Layout.fillWidth: true
79 implicitHeight: rebootRow.implicitHeight + _margins * 2
80 visible: controller.changedPortCount > 0
82 border.color: qgcPal.warningText
83 radius: ScreenTools.defaultFontPixelHeight / 4
87 anchors.margins: _margins
92 Layout.fillWidth: true
93 wrapMode: Text.WordWrap
94 color: qgcPal.warningText
95 text: controller.changedPortCount === 1 ?
96 qsTr("1 port changed. Changes take effect after the vehicle reboots.") :
97 qsTr("%1 ports changed. Changes take effect after the vehicle reboots.").arg(controller.changedPortCount)
101 text: qsTr("Revert Changes")
102 enabled: !_pendingWrites
103 onClicked: controller.revertChanges()
107 text: qsTr("Reboot Vehicle")
109 enabled: controller.vehicle && !controller.vehicle.armed && !_pendingWrites
110 onClicked: controller.vehicle.rebootVehicle()
116 Layout.fillWidth: true
117 implicitWidth: panelLayout.implicitWidth + _margins * 2
118 implicitHeight: panelLayout.implicitHeight + _margins * 2
119 color: qgcPal.windowPanel
120 border.color: qgcPal.borderSubtle
121 radius: ScreenTools.defaultBorderRadius * 2
126 anchors.margins: _margins
130 Layout.fillWidth: true
134 objectName: "ports_filter"
135 model: [ qsTr("All Ports"), qsTr("In Use") ]
136 currentIndex: _showInUseOnly ? 1 : 0
137 onActivated: (index) => { _showInUseOnly = index === 1 }
141 objectName: "ports_summary"
142 Layout.fillWidth: true
143 color: qgcPal.textSecondary
144 text: _showInUseOnly ?
145 qsTr("Showing %1 of %2 ports.").arg(_shownPortCount).arg(controller.ports.count) :
146 qsTr("Showing all %1 ports.").arg(controller.ports.count)
151 Layout.fillWidth: true
153 columnSpacing: _margins
154 rowSpacing: _margins * 0.75
157 model: controller.ports
160 Layout.row: index * _rowsPerPort
163 Layout.fillWidth: true
165 color: qgcPal.borderSubtle
166 visible: _portShown(object)
168 required property int index
169 required property var object
174 model: controller.ports
177 objectName: "ports_port_" + object.portId
178 Layout.row: 1 + index * _rowsPerPort
180 Layout.alignment: Qt.AlignTop
181 Layout.topMargin: _cellPadding
182 spacing: ScreenTools.defaultFontPixelHeight * 0.25
183 visible: _portShown(object)
185 required property int index
186 required property var object
188 readonly property bool _inUse: object.assignments.length > 0
189 readonly property bool _attention: object.rebootRequired || object.conflictText !== ""
192 spacing: ScreenTools.defaultFontPixelWidth
195 implicitWidth: ScreenTools.defaultFontPixelHeight * 0.5
196 implicitHeight: implicitWidth
197 radius: implicitWidth / 2
198 color: _attention ? qgcPal.warningText : (_inUse ? qgcPal.colorGreen : "transparent")
199 border.color: (_attention || _inUse) ? color : qgcPal.textSecondary
205 font.capitalization: Font.AllUppercase
206 font.letterSpacing: ScreenTools.defaultFontPixelWidth * 0.1
211 model: object.assignments
215 font.family: ScreenTools.fixedFontFamily
216 font.pointSize: ScreenTools.smallFontPointSize
217 color: qgcPal.textSecondary
219 required property string modelData
224 text: qsTr("No function assigned")
225 font.pointSize: ScreenTools.smallFontPointSize
226 color: qgcPal.textSecondary
231 spacing: ScreenTools.defaultFontPixelWidth / 2
232 visible: object.shared || object.rebootRequired
236 visible: object.shared
240 text: qsTr("Reboot required")
241 textColor: qgcPal.warningText
242 visible: object.rebootRequired
249 model: controller.ports
253 Layout.row: 1 + index * _rowsPerPort
255 Layout.alignment: Qt.AlignTop
256 Layout.fillWidth: true
257 Layout.horizontalStretchFactor: 0
258 caption: object.shared ? qsTr("Functions") : qsTr("Function")
259 visible: _portShown(object)
261 required property int index
262 required property var object
266 Layout.fillWidth: true
267 model: functionCell.object.functionLabels
268 currentIndex: functionCell.object.functionIndex
270 visible: !functionCell.object.shared
272 onActivated: (comboIndex) => {
273 controller.setPortFunction(functionCell.object.portId, comboIndex)
274 currentIndex = Qt.binding(function() { return functionCell.object.functionIndex })
277 // A model change resets the index, so restore the binding once the row has updated
278 onModelChanged: Qt.callLater(function() {
279 currentIndex = Qt.binding(function() { return functionCell.object.functionIndex })
283 // Shown instead of the combo on ports several functions can use at once
285 // Skip "None", which is index 0
286 model: functionCell.object.shared ? functionCell.object.functionLabels.length - 1 : 0
289 Layout.fillWidth: true
290 text: functionCell.object.functionLabels[functionIndex]
291 checked: functionCell.object.functionEnabled[functionIndex] === true
293 required property int index
294 readonly property int functionIndex: index + 1
297 controller.setPortFunctionEnabled(functionCell.object.portId, functionIndex, checked)
298 checked = Qt.binding(function() { return functionCell.object.functionEnabled[functionIndex] === true })
304 Layout.fillWidth: true
305 Layout.preferredWidth: functionCombo.implicitWidth
306 wrapMode: Text.WordWrap
307 font.pointSize: ScreenTools.smallFontPointSize
308 color: qgcPal.textSecondary
309 text: qsTr("%1 always runs on this port unless it is assigned to another port.")
310 .arg(functionCell.object.functionLabels[functionCell.object.functionIndex])
311 visible: functionCell.object.defaultFunctionOnPort && functionCell.object.conflictText === ""
317 model: controller.ports
321 Layout.row: 1 + index * _rowsPerPort
323 Layout.alignment: Qt.AlignTop
324 Layout.fillWidth: true
325 Layout.horizontalStretchFactor: 0
326 caption: qsTr("Baud")
327 visible: _portShown(object)
329 required property int index
330 required property var object
333 Layout.fillWidth: true
334 fact: baudCell.object.baudFact
337 visible: baudCell.object.baudFact
341 text: baudCell.object.baudLoading ? qsTr("Loading...") : qsTr("N/A")
342 color: qgcPal.textSecondary
343 visible: !baudCell.object.baudFact
348 // Only the Options column takes spare width. The other columns size to their widest cell.
349 // Options wrap instead of widening the page, so the column only needs its widest single cell.
351 model: controller.ports
355 Layout.row: 1 + index * _rowsPerPort
357 Layout.alignment: Qt.AlignTop
358 Layout.fillWidth: true
359 Layout.horizontalStretchFactor: 1
360 Layout.minimumWidth: _widestChildWidth
361 Layout.preferredWidth: _widestChildWidth
363 visible: _portShown(object)
365 required property int index
366 required property var object
368 // The message wraps, so only option cells set the column's minimum width
369 readonly property real _widestChildWidth: {
370 let widest = optionsMessage.visible ? ScreenTools.defaultFontPixelWidth * 20 : 0
371 for (let i = 0; i < children.length; i++) {
372 if (children[i].visible && children[i] !== optionsMessage) {
373 widest = Math.max(widest, children[i].implicitWidth)
380 model: optionsFlow.object.optionFacts
383 caption: _optionLabel(modelData.name, optionsFlow.object.shared)
385 required property var modelData
388 Layout.fillWidth: true
392 visible: modelData.enumStrings.length > 0
396 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 12
398 visible: modelData.enumStrings.length === 0
402 Layout.fillWidth: true
403 Layout.preferredWidth: Math.min(implicitWidth, ScreenTools.defaultFontPixelWidth * 20)
404 wrapMode: Text.WordWrap
405 font.pointSize: ScreenTools.smallFontPointSize
406 color: qgcPal.textSecondary
407 text: _optionNote(modelData.name, optionsFlow.object.shared)
415 width: Math.min(implicitWidth, optionsFlow.width)
416 topPadding: _cellPadding
417 wrapMode: Text.WordWrap
418 color: qgcPal.textSecondary
419 text: optionsFlow.object.optionsLoading ? qsTr("Loading...") :
420 (optionsFlow.object.conflictText !== "" ?
421 qsTr("Options are hidden while more than one function is assigned.") :
422 qsTr("No options for this port."))
423 visible: optionsFlow.object.optionsLoading || optionsFlow.object.optionFacts.length === 0
429 model: controller.ports
433 Layout.row: 2 + index * _rowsPerPort
436 Layout.fillWidth: true
437 implicitHeight: conflictLabel.implicitHeight + _margins * 2
439 border.color: qgcPal.warningText
440 radius: ScreenTools.defaultBorderRadius * 2
441 visible: object.conflictText !== "" && _portShown(object)
443 required property int index
444 required property var object
448 anchors.left: parent.left
449 anchors.right: parent.right
450 anchors.margins: _cellPadding
451 anchors.verticalCenter: parent.verticalCenter
452 wrapMode: Text.WordWrap
453 color: qgcPal.warningText
454 text: conflictBox.object.conflictText
464 // Opening on the ports in use keeps the page short on boards with many ports
465 Component.onCompleted: {
466 for (let i = 0; i < controller.ports.count; i++) {
467 if (controller.ports.get(i).assignments.length > 0) {
468 _showInUseOnly = true